Example #1
0
def mergelist(location_string, cluster):
    if not cluster:
        return location_string

    locations = location_string.split(":")

    return client_utils.merge_nodelist(locations)
Example #2
0
def mergelist(location_string, cluster):
    if not cluster:
        return location_string

    locations = location_string.split(":")

    return client_utils.merge_nodelist(locations)
Example #3
0
File: qstat.py Project: ido/cobalt
def get_output_for_jobs(parser,hinfo,queues):
    """
    get jobs from specified jobids
    """
    names              = parser.args if not parser.no_args() else ['*']
    user_name          = parser.options.user if parser.options.user != None else '*'
    query_dependencies = {'QueuedTime':
                              ['SubmitTime','StartTime'],'RunTime':['StartTime'],'TimeRemaining':['WallTime','StartTime']}

    try:
        query = []
        for n in names:
            if n=='*':
                query.append({'tag':'job', 'jobid':n, 'queue':'*'})
            elif [q['name'] for q in queues if q['name'] == n]:
                query.append({'tag':'job', 'queue':n, 'jobid':'*'})
            else:
                query.append({'tag':'job', 'jobid':int(n), 'queue':'*'})
    except ValueError:
        client_utils.logger.error("%s is not a valid jobid or queue name" % n)
        sys.exit(1)
    for q in query:
        for h in hinfo.long_header:
            if h == 'JobName':
                q.update({'jobname':'*'})
            elif h not in ['JobID', 'Queue']:
                q.update({h.lower():'*'})
            if h in query_dependencies:
                for x in query_dependencies[h]:
                    if x not in hinfo.header:
                        q.update({x.lower():'*'})
        q["user"] = user_name

    response = client_utils.component_call(QUEMGR, False, 'get_jobs', (query,))

    if not parser.no_args() and not response:
        sys.exit(1)

    if response:
        maxjoblen = max([len(str(item.get('jobid'))) for item in response])
        jobidfmt = "%%%ss" % maxjoblen
    # calculate derived values
    for j in response:
        # walltime
        walltime_secs = int(j['walltime']) * 60
        t = int(float(j['walltime']))
        h = int(math.floor(t/60))
        t -= (h * 60)
        j['walltime'] = "%02d:%02d:00" % (h, t)
        # jobid
        j['jobid'] = jobidfmt % j['jobid']
        # location
        if isinstance(j['location'], types.ListType) and len(j['location']) > 1:
            j['location'] = client_utils.merge_nodelist(j['location'])
        elif isinstance(j['location'], types.ListType) and len(j['location']) == 1:
            j['location'] = j['location'][0]
        # queuedtime
        if j.get('starttime') in ('-1', 'BUG', 'N/A', None):
            j['queuedtime'] = client_utils.get_elapsed_time(float(j.get('submittime')), time.time())
        else:
            j['queuedtime'] = client_utils.get_elapsed_time(float(j.get('submittime')), float(j['starttime']))
        # runtime
        if j.get('starttime') in ('-1', 'BUG', 'N/A', None):
            j['runtime'] = 'N/A'
        else:
            currtime = time.time()
            j['runtime'] = client_utils.get_elapsed_time( float(j['starttime']), time.time())
        # starttime
        if j.get('starttime') in ('-1', 'BUG', None):
            j['starttime'] = 'N/A'
        else:
            orig_starttime = float(j['starttime'])
            j['starttime'] = client_utils.sec_to_str(float(j['starttime']))
        # timeremaining
        if j.get('starttime') in ['-1', 'BUG', 'N/A' ,None]:
            j['timeremaining'] = 'N/A'
        else:
            time_remaining = walltime_secs - (currtime - orig_starttime)
            if time_remaining < 0:
                j['timeremaining'] = '00:00:00'
            else:
                s = int(time_remaining) % 60
                m = (int(time_remaining) % 3600) / 60
                h = int(time_remaining) / 3600
                j['timeremaining'] = "%02d:%02d:%02d" % (h, m, s)
        # jobname
        outputpath = j.get('outputpath')
        jobname    = j.get('jobname')
        # envs
        if j['envs'] is None:
            j.update({'envs':''})
        else:
            j['envs'] = ' '.join([str(x) + '=' + str(y) for x, y in j['envs'].iteritems()])
        # args
        j['args'] = ' '.join(j['args'])

        # make the SubmitTime readable by humans
        j['submittime'] = client_utils.sec_to_str(float(j['submittime']))

        j['outputpath'] = outputpath
        j['errorpath'] = j.get('errorpath')
        j['user_list'] = ':'.join(j['user_list'])

        if j['geometry'] != None:
            j['geometry'] = "x".join([str(i) for i in j['geometry']])
        else:
            j['geometry'] = 'Any'
    # any header that was not present in the query response has value set to '-'
    output = [[j.get(x, '-') for x in [y.lower() for y in hinfo.header]]
              for j in response]

    return output
