From 26ee1761cb4ab8a73e95be10e055e6dc96948cf1 Mon Sep 17 00:00:00 2001 From: Diego Rodriguez Date: Fri, 6 Oct 2017 14:09:02 +0200 Subject: [PATCH] cli: add analysis seeding option * Adds a redundant field `file_name` since bravado client doesn't propagate the file name. Waiting for Yelp/bravado-core#201 to be implemented. Signed-off-by: Diego Rodriguez --- reana_client/api/client.py | 29 ++++++- reana_client/cli/__init__.py | 1 + reana_client/cli/analyses.py | 24 ++++++ .../openapi_connections/reana_server.json | 77 ++++++++++++++++++- 4 files changed, 126 insertions(+), 5 deletions(-) diff --git a/reana_client/api/client.py b/reana_client/api/client.py index 85ba5f20..510fbb28 100644 --- a/reana_client/api/client.py +++ b/reana_client/api/client.py @@ -43,9 +43,12 @@ def __init__(self, server_url): def _get_spec(self, spec_file): """Get json specification from package data.""" spec_file_path = os.path.join( - pkg_resources.resource_filename('reana_client', - 'openapi_connections'), + pkg_resources. + resource_filename( + 'reana_client', + 'openapi_connections'), spec_file) + with open(spec_file_path) as f: json_spec = json.load(f) return json_spec @@ -101,3 +104,25 @@ def run_analysis(self, user, organization, reana_spec): except Exception: raise + + def seed_analysis(self, user, organization, analysis_id, file_, file_name): + """Seed analysis with file.""" + try: + (response, + http_response) = self._client.api.seed_analysis( + user=user, + organization=organization, + analysis_id=analysis_id, + file_content=file_, + file_name=file_name).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 Exception: + raise diff --git a/reana_client/cli/__init__.py b/reana_client/cli/__init__.py index 735396be..8b218001 100644 --- a/reana_client/cli/__init__.py +++ b/reana_client/cli/__init__.py @@ -65,3 +65,4 @@ def cli(ctx, loglevel): cli.add_command(analyses.list_) cli.add_command(analyses.run) cli.add_command(analyses.validate) +cli.add_command(analyses.seed) diff --git a/reana_client/cli/analyses.py b/reana_client/cli/analyses.py index 35b7e5d4..c6a1d734 100644 --- a/reana_client/cli/analyses.py +++ b/reana_client/cli/analyses.py @@ -100,3 +100,27 @@ def run(ctx, file, user, organization, skip_validation): except Exception as e: logging.debug(str(e)) + + +@click.command() +@click.option('-u', '--user', default='00000000-0000-0000-0000-000000000000', + help='User who submits the analysis.') +@click.option('-o', '--organization', default='default', + help='Organization which resources will be used.') +@click.option('-a', '--analysis', + help='UUID which identifies the analysis to be seeded.') +@click.argument('file_', type=click.File('rb')) +@click.pass_context +def seed(ctx, user, organization, analysis, file_): + """Seed files to analysis workspace.""" + try: + response = ctx.obj.client.seed_analysis( + user, + organization, + analysis, + file_, + file_.name) + click.echo(response) + + except Exception as e: + logging.debug(str(e)) diff --git a/reana_client/openapi_connections/reana_server.json b/reana_client/openapi_connections/reana_server.json index 9a3a6db2..ab1e7820 100644 --- a/reana_client/openapi_connections/reana_server.json +++ b/reana_client/openapi_connections/reana_server.json @@ -9,7 +9,7 @@ "paths": { "/api/analyses": { "get": { - "description": "This resource return all analyses in JSON format.", + "description": "This resource return all current analyses in JSON format.", "produces": [ "application/json" ], @@ -74,13 +74,13 @@ } } }, - "summary": "Returns list of all analyses." + "summary": "Returns list of all current analyses in REANA." }, "post": { "consumes": [ "application/json" ], - "description": "This resource is expecting JSON data with all the necessary informations to instantiate a yadage workflow.", + "description": "This resource is expecting JSON data with all the necessary information to instantiate a yadage workflow.", "operationId": "create_analysis", "parameters": [ { @@ -145,6 +145,77 @@ "summary": "Creates a new yadage workflow." } }, + "/api/analyses/{analysis_id}/workspace": { + "post": { + "consumes": [ + "multipart/form-data" + ], + "description": "This resource expects a file which will be placed in the analysis workspace identified by the UUID `analysis_id`.", + "operationId": "seed_analysis", + "parameters": [ + { + "description": "Required. Organization which the analysis belongs to.", + "in": "query", + "name": "organization", + "required": true, + "type": "string" + }, + { + "description": "Required. UUID of analysis owner.", + "in": "query", + "name": "user", + "required": true, + "type": "string" + }, + { + "description": "Required. Analysis UUID.", + "in": "path", + "name": "analysis_id", + "required": true, + "type": "string" + }, + { + "description": "Required. File to be transferred to the analysis workspace.", + "in": "formData", + "name": "file_content", + "required": true, + "type": "file" + }, + { + "description": "Required. File name.", + "in": "query", + "name": "file_name", + "required": true, + "type": "string" + } + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Request succeeded. File successfully trasferred.", + "examples": { + "application/json": { + "message": "File successfully transferred" + } + }, + "schema": { + "properties": { + "message": { + "type": "string" + } + }, + "type": "object" + } + }, + "400": { + "description": "Request failed. The incoming data specification seems malformed" + } + }, + "summary": "Seeds the analysis workspace with the provided file." + } + }, "/api/ping": { "get": { "description": "Ping the server.",