Exemplo n.º 1
0
def kill_workflow(experiment_id):
    """
    .. http:post:: /api/experiments/(string:experiment_id)/workflow/kill

        Kill all jobs of the currently running workflow.

        **Example response**:

        .. sourcecode:: http

            HTTP/1.1 200 OK
            Content-Type: application/json

            {
                "message": "ok"
            }

        :reqheader Authorization: JWT token issued by the server
        :statuscode 200: no error

    """
    logger.info('kill workflow for experiment %d', experiment_id)
    workflow = gc3pie.retrieve_most_recent_task(experiment_id, 'workflow')
    gc3pie.kill_task(workflow)
    return jsonify(message='ok')
Exemplo n.º 2
0
def get_job_output(experiment_id):
    '''Gets output generated by a previous submission.'''
    data = json.loads(request.data)
    project = yaml.load(data['project'])
    pipeline_description = PipelineDescription(**project['pipe']['description'])
    handles_descriptions = {
        h['name']: HandleDescriptions(**h['description'])
        for h in project['handles']
    }
    jt = ImageAnalysisPipelineEngine(
        experiment_id,
        pipeline_description=pipeline_description,
        handles_descriptions=handles_descriptions,
    )
    try:
        jobs = gc3pie.retrieve_most_recent_task(experiment_id, 'jtui')
        output = _get_output(experiment_id, jobs)
        return jsonify(output=output)
    except IndexError:
        return jsonify(output=None)
Exemplo n.º 3
0
def get_job_output(experiment_id):
    '''Gets output generated by a previous submission.'''
    data = json.loads(request.data)
    project = yaml.load(data['project'])
    pipeline_description = PipelineDescription(
        **project['pipe']['description'])
    handles_descriptions = {
        h['name']: HandleDescriptions(**h['description'])
        for h in project['handles']
    }
    jt = ImageAnalysisPipelineEngine(
        experiment_id,
        pipeline_description=pipeline_description,
        handles_descriptions=handles_descriptions,
    )
    try:
        jobs = gc3pie.retrieve_most_recent_task(experiment_id, 'jtui')
        output = _get_output(experiment_id, jobs)
        return jsonify(output=output)
    except IndexError:
        return jsonify(output=None)
Exemplo n.º 4
0
def resubmit_workflow(experiment_id):
    """
    .. http:post:: /api/experiments/(string:experiment_id)/workflow/resubmit

        Resubmit a workflow for an experiment providing a new
        :class:`WorkflowDescription <tmlib.workflow.description.WorkflowDescription>`
        in YAML format and optionally an ``index`` of a stage at which the
        workflow should be resubmitted.

        **Example request**:

        .. sourcecode:: http

            Content-Type: application/json

            {
                "description": {...},
                "index": 1
            }

        **Example response**:

        .. sourcecode:: http

            HTTP/1.1 200 OK
            Content-Type: application/json

            {
                "message": "ok",
                "submission_id": 1
            }

        :reqheader Authorization: JWT token issued by the server
        :statuscode 400: malformed request
        :statuscode 200: no error

    """
    logger.info('resubmit workflow for experiment %d', experiment_id)
    data = json.loads(request.data)
    logger.debug(
        "/experiments/%s/workflow/resubmit:"
        " Received data:\n"
        "========\n"
        "%s"
        "\n========", experiment_id, request.data)
    index = data.get('index')
    stage_name = data.get('stage_name')
    with tm.utils.ExperimentSession(experiment_id) as session:
        experiment = _retrieve_experiment_or_abort(experiment_id, session)
        if 'description' in data:
            logger.info('use provided workflow description')
            workflow_description = WorkflowDescription(**data['description'])
            experiment.persist_workflow_description(workflow_description)
        else:
            logger.info('load workflow description')
            workflow_description = experiment.workflow_description
    logger.debug(
        "/experiments/%s/workflow/resubmit:"
        " Using workflow description:\n"
        "========\n"
        "%r"
        "\n========", experiment_id, workflow_description)
    if stage_name is None and index is None:
        index = 0
    elif index is not None:
        index = int(index)
    elif stage_name is not None:
        indices = [
            i for i, d in enumerate(workflow_description.stages)
            if d.name == stage_name and d.active
        ]
        if len(indices) == 0:
            raise MalformedRequestError(
                'The specified stage "%s" does not exist or is not set active.'
                % stage_name)
        index = indices[0]
    else:
        raise MalformedRequestError(
            'Only one of the following parameters can be specified in the '
            'request body: "index", "stage_name"')
    workflow = gc3pie.retrieve_most_recent_task(experiment_id, 'workflow')
    workflow.update_description(workflow_description)
    workflow.update_stage(index)
    gc3pie.resubmit_task(workflow, index)
    return jsonify({'message': 'ok', 'submission_id': workflow.submission_id})
