Skip to content

Commit

Permalink
Merge bda3815 into be4fd89
Browse files Browse the repository at this point in the history
  • Loading branch information
hjhsalo committed Nov 3, 2017
2 parents be4fd89 + bda3815 commit 9848133
Show file tree
Hide file tree
Showing 2 changed files with 222 additions and 0 deletions.
90 changes: 90 additions & 0 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,96 @@
"summary": "Create workflow and its workspace."
}
},
"/api/workflows/{workflow_id}/status": {
"get": {
"description": "This resource reports the status of workflow.",
"operationId": "get_workflow_status",
"parameters": [
{
"description": "Required. Organization which the workflow 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": "Required. Workflow UUID.",
"in": "path",
"name": "workflow_id",
"required": true,
"type": "string"
}
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Request succeeded. Info about workflow, including the status is returned.",
"examples": {
"application/json": {
"id": "256b25f4-4cfb-4684-b7a8-73872ef455a1",
"organization": "default_org",
"status": "running",
"user": "00000000-0000-0000-0000-000000000000"
}
},
"schema": {
"properties": {
"id": {
"type": "string"
},
"organization": {
"type": "string"
},
"status": {
"type": "string"
},
"user": {
"type": "string"
}
},
"type": "object"
}
},
"400": {
"description": "Request failed. The incoming data specification seems malformed.",
"examples": {
"application/json": {
"message": "Malformed request."
}
}
},
"403": {
"description": "Request failed. User is not allowed to access workflow.",
"examples": {
"application/json": {
"message": "User 00000000-0000-0000-0000-000000000000 is not allowed to access workflow 256b25f4-4cfb-4684-b7a8-73872ef455a1"
}
}
},
"404": {
"description": "Request failed. Either User or Workflow doesn't exist.",
"examples": {
"application/json": {
"message": "Workflow 256b25f4-4cfb-4684-b7a8-73872ef455a1 doesn't exist"
}
}
},
"500": {
"description": "Request failed. Internal controller error."
}
},
"summary": "Get workflow status."
}
},
"/api/workflows/{workflow_id}/workspace": {
"post": {
"consumes": [
Expand Down
132 changes: 132 additions & 0 deletions reana_workflow_controller/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

"""REANA Workflow Controller REST API."""

from __future__ import print_function

import os
import traceback
from uuid import uuid4
Expand Down Expand Up @@ -630,3 +632,133 @@ def run_yadage_workflow_from_spec_endpoint(): # noqa
except (KeyError, ValueError):
traceback.print_exc()
abort(400)


@restapi_blueprint.route('/workflows/<workflow_id>/status', methods=['GET'])
def get_workflow_status(workflow_id): # noqa
r"""Get workflow status.
---
get:
summary: Get workflow status.
description: >-
This resource reports the status of workflow.
operationId: get_workflow_status
produces:
- application/json
parameters:
- name: organization
in: query
description: Required. Organization which the workflow belongs to.
required: true
type: string
- name: user
in: query
description: Required. UUID of workflow owner.
required: true
type: string
- name: workflow_id
in: path
description: Required. Workflow UUID.
required: true
type: string
responses:
200:
description: >-
Request succeeded. Info about workflow, including the status is
returned.
schema:
type: object
properties:
id:
type: string
organization:
type: string
status:
type: string
user:
type: string
examples:
application/json:
{
"id": "256b25f4-4cfb-4684-b7a8-73872ef455a1",
"organization": "default_org",
"status": "running",
"user": "00000000-0000-0000-0000-000000000000"
}
400:
description: >-
Request failed. The incoming data specification seems malformed.
examples:
application/json:
{
"message": "Malformed request."
}
403:
description: >-
Request failed. User is not allowed to access workflow.
examples:
application/json:
{
"message": "User 00000000-0000-0000-0000-000000000000
is not allowed to access workflow
256b25f4-4cfb-4684-b7a8-73872ef455a1"
}
404:
description: >-
Request failed. Either User or Workflow doesn't exist.
examples:
application/json:
{
"message": "User 00000000-0000-0000-0000-000000000000 doesn't
exist"
}
application/json:
{
"message": "Workflow 256b25f4-4cfb-4684-b7a8-73872ef455a1
doesn't exist"
}
500:
description: >-
Request failed. Internal controller error.
"""

try:
organization = request.args['organization']
user_uuid = request.args['user']
user = User.query.filter(User.id_ == user_uuid).first()
if not user:
return jsonify(
{'message': 'User {} does not exist'.format(user_uuid)}), 404

resp = None

# Make sure that user can access the workflow.
for workflow in user.workflows:
current_app.logger.debug(workflow_id,)
current_app.logger.debug(workflow.id_)
if workflow_id == str(workflow.id_):
resp = {'id': workflow.id_,
'status': workflow.status.name,
'organization': organization,
'user': user_uuid}

if resp:
return jsonify(resp), 200
else: # Check if workflow exists at all.
workflow = Workflow.query.filter(Workflow.id_ == workflow_id).\
first()

if not workflow:
return jsonify(
{'message': 'Workflow {} does not exist'
.format(workflow_id)}), 404
else:
return jsonify(
{'message': 'User {} is not allowed to access workflow {}'
.format(user_uuid, workflow_id)}), 403

except KeyError as e:
return jsonify({"message": str(e)}), 400
except Exception as e:
return jsonify({"message": str(e)}), 500

0 comments on commit 9848133

Please sign in to comment.