Skip to content

Commit

Permalink
Merge 605f2da into d5dc320
Browse files Browse the repository at this point in the history
  • Loading branch information
roksys committed Nov 9, 2018
2 parents d5dc320 + 605f2da commit 43d8379
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
27 changes: 27 additions & 0 deletions reana_client/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,30 @@ def upload_to_server(self, workflow, paths, access_token):
logging.debug(str(e))
logging.info("Something went wrong while uploading {}".
format(fname))

def get_workflow_parameters(self, workflow, access_token):
"""Get parameters of previously created workflow."""
try:
response, http_response = self.\
_client.api.get_workflow_parameters(
workflow_id_or_name=workflow,
access_token=access_token)\
.result()
if http_response.status_code == 200:
return response
else:
raise Exception(
"Expected status code 200 but replied with "
"{status_code}".format(
status_code=http_response.status_code))

except HTTPError as e:
logging.debug(
'Workflow parameters could not be retrieved: '
'\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
46 changes: 42 additions & 4 deletions reana_client/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
from reana_client.cli.utils import add_access_token_options
from reana_client.cli.files import upload_files

from reana_client.cli.files import upload_files

from reana_db.database import Session
from reana_db.models import Workflow


class _WorkflowStatus(Enum):
created = 0
Expand Down Expand Up @@ -215,9 +220,16 @@ def workflow_create(ctx, file, name, skip_validation, access_token):
help='Optional operational parameters for the workflow execution. '
'E.g. CACHE=off.',
)
@click.option(
'-wp', '--workflow-parameter',
multiple=True,
help='Workflow specification parameters to be overriden. '
'E.g. inputfile=new_input.txt.',
)
@click.pass_context
@with_api_client
def workflow_start(ctx, workflow, access_token, parameter): # noqa: D301
def workflow_start(ctx, workflow, access_token,
parameter, workflow_parameter): # noqa: D301
"""Start previously created workflow."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
Expand All @@ -229,15 +241,41 @@ def workflow_start(ctx, workflow, access_token, parameter): # noqa: D301
fg='red'), err=True)
sys.exit(1)

parsed_parameters = {'parameters':
dict(p.split('=') for p in parameter)}
parameters = {'operational_parameters':
dict(p.split('=') for p in parameter)}
new_input_parameters = dict()
if workflow_parameter:
try:
import wdb
wdb.set_trace()
parsed_wf_parameters = \
dict(p.split('=') for p in workflow_parameter)
response = \
ctx.obj.client.get_workflow_parameters(workflow,
access_token)
new_input_parameters = dict(response['parameters'])
for parameter, value in parsed_wf_parameters.items():
if parameter in new_input_parameters:
new_input_parameters[parameter] = value
else:
click.echo(
click.style('Given parameter - {0}, does not exist in '
'original parameters'.format(parameter),
fg='red'),
err=True)
if new_input_parameters == response['parameters']:
# if none parameters are overriden, we will send empty dict
new_input_parameters = dict()
parameters['input_parameters'] = new_input_parameters
except Exception as e:
click.echo("")

if workflow:
try:
logging.info('Connecting to {0}'.format(ctx.obj.client.server_url))
response = ctx.obj.client.start_workflow(workflow,
access_token,
parsed_parameters)
parameters)
click.echo(
click.style('{} has been started.'.format(workflow),
fg='green'))
Expand Down

0 comments on commit 43d8379

Please sign in to comment.