Example #1
0
def main():
    """
    qmove main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [cb_debug, ()]
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    user = client_utils.getuid()

    # Set required default values: None

    parser.parse_it()  # parse the command line

    queue, jobs = validate_args(parser, user)
    filters = client_utils.get_filters()
    jobdata = client_utils.component_call(QUEMGR, False, 'get_jobs', (jobs, ))

    response = []
    # move jobs to queue
    for job in jobdata:
        orig_job = job.copy()
        job.update({'queue': queue})
        client_utils.process_filters(filters, job)
        [j] = client_utils.component_call(QUEMGR, False, 'set_jobs',
                                          ([orig_job], job, user))
        response.append("moved job %d to queue '%s'" %
                        (j.get('jobid'), j.get('queue')))

    if not response:
        client_utils.logger.error("Failed to match any jobs or queues")
    else:
        for line in response:
            client_utils.logger.info(line)
Example #2
0
def main():
    """
    qmove main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [ cb_debug        , () ] ]

    # Get the version information
    opt_def =  __doc__.replace('__revision__',__revision__)
    opt_def =  opt_def.replace('__version__',__version__)

    parser = ArgParse(opt_def,callbacks)

    user = client_utils.getuid()

    # Set required default values: None

    parser.parse_it() # parse the command line

    queue,jobs = validate_args(parser,user)
    filters    = client_utils.get_filters()
    jobdata    = client_utils.component_call(QUEMGR, False, 'get_jobs', (jobs,))

    response = []
    # move jobs to queue
    for job in jobdata:
        orig_job = job.copy()
        job.update({'queue':queue})
        client_utils.process_filters(filters,job)
        [j] = client_utils.component_call(QUEMGR, False, 'set_jobs', ([orig_job],job,user))
        response.append("moved job %d to queue '%s'" % (j.get('jobid'), j.get('queue')))

    if not response:
        client_utils.logger.error("Failed to match any jobs or queues")
    else:
        for line in response:
            client_utils.logger.info(line)
