def getStatus(jobID): """ @param jobID: the url of the job @type jobID: string @return: the current status of the job @rtype: string @raise MobyleError: if the job has no number or if the job doesn't exist anymore @raise OSError: if the user is not the owner of the process """ from Mobyle.JobState import JobState, normUri from urlparse import urlparse from Mobyle.StatusManager import StatusManager path = normUri(jobID) protocol, host, path, a, b, c = urlparse(path) if protocol == "http": raise NotImplementedError, "trying to querying a distant server" if path[-9:] == "index.xml": path = path[:-10] sm = StatusManager() oldStatus = sm.getStatus(path) #'killed' , 'finished' , 'error' the status cannot change anymore #'building' these jobs have not yet batch number # ( 'finished' , 'error' , 'killed' , 'building' ): if not oldStatus.isQueryable(): return oldStatus else: adm = Admin(path) batch = adm.getExecutionAlias() jobNum = adm.getNumber() if batch is None or jobNum is None: return oldStatus try: exec_engine = executionLoader(jobID=jobID) newStatus = exec_engine.getStatus(jobNum) except MobyleError, err: u_log.error(str(err), exc_info=True) raise err if not newStatus.isKnown(): return oldStatus if newStatus != oldStatus: sm.setStatus(path, newStatus) return newStatus
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
def isExecuting(jobID): """ @param jobID: the url of the job @type jobID: string @return True if the job is currently executing ( submitted , running , pending , hold ). False otherwise ( building, finished , error , killed ) @rtype: boolean @raise MobyleError: if the job has no number @raise OSError: if the user is not the owner of the process """ from Mobyle.JobState import normUri from urlparse import urlparse from Mobyle.StatusManager import StatusManager path = normUri(jobID) protocol, host, path, a, b, c = urlparse(path) if protocol == "http": raise NotImplementedError, "trying to querying a distant server" if path[-9:] == "index.xml": path = path[:-10] adm = Admin(path) batch = adm.getExecutionAlias() jobNum = adm.getNumber() if batch is None or jobNum is None: sm = StatusManager() status = sm.getStatus(path) if not status.isQueryable(): return False else: raise MobyleError("inconsistency in .admin file %s" % path) try: execKlass = executionLoader(jobID=jobID) newStatus = execKlass.getStatus(jobNum) except MobyleError, err: u_log.error(str(err), exc_info=True) raise err
def executionLoader(jobID=None, alias=None, execution_config=None): assert ( bool(jobID) + bool(alias) + bool(execution_config) == 1 ), "please provide either a jobID, an alias or an execution_config" from Mobyle.ConfigManager import Config cfg = Config() if not execution_config: if jobID: from Mobyle.JobState import normUri from urlparse import urlparse path = normUri(jobID) protocol, host, path, a, b, c = urlparse(path) if protocol == "http": raise NotImplementedError, "trying to instanciate an Execution system from a remote Job" if path[-9:] == "index.xml": path = path[:-10] adm = Admin(path) alias = adm.getExecutionAlias() if not alias: msg = "cant determine the Execution system for %s " % (jobID) u_log.error(msg) raise MobyleError(msg) try: execution_config = cfg.getExecutionConfigFromAlias(alias) except KeyError: msg = "the ExecutionConfig alias %s doesn't match with any alias in Config" % alias u_log.critical(msg) raise MobyleError(msg) klass_name = execution_config.execution_class_name try: module = __import__("Mobyle.Execution.%s" % klass_name) except ImportError, err: msg = "The Execution.%s module is missing" % klass_name u_log.critical(msg) raise MobyleError, msg