Skip to content

Commit

Permalink
Merge 1aa3b8c into 76853ed
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego committed Feb 7, 2019
2 parents 76853ed + 1aa3b8c commit 202bbbd
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 9 deletions.
43 changes: 43 additions & 0 deletions reana_client/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,46 @@ 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.
:param workflow: Workflow which workspace will be available inside the
interactive process.
:param access_token: Workflow owner REANA access token.
:param image: Image to use in the interactive process, by default it is
``jupyter/scipy-notebook``.
:param port: Port exposed by the service run inside the container spawned
with ``image``, by default ``8888`` for Jupyter notebooks.
:return: Gives the relative path to the interactive service.
"""
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['path']
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
9 changes: 3 additions & 6 deletions reana_client/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@
class Config(object):
"""Configuration object to share across commands."""

def __init__(self, client=None):
"""Initialize config variables.
:param client: :reana_commons:`reana_commons.api_client.BaseAPIClient`.
"""
self.client = client
def __init__(self):
"""Initialize config variables."""
self.reana_server_url = os.getenv('REANA_SERVER_URL', None)


@click.group()
Expand Down
41 changes: 38 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,39 @@ 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))
path = open_interactive_process(workflow, access_token)
click.secho("{reana_server_url}{path}".format(
reana_server_url=ctx.obj.reana_server_url,
path=path), 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 +864,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 202bbbd

Please sign in to comment.