예제 #1
0
파일: Job.py 프로젝트: dmwm/ProdCommon
    def save(self, db):
        """
        save complete job object in database
        """

        # verify data is complete
        if not self.valid(['jobId', 'taskId', 'name']):
            raise JobError("The following job instance cannot be saved," + \
                     " since it is not completely specified: %s" % self)

        # insert job
        try:

            # create entry in database
            status = db.insert(self)
            if status != 1:
                raise JobError("Cannot insert job %s" % self)

            # create entry for runningJob
            if self.runningJob is not None:
                self.runningJob['jobId'] = self.data['jobId']
                self.runningJob['taskId'] = self.data['taskId']
                self.runningJob['submission'] = self.data['submissionNumber']
                self.runningJob.save(db)

        # database error
        except DbError, msg:
            raise JobError(str(msg))
예제 #2
0
파일: Job.py 프로젝트: dmwm/ProdCommon
    def update(self, db, deep=True):
        """
        update job information in database
        """

        # verify if the object exists in database
        if not self.existsInDataBase:

            # no, use save instead of update
            return self.save(db)

        # verify data is complete
        if not self.valid(['jobId', 'taskId']):
            raise JobError("The following job instance cannot be updated," + \
                     " since it is not completely specified: %s" % self)

        # update it on database
        try:
            status = db.update(self)

            # update running job if associated
            if deep and self.runningJob is not None:
                if self.data['submissionNumber'] != \
                       self.runningJob['submission']:
                    raise JobError(
                        "Running instance of job %s.%s with invalid " \
                        + " submission number: %s instead of %s " \
                        % ( self.data['jobId'], self.data['taskId'], \
                            self.runningJob['submission'], \
                            self.data['submissionNumber'] ) )
                status += self.runningJob.update(db)

        # database error
        except DbError, msg:
            raise JobError(str(msg))
예제 #3
0
파일: Job.py 프로젝트: dmwm/ProdCommon
    def getRunningInstance(self, db):
        """
        get running job information
        """

        # create template
        template = RunningJob()
        template['jobId'] = self['jobId']
        template['taskId'] = self['taskId']
        template['submission'] = self['submissionNumber']
        # template['closed'] = "N"

        # get running job
        runningJobs = db.select(template)

        # no running instance
        if runningJobs == []:
            self.runningJob = None

        # one running instance
        elif len(runningJobs) == 1:
            self.runningJob = runningJobs[0]

        # oops, more than one!
        else:
            raise JobError("Multiple running instances of job %s : %s" % \
                           (self['jobId'], len(runningJobs)))
예제 #4
0
파일: Job.py 프로젝트: dmwm/ProdCommon
    def setRunningInstance(self, runningJob):
        """
        set currently running job
        """

        # check if the running instance is plain
        if not runningJob.valid(['taskId']):
            runningJob['taskId'] = self.data['taskId']
        if not runningJob.valid(['jobId']):
            runningJob['jobId'] = self.data['jobId']
        if not runningJob.valid(['submission']):
            runningJob['submission'] = self.data['submissionNumber']

        # check consistency
        if runningJob['taskId'] != self.data['taskId'] or \
               runningJob['jobId'] != self.data['jobId'] or \
               runningJob['submission'] != self.data['submissionNumber'] :
            raise JobError("Invalid running instance with keys %s.%s.%s " + \
                           " instead of %s.%s.%s" % ( \
            runningJob['taskId'], runningJob['jobId'],
            runningJob['submission'], self.data['taskId'], \
            self.data['jobId'], self.data['submissionNumber'] ) )

        # store instance
        self.runningJob = runningJob
예제 #5
0
    def load(self, db, deep = True):
        """
        load information from database
        """

       # verify data is complete
        if not self.valid(['name']):
            raise JobError("The following running job instance cannot be" + \
                     " loaded since it is not completely specified: %s" % self)

        # get information from database based on template object
        try:
            objects = db.select(self)

        # database error
        except DbError, msg:
            raise JobError(str(msg))
예제 #6
0
    def remove(self, db):
        """
        remove job object from database
        """

        # verify data is complete
        if not self.valid(['submission', 'jobId']):
            raise JobError("The following job instance cannot be removed," + \
                     " since it is not completely specified: %s" % self)

        # remove from database
        try:
            status = db.delete(self)
            if status < 1:
                raise JobError("Cannot remove running job %s" % str(self))

        # database error
        except DbError, msg:
            raise JobError(str(msg))
