def cancelJobs(self, allIds):
		if len(allIds) == 0:
			raise StopIteration

		waitFlag = False
		for ids in imap(lambda x: allIds[x:x+5], irange(0, len(allIds), 5)):
			# Delete jobs in groups of 5 - with 5 seconds between groups
			if waitFlag and not utils.wait(5):
				break
			waitFlag = True

			jobNumMap = dict(ids)
			jobs = self.writeWMSIds(ids)

			activity = utils.ActivityLog('cancelling jobs')
			proc = LocalProcess(self._cancelExec, '--noint', '--logfile', '/dev/stderr', '-i', jobs)
			retCode = proc.status(timeout = 60, terminate = True)
			del activity

			# select cancelled jobs
			for deletedWMSId in ifilter(lambda x: x.startswith('- '), proc.stdout.iter()):
				deletedWMSId = self._createId(deletedWMSId.strip('- \n'))
				yield (jobNumMap.get(deletedWMSId), deletedWMSId)

			if retCode != 0:
				if self.explainError(proc, retCode):
					pass
				else:
					self._log.log_process(proc, files = {'jobs': utils.safeRead(jobs)})
			utils.removeFiles([jobs])
	def _submitJob(self, jobNum, module):
		fd, jdl = tempfile.mkstemp('.jdl')
		try:
			jdlData = self.makeJDL(jobNum, module)
			utils.safeWrite(os.fdopen(fd, 'w'), jdlData)
		except Exception:
			utils.removeFiles([jdl])
			raise BackendError('Could not write jdl data to %s.' % jdl)

		try:
			submitArgs = []
			for key_value in utils.filterDict(self._submitParams, vF = lambda v: v).items():
				submitArgs.extend(key_value)
			submitArgs.append(jdl)

			activity = utils.ActivityLog('submitting jobs')
			proc = LocalProcess(self._submitExec, '--nomsg', '--noint', '--logfile', '/dev/stderr', *submitArgs)

			wmsId = None
			for line in ifilter(lambda x: x.startswith('http'), imap(str.strip, proc.stdout.iter(timeout = 60))):
				wmsId = line
			retCode = proc.status(timeout = 0, terminate = True)

			del activity

			if (retCode != 0) or (wmsId is None):
				if self.explainError(proc, retCode):
					pass
				else:
					self._log.log_process(proc, files = {'jdl': utils.safeRead(jdl)})
		finally:
			utils.removeFiles([jdl])
		return (jobNum, utils.QM(wmsId, self._createId(wmsId), None), {'jdl': str.join('', jdlData)})
