Example #1
0
    def stop_job(self, job):
        """Attempts to delete a job from the PBS queue"""
        job_id = job.get_job_runner_external_id().encode('utf-8')
        job_tag = "(%s/%s)" % (job.get_id_tag(), job_id)
        log.debug("%s Stopping PBS job" % job_tag)

        # Declare the connection handle c so that it can be cleaned up:
        c = None

        try:
            pbs_server_name = self.__get_pbs_server(job.destination_params)
            if pbs_server_name is None:
                log.debug(
                    "(%s) Job queued but no destination stored in job params, cannot delete"
                    % job_tag)
                return
            c = pbs.pbs_connect(util.smart_str(pbs_server_name))
            if c <= 0:
                log.debug(
                    "(%s) Connection to PBS server for job delete failed" %
                    job_tag)
                return
            pbs.pbs_deljob(c, job_id, '')
            log.debug("%s Removed from PBS queue before job completion" %
                      job_tag)
        except:
            e = traceback.format_exc()
            log.debug("%s Unable to stop job: %s" % (job_tag, e))
        finally:
            # Cleanup: disconnect from the server.
            if (None is not c):
                pbs.pbs_disconnect(c)
Example #2
0
    def stop_job( self, job ):
        """Attempts to delete a job from the PBS queue"""
        job_id = job.get_job_runner_external_id().encode('utf-8')
        job_tag = "(%s/%s)" % ( job.get_id_tag(), job_id )
        log.debug( "%s Stopping PBS job" % job_tag )

        # Declare the connection handle c so that it can be cleaned up:
        c = None

        try:
            pbs_server_name = self.__get_pbs_server( job.destination_params )
            if pbs_server_name is None:
                log.debug("(%s) Job queued but no destination stored in job params, cannot delete"
                          % job_tag )
                return
            c = pbs.pbs_connect( util.smart_str( pbs_server_name ) )
            if c <= 0:
                log.debug("(%s) Connection to PBS server for job delete failed"
                          % job_tag )
                return
            pbs.pbs_deljob( c, job_id, '' )
            log.debug( "%s Removed from PBS queue before job completion"
                       % job_tag )
        except:
            e = traceback.format_exc()
            log.debug( "%s Unable to stop job: %s" % ( job_tag, e ) )
        finally:
            # Cleanup: disconnect from the server.
            if ( None is not c ):
                pbs.pbs_disconnect( c )
Example #3
0
    def alive(self, process_id):
        alive = False
        try:
            status = self.pbsquery.getjob(str(process_id))['job_state'][0]            
        except:
            # job not found
            status = -1
            sys.stderr.write("EXC: %s\n" % str(sys.exc_info()[0]))
            sys.stderr.write("Could not find job for process id %d\n" % process_id)

        if status == 'Q':
            sys.stderr.write("Job %d waiting in queue.\n" % (process_id))
            alive = True
        elif status == 'R':
            sys.stderr.write("Job %d is running.\n" % (process_id))
            alive = True
        elif status in ['H','S']:
            sys.stderr.write("Job %d is held or suspended.\n" % (process_id))
            alive = False

        if not alive:
            try:
                # Kill the job.
                c = pbs.pbs_connect(pbs.pbs_default())
                result = pbs.pbs_deljob(c, str(process_id))                    
                sys.stderr.write("Killed job %d.\n" % (process_id))
            except:
                sys.stderr.write("Failed to kill job %d.\n" % (process_id))

            return False
        else:
            return True
Example #4
0
 def remove(self):
     """Remove the job with id jobid"""
     result = pbs.pbs_deljob(self.pbsconn, self.jobid, '')  # use empty string, not NULL
     if result:
         self.log.error("Failed to delete job %s: error %s" % (self.jobid, result))
     else:
         self.log.debug("Succesfully deleted job %s" % self.jobid)
 def remove(self):
     """Remove the job with id jobid"""
     result = pbs.pbs_deljob(self.pbsconn, self.jobid, '')  # use empty string, not NULL
     if result:
         raise EasyBuildError("Failed to delete job %s: error %s", self.jobid, result)
     else:
         self.log.debug("Succesfully deleted job %s" % self.jobid)
Example #6
0
 def del_job(self, job_id, server):
     c = pbs.pbs_connect(str(
         pbs.pbs_default()))  # Create new connection for the child process
     if server is None:
         server = pbs.pbs_default()
     job_full_id = job_id + '.' + server
     result = pbs.pbs_deljob(c, job_full_id, 'NULL')
     return result  # If operation is successfull, result == 0
Example #7
0
    def remove(self, jobid=None):
        """Remove the job with id jobid."""
        if jobid is None:
            jobid = self.jobid

        result = pbs.pbs_deljob(self.pbsconn, self.jobid, '')  # use empty string, not NULL (one can pass the deldelay=nnnn option)
        if result:
            self.log.error("Failed to delete job %s: error %s", jobid, result)
        else:
            self.log.debug("Succesfully deleted job %s", jobid)
Example #8
0
    def delete_job(self, job_id):
        """
           Sends job delete request to pbs_server for job

           :param job_id: job id to delete
           :return:  pbs_deljob return value (0 on success)
        """
        connection = _connect_to_server(self.pbs_server)
        rval = pbs.pbs_deljob(connection, job_id, '')
        pbs.pbs_disconnect(connection)
        return rval
Example #9
0
    def delete_all_jobs(self, ids):
        """

        delete all jobs in a list of jobs

        :param ids: list of all jobs
        :return: zero on success, otherwise return value of failed pbs_deljob
        """
        for job_id in ids:
            connection = _connect_to_server(self.pbs_server)
            rval = pbs.pbs_deljob(connection, job_id, '')
            pbs.pbs_disconnect(connection)
            if rval and (rval != self.E_UNKNOWN or rval != self.E_STATE):
                return rval
        return 0
Example #10
0
    def kill(self, obj):

        conn=self.pbs_conn()

        for job in obj.jobs :
            if not self.valid( job.runningJob ): continue
            id=str(job.runningJob['schedulerId']).strip()
            res=pbs.pbs_deljob(conn, id, '')

            if res!=0:
                err, err_text=pbs.error()
                self.logging.error('Error in job kill for '+id)
                self.logging.error('PBS error code '+str(err)+': '+err_text)
                self.pbs_disconn(conn)
                raise SchedulerError('PBS error', str(err)+': '+err_text)
                    
        self.pbs_disconn(conn)
Example #11
0
    def kill(self, obj):

        conn = self.pbs_conn()

        for job in obj.jobs:
            if not self.valid(job.runningJob): continue
            id = str(job.runningJob['schedulerId']).strip()
            res = pbs.pbs_deljob(conn, id, '')

            if res != 0:
                err, err_text = pbs.error()
                self.logging.error('Error in job kill for ' + id)
                self.logging.error('PBS error code ' + str(err) + ': ' +
                                   err_text)
                self.pbs_disconn(conn)
                raise SchedulerError('PBS error', str(err) + ': ' + err_text)

        self.pbs_disconn(conn)