Skip to content

Commit

Permalink
Merge b6bdf62 into 76853ed
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego committed Feb 6, 2019
2 parents 76853ed + b6bdf62 commit 1e75795
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
32 changes: 32 additions & 0 deletions reana_client/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,35 @@ def diff_workflows(workflow_id_a, workflow_id_b,
raise Exception(e.response.json()['message'])
except Exception as e:
raise e


def open_interactive_process(workflow, access_token, image=None, port=None):
"""Open an interactive process on the workflow workspace."""
try:
interactive_environment = {}
if image:
interactive_environment['image'] = image
if port:
interactive_environment['port'] = port
(response, http_response) = current_rs_api_client.api\
.open_interactive_process(
workflow_id_or_name=workflow,
access_token=access_token,
interactive_environment=interactive_environment).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 run could not be stopped: '
'\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
39 changes: 36 additions & 3 deletions reana_client/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
get_workflow_logs,
get_workflow_parameters,
get_workflow_status, get_workflows,
start_workflow, stop_workflow)
open_interactive_process, start_workflow,
stop_workflow)
from reana_client.cli.files import upload_files
from reana_client.cli.utils import (add_access_token_options, filter_data,
parse_parameters)
from reana_client.config import ERROR_MESSAGES, reana_yaml_default_file_path
from reana_client.utils import (get_workflow_status_change_msg,
get_workflow_name_and_run_number, is_uuid_v4,
from reana_client.utils import (get_workflow_name_and_run_number,
get_workflow_status_change_msg, is_uuid_v4,
load_reana_spec,
validate_cwl_operational_options,
validate_input_parameters,
Expand Down Expand Up @@ -820,6 +821,37 @@ def print_color_diff(lines):
err=True)


@click.command(
'open',
help='Open an interactive process in the workflow workspace')
@click.argument(
'workflow',
default=os.environ.get('REANA_WORKON', None),
callback=workflow_uuid_or_name)
@add_access_token_options
@click.pass_context
def workflow_open_interactive_process(ctx, workflow, access_token):
"""Open an interactive process on the workflow workspace."""
if not access_token:
click.secho(
ERROR_MESSAGES['missing_access_token'], fg='red', err=True)
sys.exit(1)
if workflow:
try:
logging.info(
"Opening an interactive process on {}".format(workflow))
response = open_interactive_process(workflow, access_token)
click.secho(response, fg="green")
except Exception as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
click.secho("Interactive process could not be opened: \n{}"
.format(str(e)), fg='red', err=True)
else:
# create workflow if it does not exist.
pass


workflow.add_command(workflow_workflows)
workflow.add_command(workflow_create)
workflow.add_command(workflow_start)
Expand All @@ -830,3 +862,4 @@ def print_color_diff(lines):
workflow.add_command(workflow_delete)
workflow.add_command(workflow_diff)
workflow.add_command(workflow_logs)
workflow.add_command(workflow_open_interactive_process)

0 comments on commit 1e75795

Please sign in to comment.