예제 #1
0
def get_jobs(job_id=0, job_name=None, user_name=lsf.ALL_USERS, queue_name=None, host_name=None,
             option=lsf.ALL_JOB):
    """
    Standard job_ent query function.
    :param job_id: 
    :param job_name: 
    :param user_name: 
    :param queue_name: 
    :param host_name: 
    :param option: 
    :return: 
    """
    job_cnt = lsf.lsb_openjobinfo(job_id, job_name, user_name, queue_name, host_name, option)
    more = lsf.new_intp()
    job_list = list()
    for _ in xrange(job_cnt):
        job_info = lsf.lsb_readjobinfo(more)
        job_list.append(_convert_job_dict(job_info))
    lsf.delete_intp(more)
    lsf.lsb_closejobinfo()
    return job_list
예제 #2
0
    def get_jobs(self,
                 jobid=0,
                 jobName=None,
                 user="******",
                 queue=None,
                 hostname=None,
                 status='all'):
        """
        Enter certain parameters to reduce the search space of all jobs in LSF or that have been recently completed.
        The default is to return all possible jobs.

        :param  jobid: (int) jobid to match with.
        :param  jobName: (str) Name of job to match.
        :param  user: (str) User to match.
        :param  queue: (str) LSF queue to search.
        :param  hostname: (str) Hostname to search.
        :param  status: (str, list) Group of status to match.
        :return: (list) List of jobs that match above criteria.
        """
        # Since attempting to choose job status based on options does not work, we instead filter the jobs after
        # we have found all the matches.
        search_status = lsf.ALL_JOB
        if status == "all":
            status = Job.get_viable_status()
        job_status = Job.get_viable_status()

        # LSF uses numbers for each type of job so initialize the options as 0.
        options = []
        # Try to go through all status' set.
        try:
            # If the user entered a list, the options are already set. Just make sure they are all in the dictionary.
            if type(status) is list:
                # Using or, put that status into the possible job options.
                for s in status:
                    if s not in job_status:
                        raise KeyError
                    options.append(s)
            # If it is a string then it is only one status to look for.
            elif type(status) is str:
                if status not in job_status:
                    raise KeyError
                options.append(status)
        # If incorrect key was entered then print out error with correct options.
        except KeyError:
            status_str = ""
            index = 0
            for key in job_status:
                status_str += key
                status_str += ", "
                index += 1
            status_str += "all"
            raise KeyError("Invalid status, " + str(status) +
                           ". Options are: " + status_str)

        # Create an array for holding each job.
        jobs = []
        if self.verbose:
            print("jobid:", jobid, "jobName:", jobName, "user:"******"queue:", queue, "hostname:", hostname, "options:",
                  search_status)
        # Get a generator that will return a job whenever querried.
        jobinfohead = lsf.lsb_openjobinfo_a(jobid, jobName, user, queue,
                                            hostname, search_status)

        # If there are some jobs that exist under certain parameters then get the number of jobs.
        if jobinfohead is not None:
            num_jobs = jobinfohead.numJobs
        # Otherwise there are no jobs.
        else:
            num_jobs = 0

        if self.verbose:
            print("Found " + str(num_jobs) + " job(s)")

        # Repeatedly call jobinfo for how many jobs are there.
        for _ in range(num_jobs):
            # Append the job to the list after transforming it into a Job class.
            # Once job info is closed, lsf.lsb_readjobinfo does not work again.
            # It is also a generator and can thus only be gone through once.
            lsf_job = lsf.lsb_readjobinfo(None)
            # This occurs if the job pops out of queue after getting the number of lsf jobs.
            if lsf_job is None:
                continue
            j = Job(lsf_job)
            if j.status in options:
                jobs.append(j)
        # All done with this job info.
        lsf.lsb_closejobinfo()

        # Return the list of jobs.
        return jobs
예제 #3
0
def _close_jobinfo():
    try:
        api.lsb_closejobinfo()
    except:
        raise LSFBindingException("Caught exception in lsb_closejobinfo")
예제 #4
0
def _unconditionally_close_jobinfo():
    try:
        api.lsb_closejobinfo()
    except:
        pass
예제 #5
0
파일: lsf.py 프로젝트: zgiles/lsf-stats
        # ALL_JOB Select jobs matching any status, including unfinished jobs and recently finished jobs.
        # LSF batch remembers finished jobs within the CLEAN_PERIOD, as defined in the lsb.params file.
        # in /hpc/lsf/conf/lsbatch/minerva/configdir/lsb.params:
        # CLEAN_PERIOD=1800

        # CUR_JOB Return jobs that have not finished yet
        # DONE_JOB Return jobs that have finished recently.
        # PEND_JOB Return jobs that are in the pending status.
        # SUSP_JOB Return jobs that are in the suspended status.
        # LAST_JOB Return jobs that are submitted most recently.
        # JGRP_ARRAY_INFO Return job array information.

    count = lsf.lsb_openjobinfo(job_id, job_name, user_name, queue_name,
                                host_name, options)
    jobs = read_all_jobs(count)
    lsf.lsb_closejobinfo()
    return jobs


def get_all_job_info():
    return get_job_info()


def get_job_info_id(job_ids):
    if isinstance(job_ids, list):
        jobs = []
        for job_id in job_ids:
            jobs = jobs + get_job_info(long(job_id), None, None, None, None, 0)
        return jobs
    else:
        return get_job_info(long(job_ids), None, None, None, None, 0)
예제 #6
0
def _close_jobinfo():
    try:
        api.lsb_closejobinfo()
    except:
        raise LSFBindingException('Caught exception in lsb_closejobinfo')
예제 #7
0
def _unconditionally_close_jobinfo():
    try:
        api.lsb_closejobinfo()
    except:
        pass
예제 #8
0
    '''a wrapper for c lsf api: 
       int lsb_openjobinfo(
       LS_LONG_INT jobId, 
       char *jobName, 
       char *userName, 
       char *queueName, 
       char *hostName, 
       int options) '''
    if user_name == None:
        user_name = lsf.ALL_USERS
    if options == 0:
        options = lsf.ALL_JOB

    count = lsf.lsb_openjobinfo(job_id, job_name, user_name, queue_name, host_name, options)
    jobs = read_all_jobs(count)
    lsf.lsb_closejobinfo()
    return jobs

def get_all_job_info():
    return get_job_info()

def read_all_jobs(count):
    jobs = []
    more = lsf.new_intp()
    while count > 0:
        jobp = lsf.lsb_readjobinfo(more)
        #create a copy of data
        job = JobInfo(jobp)
        jobs.append(job)
        count = lsf.intp_value(more)
    lsf.delete_intp(more)