Example #1
0
def status():
    """
    Main status function.
    Gets the status of the requested job identifier and prints it
    through stdout.
    :return: None
    """
    if VERBOSE:
        print("Checking status PyCOMPSs interactive job...")

    # Get command line arguments
    job_id = sys.argv[1]

    if VERBOSE:
        print(" - Job: " + str(job_id))

    # Load the Supercomputer configuration to get the appropriate status command
    setup_supercomputer_configuration()

    # Get the job status
    job_status, return_code = get_job_status(job_id)

    if VERBOSE:
        print("Finished checking status.")

    # Print to notify the status result
    if return_code != 0:
        print(ERROR_KEYWORD)
        exit(1)
    else:
        print(SUCCESS_KEYWORD)
        print("STATUS:" + job_status)
Example #2
0
def cancel():
    """
    Main cancel function.
    Gets the cancel command from the environment variable (defined in supercomputer cfgs)
    and includes the job identifiers to be cancelled.
    :return: None
    """
    if VERBOSE:
        print("Cancelling PyCOMPSs interactive job...")

    # Get command line arguments
    job_ids = sys.argv[1:]

    # Load the Supercomputer configuration to get the appropriate cancel command
    setup_supercomputer_configuration()

    success = True
    # There might be more than one to cancel
    for job_id in job_ids:
        if VERBOSE:
            print(" - Job: " + str(job_id))

        # Check if the job_id belongs to a notebook before continuing
        if not is_notebook_job(job_id):
            not_a_notebook(job_id)

        # Get the command to cancel the job
        raw_cancel_command = os.environ['QUEUE_JOB_CANCEL_CMD']
        cancel_command = update_command(raw_cancel_command, job_id)

        # Cancel the job
        return_code, _, _ = command_runner(cancel_command)

        if return_code != 0:
            success = False

    if VERBOSE:
        print("Finished cancellation.")

    # Print to notify the cancel result
    if success:
        print(SUCCESS_KEYWORD)
    else:
        print(ERROR_KEYWORD)
        exit(1)
Example #3
0
File: find.py Project: mF2C/compss
def find():
    """
    Main find function.
    Gets the jobs list command from the environment variable (defined in supercomputer cfgs)
    and runs it. It also gets each job identifier name and status to provide more information
    to the users.
    :return: None
    """
    if VERBOSE:
        print("Looking for PyCOMPSs interactive jobs...")

    # Load the Supercomputer configuration to get the appropriate status command
    setup_supercomputer_configuration()

    # Get the list of running job ids
    job_list_command = os.environ['QUEUE_JOB_LIST_CMD']
    return_code, raw_job_ids, _ = command_runner(job_list_command.split())
    job_ids = raw_job_ids.splitlines()

    # Filter the jobs (keep only the notebook related ones)
    notebook_jobs = []
    for job_id in job_ids:
        name = get_job_name(job_id).strip()
        if verify_job_name(name):
            status, _ = get_job_status(job_id)
            notebook_jobs.append((job_id, status, name))

    if VERBOSE:
        print("Finished looking for jobs.")

    # Print to notify the find result
    if return_code != 0:
        print(ERROR_KEYWORD)
        exit(1)
    else:
        # Print to provide the list of jobs to the client
        print(SUCCESS_KEYWORD)
        for job_id, status, name in notebook_jobs:
            print(str(job_id) + '\t- ' + str(status) + '\t- ' + str(name))
Example #4
0
def info():
    """
    Main info function.
    Gets the information command from the jupyter server (master node and url)
    and prints it through stdout. So that the client can get it, parse and
    connect to the running notebook.
    :return: None
    """
    if VERBOSE:
        print("Checking information of PyCOMPSs interactive job...")

    # Get command line arguments
    job_id = sys.argv[1]

    if VERBOSE:
        print(" - Job: " + str(job_id))

    # Load the Supercomputer configuration to get the appropriate status command
    setup_supercomputer_configuration()

    # Check if the job_id belongs to a notebook before continuing
    if not is_notebook_job(job_id):
        not_a_notebook(job_id)

    # Get the list of nodes
    raw_nodes_command = os.environ['QUEUE_JOB_NODES_CMD']
    nodes_command = update_command(raw_nodes_command, job_id)
    return_code, nodes, _ = command_runner(nodes_command)
    if return_code != 0:
        print(ERROR_KEYWORD)
        exit(1)

    # Look for the master node
    if nodes.strip():
        nodes_expansor = os.environ['HOSTLIST_CMD'] + ' ' + nodes
        _, expanded_nodes, _ = command_runner(nodes_expansor.split())
        expanded_nodes = expanded_nodes.splitlines()
        master = expanded_nodes[0]

        if VERBOSE:
            print(" - Nodes: " + str(expanded_nodes))
            print(" - Found master: " + str(master))

        # Get the command to contact with the node where the job is running
        server_list = os.environ[
            'CONTACT_CMD'] + ' ' + master + " jupyter-notebook list"
        return_code, jupyter_server_list, _ = command_runner(
            server_list.split())

        if VERBOSE:
            print("Finished checking the information.")

        # Print to notify the info result
        if return_code != 0:
            print(ERROR_KEYWORD)
            exit(1)
        else:
            print(SUCCESS_KEYWORD)
            print("MASTER:" + str(master))
            print("SERVER: " + str(jupyter_server_list.replace('\n', ' ')))
    else:
        # Print to provide information to the client
        print(NOT_RUNNING_KEYWORD)  # The notebook is not ready yet
        exit(1)
Example #5
0
def info():
    """
    Main info function.
    Gets the information command from the jupyter server (master node and url)
    and prints it through stdout. So that the client can get it, parse and
    connect to the running notebook.
    :return: None
    """
    if VERBOSE:
        print("Checking information of PyCOMPSs interactive job...")

    # Get command line arguments
    job_id = sys.argv[1]
    app_path = sys.argv[2]

    if VERBOSE:
        print(" - Job: " + str(job_id))

    # Load the Supercomputer configuration to get the appropriate status command
    setup_supercomputer_configuration()

    # Get the list of nodes
    raw_nodes_command = os.environ['QUEUE_JOB_NODES_CMD']
    nodes_command = update_command(raw_nodes_command, job_id)
    return_code, nodes, _ = command_runner(nodes_command)
    if return_code != 0:
        print(ERROR_KEYWORD)
        exit(1)

    # Look for the master node
    if nodes.strip():
        nodes_expansor = os.environ['HOSTLIST_CMD'] + ' ' + nodes
        _, expanded_nodes, _ = command_runner(nodes_expansor.split())
        expanded_nodes = expanded_nodes.splitlines()
        master = expanded_nodes[0]

        if VERBOSE:
            print(" - Nodes: " + str(expanded_nodes))
            print(" - Found master: " + str(master))

        jpy_server_out = ''
        timeout = time.time() + 60 * 2
        jup_out_file = f'{app_path}/compss-{job_id}.err'
        while 'The Jupyter Notebook is running at' not in jpy_server_out:
            if time.time() > timeout:
                print(ERROR_KEYWORD)
                exit(1)
            if os.path.isfile(jup_out_file):
                with open(jup_out_file, 'r') as of:
                    jpy_server_out = of.read()

        if VERBOSE:
            print("Finished checking the information.")

        # Print to notify the info result
        print(SUCCESS_KEYWORD)
        print("MASTER:" + str(master))
        print("SERVER: " + str(jpy_server_out.replace('\n', ' ')))
    else:
        # Print to provide information to the client
        print(NOT_RUNNING_KEYWORD)  # The notebook is not ready yet
        exit(1)