Add basic swagger specifications and corresponding controllers 15/29815/8
authorakhilbatra898 <akhil.batra@research.iiit.ac.in>
Mon, 6 Mar 2017 00:15:54 +0000 (05:45 +0530)
committerakhilbatra898 <akhil.batra@research.iiit.ac.in>
Thu, 9 Mar 2017 11:13:12 +0000 (16:43 +0530)
- Update specifications as per requirements
- map specifications with controllers
- make api installable

JIRA: QTIP-220

Change-Id: Id149fdcf68e869e31a00cf16d7e725e368d2b25f
Signed-off-by: akhilbatra898 <akhil.batra@research.iiit.ac.in>
qtip/api/__main__.py
qtip/api/controllers/metric.py [new file with mode: 0644]
qtip/api/controllers/plan.py [new file with mode: 0644]
qtip/api/controllers/qpi.py [new file with mode: 0644]
qtip/api/swagger/swagger.yaml
setup.cfg

index aa2941a..7b9cdaf 100644 (file)
@@ -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 (file)
index 0000000..a026b5f
--- /dev/null
@@ -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 (file)
index 0000000..e202b41
--- /dev/null
@@ -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 (file)
index 0000000..0b5c5b0
--- /dev/null
@@ -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')
index a5a815f..96d3468 100644 (file)
 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
index 5b9b956..bd263e7 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -14,7 +14,7 @@ setup-hooks =
 [entry_points]
 console_scripts =
     qtip = qtip.cli.entry:cli
-    # TODO(akhil) add qtip-api
+    qtip-api = qtip.api.__main__:main
 
 [files]
 packages =