def jobended(*condorqargs): from jobsubmission import jobtype if jobtype(): return False #can't use condor_q on condor machines condorqout = subprocess.check_output(["condor_q"]+list(condorqargs), stderr=subprocess.STDOUT) match = re.search("([0-9]*) jobs; ([0-9]*) completed, ([0-9]*) removed, ([0-9]*) idle, ([0-9]*) running, ([0-9]*) held, ([0-9]*) suspended", condorqout) if not match: raise ValueError("Couldn't parse output of condor_q " + " ".join(condorqargs)) return all(int(match.group(i)) == 0 for i in xrange(4, 7))
def getprepid(self): super(ClonedRequest, self).getprepid() if self.prepid: return if jobtype(): return query = "dataset_name={}&extension={}&prepid={}-{}-*".format(self.originalfullinfo["dataset_name"], self.extensionnumber, self.pwg, self.campaign) output = McM().get('requests', query=query) prepids = {_["prepid"] for _ in output} if not prepids: return None if len(prepids) != 1: raise RuntimeError("Multiple prepids for {} ({})".format(self, self.datasetname, query)) assert len(prepids) == 1, prepids self.prepid = prepids.pop()
def createrequest(self, clonequeue): self.needsupdate = True return clonequeue.add(self, self.pwg, self.newcampaign) if jobtype(): return "run locally to submit to McM" mcm = McM() clone_req = mcm.get('requests', self.originalprepid) clone_req['member_of_campaign'] = self.campaign answer = mcm.clone(self.originalprepid, clone_req) if not (answer and answer.get("results")): raise RuntimeError("Failed to create the request on McM\n{}\n{}".format(self, answer)) self.getprepid() if self.prepid != answer["prepid"]: raise RuntimeError("Wrong prepid?? {} {}".format(self.prepid, answer["prepid"])) self.updaterequest() return "cloned request "+self.originalprepid+" as "+self.prepid+" on McM"
def checkandfixtarball(self): mkdir_p(self.workdirforgridpack) with KeepWhileOpenFile(os.path.join(self.workdirforgridpack, self.prepid + '.tmp'), deleteifjobdied=True) as kwof: if not kwof: return " check in progress" if not jobtype(): self.submitLSF() return "Check if the tarball needs fixing" with cdtemp(): subprocess.call(['cp', self.cvmfstarball, '.']) subprocess.check_call(['tar', 'xzvf', self.cvmfstarball]) subprocess.call(['cp', 'readInput.DAT', 'readInput.DAT_bak']) os.system('chmod 755 runcmsgrid.sh') try: output = subprocess.check_output( ['bash', 'runcmsgrid.sh', '1', '31313', '12'], stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: output = e.output for line in output.split('\n'): if not 'Reading in vegas grid from' in line: continue else: line = line.split()[-2] internalgridname = line.split('CMS_')[1] internalgridname = str(internalgridname) print "internal tarball name: " + internalgridname if self.datasetname + '_grid' == internalgridname: with open(os.path.join(self.workdirforgridpack, 'INTACT'), 'w') as fout: fout.write(jobid()) return str(self.identifiers) + "'s gridpack is intact" else: os.system('cp ' + self.datasetname + '_grid ' + internalgridname) os.system('mv readInput.DAT_bak readInput.DAT') os.system('rm -r *tgz CMSSW*') curdirpath = subprocess.check_output(['pwd']) os.system('tar cvaf ' + self.tmptarball + ' ./*') if os.path.exists(self.tmptarball): with open( os.path.join(self.workdirforgridpack, 'FIXED'), 'w') as fout: fout.write(jobid())
def newfunction(**kwargs): if "dir" not in kwargs: from jobsubmission import jobid, jobtype if jobtype() == "LSF": kwargs["dir"] = "/pool/lsf/{}/{}/".format(getpass.getuser(), jobid()) return function(**kwargs)