Exemple #3
0
    def cancelJobs(self, allIds):
        if len(allIds) == 0:
            raise StopIteration

        waitFlag = False
        for ids in imap(lambda x: allIds[x:x + 5], irange(0, len(allIds), 5)):
            # Delete jobs in groups of 5 - with 5 seconds between groups
            if waitFlag and not utils.wait(5):
                break
            waitFlag = True

            jobNumMap = dict(ids)
            jobs = self.writeWMSIds(ids)

            activity = utils.ActivityLog('cancelling jobs')
            proc = LocalProcess(self._cancelExec, '--noint', '--logfile',
                                '/dev/stderr', '-i', jobs)
            retCode = proc.status(timeout=60, terminate=True)
            del activity

            # select cancelled jobs
            for deletedWMSId in ifilter(lambda x: x.startswith('- '),
                                        proc.stdout.iter()):
                deletedWMSId = self._createId(deletedWMSId.strip('- \n'))
                yield (jobNumMap.get(deletedWMSId), deletedWMSId)

            if retCode != 0:
                if self.explainError(proc, retCode):
                    pass
                else:
                    self._log.log_process(proc,
                                          files={'jobs': utils.safeRead(jobs)})
            utils.removeFiles([jobs])
	def _getJobsOutput(self, ids):
		if len(ids) == 0:
			raise StopIteration

		basePath = os.path.join(self._outputPath, 'tmp')
		try:
			if len(ids) == 1:
				# For single jobs create single subdir
				tmpPath = os.path.join(basePath, md5(ids[0][0]).hexdigest())
			else:
				tmpPath = basePath
			utils.ensureDirExists(tmpPath)
		except Exception:
			raise BackendError('Temporary path "%s" could not be created.' % tmpPath, BackendError)

		jobNumMap = dict(ids)
		jobs = self.writeWMSIds(ids)

		activity = utils.ActivityLog('retrieving job outputs')
		proc = LocalProcess(self._outputExec, '--noint', '--logfile', '/dev/stderr', '-i', jobs, '--dir', tmpPath)

		# yield output dirs
		todo = jobNumMap.values()
		currentJobNum = None
		for line in imap(str.strip, proc.stdout.iter(timeout = 60)):
			if line.startswith(tmpPath):
				todo.remove(currentJobNum)
				outputDir = line.strip()
				if os.path.exists(outputDir):
					if 'GC_WC.tar.gz' in os.listdir(outputDir):
						wildcardTar = os.path.join(outputDir, 'GC_WC.tar.gz')
						try:
							tarfile.TarFile.open(wildcardTar, 'r:gz').extractall(outputDir)
							os.unlink(wildcardTar)
						except Exception:
							utils.eprint("Can't unpack output files contained in %s" % wildcardTar)
				yield (currentJobNum, line.strip())
				currentJobNum = None
			else:
				currentJobNum = jobNumMap.get(self._createId(line), currentJobNum)
		retCode = proc.status(timeout = 0, terminate = True)
		del activity

		if retCode != 0:
			if 'Keyboard interrupt raised by user' in proc.stderr.read(timeout = 0):
				utils.removeFiles([jobs, basePath])
				raise StopIteration
			else:
				self._log.log_process(proc, files = {'jobs': utils.safeRead(jobs)})
			utils.eprint('Trying to recover from error ...')
			for dirName in os.listdir(basePath):
				yield (None, os.path.join(basePath, dirName))

		# return unretrievable jobs
		for jobNum in todo:
			yield (jobNum, None)

		utils.removeFiles([jobs, basePath])
	def checkJobs(self, ids):
		if len(ids) == 0:
			raise StopIteration

		jobNumMap = dict(ids)
		jobs = self.writeWMSIds(ids)

		activity = utils.ActivityLog('checking job status')
		proc = LocalProcess(self._statusExec, '--verbosity', 1, '--noint', '--logfile', '/dev/stderr', '-i', jobs)
		for data in self._parseStatus(proc.stdout.iter(timeout = 60)):
			data['id'] = self._createId(data['id'])
			yield (jobNumMap.get(data['id']), data['id'], self._statusMap[data['status']], data)
		retCode = proc.status(timeout = 0, terminate = True)
		del activity

		if retCode != 0:
			if self.explainError(proc, retCode):
				pass
			else:
				self._log.log_process(proc, files = {'jobs': utils.safeRead(jobs)})
		utils.removeFiles([jobs])
Exemple #6
0
    def _submitJob(self, jobNum, module):
        fd, jdl = tempfile.mkstemp('.jdl')
        try:
            jdlData = self.makeJDL(jobNum, module)
            utils.safeWrite(os.fdopen(fd, 'w'), jdlData)
        except Exception:
            utils.removeFiles([jdl])
            raise BackendError('Could not write jdl data to %s.' % jdl)

        try:
            submitArgs = []
            for key_value in utils.filterDict(self._submitParams,
                                              vF=lambda v: v).items():
                submitArgs.extend(key_value)
            submitArgs.append(jdl)

            activity = utils.ActivityLog('submitting jobs')
            proc = LocalProcess(self._submitExec, '--nomsg', '--noint',
                                '--logfile', '/dev/stderr', *submitArgs)

            wmsId = None
            for line in ifilter(lambda x: x.startswith('http'),
                                imap(str.strip, proc.stdout.iter(timeout=60))):
                wmsId = line
            retCode = proc.status(timeout=0, terminate=True)

            del activity

            if (retCode != 0) or (wmsId is None):
                if self.explainError(proc, retCode):
                    pass
                else:
                    self._log.log_process(proc,
                                          files={'jdl': utils.safeRead(jdl)})
        finally:
            utils.removeFiles([jdl])
        return (jobNum, utils.QM(wmsId, self._createId(wmsId), None), {
            'jdl': str.join('', jdlData)
        })
