def workflow_create(ctx, file, name, skip_validation, access_token): # noqa: D301 """Create a new workflow. The `create` command allows to create a new workflow from reana.yaml specifications file. The file is expected to be located in the current working directory, or supplied via command-line -f option, see examples below. Examples: \n \t $ reana-client create\n \t $ reana-client create -w myanalysis\n \t $ reana-client create -w myanalysis -f myreana.yaml\n """ logging.debug('command: {}'.format(ctx.command_path.replace(" ", "."))) for p in ctx.params: logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p])) # Check that name is not an UUIDv4. # Otherwise it would mess up `--workflow` flag usage because no distinction # could be made between the name and actual UUID of workflow. if is_uuid_v4(name): click.echo(click.style('Workflow name cannot be a valid UUIDv4', fg='red'), err=True) if not access_token: click.echo(click.style(ERROR_MESSAGES['missing_access_token'], fg='red'), err=True) sys.exit(1) try: reana_specification = load_reana_spec(click.format_filename(file), skip_validation) logging.info('Connecting to {0}'.format( current_rs_api_client.swagger_spec.api_url)) response = create_workflow(reana_specification, name, access_token) click.echo(click.style(response['workflow_name'], fg='green')) # check if command is called from wrapper command if 'invoked_by_subcommand' in ctx.parent.__dict__: ctx.parent.workflow_name = response['workflow_name'] except Exception as e: logging.debug(traceback.format_exc()) logging.debug(str(e)) click.echo(click.style('Workflow could not be created: \n{}'.format( str(e)), fg='red'), err=True) if 'invoked_by_subcommand' in ctx.parent.__dict__: sys.exit(1)
def workflow_create(ctx, file, name, skip_validation, access_token): # noqa: D301 """Create a new workflow. The `create` command allows to create a new workflow from reana.yaml specifications file. The file is expected to be located in the current working directory, or supplied via command-line -f option, see examples below. Examples: \n \t $ reana-client create\n \t $ reana-client create -w myanalysis\n \t $ reana-client create -w myanalysis -f myreana.yaml\n """ from reana_client.api.client import create_workflow 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])) # Check that name is not an UUIDv4. # Otherwise it would mess up `--workflow` flag usage because no distinction # could be made between the name and actual UUID of workflow. if is_uuid_v4(name): click.echo(click.style("Workflow name cannot be a valid UUIDv4", fg="red"), err=True) try: reana_specification = load_reana_spec(click.format_filename(file), skip_validation) logging.info("Connecting to {0}".format(get_api_url())) response = create_workflow(reana_specification, name, access_token) click.echo(click.style(response["workflow_name"], fg="green")) # check if command is called from wrapper command if "invoked_by_subcommand" in ctx.parent.__dict__: ctx.parent.workflow_name = response["workflow_name"] except Exception as e: logging.debug(traceback.format_exc()) logging.debug(str(e)) click.echo( click.style("Cannot create workflow {}: \n{}".format(name, str(e)), fg="red"), err=True, ) if "invoked_by_subcommand" in ctx.parent.__dict__: sys.exit(1)
def workflow_create(ctx, file, name, skip_validation, access_token): """Create a REANA compatible workflow from REANA spec file.""" logging.debug('command: {}'.format(ctx.command_path.replace(" ", "."))) for p in ctx.params: logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p])) # Check that name is not an UUIDv4. # Otherwise it would mess up `--workflow` flag usage because no distinction # could be made between the name and actual UUID of workflow. if is_uuid_v4(name): click.echo( click.style('Workflow name cannot be a valid UUIDv4', fg='red'), err=True) if not access_token: click.echo( click.style(ERROR_MESSAGES['missing_access_token'], fg='red'), err=True) sys.exit(1) try: reana_specification = load_reana_spec(click.format_filename(file), skip_validation) logging.info('Connecting to {0}'.format( current_rs_api_client.swagger_spec.api_url)) response = create_workflow(reana_specification, name, access_token) click.echo(click.style(response['workflow_name'], fg='green')) # check if command is called from wrapper command if 'invoked_by_subcommand' in ctx.parent.__dict__: ctx.parent.workflow_name = response['workflow_name'] except Exception as e: logging.debug(traceback.format_exc()) logging.debug(str(e)) click.echo( click.style('Workflow could not be created: \n{}' .format(str(e)), fg='red'), err=True) if 'invoked_by_subcommand' in ctx.parent.__dict__: sys.exit(1)
def create_workflow_from_json( name, access_token, workflow_json=None, workflow_file=None, parameters=None, workflow_engine="yadage", outputs=None, ): """Create a workflow from json specification. :param name: name or UUID of the workflow to be started. :param access_token: access token of the current user. :param workflow_json: workflow specification in json format. :param workflow_file: workflow specification file path. Ignores ``workflow_json`` if provided. :param parameters: workflow input parameters dictionary. :param workflow_engine: one of the workflow engines (yadage, serial, cwl) :param outputs: dictionary with expected workflow outputs. :Example: .. code:: python create_workflow_from_json( workflow_json=workflow_json, name='workflow_name.1', access_token='access_token', parameters={'files': ['file.txt'], 'parameters': {'key': 'value'}}, workflow_engine='serial') """ validate_workflow_name(name) if is_uuid_v4(name): raise ValueError("Workflow name cannot be a valid UUIDv4") if not access_token: raise Exception(ERROR_MESSAGES["missing_access_token"]) if os.environ.get("REANA_SERVER_URL") is None: raise Exception("Environment variable REANA_SERVER_URL is not set") workflow_engine = workflow_engine.lower() if workflow_engine not in REANA_WORKFLOW_ENGINES: raise Exception("Workflow engine - {} not found. You must use one of " "these engines - {}".format(workflow_engine, REANA_WORKFLOW_ENGINES)) try: reana_yaml = dict(workflow={}) if workflow_file: reana_yaml["workflow"]["file"] = workflow_file else: reana_yaml["workflow"]["specification"] = workflow_json reana_yaml["workflow"]["type"] = workflow_engine if parameters: reana_yaml["inputs"] = parameters if outputs: reana_yaml["outputs"] = outputs _validate_reana_yaml(reana_yaml) reana_specification = reana_yaml (response, http_response) = current_rs_api_client.api.create_workflow( reana_specification=json.loads( json.dumps(reana_specification, sort_keys=True)), workflow_name=name, access_token=access_token, ).result() if http_response.status_code == 201: return response else: raise Exception( "Expected status code 201 but replied with " "{status_code}".format(status_code=http_response.status_code)) except HTTPError as e: logging.debug("Workflow creation failed: " "\nStatus: {}\nReason: {}\n" "Message: {}".format(e.response.status_code, e.response.reason, e.response.json()["message"])) raise Exception(e.response.json()["message"]) except Exception as e: raise e
def create_workflow_from_json(workflow_json, name, access_token, parameters=None, workflow_engine='yadage', outputs=None): """Create a workflow from json specification. :param workflow_json: workflow specification in json format. :param name: name or UUID of the workflow to be started. :param access_token: Access token of the current user. :param parameters: workflow input parameters dictionary. :param workflow_engine: one of the workflow engines (yadage, serial, cwl) :param outputs: dictionary with expected workflow outputs. :Example: .. code:: python create_workflow_from_json( workflow_json=workflow_json, name='workflow_name.1', access_token='access_token', parameters={'files': ['file.txt'], 'parameters': {'key': 'value'}}, workflow_engine='serial') """ if is_uuid_v4(name): raise ValueError('Workflow name cannot be a valid UUIDv4') if not access_token: raise Exception(ERROR_MESSAGES['missing_access_token']) if os.environ.get('REANA_SERVER_URL') is None: raise Exception('Environment variable REANA_SERVER_URL is not set') workflow_engine = workflow_engine.lower() if workflow_engine not in WORKFLOW_ENGINES: raise Exception('Workflow engine - {} not found. You must use one of ' 'these engines - {}'.format(workflow_engine, WORKFLOW_ENGINES)) try: reana_yaml = {} reana_yaml['workflow'] = {'specification': workflow_json} reana_yaml['workflow']['type'] = workflow_engine if parameters: reana_yaml['inputs'] = parameters if outputs: reana_yaml['outputs'] = outputs _validate_reana_yaml(reana_yaml) reana_specification = reana_yaml (response, http_response) = current_rs_api_client.api.create_workflow( reana_specification=json.loads(json.dumps( reana_specification, sort_keys=True)), workflow_name=name, access_token=access_token).result() if http_response.status_code == 201: return response else: raise Exception( "Expected status code 201 but replied with " "{status_code}".format( status_code=http_response.status_code)) except HTTPError as e: logging.debug( 'Workflow creation failed: ' '\nStatus: {}\nReason: {}\n' 'Message: {}'.format(e.response.status_code, e.response.reason, e.response.json()['message'])) raise Exception(e.response.json()['message']) except Exception as e: raise e