Example #3
0
def main():
    """
    qalter main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    spec     = {} # map of destination option strings and parsed values
    opts     = {} # old map
    opt2spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>           <cb args>
        [ cb_debug               , () ],
        [ cb_gtzero              , (True,) ], # return int
        [ cb_nodes               , (True,) ], # return int
        [ cb_time                , (True, False, False) ], # delta time allowed, return minutes, return string
        [ cb_upd_dep             , () ],
        [ cb_attrs               , () ],
        [ cb_user_list           , (opts,) ],
        [ cb_geometry            , (opts,) ],
        [ cb_mode                , () ]]

    # Get the version information
    opt_def =  __doc__.replace('__revision__', __revision__)
    opt_def =  opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    user = client_utils.getuid()

    # Set required default values: None

    parser.parse_it() # parse the command line
    opt_count = client_utils.get_options(spec, opts, opt2spec, parser)

    # if run_project set then set run users to current user
    if parser.options.run_project != None:
        spec['user_list'] = [user]

    jobids  = validate_args(parser, opt_count)
    filters = client_utils.get_filters()

    jobdata = get_jobdata(jobids, parser, user)

    if parser.options.defer != None:
        client_utils.set_scores(0, jobids, user)
        if opt_count == 1:
            return

    response = []
    # for every job go update the spec info
    for job in jobdata:
        # append the parsed spec to the updates list
        new_spec          = spec.copy()
        new_spec['jobid'] = job['jobid']
        if parser.options.walltime is not None:
            update_time(job, new_spec, parser)
        if parser.options.nodes is not None or parser.options.mode is not None:
            if parser.options.nodes is None:
                new_spec['nodes'] = job['nodes']
            if parser.options.mode is None:
                new_spec['mode'] = job['mode']
            update_procs(new_spec, parser)
        if parser.options.geometry is not None:
            client_utils.validate_geometry(opts['geometry'], job['nodes'])

        del job['is_active']
        orig_job = job.copy()
        job.update(new_spec)

        client_utils.process_filters(filters, job)
        response = client_utils.component_call(QUEMGR, False, 'set_jobs', ([orig_job], job, user))
        do_some_logging(job, orig_job, parser)

    if not response:
        client_utils.logger.error("Failed to match any jobs or queues")
    else:
        client_utils.logger.debug(response)
Example #4
0
File: qsub.py Project: ido/cobalt
def main():
    """
    qsub main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)



    spec     = {} # map of destination option strings and parsed values
    opts     = {} # old map
    opt2spec = {}
    def_spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        ( cb_debug        , () ),
        ( cb_interactive  , () ),
        ( cb_env          , (opts,) ),
        ( cb_nodes        , (False,) ), # return string
        ( cb_gtzero       , (False,) ), # return string
        ( cb_time         , (False, False, False) ), # no delta time, minutes, return string
        ( cb_umask        , () ),
        ( cb_path         , (opts, True) ), # use CWD
        ( cb_dep          , () ),
        ( cb_attrs        , () ),
        ( cb_mode         , () ),
        ( cb_user_list    , (opts,) ),
        ( cb_geometry     , (opts,) )]

    # Get the version information
    opt_def =  __doc__.replace('__revision__', __revision__)
    opt_def =  opt_def.replace('__version__', __version__)

    user = client_utils.getuid()

    def_spec['tag']            = 'job'
    def_spec['user']           = user
    def_spec['outputdir']      = client_utils.CWD_TAG
    def_spec['jobid']          = '*'
    def_spec['path']           = client_utils.getpath()
    def_spec['mode']           = False
    def_spec['cwd']            = client_utils.getcwd()
    def_spec['kernel']         = CN_DEFAULT_KERNEL
    def_spec['ion_kernel']     = ION_DEFAULT_KERNEL
    def_spec['queue']          = 'default'
    def_spec['umask']          = 022
    def_spec['run_project']    = False
    def_spec['user_list']      = [user]
    def_spec['procs']          = False
    def_spec['script_preboot'] = True

    parser    = ArgParse(opt_def, callbacks)
    opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)
    reparse  = validate_args(parser, spec)

    if reparse:
        # re-parse with new sys.argv
        # note: the first parse is necessary to make sure that
        #       the env syntax is correct for every --env option provided
        #       If not parsed prior to the union then the union could result
        #       in a valid syntax, but it would not be what the user would want.
        opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)

    client_utils.setumask(spec['umask'])
    validate_options(parser, opt_count)
    update_outputprefix(parser, spec)
    update_paths(spec)
    check_inputfile(parser, spec)

    not_exit_on_interrupt()
    opts['qsub_host'] = socket.gethostname()
    opts = client_utils.component_call(SYSMGR, False, 'validate_job',(opts,))
    impl = client_utils.component_call(SYSMGR, False, 'get_implementation',())
    exit_on_interrupt()

    if impl in ['alps_system']:
        # If we're interactive, remote and go.
        if opts['mode'] == 'interactive':
            if opts.get('ssh_host', None) is not None:
                if opts['qsub_host'] != opts['ssh_host']:
                    #remote execute qsub on the ssh_host
                    client_utils.logger.info('Connecting to %s for interactive qsub...', opts['ssh_host'])
                    sys.exit(qsub_remote_host(opts['ssh_host'])) # return status from qsub-ssh

    filters = client_utils.get_filters()
    client_utils.process_filters(filters, spec)
    # Attrs needs special handling filter won't set otherwise
    if spec.get('attrs', None) is not None:
        opts['attrs'].update(ast.literal_eval(str(spec['attrs'])))
    update_spec(parser, opts, spec, opt2spec)
    run_job(parser, user, spec, opts)
