Example #1
0
def _read_jobinfo():
    try:
        return api.lsb_readjobinfo(None)

    except:
        _unconditionally_close_jobinfo()
        raise LSFBindingException("Caught exception in lsb_readjobinfo")
Example #2
0
def _read_jobinfo():
    try:
        return api.lsb_readjobinfo(None)

    except:
        _unconditionally_close_jobinfo()
        raise LSFBindingException('Caught exception in lsb_readjobinfo')
Example #3
0
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)
    return jobs
Example #4
0
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)
        #print job
        count = lsf.intp_value(more)
    lsf.delete_intp(more)
    return jobs
Example #5
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
Example #6
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