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 <[email protected]>
  • Loading branch information
Diego Rodriguez committed Oct 19, 2017
1 parent 76cefc2 commit 26ee176
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 5 deletions.
29 changes: 27 additions & 2 deletions reana_client/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions reana_client/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
24 changes: 24 additions & 0 deletions reana_client/cli/analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
77 changes: 74 additions & 3 deletions reana_client/openapi_connections/reana_server.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down Expand Up @@ -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": [
{
Expand Down 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 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.",
Expand Down

0 comments on commit 26ee176

Please sign in to comment.