def submit(self, session=None): """ submits the job on the local server @param session: the session used to load infile values @type session: Mobyle.Session @return: job information as a dictionary @rtype: dictionary """ try: if isinstance(self.service, Program): self.job = MobyleJob( service = self.service , email = self.email, session = session, workflowID = self.workflowId) elif isinstance(self.service, Workflow): self.job = WorkflowJob( workflow = self.service, email = self.email, session = session, workflowID = self.workflowId) else: raise NotImplementedError("No Job can be instanciated for a %s service" % str(self.service.__class__)) for name, param in self.params.items(): if param['parameter'].isInfile(): if param['src']: param['src'] = DataProvider.get(param['src']) self.job.setValue(name, (param['userName'], None, param['src'], param['srcFileName'])) else: self.job.setValue(name, (param['userName'], param['value'], None, None)) else: if param['parameter'].getDataType().getName() == 'MultipleChoice': from types import StringTypes if isinstance( param['value'] , StringTypes ): param['value'] = [ param['value'] ] self.job.setValue(name, param['value']) # run Job self.job.run() return { 'id': str(self.job.getJobid()), 'date':str(time.strftime( "%x %X", self.job.getDate())), 'status': str( self.job.getStatus() ), } except UserValueError, e: if hasattr(e, 'message') and e.message: msg = {'errormsg':str(e.message)} else: msg = {'errormsg':str(e)} if hasattr(self, 'job') and self.job: jobId = self.job.getJobid() msg['id'] = str(jobId) if hasattr(e, 'param') and e.param: msg["errorparam"] = e.param.getName() if jobId: pid_str = str(registry.getJobPID(jobId)) else: pid_str = "none" j_log.error("user error in job %s (email %s): %s"% (pid_str, getattr(self,"email","anonymous"),str(e))) return msg
def killJob(jobID): """ @param jobID: the url of the job or a sequence of jobID @type jobID: string or sequence of jobID @return: @rtype: @raise MobyleError: if the job has no number or if the job doesn't exist anymore @todo: tester la partie sge """ from types import StringTypes, TupleType, ListType from Mobyle.MobyleError import MobyleError from Mobyle.JobState import JobState, normUri from Mobyle.Job import Job from Mobyle.WorkflowJob import WorkflowJob if isinstance(jobID, StringTypes): jobIDs = [jobID] elif isinstance(jobID, (ListType, TupleType)): jobIDs = jobID else: raise MobyleError, "jobID must be a string or a Sequence of strings :%s" % type(jobID) errors = [] for jobID in jobIDs: try: path = normUri(jobID) except MobyleError, err: errors.append((jobID, str(err))) continue if path[:4] == "http": # the jobID is not on this Mobyle server errors.append((jobID, "can't kill distant job")) continue js = JobState(uri=jobID) if js.isWorkflow(): job = WorkflowJob(id=jobID) else: job = Job(ID=jobID) try: job.kill() except MobyleError, err: errors.append((jobID, str(err))) continue
# Author: Herve Menager, # # Organization:'Biological Software and Databases' Group, Institut Pasteur, Paris. # # Distributed under GPLv2 Licence. Please refer to the COPYING.LIB document. # # # ######################################################################################## from Mobyle.Workflow import Parser from Mobyle.WorkflowJob import WorkflowJob if __name__ == "__main__": mp = Parser() #wf = mp.parse('/tmp/workflow.xml') # 1st example wf = mp.parse('/tmp/workflow2.xml') # 2nd example class SessionFake(object): def getKey(self): return "workflowjobdemotestmodule" wf.owner = SessionFake() parameters = {'sequences': """>A TTTT >B TATA""", 'alignment_format': 'PHYLIP'} wj = WorkflowJob(workflow=wf,email='*****@*****.**') print wj.id #for key, value in parameters.items(): # set values for 1st example # wj.set_value(key, value) wj.srun() #synchronous calls #wj.run #asynchronous calls