From 5ff56986c84e35c4d3f52a7d37f33579e189fa89 Mon Sep 17 00:00:00 2001 From: akhilbatra898 Date: Mon, 6 Mar 2017 05:45:54 +0530 Subject: Add basic swagger specifications and corresponding controllers - Update specifications as per requirements - map specifications with controllers - make api installable JIRA: QTIP-220 Change-Id: Id149fdcf68e869e31a00cf16d7e725e368d2b25f Signed-off-by: akhilbatra898 --- qtip/api/__main__.py | 5 +- qtip/api/controllers/metric.py | 23 +++++ qtip/api/controllers/plan.py | 29 ++++++ qtip/api/controllers/qpi.py | 23 +++++ qtip/api/swagger/swagger.yaml | 200 ++++++++++++++++++++++++++++++++++++++++- 5 files changed, 278 insertions(+), 2 deletions(-) create mode 100644 qtip/api/controllers/metric.py create mode 100644 qtip/api/controllers/plan.py create mode 100644 qtip/api/controllers/qpi.py (limited to 'qtip') diff --git a/qtip/api/__main__.py b/qtip/api/__main__.py index aa2941a7..7b9cdaf5 100644 --- a/qtip/api/__main__.py +++ b/qtip/api/__main__.py @@ -8,10 +8,13 @@ ############################################################################## import connexion +import os + +swagger_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'swagger/')) def main(): - app = connexion.App(__name__, specification_dir='swagger/') + app = connexion.App(__name__, specification_dir=swagger_dir) app.add_api('swagger.yaml', base_path='/v1.0') app.run(host='0.0.0.0', port='5000') diff --git a/qtip/api/controllers/metric.py b/qtip/api/controllers/metric.py new file mode 100644 index 00000000..a026b5fc --- /dev/null +++ b/qtip/api/controllers/metric.py @@ -0,0 +1,23 @@ +############################################################################## +# Copyright (c) 2017 akhil.batra@research.iiit.ac.in and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import connexion +import httplib + + +def list_metrics(): + return connexion.problem(httplib.NOT_IMPLEMENTED, + 'List metrics', + 'Metrics listing not implemented') + + +def get_metric(name): + return connexion.problem(httplib.NOT_IMPLEMENTED, + 'Get a metric', + 'metric retrieval not implemented') diff --git a/qtip/api/controllers/plan.py b/qtip/api/controllers/plan.py new file mode 100644 index 00000000..e202b413 --- /dev/null +++ b/qtip/api/controllers/plan.py @@ -0,0 +1,29 @@ +############################################################################## +# Copyright (c) 2017 akhil.batra@research.iiit.ac.in and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import connexion +import httplib + + +def list_plans(): + return connexion.problem(httplib.NOT_IMPLEMENTED, + 'List plans', + 'Plans listing not implemented') + + +def get_plan(name): + return connexion.problem(httplib.NOT_IMPLEMENTED, + 'Get a plan', + 'Plan retrieval not implemented') + + +def run_plan(name, action="run"): + return connexion.problem(httplib.NOT_IMPLEMENTED, + 'Run a plan', + 'Plan runner not implemented') diff --git a/qtip/api/controllers/qpi.py b/qtip/api/controllers/qpi.py new file mode 100644 index 00000000..0b5c5b09 --- /dev/null +++ b/qtip/api/controllers/qpi.py @@ -0,0 +1,23 @@ +############################################################################## +# Copyright (c) 2017 akhil.batra@research.iiit.ac.in and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import connexion +import httplib + + +def list_qpis(): + return connexion.problem(httplib.NOT_IMPLEMENTED, + 'List QPIs', + 'QPIs listing not implemented') + + +def get_qpi(name): + return connexion.problem(httplib.NOT_IMPLEMENTED, + 'Get a QPI', + 'QPI retrieval not implemented') diff --git a/qtip/api/swagger/swagger.yaml b/qtip/api/swagger/swagger.yaml index a5a815f1..96d34681 100644 --- a/qtip/api/swagger/swagger.yaml +++ b/qtip/api/swagger/swagger.yaml @@ -10,9 +10,207 @@ swagger: '2.0' info: title: QTIP-API + version: "1.0" consumes: - application/json produces: - application/json paths: - #TODO (akhil) add paths \ No newline at end of file + /plans: + get: + summary: List all plans + operationId: qtip.api.controllers.plan.list_plans + tags: + - Plan + - standalone + responses: + 200: + description: A list of plans + #TODO (akhil) add item with properties and parameters + 501: + description: Resource not implemented + schema: + $ref: '#/definitions/Error' + default: + description: Unexpected error + schema: + $ref: '#/definitions/Error' + /plans/{name}: + get: + summary: Get a plan by plan name + operationId: qtip.api.controllers.plan.get_plan + tags: + - Plan + - standalone + parameters: + - name: name + in: path + description: Plan name + required: true + type: string + responses: + 200: + description: Plan information + #TODO (akhil) define schema + 404: + description: Plan not found + schema: + $ref: '#/definitions/Error' + 501: + description: Resource not implemented + schema: + $ref: '#/definitions/Error' + default: + description: Unexpected error + schema: + $ref: '#/definitions/Error' + post: + summary: Run a plan and return results + operationId: qtip.api.controllers.plan.run_plan + tags: + - Plan + - Standalone + parameters: + - name: name + in: path + description: Plan name + required: true + type: string + - name: action + in: query + description: action for a plan + required: true + type: string + responses: + 200: + description: Result of the run of the plan + #TODO (akhil) define schema + 404: + description: Plan not found + schema: + $ref: '#/definitions/Error' + 400: + description: Invalid parameters + schema: + $ref: '#/definitions/Error' + 501: + description: Resource not implemented + schema: + $ref: '#/definitions/Error' + default: + description: Unexpected error + schema: + $ref: '#/definitions/Error' + /qpis: + get: + summary: List all QPIs + operationId: qtip.api.controllers.qpi.list_qpis + tags: + - QPI + - Standalone + - Agent + responses: + 200: + description: A list of QPIs + #TODO (akhil) add item with properties and parameters + 501: + description: Resource not implemented + schema: + $ref: '#/definitions/Error' + default: + description: Unexpected error + schema: + $ref: '#/definitions/Error' + /qpis/{name}: + get: + summary: Get a QPI + operationId: qtip.api.controllers.qpi.get_qpi + tags: + - QPI + - Standalone + - Agent + parameters: + - name: name + in: path + description: QPI name + required: true + type: string + responses: + 200: + description: QPI information + #TODO (akhil) define schema + 404: + description: QPI not found + schema: + $ref: '#/definitions/Error' + 501: + description: Resource not implemented + schema: + $ref: '#/definitions/Error' + default: + description: Unexpected error + schema: + $ref: '#/definitions/Error' + /metrics: + get: + summary: List all metrics + operationId: qtip.api.controllers.metric.list_metrics + tags: + - Metric + - Standalone + - Agent + responses: + 200: + description: A list of metrics + #TODO (akhil) add item with properties and parameters + 501: + description: Resource not implemented + schema: + $ref: '#/definitions/Error' + default: + description: Unexpected error + schema: + $ref: '#/definitions/Error' + /metrics/{name}: + get: + summary: Get a metric + operationId: qtip.api.controllers.metric.get_metric + tags: + - Metric + - Standalone + - Agent + parameters: + - name: name + in: path + description: Metric name + required: true + type: string + responses: + 200: + description: Metric information + #TODO (akhil) define schema + 404: + description: Metric not found + schema: + $ref: '#/definitions/Error' + 501: + description: Resource not implemented + schema: + $ref: '#/definitions/Error' + default: + description: Unexpected error + schema: + $ref: '#/definitions/Error' +definitions: + Error: + type: object + properties: + status: + type: integer + format: int32 + title: + type: string + detail: + type: string + type: + type: string \ No newline at end of file -- cgit 1.2.3-korg