Exemplo n.º 5
0
def resubmit_workflow(experiment_id):
    """
    .. http:post:: /api/experiments/(string:experiment_id)/workflow/resubmit

        Resubmit a workflow for an experiment providing a new
        :class:`WorkflowDescription <tmlib.workflow.description.WorkflowDescription>`
        in YAML format and optionally an ``index`` of a stage at which the
        workflow should be resubmitted.

        **Example request**:

        .. sourcecode:: http

            Content-Type: application/json

            {
                "description": {...},
                "index": 1
            }

        **Example response**:

        .. sourcecode:: http

            HTTP/1.1 200 OK
            Content-Type: application/json

            {
                "message": "ok",
                "submission_id": 1
            }

        :reqheader Authorization: JWT token issued by the server
        :statuscode 400: malformed request
        :statuscode 200: no error

    """
    logger.info('resubmit workflow for experiment %d', experiment_id)
    data = json.loads(request.data)
    index = data.get('index')
    stage_name = data.get('stage_name')
    with tm.utils.ExperimentSession(experiment_id) as session:
        experiment = _retrieve_experiment_or_abort(experiment_id, session)
        if 'description' in data:
            logger.info('use provided workflow description')
            workflow_description = WorkflowDescription(**data['description'])
            experiment.persist_workflow_description(workflow_description)
        else:
            logger.info('load workflow description')
            workflow_description = experiment.workflow_description
    if stage_name is None and index is None:
        index = 0
    elif index is not None:
        index = int(index)
    elif stage_name is not None:
        indices = [
            i for i, d in enumerate(workflow_description.stages)
            if d.name == stage_name and d.active
        ]
        if len(indices) == 0:
            raise MalformedRequestError(
                'The specified stage "%s" does not exist or is not set active.'
                % stage_name
            )
        index = indices[0]
    else:
        raise MalformedRequestError(
            'Only one of the following parameters can be specified in the '
            'request body: "index", "stage_name"'
        )
    workflow = gc3pie.retrieve_most_recent_task(experiment_id, 'workflow')
    # sanity check -- the job daemon will report the same error, but
    # at that point it'd be too late to report to HTTP API clients
    total_stages = len(workflow.tasks)
    if index <= total_stages:
        if (index > 0 and not workflow.tasks[index-1].is_terminated):
            raise MalformedRequestError(
                'Cannot resubmit workflow from stage %d:'
                ' the preceding stage (task ID %s)'
                ' has not completed running yet.'
                % (index, workflow.tasks[index-1].persistent_id)
            )
    else:
        raise MalformedRequestError(
            'Workflow has only %d stages, cannot resubmit from stage %d'
            % (total_stages, index)
        )
    workflow.update_description(workflow_description)
    workflow.update_stage(index)
    gc3pie.resubmit_task(workflow, index)
    return jsonify({
        'message': 'ok',
        'submission_id': workflow.submission_id
    })
Exemplo n.º 6
0
def resubmit_workflow(experiment_id):
    """
    .. http:post:: /api/experiments/(string:experiment_id)/workflow/resubmit

        Resubmit a workflow for an experiment providing a new
        :class:`WorkflowDescription <tmlib.workflow.description.WorkflowDescription>`
        in YAML format and optionally an ``index`` of a stage at which the
        workflow should be resubmitted.

        **Example request**:

        .. sourcecode:: http

            Content-Type: application/json

            {
                "description": {...},
                "index": 1
            }

        **Example response**:

        .. sourcecode:: http

            HTTP/1.1 200 OK
            Content-Type: application/json

            {
                "message": "ok",
                "submission_id": 1
            }

        :reqheader Authorization: JWT token issued by the server
        :statuscode 400: malformed request
        :statuscode 200: no error

    """
    logger.info('resubmit workflow for experiment %d', experiment_id)
    data = json.loads(request.data)
    index = data.get('index')
    stage_name = data.get('stage_name')
    with tm.utils.ExperimentSession(experiment_id) as session:
        experiment = _retrieve_experiment_or_abort(experiment_id, session)
        if 'description' in data:
            logger.info('use provided workflow description')
            workflow_description = WorkflowDescription(**data['description'])
            experiment.persist_workflow_description(workflow_description)
        else:
            logger.info('load workflow description')
            workflow_description = experiment.workflow_description
    if stage_name is None and index is None:
        index = 0
    elif index is not None:
        index = int(index)
    elif stage_name is not None:
        indices = [
            i for i, d in enumerate(workflow_description.stages)
            if d.name == stage_name and d.active
        ]
        if len(indices) == 0:
            raise MalformedRequestError(
                'The specified stage "%s" does not exist or is not set active.'
                % stage_name)
        index = indices[0]
    else:
        raise MalformedRequestError(
            'Only one of the following parameters can be specified in the '
            'request body: "index", "stage_name"')
    workflow = gc3pie.retrieve_most_recent_task(experiment_id, 'workflow')
    # sanity check -- the job daemon will report the same error, but
    # at that point it'd be too late to report to HTTP API clients
    total_stages = len(workflow.tasks)
    if index <= total_stages:
        if (index > 0 and not workflow.tasks[index - 1].is_terminated):
            raise MalformedRequestError(
                'Cannot resubmit workflow from stage %d:'
                ' the preceding stage (task ID %s)'
                ' has not completed running yet.' %
                (index, workflow.tasks[index - 1].persistent_id))
    else:
        raise MalformedRequestError(
            'Workflow has only %d stages, cannot resubmit from stage %d' %
            (total_stages, index))
    workflow.update_description(workflow_description)
    workflow.update_stage(index)
    gc3pie.resubmit_task(workflow, index)
    return jsonify({'message': 'ok', 'submission_id': workflow.submission_id})