def subscribeToCREAMJobs(cemonURL, parameters, proxyFile, useSSL=False): if useSSL: consumerURL = 'https://%s:%d' % (hostname, parameters.consumerPort) else: consumerURL = 'http://%s:%d' % (hostname, parameters.consumerPort) subscrCmd = '''%s --cert %s --key %s --topic %s --dialects %s \ --consumer-url %s --rate %d --duration %d %s''' % \ (cmdTable['subscribe'], proxyFile, proxyFile, \ 'CREAM_JOBS', 'CLASSAD', consumerURL, parameters.rate, 31536000, cemonURL) mainLogger.debug("Subscription command: " + subscrCmd) subscriptionId = None errBuffer = '' subscrProc = popen2.Popen4(subscrCmd) for line in subscrProc.fromchild: tmpm = subscriptionRE.search(line) if tmpm<>None: subscriptionId = tmpm.group(1) mainLogger.debug("Registered subscription " + subscriptionId) else: errBuffer += line subscrProc.fromchild.close() if subscriptionId==None: mainLogger.error(errBuffer) raise Exception('Cannot subscribe to ' + cemonURL) return subscriptionId
def eraseJobs(jobList, cmd='purge', proxyMan=None, timeout=30): if len(jobList)>0: tempFD, tempFilename = tempfile.mkstemp(dir='/tmp') try: tFile = os.fdopen(tempFD, 'w+b') tFile.write("##CREAMJOBS##\n") for job in jobList: tFile.write(job + "\n") tFile.close() eraseCmdLine = "%s -N -i %s -t %d" % \ (cmdTable[cmd], tempFilename, timeout) mainLogger.debug("Command line: " + eraseCmdLine) if proxyMan<>None: proxyMan.beginLock() try: eraseProc = popen2.Popen4(eraseCmdLine) for line in eraseProc.fromchild: if 'ERROR' in line or 'FATAL' in line: mainLogger.error(line[24:]) eraseProc.fromchild.close() finally: if proxyMan<>None: proxyMan.endLock() os.remove(tempFilename) except: if 'tFile' in dir() and not tFile.closed: mainLogger.error('Cannot write job file list') else: mainLogger.error("Cannot purge jobs in " + tempFilename + ": " + str(sys.exc_info()[0]))