Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
closes #35
Browse files Browse the repository at this point in the history
  • Loading branch information
Víctor Méndez committed Jun 25, 2013
2 parents 7a800aa + 995725c commit 2e9c077
Showing 1 changed file with 61 additions and 31 deletions.
92 changes: 61 additions & 31 deletions WorkloadManagementSystem/Agent/VirtualMachineConfigUpdater.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
import glob
import os

from DIRAC import gConfig, S_OK, rootPath
from distutils.version import LooseVersion

from DIRAC import gConfig, S_ERROR, S_OK
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
from DIRAC.Core.Base.AgentModule import AgentModule
from DIRAC.Core.Utilities.CFG import CFG

__RCSID__ = '$Id: $'
__RCSID__ = '$Id: $'
AGENT_NAME = 'WorkloadManagement/VirtualMachineConfigUpdater'


class VirtualMachineConfigUpdater( AgentModule ):
Expand All @@ -27,14 +30,8 @@ def __init__( self, *args, **kwargs ):
AgentModule.__init__( self, *args, **kwargs )

self.opHelper = None
self.controlPath = ''
self.stopAgentPath = ''


self.am_setOption( "PollingTime", 60.0 )

return S_OK()

self.cfgToUpdate = ''

def initialize( self ):
""" initialize
Expand All @@ -43,18 +40,15 @@ def initialize( self ):

self.opHelper = Operations()

# Set control path
instancePath = gConfig.getValue( '/LocalSite/InstancePath', rootPath )
self.controlPath = os.path.join( instancePath, 'control', '*', '*' )
self.stopAgentPath = os.path.join( self.controlPath, 'stop_agent' )

self.log.info( 'Instance path: %s' % instancePath )
self.log.info( 'Control path: %s' % self.controlPath )
self.stopAgentPath = self.am_getStopAgentFile().replace( AGENT_NAME, '*/*' )
self.cfgToUpdate = self.am_getOption( 'cfgToUpdate', gConfig.diracConfigFilePath )

self.log.info( 'Stop Agent path: %s' % self.stopAgentPath )
self.log.info( 'Config To Update: %s' % self.cfgToUpdate )

return S_OK()


return S_OK()
def execute( self ):
""" execute
Expand All @@ -66,24 +60,56 @@ def execute( self ):
return S_OK()

pilotVersion = self.opHelper.getValue( 'Pilot/Version', '' )
localCFG = CFG()
if not pilotVersion:
self.log.error( 'There is no pilot version on the CS' )
return S_OK()

pilotVersion = self.getNewestPilotVersion()
if not pilotVersion[ 'OK' ]:
self.log.error( pilotVersion[ 'Message' ] )
return S_ERROR( pilotVersion[ 'Message' ] )
pilotVersion = pilotVersion[ 'Value' ]

localCFG = CFG()

#load local CFG
localCFG.loadFromFile( gConfig.diracConfigFilePath )
releaseVersion = localCFG.getRecursive( 'LocalSite/ReleaseVersion' )
localCFG.loadFromFile( self.cfgToUpdate )
releaseVersion = localCFG.getRecursive( 'LocalSite/ReleaseVersion' )[ 'value' ]

if pilotVersion > releaseVersion:
self.log.info( 'PilotVersion : %s' % pilotVersion )
self.log.info( 'ReleaseVersion : %s' % releaseVersion )

if LooseVersion( pilotVersion ) > LooseVersion( releaseVersion ):

self.log.info( 'UPDATING %s > %s' % ( pilotVersion, releaseVersion ) )

localCFG.setOption( 'LocalSite/ReleaseVersion', pilotVersion )
localCFG.writeToFile( gConfig.diracConfigFilePath )
localCFG.writeToFile( self.cfgToUpdate )

self.touchStopAgents()


else:

self.log.info( 'Nothing to do' )

return S_OK()


def getNewestPilotVersion( self ):
""" getNewestPilotVersion
"""

pilotVersion = self.opHelper.getValue( 'Pilot/Version', [] )
if not pilotVersion:
return S_ERROR( 'Empty pilot version' )

pilotVersion = [ LooseVersion( pV ) for pV in pilotVersion ]
pilotVersion.sort()

return S_OK( pilotVersion.pop().vstring )


def findStopAgents( self ):
""" findStopAgents
Expand All @@ -101,14 +127,18 @@ def touchStopAgents( self ):
"""

controlAgents = glob.glob( self.controlPath )
for controlAgent in controlAgents:
stopAgentDirs = glob.glob( self.stopAgentPath.replace( 'stop_agent' , '' ) )
for stopAgentDir in stopAgentDirs:

# Do not restart itself
if AGENT_NAME in stopAgentDir:
continue

stopAgent = os.path.join( controlAgent, 'stop_agent' )
stopAgentFile = os.path.join( stopAgentDir, 'stop_agent' )

with file( stopAgent, 'a' ):
os.utime( stopAgent, None )
self.log.info( 'Written stop_agent in: %s' % stopAgent )
with file( stopAgentFile, 'a' ):
os.utime( stopAgentFile, None )
self.log.info( 'Written stop_agent in: %s' % stopAgentFile )

return S_OK()

Expand Down

0 comments on commit 2e9c077

Please sign in to comment.