You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metamodel.apache.org by ka...@apache.org on 2016/06/14 05:20:55 UTC

[11/11] metamodel git commit: Updated interface definitions as per new Swagger yaml file

Updated interface definitions as per new Swagger yaml file

Project: http://git-wip-us.apache.org/repos/asf/metamodel/repo
Commit: http://git-wip-us.apache.org/repos/asf/metamodel/commit/0a82d13b
Tree: http://git-wip-us.apache.org/repos/asf/metamodel/tree/0a82d13b
Diff: http://git-wip-us.apache.org/repos/asf/metamodel/diff/0a82d13b

Branch: refs/heads/feature/5.x/swagger-docs
Commit: 0a82d13b19ea0f8aa3aabcd140caaf3274a8e5b4
Parents: 79af7dd
Author: Kasper S�rensen <i....@gmail.com>
Authored: Mon Jun 13 22:15:34 2016 -0700
Committer: Kasper S�rensen <i....@gmail.com>
Committed: Mon Jun 13 22:15:34 2016 -0700

----------------------------------------------------------------------
 .../service/controllers/ColumnController.java   |   2 +-
 .../controllers/DataSourceController.java       |   2 +-
 .../service/controllers/SchemaController.java   |   2 +-
 .../service/controllers/TableController.java    |   2 +-
 .../controllers/TableDataController.java        |  26 +-
 .../TenantInteractionScenarioTest.java          |   4 +-
 service-webapp/swagger.yaml                     | 503 +++++++++++++++++++
 7 files changed, 526 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/metamodel/blob/0a82d13b/service-webapp/src/main/java/org/apache/metamodel/service/controllers/ColumnController.java