Example #4
0
def get_output_for_jobs(parser, hinfo, queues):
    """
    get jobs from specified jobids
    """
    names = parser.args if not parser.no_args() else ['*']
    user_name = parser.options.user if parser.options.user != None else '*'
    query_dependencies = {
        'QueuedTime': ['SubmitTime', 'StartTime'],
        'RunTime': ['StartTime'],
        'TimeRemaining': ['WallTime', 'StartTime']
    }

    try:
        query = []
        for n in names:
            if n == '*':
                query.append({'tag': 'job', 'jobid': n, 'queue': '*'})
            elif [q['name'] for q in queues if q['name'] == n]:
                query.append({'tag': 'job', 'queue': n, 'jobid': '*'})
            else:
                query.append({'tag': 'job', 'jobid': int(n), 'queue': '*'})
    except ValueError:
        client_utils.logger.error("%s is not a valid jobid or queue name" % n)
        sys.exit(1)
    for q in query:
        for h in hinfo.long_header:
            if h == 'JobName':
                q.update({'jobname': '*'})
            elif h not in ['JobID', 'Queue']:
                q.update({h.lower(): '*'})
            if h in query_dependencies:
                for x in query_dependencies[h]:
                    if x not in hinfo.header:
                        q.update({x.lower(): '*'})
        q["user"] = user_name

    response = client_utils.component_call(QUEMGR, False, 'get_jobs',
                                           (query, ))

    if not parser.no_args() and not response:
        sys.exit(1)

    if response:
        maxjoblen = max([len(str(item.get('jobid'))) for item in response])
        jobidfmt = "%%%ss" % maxjoblen
    # calculate derived values
    for j in response:
        # walltime
        walltime_secs = int(j['walltime']) * 60
        t = int(float(j['walltime']))
        h = int(math.floor(t / 60))
        t -= (h * 60)
        j['walltime'] = "%02d:%02d:00" % (h, t)
        # jobid
        j['jobid'] = jobidfmt % j['jobid']
        # location
        if isinstance(j['location'],
                      types.ListType) and len(j['location']) > 1:
            j['location'] = client_utils.merge_nodelist(j['location'])
        elif isinstance(j['location'], types.ListType) and len(
                j['location']) == 1:
            j['location'] = j['location'][0]
        # queuedtime
        if j.get('starttime') in ('-1', 'BUG', 'N/A', None):
            j['queuedtime'] = client_utils.get_elapsed_time(
                float(j.get('submittime')), time.time())
        else:
            j['queuedtime'] = client_utils.get_elapsed_time(
                float(j.get('submittime')), float(j['starttime']))
        # runtime
        if j.get('starttime') in ('-1', 'BUG', 'N/A', None):
            j['runtime'] = 'N/A'
        else:
            currtime = time.time()
            j['runtime'] = client_utils.get_elapsed_time(
                float(j['starttime']), time.time())
        # starttime
        if j.get('starttime') in ('-1', 'BUG', None):
            j['starttime'] = 'N/A'
        else:
            orig_starttime = float(j['starttime'])
            j['starttime'] = client_utils.sec_to_str(float(j['starttime']))
        # timeremaining
        if j.get('starttime') in ['-1', 'BUG', 'N/A', None]:
            j['timeremaining'] = 'N/A'
        else:
            time_remaining = walltime_secs - (currtime - orig_starttime)
            if time_remaining < 0:
                j['timeremaining'] = '00:00:00'
            else:
                s = int(time_remaining) % 60
                m = (int(time_remaining) % 3600) / 60
                h = int(time_remaining) / 3600
                j['timeremaining'] = "%02d:%02d:%02d" % (h, m, s)
        # jobname
        outputpath = j.get('outputpath')
        jobname = j.get('jobname')
        # envs
        if j['envs'] is None:
            j.update({'envs': ''})
        else:
            j['envs'] = ' '.join(
                [str(x) + '=' + str(y) for x, y in j['envs'].iteritems()])
        # args
        j['args'] = ' '.join(j['args'])

        # make the SubmitTime readable by humans
        j['submittime'] = client_utils.sec_to_str(float(j['submittime']))

        j['outputpath'] = outputpath
        j['errorpath'] = j.get('errorpath')
        j['user_list'] = ':'.join(j['user_list'])

        if j['geometry'] != None:
            j['geometry'] = "x".join([str(i) for i in j['geometry']])
        else:
            j['geometry'] = 'Any'
    # any header that was not present in the query response has value set to '-'
    output = [[j.get(x, '-') for x in [y.lower() for y in hinfo.header]]
              for j in response]

    return output