def __init__(self, job_info): IMonitoringService.__init__(self, job_info) if isinstance(job_info, DictionaryType): # we are on the worker node. We just need # to get values from the dictionary try: self.gangaJobId = job_info['gangaJobId'] self.gangaTaskId = job_info['gangaTaskId'] self.gridBackend = job_info['gridBackend'] self.gridCertificate = job_info['gridCertificate'] self.VO = job_info['VO'] self._complete = True except KeyError as msg: # too bad, we will not monitor the job return # on the WN, we get the job ID from envar self.gridJobId = safe_getenv('EDG_WL_JOBID') if self.gridJobId == 'unknown': self.gridJobId = safe_getenv('GLITE_WL_JOBID') if self.gridJobId == 'unknown': self._complete = False else: # we are in the client session. job_info is a Job() from Ganga.Utility.logging import getLogger self._logger = getLogger() job = job_info self.gridBackend = getattr(job, 'backend')._name if self.gridBackend not in ['LCG']: self._logger.debug('not sending monitoring because not in LCG') return self._logger.debug(job.backend) self._logger.debug(job.backend.id) self.gridJobId = job.backend.id # we compute the "jobID" and "taskID" # (which is the gangaJobId followed by the user@repository # the repository unique ID: from Ganga.Utility.Config import getConfig, ConfigError config = getConfig('Configuration') rep_type = config['repositorytype'] rep_login = config['user'] if 'Local' in rep_type: from Ganga.Runtime import Repository_runtime rep_dir = Repository_runtime.getLocalRoot() sys_config = getConfig('System') rep_hostname = sys_config['GANGA_HOSTNAME'] rep_location = rep_hostname + ':' + rep_dir elif 'Remote' in rep_type: remote_config = getConfig(rep_type + "_Repository") rep_host = remote_config['host'] rep_port = remote_config['port'] rep_location = rep_host + ':' + rep_port else: return repository_id = rep_login + '@' + rep_location master_job = job.master if master_job is not None: master_id = master_job.id self._logger.debug('found master: %d' % master_id) self.gangaTaskId = self.taskPrefix + '_' + \ str(master_id) + '_' + repository_id self.gangaJobId = str(job.id) else: self.gangaTaskId = self.taskPrefix + \ '_' + str(job.id) + '_' + repository_id self.gangaJobId = '0' self._logger.debug('task_id = %s' % self.gangaTaskId) self._logger.debug('task_job_id = %s' % self.gangaJobId) backendConfig = getConfig(self.gridBackend) try: self.VO = backendConfig['VirtualOrganisation'] except KeyError: self._logger.debug('VirtualOrganisation not configured') # we need it, it's too dangerous if we are not sure return from Ganga.GPIDev.Credentials import getCredential proxy = getCredential('GridProxy') self.gridCertificate = proxy.info('-subject') if self.gridCertificate is None: self._logger.debug('error: grid certificate not known') return if self.gridJobId is None: self._logger.debug('normal: grid job ID is None') self._logger.debug('job is complete') self._complete = True # we can now initialize the dashboard communication thing if self.gridJobId is not None: try: self.dashboard = DashboardAPI( self.gangaTaskId, self.gangaJobId + '_' + self.gridJobId) except TypeError: self.dashboard = DashboardAPI( self.gangaTaskId, self.gangaJobId + '_' + '_'.join(self.gridJobId))