Esempio n. 1
0
def workflow_delete(ctx, workflow, all_runs, workspace, hard_delete,
                    access_token):
    """Delete a workflow run given the workflow name and run number."""
    logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
    for p in ctx.params:
        logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p]))

    if not access_token:
        click.echo(click.style(ERROR_MESSAGES['missing_access_token'],
                               fg='red'),
                   err=True)
        sys.exit(1)

    if workflow:
        try:
            logging.info('Connecting to {0}'.format(
                current_rs_api_client.swagger_spec.api_url))
            response = delete_workflow(workflow, all_runs, hard_delete,
                                       workspace, access_token)
            if all_runs:
                message = 'All workflows named \'{}\' have been deleted.'.\
                    format(workflow.split('.')[0])
            else:
                message = get_workflow_status_change_msg(workflow, 'deleted')
            click.secho(message, fg='green')

        except Exception as e:
            logging.debug(traceback.format_exc())
            logging.debug(str(e))
            click.echo(click.style(
                'Workflow could not be deleted: \n{}'.format(str(e)),
                fg='red'),
                       err=True)
Esempio n. 2
0
def workflow_delete(ctx, workflow, all_runs, workspace,
                    access_token):  # noqa: D301
    """Delete a workflow.

    The `delete` command allows to remove workflow runs from the database and
    the workspace. By default, the command removes the workflow and all its
    cached information and hides the workflow from the workflow list. Note that
    workflow workspace will still be accessible until you use
    `--include-workspace` flag. Note also that you can remove all past runs of
    a workflow by specifying `--include-all-runs` flag.

    Example: \n
    \t $ reana-client delete -w myanalysis.42 \n
    \t $ reana-client delete -w myanalysis.42 --include-all-runs \n
    \t $ reana-client delete -w myanalysis.42 --include-workspace
    """
    from reana_client.api.client import delete_workflow, get_workflow_status
    from reana_client.utils import get_api_url

    logging.debug("command: {}".format(ctx.command_path.replace(" ", ".")))
    for p in ctx.params:
        logging.debug("{param}: {value}".format(param=p, value=ctx.params[p]))

    if workflow:
        try:
            logging.info("Connecting to {0}".format(get_api_url()))
            delete_workflow(workflow, all_runs, workspace, access_token)
            if all_runs:
                message = "All workflows named '{}' have been deleted.".format(
                    workflow.split(".")[0])
            else:
                message = get_workflow_status_change_msg(workflow, "deleted")
            click.secho(message, fg="green")

        except Exception as e:
            logging.debug(traceback.format_exc())
            logging.debug(str(e))
            click.echo(
                click.style("Cannot delete workflow {} \n{}".format(
                    workflow, str(e)),
                            fg="red"),
                err=True,
            )
def delete_reana_workflow(workflow_id, workflow=None):
    """Delete a workflow."""
    rec_uuid = resolve_uuid(workflow_id)
    token = get_reana_token(rec_uuid)

    try:
        # all_runs, hard_delete and workspace
        resp = delete_workflow(workflow_id, 0, 1, 1, token)
        update_workflow(workflow_id, 'status', 'deleted')
        return jsonify(resp)
    except Exception:
        return jsonify({
            'message':
            'Workflow {} does not exist. Aborting '
            'deletion.'.format(workflow_id)
        }), 400
Esempio n. 4
0
def workflow_delete(ctx, workflow, all_runs, workspace, hard_delete,
                    access_token):  # noqa: D301
    """Delete a workflow.

    The `delete` command allows to remove workflow runs from the database and
    the workspace. By default, the command removes the workflow and all its
    cached information and hides the workflow from the workflow list. Note that
    workflow workspace will still be accessible until you use
    `--include-workspace` flag. Note also that you can remove all past runs of
    a workflow by specifying `--include-all-runs` flag.

    Example: \n
    \t $ reana-client delete -w myanalysis.42 \n
    \t $ reana-client delete -w myanalysis.42 --include-records
    """
    logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
    for p in ctx.params:
        logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p]))

    if not access_token:
        click.echo(click.style(ERROR_MESSAGES['missing_access_token'],
                               fg='red'),
                   err=True)
        sys.exit(1)

    if workflow:
        try:
            logging.info('Connecting to {0}'.format(
                current_rs_api_client.swagger_spec.api_url))
            response = delete_workflow(workflow, all_runs, hard_delete,
                                       workspace, access_token)
            if all_runs:
                message = 'All workflows named \'{}\' have been deleted.'.\
                    format(workflow.split('.')[0])
            else:
                message = get_workflow_status_change_msg(workflow, 'deleted')
            click.secho(message, fg='green')

        except Exception as e:
            logging.debug(traceback.format_exc())
            logging.debug(str(e))
            click.echo(click.style(
                'Workflow could not be deleted: \n{}'.format(str(e)),
                fg='red'),
                       err=True)