def _prepare_kwargs(reana_yaml): kwargs = {} workflow_type = reana_yaml["workflow"]["type"] if workflow_type == "serial": kwargs["specification"] = reana_yaml["workflow"].get( "specification") kwargs["parameters"] = reana_yaml.get("inputs", {}).get("parameters", {}) kwargs["original"] = True if "options" in reana_yaml.get("inputs", {}): try: reana_yaml["inputs"]["options"] = validate_operational_options( workflow_type, reana_yaml["inputs"]["options"]) except REANAValidationError as e: click.secho(e.message, err=True, fg="red") sys.exit(1) kwargs.update(reana_yaml["inputs"]["options"]) return kwargs
def _prepare_kwargs(reana_yaml): kwargs = {} workflow_type = reana_yaml["workflow"]["type"] if workflow_type == "serial": kwargs["specification"] = reana_yaml["workflow"].get( "specification") kwargs["parameters"] = reana_yaml.get("inputs", {}).get("parameters", {}) kwargs["original"] = True if "options" in reana_yaml.get("inputs", {}): try: reana_yaml["inputs"]["options"] = validate_operational_options( workflow_type, reana_yaml["inputs"]["options"]) except REANAValidationError as e: display_message(e.message, msg_type="error") sys.exit(1) kwargs.update(reana_yaml["inputs"]["options"]) if workflow_type == "snakemake": kwargs["input"] = (reana_yaml.get("inputs", {}).get("parameters", {}).get("input")) return kwargs
def workflow_restart( ctx, workflow, access_token, parameters, options, file ): # noqa: D301 """Restart previously run workflow. The ``restart`` command allows to restart a previous workflow on the same workspace. Note that workflow restarting can be used in a combination with operational options ``FROM`` and ``TARGET``. You can also pass a modified workflow specification with ``-f`` or ``--file`` flag. You can furthermore use modified input prameters using ``-p`` or ``--parameters`` flag and by setting additional operational options using ``-o`` or ``--options``. The input parameters and operational options can be repetitive. Examples: \n \t $ reana-client restart -w myanalysis.42 -p sleeptime=10 -p myparam=4 \n \t $ reana-client restart -w myanalysis.42 -p myparam=myvalue\n \t $ reana-client restart -w myanalysis.42 -o TARGET=gendata\n \t $ reana-client restart -w myanalysis.42 -o FROM=fitdata """ from reana_client.utils import get_api_url from reana_client.api.client import ( get_workflow_parameters, get_workflow_status, start_workflow, ) logging.debug("command: {}".format(ctx.command_path.replace(" ", "."))) for p in ctx.params: logging.debug("{param}: {value}".format(param=p, value=ctx.params[p])) parsed_parameters = { "input_parameters": parameters, "operational_options": options, "restart": True, } if file: parsed_parameters["reana_specification"] = load_reana_spec( click.format_filename(file) ) if workflow: if parameters or options: try: if "reana_specification" in parsed_parameters: workflow_type = parsed_parameters["reana_specification"][ "workflow" ]["type"] original_parameters = ( parsed_parameters["reana_specification"] .get("inputs", {}) .get("parameters", {}) ) else: response = get_workflow_parameters(workflow, access_token) workflow_type = response["type"] original_parameters = response["parameters"] parsed_parameters["operational_options"] = validate_operational_options( workflow_type, parsed_parameters["operational_options"] ) parsed_parameters["input_parameters"] = validate_input_parameters( parsed_parameters["input_parameters"], original_parameters ) except REANAValidationError as e: display_message(e.message, msg_type="error") sys.exit(1) except Exception as e: display_message( "Could not apply given input parameters: " "{0} \n{1}".format(parameters, str(e)), msg_type="error", ) try: logging.info("Connecting to {0}".format(get_api_url())) response = start_workflow(workflow, access_token, parsed_parameters) workflow = response["workflow_name"] + "." + str(response["run_number"]) current_status = get_workflow_status(workflow, access_token).get("status") display_message( get_workflow_status_change_msg(workflow, current_status), msg_type="success", ) except Exception as e: logging.debug(traceback.format_exc()) logging.debug(str(e)) display_message( "Cannot start workflow {}: \n{}".format(workflow, str(e)), msg_type="error", ) if "invoked_by_subcommand" in ctx.parent.__dict__: sys.exit(1)
def workflow_start( ctx, workflow, access_token, parameters, options, follow ): # noqa: D301 """Start previously created workflow. The ``start`` command allows to start previously created workflow. The workflow execution can be further influenced by passing input prameters using ``-p`` or ``--parameters`` flag and by setting additional operational options using ``-o`` or ``--options``. The input parameters and operational options can be repetitive. For example, to disable caching for the Serial workflow engine, you can set ``-o CACHE=off``. Examples: \n \t $ reana-client start -w myanalysis.42 -p sleeptime=10 -p myparam=4 \n \t $ reana-client start -w myanalysis.42 -p myparam1=myvalue1 -o CACHE=off """ from reana_client.utils import get_api_url from reana_client.api.client import ( get_workflow_parameters, get_workflow_status, start_workflow, ) logging.debug("command: {}".format(ctx.command_path.replace(" ", "."))) for p in ctx.params: logging.debug("{param}: {value}".format(param=p, value=ctx.params[p])) parsed_parameters = {"input_parameters": parameters, "operational_options": options} if workflow: if parameters or options: try: response = get_workflow_parameters(workflow, access_token) workflow_type = response["type"] original_parameters = response["parameters"] validate_operational_options( workflow_type, parsed_parameters["operational_options"] ) parsed_parameters["input_parameters"] = validate_input_parameters( parsed_parameters["input_parameters"], original_parameters ) except REANAValidationError as e: display_message(e.message, msg_type="error") sys.exit(1) except Exception as e: display_message( "Could not apply given input parameters: " "{0} \n{1}".format(parameters, str(e)), msg_type="error", ) try: logging.info("Connecting to {0}".format(get_api_url())) response = start_workflow(workflow, access_token, parsed_parameters) current_status = get_workflow_status(workflow, access_token).get("status") display_message( get_workflow_status_change_msg(workflow, current_status), msg_type="success", ) if follow: while "running" in current_status: time.sleep(TIMECHECK) current_status = get_workflow_status(workflow, access_token).get( "status" ) display_message( get_workflow_status_change_msg(workflow, current_status), msg_type="success", ) if "finished" in current_status: if follow: display_message( "Listing workflow output files...", msg_type="info", ) ctx.invoke( get_files, workflow=workflow, access_token=access_token, output_format="url", ) sys.exit(0) elif "failed" in current_status or "stopped" in current_status: sys.exit(1) except Exception as e: logging.debug(traceback.format_exc()) logging.debug(str(e)) display_message( "Cannot start workflow {}: \n{}".format(workflow, str(e)), msg_type="error", ) if "invoked_by_subcommand" in ctx.parent.__dict__: sys.exit(1)
def test_successful(workflow_type, options, option): """Test successful operational options cases.""" validated_options = validate_operational_options(workflow_type, options) assert validated_options[option]
def test_unsupported(workflow_type, options, except_msg): """Test unsupported operational options cases.""" with pytest.raises(REANAValidationError) as e: validate_operational_options(workflow_type, options) assert except_msg.format(workflow_type=workflow_type) in e.value.message
def workflow_restart(ctx, workflow, access_token, parameters, options, file): # noqa: D301 """Restart previously run workflow. The `restart` command allows to restart a previous workflow on the same workspace. Note that workflow restarting can be used in a combination with operational options ``FROM`` and ``TARGET``. You can also pass a modified workflow specification with ``-f`` or `--file`` flag. You can furthermore use modified input prameters using `-p` or `--parameters` flag and by setting additional operational options using `-o` or `--options`. The input parameters and operational options can be repetitive. Examples: \n \t $ reana-client restart -w myanalysis.42 -p sleeptime=10 -p myparam=4 \n \t $ reana-client restart -w myanalysis.42 -p myparam=myvalue\n \t $ reana-client restart -w myanalysis.42 -o TARGET=gendata\n \t $ reana-client restart -w myanalysis.42 -o FROM=fitdata """ from reana_client.utils import get_api_url from reana_client.api.client import (get_workflow_parameters, get_workflow_status, start_workflow) logging.debug('command: {}'.format(ctx.command_path.replace(" ", "."))) for p in ctx.params: logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p])) parsed_parameters = { 'input_parameters': parameters, 'operational_options': options, 'restart': True } if file: parsed_parameters['reana_specification'] = \ load_reana_spec(click.format_filename(file)) if workflow: if parameters or options: try: if 'reana_specification' in parsed_parameters: workflow_type = \ parsed_parameters['reana_specification']['workflow'][ 'type'] original_parameters = \ parsed_parameters['reana_specification'].get( 'inputs', {}).get('parameters', {}) else: response = get_workflow_parameters(workflow, access_token) workflow_type = response['type'] original_parameters = response['parameters'] parsed_parameters['operational_options'] = \ validate_operational_options( workflow_type, parsed_parameters['operational_options']) parsed_parameters['input_parameters'] = \ validate_input_parameters( parsed_parameters['input_parameters'], original_parameters) except REANAValidationError as e: click.secho(e.message, err=True, fg='red') sys.exit(1) except Exception as e: click.secho('Could not apply given input parameters: ' '{0} \n{1}'.format(parameters, str(e)), err=True) try: logging.info('Connecting to {0}'.format(get_api_url())) response = start_workflow(workflow, access_token, parsed_parameters) workflow = response['workflow_name'] + '.' + \ str(response['run_number']) current_status = get_workflow_status(workflow, access_token).get('status') click.secho(get_workflow_status_change_msg(workflow, current_status), fg='green') except Exception as e: logging.debug(traceback.format_exc()) logging.debug(str(e)) click.echo(click.style('Cannot start workflow {}: \n{}'.format( workflow, str(e)), fg='red'), err=True) if 'invoked_by_subcommand' in ctx.parent.__dict__: sys.exit(1)
def workflow_start(ctx, workflow, access_token, parameters, options, follow): # noqa: D301 """Start previously created workflow. The `start` command allows to start previously created workflow. The workflow execution can be further influenced by passing input prameters using `-p` or `--parameters` flag and by setting additional operational options using `-o` or `--options`. The input parameters and operational options can be repetitive. For example, to disable caching for the Serial workflow engine, you can set `-o CACHE=off`. Examples: \n \t $ reana-client start -w myanalysis.42 -p sleeptime=10 -p myparam=4 \n \t $ reana-client start -w myanalysis.42 -p myparam1=myvalue1 -o CACHE=off """ from reana_client.utils import get_api_url from reana_client.api.client import (get_workflow_parameters, get_workflow_status, start_workflow) logging.debug('command: {}'.format(ctx.command_path.replace(" ", "."))) for p in ctx.params: logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p])) parsed_parameters = { 'input_parameters': parameters, 'operational_options': options } if workflow: if parameters or options: try: response = get_workflow_parameters(workflow, access_token) workflow_type = response['type'] original_parameters = response['parameters'] validate_operational_options( workflow_type, parsed_parameters['operational_options']) parsed_parameters['input_parameters'] = \ validate_input_parameters( parsed_parameters['input_parameters'], original_parameters) except REANAValidationError as e: click.secho(e.message, err=True, fg='red') sys.exit(1) except Exception as e: click.secho('Could not apply given input parameters: ' '{0} \n{1}'.format(parameters, str(e)), err=True) try: logging.info('Connecting to {0}'.format(get_api_url())) response = start_workflow(workflow, access_token, parsed_parameters) current_status = get_workflow_status(workflow, access_token).get('status') click.secho(get_workflow_status_change_msg(workflow, current_status), fg='green') if follow: while 'running' in current_status: time.sleep(TIMECHECK) current_status = get_workflow_status( workflow, access_token).get('status') click.secho(get_workflow_status_change_msg( workflow, current_status), fg='green') if 'finished' in current_status: if follow: click.secho( '[INFO] Listing workflow output ' 'files...', bold=True) ctx.invoke(get_files, workflow=workflow, access_token=access_token, output_format='url') sys.exit(0) elif 'failed' in current_status or \ 'stopped' in current_status: sys.exit(1) except Exception as e: logging.debug(traceback.format_exc()) logging.debug(str(e)) click.echo(click.style('Cannot start workflow {}: \n{}'.format( workflow, str(e)), fg='red'), err=True) if 'invoked_by_subcommand' in ctx.parent.__dict__: sys.exit(1)