def testAddingJobs(self): """ _testAddingJobs_ Verify that adding jobs to the package works as expected. """ package = JobPackage() for i in range(100): newJob = Job("Job%s" % i) newJob["id"] = i package[i] = newJob # There is an extra key for the directory the package is stored in. assert len(package.keys()) == 101, \ "Error: Wrong number of jobs in package." for i in range(100): job = package[i] assert job["id"] == i, \ "Error: Jobs has wrong ID." assert job["name"] == "Job%d" % i, \ "Error: Job has wrong name." return
def testPersist(self): """ _testPersist_ Verify that we're able to save and load the job package. """ package = JobPackage() for i in range(100): newJob = Job("Job%s" % i) newJob["id"] = i package[i] = newJob package.save(self.persistFile) assert os.path.exists(self.persistFile), \ "Error: Package file was never created." newPackage = JobPackage() newPackage.load(self.persistFile) # There is an extra key for the directory the package is stored in. assert len(newPackage.keys()) == 101, \ "Error: Wrong number of jobs in package." for i in range(100): job = newPackage[i] assert job["id"] == i, \ "Error: Jobs has wrong ID." assert job["name"] == "Job%d" % i, \ "Error: Job has wrong name." return
def loadJobDefinition(): """ _loadJobDefinition_ Load the job package and pull out the indexed job, return WMBS Job instance Although this will create a JobReport, it won't necessarily bring it back. Report names are dependent on the retry_count, but if it fails unpacking the job it doesn't know the retry_count and will create the wrong file """ sandboxLoc = locateWMSandbox() package = JobPackage() packageLoc = os.path.join(sandboxLoc, "JobPackage.pcl") try: package.load(packageLoc) except Exception as ex: msg = "Failed to load JobPackage:%s\n" % packageLoc msg += str(ex) createErrorReport(exitCode=11001, errorType="JobPackageError", errorDetails=msg) raise BootstrapException(msg) try: import WMSandbox.JobIndex except ImportError as ex: msg = "Failed to import WMSandbox.JobIndex module\n" msg += str(ex) createErrorReport(exitCode=11002, errorType="JobIndexError", errorDetails=msg) raise BootstrapException(msg) index = WMSandbox.JobIndex.jobIndex try: job = package[index] except Exception as ex: msg = "Failed to extract Job %i\n" % (index) msg += str(ex) createErrorReport(exitCode=11003, errorType="JobExtractionError", errorDetails=msg) raise BootstrapException(msg) diagnostic = """ Job Index = %s Job Instance = %s """ % (index, job) logging.info(diagnostic) return job
def testBaggage(self): """ _testBaggage_ Verify that job baggage is persisted with the package. """ package = JobPackage() for i in range(100): newJob = Job("Job%s" % i) newJob["id"] = i baggage = newJob.getBaggage() setattr(baggage, "thisJob", newJob["name"]) setattr(baggage, "seed1", 11111111) setattr(baggage, "seed2", 22222222) setattr(baggage, "seed3", 33333333) setattr(baggage, "seed4", 44444444) setattr(baggage, "seed5", 55555555) package[i] = newJob package.save(self.persistFile) assert os.path.exists(self.persistFile), \ "Error: Package file was never created." newPackage = JobPackage() newPackage.load(self.persistFile) # There is an extra key for the directory the package is stored in. assert len(newPackage.keys()) == 101, \ "Error: Wrong number of jobs in package." for i in range(100): job = newPackage[i] assert job["id"] == i, \ "Error: Jobs has wrong ID." assert job["name"] == "Job%d" % i, \ "Error: Job has wrong name." jobBaggage = job.getBaggage() assert jobBaggage.thisJob == "Job%d" % i, \ "Error: Job baggage has wrong name." assert jobBaggage.seed1 == 11111111, \ "Error: Job baggee has wrong value for seed1." assert jobBaggage.seed2 == 22222222, \ "Error: Job baggee has wrong value for seed2." assert jobBaggage.seed3 == 33333333, \ "Error: Job baggee has wrong value for seed3." assert jobBaggage.seed4 == 44444444, \ "Error: Job baggee has wrong value for seed4." assert jobBaggage.seed5 == 55555555, \ "Error: Job baggee has wrong value for seed5." return
def loadJobDefinition(): """ _loadJobDefinition_ Load the job package and pull out the indexed job, return WMBS Job instance Although this will create a JobReport, it won't necessarily bring it back. Report names are dependent on the retry_count, but if it fails unpacking the job it doesn't know the retry_count and will create the wrong file """ sandboxLoc = locateWMSandbox() package = JobPackage() packageLoc = os.path.join(sandboxLoc, "JobPackage.pcl") try: package.load(packageLoc) except Exception as ex: msg = "Failed to load JobPackage:%s\n" % packageLoc msg += str(ex) createErrorReport(exitCode = 11001, errorType = "JobPackageError", errorDetails = msg) raise BootstrapException(msg) try: import WMSandbox.JobIndex except ImportError as ex: msg = "Failed to import WMSandbox.JobIndex module\n" msg += str(ex) createErrorReport(exitCode = 11002, errorType = "JobIndexError", errorDetails = msg) raise BootstrapException(msg) index = WMSandbox.JobIndex.jobIndex try: job = package[index] except Exception as ex: msg = "Failed to extract Job %i\n" % (index) msg += str(ex) createErrorReport(exitCode = 11003, errorType = "JobExtractionError", errorDetails = msg) raise BootstrapException(msg) diagnostic = """ Job Index = %s Job Instance = %s """ % (index, job) logging.info(diagnostic) return job
def loadJobDefinition(): """ _loadJobDefinition_ Load the job package and pull out the indexed job, return WMBS Job instance Although this will create a JobReport, it won't necessarily bring it back. Report names are dependent on the retry_count, but if it fails unpacking the job it doesn't know the retry_count and will create the wrong file """ sandboxLoc = locateWMSandbox() package = JobPackage() packageLoc = os.path.join(sandboxLoc, "JobPackage.pcl") try: package.load(packageLoc) except Exception, ex: msg = "Failed to load JobPackage:%s\n" % packageLoc msg += str(ex) createErrorReport(exitCode = 11001, errorType = "JobPackageError", errorDetails = msg) raise BootstrapException, msg
def addJobsToPackage(self, loadedJob): """ _addJobsToPackage_ Add a job to a job package and then return the batch ID for the job. Packages are only written out to disk when they contain 100 jobs. The flushJobsPackages() method must be called after all jobs have been added to the cache and before they are actually submitted to make sure all the job packages have been written to disk. """ if loadedJob["workflow"] not in self.jobsToPackage: # First, let's pull all the information from the loadedJob batchid = "%s-%s" % (loadedJob["id"], loadedJob["retry_count"]) sandboxDir = os.path.dirname(loadedJob["sandbox"]) # Second, assemble the jobPackage location collectionIndex = self.getPackageCollection(sandboxDir) collectionDir = os.path.join( sandboxDir, 'PackageCollection_%i' % collectionIndex, 'batch_%s' % batchid) # Now create the package object self.jobsToPackage[loadedJob["workflow"]] = { "batchid": batchid, 'id': loadedJob['id'], "package": JobPackage(directory=collectionDir) } jobPackage = self.jobsToPackage[loadedJob["workflow"]]["package"] jobPackage[loadedJob["id"]] = loadedJob.getDataStructsJob() batchDir = jobPackage['directory'] if len(jobPackage.keys()) == self.packageSize: if not os.path.exists(batchDir): os.makedirs(batchDir) batchPath = os.path.join(batchDir, "JobPackage.pkl") jobPackage.save(batchPath) del self.jobsToPackage[loadedJob["workflow"]] return batchDir
def createWMBSJobs(self, subscription, task): """ Create the jobs for WMBS Components Send a subscription/task, get back a package. """ splitter = SplitterFactory() geneFac = GeneratorFactory() jobfactory = splitter(subscription = subscription, package = "WMCore.DataStructs", generators = geneFac.makeGenerators(task)) params = task.jobSplittingParameters() jobGroups = jobfactory(**params) jobID = 1 package = JobPackage() for group in jobGroups: for job in group.jobs: job['id'] = jobID jobID += 1 package[job['id']] = job return package