예제 #7
0
    def update(self, db, deep = True):
        """
        update job information in database
        """

        # verify if the object exists in database
        if not self.existsInDataBase:

            # no, use save instead of update
            return self.save(db)

        # verify data is complete
        if not self.valid(['submission', 'jobId', 'taskId']):
            raise JobError("The following job instance cannot be updated," + \
                     " since it is not completely specified: %s" % self)

        # convert timestamp fields as required by mysql ('YYYY-MM-DD HH:MM:SS')
        for key in self.timeFields :
            try :
                self.data[key] = time.strftime("%Y-%m-%d %H:%M:%S", \
                                              time.gmtime(int(self.data[key])))
            # skip None and already formed strings
            except TypeError :
                pass
            except ValueError :
                pass

        # skip closed jobs?
        if deep :
            skipAttributes = None
        else :
            skipAttributes = {'closed' : 'Y'}

        # update it on database
        try:
            status = db.update(self, skipAttributes)
            # if status < 1:
            #     raise JobError("Cannot update job %s" % str(self))

        # database error
        except DbError, msg:
            raise JobError(str(msg))
예제 #8
0
    def save(self, db):
        """
        save running job object in database. checking that static information
        is automatically performed due to database constraints
        """

        # verify data is complete
        if not self.valid(['submission', 'jobId', 'taskId']):
            raise JobError("The following job instance cannot be saved," + \
                     " since it is not completely specified: %s" % self)

        # insert running job
        try:

            # create entry in database
            status = db.insert(self)
            if status != 1:
                raise JobError("Cannot insert running job %s" % str(self))

        # database error
        except DbError, msg:
            raise JobError(str(msg))
예제 #9
0
    def loadJobByName(self, jobName):
        """
        retrieve job information from db for jobs with name 'name'
        """

        jobList = self.loadJobsByAttr({'name': jobName})

        if jobList is None or jobList == []:
            return None

        if len(jobList) > 1:
            raise JobError("Multiple job instances corresponds to the" + \
                     " name specified: %s" % jobName)

        return jobList[0]
예제 #10
0
파일: Job.py 프로젝트: dmwm/ProdCommon
    def updateRunningInstance(self, db, notSkipClosed=True):
        """
        update current running job
        """

        # check consistency
        if self.runningJob['taskId'] != self.data['taskId'] or \
               self.runningJob['jobId'] != self.data['jobId'] or \
               self.runningJob['submission'] != self.data['submissionNumber'] :
            raise JobError( "Running instance of job %s.%s with invalid " \
                            + " submission number: %s instead of %s " \
                            % ( self.data['jobId'], self.data['taskId'], \
                                self.runningJob['submission'], \
                                self.data['submissionNumber'] ) )

        # update
        self.runningJob.update(db, notSkipClosed)
예제 #11
0
       # verify data is complete
        if not self.valid(['name']):
            raise JobError("The following running job instance cannot be" + \
                     " loaded since it is not completely specified: %s" % self)

        # get information from database based on template object
        try:
            objects = db.select(self)

        # database error
        except DbError, msg:
            raise JobError(str(msg))

        # since required data is a key, it should be a single object list
        if len(objects) == 0:
            raise JobError("No running job instances corresponds to the," + \
                     " template specified: %s" % self)

        if len(objects) > 1:
            raise JobError("Multiple running job instances corresponds to" + \
                     " the template specified: %s" % self)

        # copy fields
        for key in self.fields:
            self.data[key] = objects[0][key]

        # update status
        self.existsInDataBase = True

예제 #12
0
파일: Job.py 프로젝트: dmwm/ProdCommon
        if not self.valid(['id']) and not self.valid(['name']) and \
           not self.valid(['jobId']):
            raise JobError("The following job instance cannot be loaded" + \
                     " since it is not completely specified: %s" % self)

        # get information from database based on template object
        try:
            objects = db.select(self)

        # database error
        except DbError, msg:
            raise JobError(str(msg))

        # since required data is a key, it should be a single object list
        if len(objects) == 0:
            raise JobError("No job instances corresponds to the," + \
                     " template specified: %s" % self)

        if len(objects) > 1:
            raise JobError("Multiple job instances corresponds to the" + \
                     " template specified: %s" % self)

        # copy fields
        for key in self.fields:
            self.data[key] = objects[0][key]

        # get associated running job if it exists
        if deep:
            self.getRunningInstance(db)

        # update status
        self.existsInDataBase = True