Skip to content

Commit

Permalink
api: modify create analysis endpoint
Browse files Browse the repository at this point in the history
* Updates to lastest `rwc` OpenAPI version.

* Create analysis doens't start the workflow straight away, now it creates it in DB
  and bootstraps the working space (closes reanahub#13).

Signed-off-by: Diego Rodriguez <diego.rodriguez@cern.ch>
  • Loading branch information
Diego Rodriguez committed Oct 28, 2017
1 parent 62300ad commit ae186f1
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 30 deletions.
10 changes: 5 additions & 5 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"consumes": [
"application/json"
],
"description": "This resource is expecting JSON data with all the necessary information to instantiate a yadage workflow.",
"description": "This resource is expecting a REANA specification in JSON format with all the necessary information to instantiate a workflow.",
"operationId": "create_analysis",
"parameters": [
{
Expand Down Expand Up @@ -119,10 +119,10 @@
],
"responses": {
"200": {
"description": "Request succeeded. The workflow has been instantiated.",
"description": "Request succeeded. The workflow has been created.",
"examples": {
"application/json": {
"message": "Analysis successfully launched",
"message": "The workflow has been successfully created.",
"workflow_id": "cdcf48b1-c2f3-4693-8230-b066e088c6ac"
}
},
Expand All @@ -142,7 +142,7 @@
"description": "Request failed. The incoming data specification seems malformed"
}
},
"summary": "Creates a new yadage workflow."
"summary": "Creates a new workflow based on a REANA specification file."
}
},
"/api/analyses/{analysis_id}/workspace": {
Expand Down Expand Up @@ -250,4 +250,4 @@
},
"swagger": "2.0",
"tags": []
}
}
94 changes: 92 additions & 2 deletions reana_server/openapi_connections/reana_workflow_controller.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@
"400": {
"description": "Request failed. The incoming data specification seems malformed."
},
"404": {
"description": "Request failed. User doesn't exist.",
"examples": {
"application/json": {
"message": "User 00000000-0000-0000-0000-000000000000 doesn't exist"
}
}
},
"500": {
"description": "Request failed. Internal controller error.",
"examples": {
Expand All @@ -95,6 +103,86 @@
}
},
"summary": "Returns all workflows."
},
"post": {
"description": "This resource expects a POST call to create a new workflow workspace.",
"operationId": "create_workflow",
"parameters": [
{
"description": "Required. Organization which the worklow belongs to.",
"in": "query",
"name": "organization",
"required": true,
"type": "string"
},
{
"description": "Required. UUID of workflow owner.",
"in": "query",
"name": "user",
"required": true,
"type": "string"
},
{
"description": "JSON object including workflow parameters and workflow specification in JSON format (`yadageschemas.load()` output) with necessary data to instantiate a yadage workflow.",
"in": "body",
"name": "workflow",
"required": true,
"schema": {
"properties": {
"parameters": {
"description": "Workflow parameters.",
"type": "object"
},
"specification": {
"description": "Yadage specification in JSON format.",
"type": "object"
},
"type": {
"description": "Workflow type.",
"type": "string"
}
},
"type": "object"
}
}
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Request succeeded. The file has been added to the workspace.",
"examples": {
"application/json": {
"message": "Workflow workspace has been created.",
"workflow_id": "cdcf48b1-c2f3-4693-8230-b066e088c6ac"
}
},
"schema": {
"properties": {
"message": {
"type": "string"
},
"workflow_id": {
"type": "string"
}
},
"type": "object"
}
},
"400": {
"description": "Request failed. The incoming data specification seems malformed"
},
"404": {
"description": "Request failed. User doesn't exist.",
"examples": {
"application/json": {
"message": "User 00000000-0000-0000-0000-000000000000 doesn't exist"
}
}
}
},
"summary": "Create workflow and its workspace."
}
},
"/api/workflows/{workflow_id}/workspace": {
Expand Down Expand Up @@ -149,8 +237,7 @@
"description": "Request succeeded. The file has been added to the workspace.",
"examples": {
"application/json": {
"message": "Workflow has been added to the workspace",
"workflow_id": "cdcf48b1-c2f3-4693-8230-b066e088c6ac"
"message": "The file input.csv has been successfully transferred."
}
},
"schema": {
Expand All @@ -167,6 +254,9 @@
},
"400": {
"description": "Request failed. The incoming data specification seems malformed"
},
"500": {
"description": "Request failed. Internal controller error."
}
},
"summary": "Adds a file to the workflow workspace."
Expand Down
41 changes: 18 additions & 23 deletions reana_server/rest/analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ def create_analysis(): # noqa
---
post:
summary: Creates a new yadage workflow.
summary: Creates a new workflow based on a REANA specification file.
description: >-
This resource is expecting JSON data with all the necessary
information to instantiate a yadage workflow.
This resource is expecting a REANA specification in JSON format with
all the necessary information to instantiate a workflow.
operationId: create_analysis
consumes:
- application/json
Expand Down Expand Up @@ -146,7 +146,7 @@ def create_analysis(): # noqa
responses:
200:
description: >-
Request succeeded. The workflow has been instantiated.
Request succeeded. The workflow has been created.
schema:
type: object
properties:
Expand All @@ -157,43 +157,38 @@ def create_analysis(): # noqa
examples:
application/json:
{
"message": "Analysis successfully launched",
"message": "The workflow has been successfully created.",
"workflow_id": "cdcf48b1-c2f3-4693-8230-b066e088c6ac"
}
400:
description: >-
Request failed. The incoming data specification seems malformed
"""
try:
reana_spec_file = None
reana_spec_url = None
if request.json:
# validate against schema
reana_spec = request.json
workflow_engine = reana_spec['workflow']['type']
reana_spec_file = request.json
workflow_engine = reana_spec_file['workflow']['type']
elif request.args.get('spec'):
# TODO implement load workflow engine from remote
# TODO implement load reana spec from remote
return jsonify('Not implemented'), 501
else:
raise Exception('Either remote repository or a reana spec need to \
be provided')

if workflow_engine not in app.config['AVAILABLE_WORKFLOW_ENGINES']:
raise Exception('Unknown workflow engine')
raise Exception('Unknown workflow type.')

if workflow_engine == 'yadage':
if reana_spec_file:
# From spec file
(response, status_code) = \
rwc_api_client.api.run_yadage_workflow_from_spec(
workflow={
'parameters': reana_spec['parameters'],
'workflow_spec': reana_spec['workflow']['spec'],
},
user=request.args.get('user'),
organization=request.args.get('organization')).result()
response, status_code = rwc_api_client.api.create_workflow(
workflow={
'parameters': reana_spec_file['parameters'],
'specification': reana_spec_file['workflow']['spec'],
'type': reana_spec_file['workflow']['type'],
},
user=request.args.get('user'),
organization=request.args.get('organization')).result()

return jsonify(response), status_code
return jsonify(response), status_code
except KeyError as e:
return jsonify({"message": str(e)}), 400
except Exception as e:
Expand Down

0 comments on commit ae186f1

Please sign in to comment.