Example #5
0
def main():
    """
    qsub main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    spec = {}  # map of destination option strings and parsed values
    opts = {}  # old map
    opt2spec = {}
    def_spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        (cb_debug, ()),
        (cb_interactive, ()),
        (cb_env, (opts, )),
        (cb_nodes, (False, )),  # return string
        (cb_gtzero, (False, )),  # return string
        (cb_time, (False, False,
                   False)),  # no delta time, minutes, return string
        (cb_umask, ()),
        (cb_path, (opts, True)),  # use CWD
        (cb_dep, ()),
        (cb_attrs, ()),
        (cb_mode, ()),
        (cb_user_list, (opts, )),
        (cb_geometry, (opts, ))
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    user = client_utils.getuid()

    def_spec['tag'] = 'job'
    def_spec['user'] = user
    def_spec['outputdir'] = client_utils.CWD_TAG
    def_spec['jobid'] = '*'
    def_spec['path'] = client_utils.getpath()
    def_spec['mode'] = False
    def_spec['cwd'] = client_utils.getcwd()
    def_spec['kernel'] = CN_DEFAULT_KERNEL
    def_spec['ion_kernel'] = ION_DEFAULT_KERNEL
    def_spec['queue'] = 'default'
    def_spec['umask'] = 022
    def_spec['run_project'] = False
    def_spec['user_list'] = [user]
    def_spec['procs'] = False
    def_spec['script_preboot'] = True

    parser = ArgParse(opt_def, callbacks)
    opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)
    reparse = validate_args(parser, spec)

    if reparse:
        # re-parse with new sys.argv
        # note: the first parse is necessary to make sure that
        #       the env syntax is correct for every --env option provided
        #       If not parsed prior to the union then the union could result
        #       in a valid syntax, but it would not be what the user would want.
        opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)

    client_utils.setumask(spec['umask'])
    validate_options(parser, opt_count)
    update_outputprefix(parser, spec)
    update_paths(spec)
    check_inputfile(parser, spec)

    not_exit_on_interrupt()
    opts = client_utils.component_call(SYSMGR, False, 'validate_job', (opts, ))
    exit_on_interrupt()

    filters = client_utils.get_filters()
    client_utils.process_filters(filters, spec)
    update_spec(parser, opts, spec, opt2spec)

    run_job(parser, user, spec, opts)
Example #6
0
def main():
    """
    qsub main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    spec     = {} # map of destination option strings and parsed values
    opts     = {} # old map
    opt2spec = {}
    def_spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        ( cb_debug        , () ),
        ( cb_interactive  , () ),
        ( cb_env          , (opts,) ),
        ( cb_nodes        , (False,) ), # return string
        ( cb_gtzero       , (False,) ), # return string
        ( cb_time         , (False, False, False) ), # no delta time, minutes, return string
        ( cb_umask        , () ),
        ( cb_path         , (opts, True) ), # use CWD
        ( cb_dep          , () ),
        ( cb_attrs        , () ),
        ( cb_mode         , () ),
        ( cb_user_list    , (opts,) ),
        ( cb_geometry     , (opts,) )]

    # Get the version information
    opt_def =  __doc__.replace('__revision__', __revision__)
    opt_def =  opt_def.replace('__version__', __version__)

    user = client_utils.getuid()

    def_spec['tag']            = 'job'
    def_spec['user']           = user
    def_spec['outputdir']      = client_utils.CWD_TAG
    def_spec['jobid']          = '*'
    def_spec['path']           = client_utils.getpath()
    def_spec['mode']           = False
    def_spec['cwd']            = client_utils.getcwd()
    def_spec['kernel']         = CN_DEFAULT_KERNEL
    def_spec['ion_kernel']     = ION_DEFAULT_KERNEL
    def_spec['queue']          = 'default'
    def_spec['umask']          = 022
    def_spec['run_project']    = False
    def_spec['user_list']      = [user]
    def_spec['procs']          = False
    def_spec['script_preboot'] = True

    parser    = ArgParse(opt_def, callbacks)
    opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)
    reparse  = validate_args(parser, spec)

    if reparse:
        # re-parse with new sys.argv
        # note: the first parse is necessary to make sure that
        #       the env syntax is correct for every --env option provided
        #       If not parsed prior to the union then the union could result
        #       in a valid syntax, but it would not be what the user would want.
        opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)

    client_utils.setumask(spec['umask'])
    validate_options(parser, opt_count)
    update_outputprefix(parser, spec)
    update_paths(spec)
    check_inputfile(parser, spec)

    not_exit_on_interrupt()
    opts = client_utils.component_call(SYSMGR, False, 'validate_job',(opts,))
    exit_on_interrupt()

    filters = client_utils.get_filters()
    client_utils.process_filters(filters, spec)
    update_spec(parser, opts, spec, opt2spec)

    run_job(parser, user, spec, opts)