Exemple #7
0
    def checkJobs(self, ids):
        if len(ids) == 0:
            raise StopIteration

        jobNumMap = dict(ids)
        jobs = self.writeWMSIds(ids)

        activity = utils.ActivityLog('checking job status')
        proc = LocalProcess(self._statusExec, '--verbosity', 1, '--noint',
                            '--logfile', '/dev/stderr', '-i', jobs)
        for data in self._parseStatus(proc.stdout.iter(timeout=60)):
            data['id'] = self._createId(data['id'])
            yield (jobNumMap.get(data['id']), data['id'],
                   self._statusMap[data['status']], data)
        retCode = proc.status(timeout=0, terminate=True)
        del activity

        if retCode != 0:
            if self.explainError(proc, retCode):
                pass
            else:
                self._log.log_process(proc,
                                      files={'jobs': utils.safeRead(jobs)})
        utils.removeFiles([jobs])
Exemple #8
0
    def _getJobsOutput(self, ids):
        if len(ids) == 0:
            raise StopIteration

        basePath = os.path.join(self._outputPath, 'tmp')
        try:
            if len(ids) == 1:
                # For single jobs create single subdir
                tmpPath = os.path.join(basePath, md5(ids[0][0]).hexdigest())
            else:
                tmpPath = basePath
            utils.ensureDirExists(tmpPath)
        except Exception:
            raise BackendError(
                'Temporary path "%s" could not be created.' % tmpPath,
                BackendError)

        jobNumMap = dict(ids)
        jobs = self.writeWMSIds(ids)

        activity = utils.ActivityLog('retrieving job outputs')
        proc = LocalProcess(self._outputExec, '--noint', '--logfile',
                            '/dev/stderr', '-i', jobs, '--dir', tmpPath)

        # yield output dirs
        todo = jobNumMap.values()
        currentJobNum = None
        for line in imap(str.strip, proc.stdout.iter(timeout=60)):
            if line.startswith(tmpPath):
                todo.remove(currentJobNum)
                outputDir = line.strip()
                if os.path.exists(outputDir):
                    if 'GC_WC.tar.gz' in os.listdir(outputDir):
                        wildcardTar = os.path.join(outputDir, 'GC_WC.tar.gz')
                        try:
                            tarfile.TarFile.open(wildcardTar,
                                                 'r:gz').extractall(outputDir)
                            os.unlink(wildcardTar)
                        except Exception:
                            utils.eprint(
                                "Can't unpack output files contained in %s" %
                                wildcardTar)
                yield (currentJobNum, line.strip())
                currentJobNum = None
            else:
                currentJobNum = jobNumMap.get(self._createId(line),
                                              currentJobNum)
        retCode = proc.status(timeout=0, terminate=True)
        del activity

        if retCode != 0:
            if 'Keyboard interrupt raised by user' in proc.stderr.read(
                    timeout=0):
                utils.removeFiles([jobs, basePath])
                raise StopIteration
            else:
                self._log.log_process(proc,
                                      files={'jobs': utils.safeRead(jobs)})
            utils.eprint('Trying to recover from error ...')
            for dirName in os.listdir(basePath):
                yield (None, os.path.join(basePath, dirName))

        # return unretrievable jobs
        for jobNum in todo:
            yield (jobNum, None)

        utils.removeFiles([jobs, basePath])