----------------------------------------------------------------------
diff --git a/service-webapp/src/main/java/org/apache/metamodel/service/controllers/ColumnController.java b/service-webapp/src/main/java/org/apache/metamodel/service/controllers/ColumnController.java
index 7d6d5ff..c811def 100644
--- a/service-webapp/src/main/java/org/apache/metamodel/service/controllers/ColumnController.java
+++ b/service-webapp/src/main/java/org/apache/metamodel/service/controllers/ColumnController.java
@@ -77,7 +77,7 @@ public class ColumnController {
         map.put("name", column.getName());
         map.put("table", tableName);
         map.put("schema", schemaName);
-        map.put("data-context", dataSourceName);
+        map.put("datasource", dataSourceName);
         map.put("tenant", tenantName);
         map.put("metadata", metadata);
 

http://git-wip-us.apache.org/repos/asf/metamodel/blob/0a82d13b/service-webapp/src/main/java/org/apache/metamodel/service/controllers/DataSourceController.java
----------------------------------------------------------------------
diff --git a/service-webapp/src/main/java/org/apache/metamodel/service/controllers/DataSourceController.java b/service-webapp/src/main/java/org/apache/metamodel/service/controllers/DataSourceController.java
index 9c678ff..524cc09 100644
--- a/service-webapp/src/main/java/org/apache/metamodel/service/controllers/DataSourceController.java
+++ b/service-webapp/src/main/java/org/apache/metamodel/service/controllers/DataSourceController.java
@@ -82,7 +82,7 @@ public class DataSourceController {
         map.put("name", dataSourceName);
         map.put("tenant", tenantName);
         map.put("updateable", dataContext instanceof UpdateableDataContext);
-        map.put("query", UriBuilder.fromPath("/{tenant}/{dataContext}/query").build(tenantName, dataSourceName));
+        map.put("query_uri", UriBuilder.fromPath("/{tenant}/{dataContext}/query").build(tenantName, dataSourceName));
         map.put("schemas", schemaLinks);
         return map;
     }

http://git-wip-us.apache.org/repos/asf/metamodel/blob/0a82d13b/service-webapp/src/main/java/org/apache/metamodel/service/controllers/SchemaController.java
----------------------------------------------------------------------
diff --git a/service-webapp/src/main/java/org/apache/metamodel/service/controllers/SchemaController.java b/service-webapp/src/main/java/org/apache/metamodel/service/controllers/SchemaController.java
index 6208d49..993c1d3 100644
--- a/service-webapp/src/main/java/org/apache/metamodel/service/controllers/SchemaController.java
+++ b/service-webapp/src/main/java/org/apache/metamodel/service/controllers/SchemaController.java
@@ -72,7 +72,7 @@ public class SchemaController {
         final Map<String, Object> map = new LinkedHashMap<>();
         map.put("type", "schema");
         map.put("name", schemaName);
-        map.put("data-context", dataSourceName);
+        map.put("datasource", dataSourceName);
         map.put("tenant", tenantName);
         map.put("tables", tableLinks);
         return map;

http://git-wip-us.apache.org/repos/asf/metamodel/blob/0a82d13b/service-webapp/src/main/java/org/apache/metamodel/service/controllers/TableController.java
----------------------------------------------------------------------
diff --git a/service-webapp/src/main/java/org/apache/metamodel/service/controllers/TableController.java b/service-webapp/src/main/java/org/apache/metamodel/service/controllers/TableController.java
index 4157dac..c914289 100644
--- a/service-webapp/src/main/java/org/apache/metamodel/service/controllers/TableController.java
+++ b/service-webapp/src/main/java/org/apache/metamodel/service/controllers/TableController.java
@@ -77,7 +77,7 @@ public class TableController {
         map.put("type", "table");
         map.put("name", tableName);
         map.put("schema", schemaName);
-        map.put("data-context", dataSourceName);
+        map.put("datasource", dataSourceName);
         map.put("tenant", tenantName);
         map.put("columns", columnsLinks);
         return map;

http://git-wip-us.apache.org/repos/asf/metamodel/blob/0a82d13b/service-webapp/src/main/java/org/apache/metamodel/service/controllers/TableDataController.java
----------------------------------------------------------------------
diff --git a/service-webapp/src/main/java/org/apache/metamodel/service/controllers/TableDataController.java b/service-webapp/src/main/java/org/apache/metamodel/service/controllers/TableDataController.java
index c48d74f..bae9923 100644
--- a/service-webapp/src/main/java/org/apache/metamodel/service/controllers/TableDataController.java
+++ b/service-webapp/src/main/java/org/apache/metamodel/service/controllers/TableDataController.java
@@ -19,13 +19,16 @@
 package org.apache.metamodel.service.controllers;
 
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
 import org.apache.metamodel.DataContext;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
 import org.apache.metamodel.UpdateSummary;
 import org.apache.metamodel.UpdateableDataContext;
-import org.apache.metamodel.insert.InsertInto;
+import org.apache.metamodel.insert.RowInsertionBuilder;
 import org.apache.metamodel.query.Query;
 import org.apache.metamodel.schema.Table;
 import org.apache.metamodel.service.app.DataContextTraverser;
@@ -75,7 +78,7 @@ public class TableDataController {
     @ResponseBody
     public Map<String, Object> post(@PathVariable("tenant") String tenantId,
             @PathVariable("dataContext") String dataSourceName, @PathVariable("schema") String schemaId,
-            @PathVariable("table") String tableId, @RequestBody Map<String, Object> inputMap) {
+            @PathVariable("table") String tableId, @RequestBody final List<Map<String, Object>> inputRecords) {
 
         final TenantContext tenantContext = tenantRegistry.getTenantContext(tenantId);
         final UpdateableDataContext dataContext = tenantContext.getDataSourceRegistry().openDataContextForUpdate(dataSourceName);
@@ -84,13 +87,18 @@ public class TableDataController {
 
         final Table table = traverser.getTable(schemaId, tableId);
 
-        final InsertInto insert = new InsertInto(table);
-        for (Entry<String, Object> entry : inputMap.entrySet()) {
-            insert.value(entry.getKey(), entry.getValue());
-        }
-
-        final UpdateableDataContext updateableDataContext = (UpdateableDataContext) dataContext;
-        final UpdateSummary result = updateableDataContext.executeUpdate(insert);
+        final UpdateSummary result = dataContext.executeUpdate(new UpdateScript() {
+            @Override
+            public void run(UpdateCallback callback) {
+                for (Map<String, Object> inputMap : inputRecords) {
+                    final RowInsertionBuilder insert = callback.insertInto(table);
+                    for (Entry<String, Object> entry : inputMap.entrySet()) {
+                        insert.value(entry.getKey(), entry.getValue());
+                    }
+                    insert.execute();
+                }
+            }
+        });
 
         final Map<String, Object> response = new LinkedHashMap<>();
         response.put("status", "ok");

http://git-wip-us.apache.org/repos/asf/metamodel/blob/0a82d13b/service-webapp/src/test/java/org/apache/metamodel/service/controllers/TenantInteractionScenarioTest.java
----------------------------------------------------------------------
diff --git a/service-webapp/src/test/java/org/apache/metamodel/service/controllers/TenantInteractionScenarioTest.java b/service-webapp/src/test/java/org/apache/metamodel/service/controllers/TenantInteractionScenarioTest.java
index 793f88c..5706153 100644
--- a/service-webapp/src/test/java/org/apache/metamodel/service/controllers/TenantInteractionScenarioTest.java
+++ b/service-webapp/src/test/java/org/apache/metamodel/service/controllers/TenantInteractionScenarioTest.java
@@ -158,7 +158,7 @@ public class TenantInteractionScenarioTest {
         // insert into table (x2)
         {
             final MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post(
-                    "/tenant1/mydata/s/mydata/t/hello_world/d").content("{'greeting':'Howdy','who':'MetaModel'}"
+                    "/tenant1/mydata/s/mydata/t/hello_world/d").content("[{'greeting':'Howdy','who':'MetaModel'}]"
                             .replace('\'', '"')).contentType(MediaType.APPLICATION_JSON)).andExpect(
                                     MockMvcResultMatchers.status().isOk()).andReturn();
 
@@ -168,7 +168,7 @@ public class TenantInteractionScenarioTest {
         }
         {
             final MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post(
-                    "/tenant1/mydata/s/mydata/t/hello_world/d").content("{'greeting':'Hi','who':'Apache'}"
+                    "/tenant1/mydata/s/mydata/t/hello_world/d").content("[{'greeting':'Hi','who':'Apache'}]"
                             .replace('\'', '"')).contentType(MediaType.APPLICATION_JSON)).andExpect(
                                     MockMvcResultMatchers.status().isOk()).andReturn();
 

http://git-wip-us.apache.org/repos/asf/metamodel/blob/0a82d13b/service-webapp/swagger.yaml
----------------------------------------------------------------------
diff --git a/service-webapp/swagger.yaml b/service-webapp/swagger.yaml
new file mode 100644
index 0000000..1edd47a
--- /dev/null
+++ b/service-webapp/swagger.yaml
@@ -0,0 +1,503 @@
+swagger: '2.0'
+info:
+  title: Apache MetaModel RESTful API
+  description: Delivers 'MetaModel-as-a-Service' for unified data federation.
+  version: "5.0.0"
+produces:
+  - application/json
+paths:
+  /:
+    get:
+      summary: Hello MetaModel
+      description: An endpoint that provides a confirmation that the system is operational
+      responses:
+        200:
+          description: The system is operational
+          schema:
+            type: object
+            properties:
+              ping:
+                type: string
+                description: Should return 'pong!' when the system is operational
+              application:
+                type: string
+                description: The name of the application running (Apache MetaModel)
+              version:
+                type: string
+                description: The version of the application running
+              server-time:
+                type: object
+                properties:
+                  timestamp:
+                    type: integer
+                    format: int64
+                    description: The server-time in timestamp format (millis since 1st of January 1970)
+                  iso8601:
+                    type: string
+                    description: The server-time in ISO-8601 format
+              canonical-hostname:
+                type: string
+                description: The canonical hostname of the server
+  /{tenant}:
+    parameters:
+      - name: tenant
+        in: path
+        type: string
+        description: The tenant name
+        required: true
+    put:
+      summary: Create new tenant
+      responses:
+        200:
+          description: Tenant created
+          schema:
+            properties:
+              type:
+                type: string
+                description: The type of entity (tenant)
+              name:
+                type: string
+                description: The tenant name/identifier
+        409:
+          description: Tenant already exist
+          schema:
+            $ref: "#/definitions/error"
+    get:
+      summary: Get tenant information
+      description: Provides basic information about a tenant of the system
+      responses:
+        404:
+          description: Tenant not found
+          schema:
+            $ref: "#/definitions/error"
+        200:
+          description: Tenant found
+          schema:
+            type: object
+            properties:
+              type:
+                type: string
+                description: The type of entity (tenant)
+              name:
+                type: string
+                description: The tenant name/identifier
+              datasources:
+                type: array
+                items:
+                  type: object
+                  properties:
+                    name:
+                      type: string
+                      description: The name of the datasource
+                    uri:
+                      type: string
+                      format: uri
+                      description: A link to the datasource information
+    delete:
+      summary: Delete tenant
+      description: Deletes a tenant from the system
+      responses:
+        200:
+          description: Tenant deleted
+          schema:
+            type: object
+            properties:
+              type:
+                type: string
+                description: The type of entity (tenant)
+              name:
+                type: string
+                description: The tenant name/identifier
+        404:
+          description: Tenant not found
+          schema:
+            $ref: "#/definitions/error"
+  /{tenant}/{datasource}:
+    parameters:
+      - name: tenant
+        in: path
+        type: string
+        description: The tenant name
+        required: true
+      - name: datasource
+        in: path
+        type: string
+        description: The datasource name
+        required: true
+    get:
+      responses:
+        200:
+          description: Datasource found
+          schema:
+            type: object
+            properties:
+              type:
+                type: string
+                description: The type of entity (datasource)
+              name:
+                type: string
+                description: The datasource name
+              tenant:
+                type: string
+                description: The tenant name
+              updateable:
+                type: boolean
+                description: Is this datasource updateable?
+              query_uri:
+                type: string
+                description: A link to the query endpoint for this datasource
+                format: uri
+              schemas:
+                type: array
+                description: The schemas of this datasource
+                items:
+                  type: object
+                  properties:
+                    name:
+                      type: string
+                      description: The schema name
+                    uri:
+                      type: string
+                      description: A link to the schema information
+                      format: uri
+        404:
+          description: Datasource not found
+          schema:
+            $ref: "#/definitions/error"
+  /{tenant}/{datasource}/q:
+    parameters:
+      - name: tenant
+        in: path
+        type: string
+        description: The tenant name
+        required: true
+      - name: datasource
+        in: path
+        type: string
+        description: The datasource name
+        required: true
+    get:
+      description: Executes a query on the datasource
+      parameters:
+      - name: sql
+        in: query
+        type: string
+        description: The MetaModel-flavoured SQL query to execute
+        required: true
+      - name: offset
+        in: query
+        type: string
+        description: An offset / first-row flag to set on the query
+        required: false
+      - name: limit
+        in: query
+        type: string
+        description: A limit / max-rows flag to set on the query
+        required: false
+      responses:
+        200:
+          description: Query executed
+          schema:
+            $ref: "#/definitions/queryResponse"
+        400:
+          description: Failure while parsing query
+          schema:
+            $ref: "#/definitions/error"
+        404:
+          description: Datasource not found
+          schema:
+            $ref: "#/definitions/error"
+        500:
+          description: Failure while executing query
+          schema:
+            $ref: "#/definitions/error"
+  /{tenant}/{datasource}/s/{schema}:
+    parameters:
+      - name: tenant
+        in: path
+        type: string
+        description: The tenant name
+        required: true
+      - name: datasource
+        in: path
+        type: string
+        description: The datasource name
+        required: true
+      - name: schema
+        in: path
+        type: string
+        description: The schema name
+        required: true
+    get:
+      responses:
+        200:
+          description: Schema found
+          schema:
+            type: object
+            properties:
+              type:
+                type: string
+                description: The type of entity (schema)
+              name:
+                type: string
+                description: The schema name
+              datasource:
+                type: string
+                description: The datasource name
+              tables:
+                type: array
+                description: The names of the schema's tables
+                items:
+                  type: object
+                  properties:
+                    name:
+                      type: string
+                      description: The table name
+                    uri:
+                      type: string
+                      description: A link to the table information
+                      format: uri
+        404:
+          description: Schema not found
+          schema:
+            $ref: "#/definitions/error"
+  /{tenant}/{datasource}/s/{schema}/t/{table}:
+    parameters:
+      - name: tenant
+        in: path
+        type: string
+        description: The tenant name
+        required: true
+      - name: datasource
+        in: path
+        type: string
+        description: The datasource name
+        required: true
+      - name: schema
+        in: path
+        type: string
+        description: The schema name
+        required: true
+      - name: table
+        in: path
+        type: string
+        description: The table name
+        required: true
+    get:
+      responses:
+        200:
+          description: Table found
+          schema:
+            type: object
+            properties:
+              type:
+                type: string
+                description: The type of entity (table)
+              name:
+                type: string
+                description: The table name
+              schema:
+                type: string
+                description: The schema name
+              datasource:
+                type: string
+                description: The datasource name
+              tenant:
+                type: string
+                description: The tenant name
+              columns:
+                type: array
+                description: The names of the table's columns
+                items:
+                  type: object
+                  properties:
+                    name:
+                      type: string
+                      description: The column name
+                    uri:
+                      type: string
+                      description: A link to the column information
+                      format: uri
+        404:
+          description: Table not found
+          schema:
+            $ref: "#/definitions/error"
+  /{tenant}/{datasource}/s/{schema}/t/{table}/d:
+    parameters:
+      - name: tenant
+        in: path
+        type: string
+        description: The tenant name
+        required: true
+      - name: datasource
+        in: path
+        type: string
+        description: The datasource name
+        required: true
+      - name: schema
+        in: path
+        type: string
+        description: The schema name
+        required: true
+      - name: table
+        in: path
+        type: string
+        description: The table name
+        required: true
+    get:
+      description: Gets the data of the table
+      responses:
+        200:
+          description: Query executed
+          schema:
+            $ref: "#/definitions/queryResponse"
+        400:
+          description: Failure while parsing query
+          schema:
+            $ref: "#/definitions/error"
+        404:
+          description: Table not found
+          schema:
+            $ref: "#/definitions/error"
+        500:
+          description: Failure while executing query
+          schema:
+            $ref: "#/definitions/error"
+    post:
+      description: Inserts data to the table
+      parameters:
+        - name: inputData
+          in: body
+          description: The data to insert
+          required: true
+          schema:
+            type: array
+            items:
+              description: A record to insert where each key is expected to match a column name and each value is the value to put.
+              type: object
+      responses:
+        200:
+          description: Data inserted
+          #TODO
+        404:
+          description: Table not found
+          schema:
+            $ref: "#/definitions/error"
+  /{tenant}/{datasource}/s/{schema}/t/{table}/c/{column}:
+    parameters:
+      - name: tenant
+        in: path
+        type: string
+        description: The tenant name
+        required: true
+      - name: datasource
+        in: path
+        type: string
+        description: The datasource name
+        required: true
+      - name: schema
+        in: path
+        type: string
+        description: The schema name
+        required: true
+      - name: table
+        in: path
+        type: string
+        description: The table name
+        required: true
+      - name: column
+        in: path
+        type: string
+        description: The column name
+        required: true
+    get:
+      description: Gets information about a column
+      responses:
+        200:
+          description: Query executed
+          schema:
+            type: object
+            properties:
+              type:
+                type: string
+                description: The type of entity (column)
+              name:
+                type: string
+                description: The column name
+              table:
+                type: string
+                description: The table name
+              schema:
+                type: string
+                description: The schema name
+              datasource:
+                type: string
+                description: The datasource name
+              tenant:
+                type: string
+                description: The tenant name
+              metadata:
+                type: object
+                description: Metadata about the column
+                properties:
+                  number:
+                    type: integer
+                    description: The column number (0-based)
+                  size:
+                    type: integer
+                    description: The column size
+                  nullable:
+                    type: boolean
+                    description: Is the column nullable?
+                  primary-key:
+                    type: boolean
+                    description: Is the column a primary key?
+                  indexed:
+                    type: boolean
+                    description: Is the column indexed?
+                  column-type:
+                    type: string
+                    description: The column type (as interpreted/adapted by Apache MetaModel)
+                  native-type:
+                    type: string
+                    description: The native column type (as defined by the datasource itself)
+                  remarks:
+                    type: string
+                    description: Any remarks on the column
+        404:
+          description: Column not found
+          schema:
+            $ref: "#/definitions/error"
+definitions:
+  queryResponse:
+    description: Represents the result of a query - a dataset
+    type: object
+    properties:
+      type:
+        type: string
+        description: The type of entity (dataset)
+      headers:
+        type: array
+        description: The dataset header names
+        items:
+          type: string
+      data:
+        type: array
+        description: The actual data returned by the query
+        items:
+          type: array
+          items:
+            type: object
+  error:
+    description: Elaborates the error that occurred
+    type: object
+    properties:
+      code:
+        type: integer
+        description: The HTTP status code
+      message:
+        type: string
+        description: A humanly readable error message
+      additional_details:
+        type: object
+        description: Any auxilary details to further elaborate the error