Example #7
0
def main():
    """
    qsub main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)


    spec     = {} # map of destination option strings and parsed values
    opts     = {} # old map
    opt2spec = {}
    def_spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        ( cb_debug        , () ),
        ( cb_env          , (opts,) ),
        ( cb_nodes        , (False,) ), # return string
        ( cb_gtzero       , (False,) ), # return string
        ( cb_time         , (False, False, False) ), # no delta time, minutes, return string
        ( cb_umask        , () ),
        ( cb_path         , (opts, True) ), # use CWD
        ( cb_dep          , () ),
        ( cb_attrs        , () ),
        ( cb_mode         , () ),
        ( cb_user_list    , (opts,) ),
        ( cb_geometry     , (opts,) )]

    # Get the version information
    opt_def =  __doc__.replace('__revision__', __revision__)
    opt_def =  opt_def.replace('__version__', __version__)

    user = client_utils.getuid()

    def_spec['tag']            = 'job'
    def_spec['user']           = user
    def_spec['outputdir']      = client_utils.CWD_TAG
    def_spec['jobid']          = '*'
    def_spec['path']           = client_utils.getpath()
    def_spec['mode']           = False
    def_spec['cwd']            = client_utils.getcwd()
    def_spec['kernel']         = CN_DEFAULT_KERNEL
    def_spec['ion_kernel']     = ION_DEFAULT_KERNEL
    def_spec['queue']          = 'default'
    def_spec['umask']          = 022
    def_spec['run_project']    = False
    def_spec['user_list']      = [user]
    def_spec['procs']          = False
    def_spec['script_preboot'] = True

    parser    = ArgParse(opt_def, callbacks)
    opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)
    reparse  = validate_args(parser, spec)

    if reparse:
        # re-parse with new sys.argv
        # note: the first parse is necessary to make sure that
        #       the env syntax is correct for every --env option provided
        #       If not parsed prior to the union then the union could result
        #       in a valid syntax, but it would not be what the user would want.
        opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)

    client_utils.setumask(spec['umask'])
    validate_options(parser, opt_count)
    update_outputprefix(parser, spec)
    update_paths(spec)
    check_inputfile(parser, spec)
    opts = client_utils.component_call(SYSMGR, False, 'validate_job',(opts,))
    filters = client_utils.get_filters()
    client_utils.process_filters(filters, spec)
    update_spec(opts, spec, opt2spec)
    get_interactive_command(parser, spec, opts, opt2spec, def_spec)
    jobs = client_utils.component_call(QUEMGR, False, 'add_jobs',([spec],))

    def on_interrupt(sig, func=None):
        '''Handler to cleanup the queued 'dummy' job if the user interrupts
        qsub -I forcibly

        '''
        try:
            spec = [{'tag':'job', 'jobid':jobs[0]['jobid'], 'user':user}]
        except NameError:
            sys.exit(1)
        except:
            raise
        client_utils.logger.info("Deleting job %d", (jobs[0]['jobid']))
        del_jobs = client_utils.component_call(QUEMGR, False, 'del_jobs', (spec, False, user))
        client_utils.logger.info("%s", del_jobs)
        sys.exit(1)

    #reset sigint and sigterm interrupt handlers to deal with interactive failures
    signal.signal(signal.SIGINT, on_interrupt)
    signal.signal(signal.SIGTERM, on_interrupt)

    if parser.options.envs:
        client_utils.logger.debug("Environment Vars: %s", parser.options.envs)
    logjob(jobs[0], spec)

    # If this is an interactive job, wait for it to start, then ssh in
    if parser.options.interactive:
        headnode = ""
        query = [{'tag':'job', 'jobid':jobs[0]['jobid'], 'location':'*', 'state':"*"}]
        while True:
            response = client_utils.component_call(QUEMGR, False, 'get_jobs', (query, ))
            state = response[0]['state']
            location = response[0]['location']
            if state == 'running' and location:
                headnode = location[0]
                client_utils.logger.info("Opening ssh session to %s", headnode)
                break
            elif state != 'running' and state != 'queued' and state != 'starting':
                client_utils.logger.error("ERROR: Something went wrong with job submission, did not expect job to reach %s state.",
                        response[0]['state'])
                break
            else:
                #using Cobalt Utils sleep here
                sleep(2)
        if not headnode:
            client_utils.logger.error("Unable to determine head node for job %d", (jobs[0]['jobid']))
        else:
            try:
                os.putenv("COBALT_NODEFILE", "/var/tmp/cobalt.%s" % (response[0]['jobid']))
                os.putenv("COBALT_JOBID", "%s" % (response[0]['jobid']))
                os.system("/usr/bin/ssh -o \"SendEnv COBALT_NODEFILE COBALT_JOBID\" %s" % (headnode))
            except:
                client_utils.logger.error('Exception occurred during execution ssh session.  Job Terminated.')
        spec = [{'tag':'job', 'jobid':jobs[0]['jobid'], 'user':user}]
        jobs = client_utils.component_call(QUEMGR, False, 'del_jobs', (spec, False, user))
Example #8
0
def main():
    """
    qsub main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    spec = {}  # map of destination option strings and parsed values
    opts = {}  # old map
    opt2spec = {}
    def_spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        (cb_debug, ()),
        (cb_env, (opts, )),
        (cb_nodes, (False, )),  # return string
        (cb_gtzero, (False, )),  # return string
        (cb_time, (False, False,
                   False)),  # no delta time, minutes, return string
        (cb_umask, ()),
        (cb_path, (opts, True)),  # use CWD
        (cb_dep, ()),
        (cb_attrs, ()),
        (cb_mode, ()),
        (cb_user_list, (opts, )),
        (cb_geometry, (opts, ))
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    user = client_utils.getuid()

    def_spec['tag'] = 'job'
    def_spec['user'] = user
    def_spec['outputdir'] = client_utils.CWD_TAG
    def_spec['jobid'] = '*'
    def_spec['path'] = client_utils.getpath()
    def_spec['mode'] = False
    def_spec['cwd'] = client_utils.getcwd()
    def_spec['kernel'] = CN_DEFAULT_KERNEL
    def_spec['ion_kernel'] = ION_DEFAULT_KERNEL
    def_spec['queue'] = 'default'
    def_spec['umask'] = 022
    def_spec['run_project'] = False
    def_spec['user_list'] = [user]
    def_spec['procs'] = False
    def_spec['script_preboot'] = True

    parser = ArgParse(opt_def, callbacks)
    opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)
    reparse = validate_args(parser, spec)

    if reparse:
        # re-parse with new sys.argv
        # note: the first parse is necessary to make sure that
        #       the env syntax is correct for every --env option provided
        #       If not parsed prior to the union then the union could result
        #       in a valid syntax, but it would not be what the user would want.
        opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)

    client_utils.setumask(spec['umask'])
    validate_options(parser, opt_count)
    update_outputprefix(parser, spec)
    update_paths(spec)
    check_inputfile(parser, spec)
    opts = client_utils.component_call(SYSMGR, False, 'validate_job', (opts, ))
    filters = client_utils.get_filters()
    client_utils.process_filters(filters, spec)
    update_spec(opts, spec, opt2spec)
    get_interactive_command(parser, spec, opts, opt2spec, def_spec)
    jobs = client_utils.component_call(QUEMGR, False, 'add_jobs', ([spec], ))

    def on_interrupt(sig, func=None):
        '''Handler to cleanup the queued 'dummy' job if the user interrupts
        qsub -I forcibly

        '''
        try:
            spec = [{'tag': 'job', 'jobid': jobs[0]['jobid'], 'user': user}]
        except NameError:
            sys.exit(1)
        except:
            raise
        client_utils.logger.info("Deleting job %d", (jobs[0]['jobid']))
        del_jobs = client_utils.component_call(QUEMGR, False, 'del_jobs',
                                               (spec, False, user))
        client_utils.logger.info("%s", del_jobs)
        sys.exit(1)

    #reset sigint and sigterm interrupt handlers to deal with interactive failures
    signal.signal(signal.SIGINT, on_interrupt)
    signal.signal(signal.SIGTERM, on_interrupt)

    if parser.options.envs:
        client_utils.logger.debug("Environment Vars: %s", parser.options.envs)
    logjob(jobs[0], spec)

    # If this is an interactive job, wait for it to start, then ssh in
    if parser.options.interactive:
        headnode = ""
        query = [{
            'tag': 'job',
            'jobid': jobs[0]['jobid'],
            'location': '*',
            'state': "*"
        }]
        while True:
            response = client_utils.component_call(QUEMGR, False, 'get_jobs',
                                                   (query, ))
            state = response[0]['state']
            location = response[0]['location']
            if state == 'running' and location:
                headnode = location[0]
                client_utils.logger.info("Opening ssh session to %s", headnode)
                break
            elif state != 'running' and state != 'queued' and state != 'starting':
                client_utils.logger.error(
                    "ERROR: Something went wrong with job submission, did not expect job to reach %s state.",
                    response[0]['state'])
                break
            else:
                #using Cobalt Utils sleep here
                sleep(2)
        if not headnode:
            client_utils.logger.error(
                "Unable to determine head node for job %d", (jobs[0]['jobid']))
        else:
            try:
                os.putenv("COBALT_NODEFILE",
                          "/var/tmp/cobalt.%s" % (response[0]['jobid']))
                os.putenv("COBALT_JOBID", "%s" % (response[0]['jobid']))
                os.system(
                    "/usr/bin/ssh -o \"SendEnv COBALT_NODEFILE COBALT_JOBID\" %s"
                    % (headnode))
            except:
                client_utils.logger.error(
                    'Exception occurred during execution ssh session.  Job Terminated.'
                )
        spec = [{'tag': 'job', 'jobid': jobs[0]['jobid'], 'user': user}]
        jobs = client_utils.component_call(QUEMGR, False, 'del_jobs',
                                           (spec, False, user))