def initialize(self): self.pollingTime = self.am_getOption('PollingTime', 86400) gMonitor.registerActivity("Iteration", "Agent Loops", AGENT_NAME, "Loops/min", gMonitor.OP_SUM) self.ppc = ProcessProdClient() self.dirac = DiracILC() self.diracadmin = DiracAdmin() self.am_setOption( 'shifterProxy', 'Admin' ) return S_OK()
def __init__(self): self.ops = Operations() self.appsToRemoveStr = '' self.appsToInstallStr = '' self.appsToRemove = [] self.appsToInstall = [] self.log = gLogger.getSubLogger( "InstallSoft" ) self.systemConfig = '' self.ppc = ProcessProdClient() #Those too are supposed to be set from the Workflow self.step_commons = {} self.workflow_commons = {}
class InstallSoftModule(): """ Module to install software, not used yet """ def __init__(self): self.ops = Operations() self.appsToRemoveStr = '' self.appsToInstallStr = '' self.appsToRemove = [] self.appsToInstall = [] self.log = gLogger.getSubLogger( "InstallSoft" ) self.systemConfig = '' self.ppc = ProcessProdClient() #Those too are supposed to be set from the Workflow self.step_commons = {} self.workflow_commons = {} def execute(self): """ Look in folders (Shared Area and Local Area) and try ot remove the applications specified. """ if self.appsToInstallStr: self.appsToInstall = self.appsToInstallStr.split(';') if self.appsToRemoveStr: self.appsToRemove = self.appsToRemoveStr.split(';') if self.workflow_commons.has_key('SystemConfig'): self.systemConfig = self.workflow_commons['SystemConfig'] else: return S_ERROR('System Config not defined') self.log.info("Will check Installed %s" % self.appsToInstall) for app in self.appsToInstall: if not app: continue jobdict = {} jobdict['JobID'] = self.workflow_commons["JOB_ID"] appname = app.split(".")[0] appversion = app.split(".")[1] jobdict['AppName'] = appname jobdict['AppVersion'] = appversion jobdict['Platform'] = self.systemConfig appDir = self.ops.getValue('/AvailableTarBalls/%s/%s/%s/TarBall' % (self.systemConfig, appname, appversion), '') appDir = appDir.replace(".tgz","").replace(".tar.gz","") mySoftwareRoot = '' sharedArea = SharedArea() if os.path.exists('%s%s%s' % (sharedArea, os.sep, appDir)): mySoftwareRoot = sharedArea self.ppc.reportOK(jobdict) else: self.ppc.reportFailed(jobdict) self.log.info("Will delete %s" % self.appsToRemove) failed = [] for app in self.appsToRemove: if not app: continue jobdict = {} jobdict['JobID'] = self.workflow_commons["JOB_ID"] appname = app.split(".")[0] appversion = app.split(".")[1] jobdict['AppName'] = appname jobdict['AppVersion'] = appversion jobdict['Platform'] = self.systemConfig appDir = self.ops.getValue('/AvailableTarBalls/%s/%s/%s/TarBall' % (self.systemConfig, appname, appversion), '') appDir = appDir.replace(".tgz", "").replace(".tar.gz", "") mySoftwareRoot = '' sharedArea = SharedArea() self.log.info("Shared Area is %s" % sharedArea) listAreaDirectory(sharedArea) if os.path.exists('%s%s%s' % (sharedArea, os.sep, appDir)): mySoftwareRoot = sharedArea if not mySoftwareRoot: self.log.error('%s: Could not find in shared area' % app) continue myappDir = os.path.join(mySoftwareRoot, appDir) self.log.info("Will attempt to remove %s " % myappDir) #### Hacky hack needed when the DB was in parallel to the Mokka version if appname.lower() == 'mokka': dbloc = os.path.join(mySoftwareRoot, "CLICMokkaDB.sql") if os.path.exists(dbloc): try: os.remove(dbloc) except Exception, x: self.log.error("Could not delete SQL DB file : %s" % (str(x))) if os.path.isdir(myappDir): try: shutil.rmtree(myappDir) except Exception, x: self.log.error("Could not delete %s : %s" % (app, str(x))) failed.append(app) else:
class SoftwareManagementAgent( AgentModule ): """ Agent to run software management things """ def initialize(self): self.pollingTime = self.am_getOption('PollingTime', 86400) gMonitor.registerActivity("Iteration", "Agent Loops", AGENT_NAME, "Loops/min", gMonitor.OP_SUM) self.ppc = ProcessProdClient() self.dirac = DiracILC() self.diracadmin = DiracAdmin() self.am_setOption( 'shifterProxy', 'Admin' ) return S_OK() ############################################################################## def execute(self): """ First we update the site list and banned site """ res = getProxyInfo(False, False) if not res['OK']: self.log.error("submitTasks: Failed to determine credentials for submission", res['Message']) return res proxyInfo = res['Value'] owner = proxyInfo['username'] ownerGroup = proxyInfo['group'] self.log.info("submitTasks: Jobs will be submitted with the credentials %s:%s" % (owner, ownerGroup)) sites = self.diracadmin.getSiteMask()['Value'] for site in sites: res = self.ppc.changeSiteStatus( {'SiteName' : site, 'Status' : 'OK'} ) if not res['OK']: self.log.error('Cannot add or update site %s' % site) banned_sites = self.diracadmin.getBannedSites()['Value'] for banned_site in banned_sites: self.ppc.changeSiteStatus( {'SiteName' : banned_site, 'Status' : 'Banned'} ) if not res['OK']: self.log.error('Cannot mark as banned site %s' % banned_site) ##Then we need to get new installation tasks res = self.ppc.getInstallSoftwareTask() if not res['OK']: self.log.error('Failed to obtain task') task_dict = res['Value'] for softdict in task_dict.values(): self.log.info('Will install %s %s at %s' % (softdict['AppName'], softdict['AppVersion'], softdict['Sites'])) for site in softdict['Sites']: j = UserJob() j.setPlatform(softdict['Platform']) j.dontPromptMe() j.setDestination(site) j.setJobGroup("Installation") j.setName('install_%s' % site) j._addSoftware(softdict['AppName'], softdict['AppVersion']) #Add the application here somehow. res = j.append(SoftwareInstall()) if not res['OK']: self.log.error(res['Message']) continue res = j.submit(self.dirac) #res = self.dirac.submit(j) if not res['OK']: self.log.error('Could not create the job') continue jobdict = {} jobdict['AppName'] = softdict['AppName'] jobdict['AppVersion'] = softdict['AppVersion'] jobdict['Platform'] = softdict['Platform'] jobdict['JobID'] = res['Value'] jobdict['Status'] = 'Waiting' jobdict['Site'] = site res = self.ppc.addOrUpdateJob(jobdict) if not res['OK']: self.log.error('Could not add job %s: %s' % (jobdict['JobID'], res['Message'])) ##Monitor jobs jobs = {} res = self.ppc.getJobs() if not res['OK']: self.log.error('Could not retrieve jobs') else: jobs = res['Value'] for job in jobs: res = self.dirac.status(job['JobID']) if res['OK']: jobstatuses = res['Value'] job['Status'] = jobstatuses['JobID']['Status'] res = self.ppc.addOrUpdateJob(job) if not res['OK']: self.log.error("Failed to updated job %s: %s" % (job['JobID'], res['Message'])) else: self.log.error("Failed to update job %s status" % job['JobID']) return S_OK()