Skip to content

Commit

Permalink
cli: add analysis seeding option
Browse files Browse the repository at this point in the history
* 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 <diego.rodriguez@cern.ch>
  • Loading branch information
Diego Rodriguez committed Oct 12, 2017
1 parent fba265b commit 2cd4c7e
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 1 deletion.
22 changes: 22 additions & 0 deletions reana_client/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,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
1 change: 1 addition & 0 deletions reana_client/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ def cli(ctx, loglevel):
cli.add_command(ping.ping)
cli.add_command(analyses.list_)
cli.add_command(analyses.run)
cli.add_command(analyses.seed)
24 changes: 24 additions & 0 deletions reana_client/cli/analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,27 @@ def run(ctx, user, organization):

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))
73 changes: 72 additions & 1 deletion reana_client/openapi_connections/reana_server.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 to 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.",
Expand Down Expand Up @@ -179,4 +250,4 @@
},
"swagger": "2.0",
"tags": []
}
}

0 comments on commit 2cd4c7e

Please sign in to comment.