From 83a7e6f68320191f13a5b97cbea93ad6d440e6ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20S=C3=B8rensen?= Date: Sun, 20 Aug 2017 01:14:16 -0700 Subject: [PATCH 1/3] Made docker build orchestrate everything (for DockerHub driven builds) --- .dockerignore | 18 ++++++++++++++++++ undertow/Dockerfile => Dockerfile | 13 ++++++++----- docker-compose.yml | 17 ++++++++++++++++- 3 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 .dockerignore rename undertow/Dockerfile => Dockerfile (77%) diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3eddedc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +**/target diff --git a/undertow/Dockerfile b/Dockerfile similarity index 77% rename from undertow/Dockerfile rename to Dockerfile index 371d24b..a10b5d8 100644 --- a/undertow/Dockerfile +++ b/Dockerfile @@ -15,12 +15,15 @@ # specific language governing permissions and limitations # under the License. -FROM openjdk:8-jre-alpine - -COPY target/membrane-undertow-server.jar membrane-undertow-server.jar +FROM maven:3.5-jdk-8-alpine +# Set data directory used for the app's persistence VOLUME /data - ENV DATA_DIRECTORY=/data -CMD java -server -jar membrane-undertow-server.jar +COPY . /usr/src/app +WORKDIR /usr/src/app + +RUN mvn clean install -Pdockerbuild -DskipTests + +CMD java -server -jar undertow/target/membrane-undertow-server.jar diff --git a/docker-compose.yml b/docker-compose.yml index c87a2bb..96d7d21 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,8 +19,23 @@ services: metamodel-membrane: container_name: metamodel-membrane image: metamodel-membrane - build: undertow + build: . ports: - "8080:8080" environment: - MEMBRANE_HTTP_PORT=8080 + example-postgres: + container_name: example-postgres + image: postgres:9.6 + environment: + - POSTGRES_USER=membrane + - POSTGRES_PASSWORD=secret + - POSTGRES_DB=membrane + example-couchdb: + container_name: example-couchdb + image: couchdb:1.6 + environment: + - COUCHDB_USER=membrane + - COUCHDB_PASSWORD=secret + ports: + - 5984:5984 From a6033aa5c13c696623ad0e279507da8d62458020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20S=C3=B8rensen?= Date: Sun, 20 Aug 2017 01:14:49 -0700 Subject: [PATCH 2/3] Added postman tests based on the setup created by docker-compose --- core/pom.xml | 12 ++ pom.xml | 29 ++- .../Membrane.postman_collection.json | 202 ++++++++++++++++++ postman-tests/README.md | 20 ++ .../docker-toolbox.postman_environment.json | 16 ++ .../localhost.postman_environment.json | 16 ++ 6 files changed, 289 insertions(+), 6 deletions(-) create mode 100644 postman-tests/Membrane.postman_collection.json create mode 100644 postman-tests/README.md create mode 100644 postman-tests/environments/docker-toolbox.postman_environment.json create mode 100644 postman-tests/environments/localhost.postman_environment.json diff --git a/core/pom.xml b/core/pom.xml index c46c699..2de9377 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -86,6 +86,18 @@ under the License. org.slf4j jcl-over-slf4j + + + + org.postgresql + postgresql + 42.1.4 + + + net.sourceforge.jtds + jtds + 1.3.1 + diff --git a/pom.xml b/pom.xml index 4b43522..4a9ec09 100644 --- a/pom.xml +++ b/pom.xml @@ -42,12 +42,29 @@ under the License. http://metamodel.apache.org 2017 pom - - swagger-codegen - core - war - undertow - + + + + all + + true + + + swagger-codegen + core + war + undertow + + + + dockerbuild + + swagger-codegen + core + undertow + + + diff --git a/postman-tests/Membrane.postman_collection.json b/postman-tests/Membrane.postman_collection.json new file mode 100644 index 0000000..d8f0896 --- /dev/null +++ b/postman-tests/Membrane.postman_collection.json @@ -0,0 +1,202 @@ +{ + "variables": [], + "info": { + "name": "Membrane", + "_postman_id": "084c91ce-fccc-8fc4-a3c4-1dc5d5b41388", + "description": "", + "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json" + }, + "item": [ + { + "name": "Create my-tenant", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "tests[\"Status code is 200\"] = responseCode.code === 200;", + "", + "var jsonData = JSON.parse(responseBody);", + "tests[\"type is tenant\"] = jsonData.type === \"tenant\";" + ] + } + } + ], + "request": { + "url": "{{baseUrl}}/my-tenant", + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "description": "" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \n}" + }, + "description": "" + }, + "response": [] + }, + { + "name": "Get my-tenant", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "tests[\"Status code is 200\"] = responseCode.code === 200;", + "", + "var jsonData = JSON.parse(responseBody);", + "tests[\"type is tenant\"] = jsonData.type === \"tenant\";" + ] + } + } + ], + "request": { + "url": "{{baseUrl}}/my-tenant", + "method": "GET", + "header": [], + "body": {}, + "description": "" + }, + "response": [] + }, + { + "name": "Create my-tenant/example-pojo", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "tests[\"Status code is 200\"] = responseCode.code === 200;", + "", + "var jsonData = JSON.parse(responseBody);", + "tests[\"type is datasource\"] = jsonData.type === \"datasource\";", + "tests[\"is updateable\"] = jsonData.updateable;" + ] + } + } + ], + "request": { + "url": "{{baseUrl}}/my-tenant/example-pojo", + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "description": "" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"type\":\"pojo\",\n \"table-defs\":\"hello_world (greeting VARCHAR, who VARCHAR); foo (bar INTEGER, baz DATE);\"\n}" + }, + "description": "" + }, + "response": [] + }, + { + "name": "Create my-tenant/example-postgres", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "tests[\"Status code is 200\"] = responseCode.code === 200;", + "", + "var jsonData = JSON.parse(responseBody);", + "tests[\"type is datasource\"] = jsonData.type === \"datasource\";", + "tests[\"is updateable\"] = jsonData.updateable;" + ] + } + } + ], + "request": { + "url": "{{baseUrl}}/my-tenant/example-postgres", + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "description": "" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"type\":\"jdbc\",\n \"url\": \"jdbc:postgresql://example-postgres/membrane\",\n \"username\": \"membrane\",\n \"password\": \"secret\"\n}" + }, + "description": "" + }, + "response": [] + }, + { + "name": "Create my-tenant/example-couchdb", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "tests[\"Status code is 200\"] = responseCode.code === 200;", + "", + "var jsonData = JSON.parse(responseBody);", + "tests[\"type is datasource\"] = jsonData.type === \"datasource\";", + "tests[\"is updateable\"] = jsonData.updateable;" + ] + } + } + ], + "request": { + "url": "{{baseUrl}}/my-tenant/example-couchdb", + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "description": "" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"type\":\"couchdb\",\n \"hostname\": \"example-couchdb\",\n \"username\": \"membrane\",\n \"password\": \"secret\"\n}" + }, + "description": "" + }, + "response": [] + }, + { + "name": "Delete my-tenant", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "tests[\"Status code is 200\"] = responseCode.code === 200;", + "", + "var jsonData = JSON.parse(responseBody);", + "tests[\"type is tenant\"] = jsonData.type === \"tenant\";", + "tests[\"deleted is true\"] = jsonData.deleted;", + "" + ] + } + } + ], + "request": { + "url": "{{baseUrl}}/my-tenant", + "method": "DELETE", + "header": [], + "body": {}, + "description": "" + }, + "response": [] + } + ] +} \ No newline at end of file diff --git a/postman-tests/README.md b/postman-tests/README.md new file mode 100644 index 0000000..0f69277 --- /dev/null +++ b/postman-tests/README.md @@ -0,0 +1,20 @@ +# Membrane Postman tests + +This folder has a set of tests and examples for use with the [Postman](https://www.getpostman.com/) tool. + +## Environment files + +The environments folder contains a set of reusable environment configs. Creating your own custom environment file should also be trivial since we only currently have one environment variable: `baseUrl`. + +## Prerequisites + +The tests are designed to work with the default `docker-compose.yml` file in the root of the membrane project. This compose file has some databases and such which are used as part of the tests. + +## Running from command line + +If you have Postman's CLI tool `newman` installed, simply go like this: + +``` +newman run -e environments/docker-toolbox.postman_environment.json Membrane.postman_collection.json +``` +(using the `docker-toolbox` environment) diff --git a/postman-tests/environments/docker-toolbox.postman_environment.json b/postman-tests/environments/docker-toolbox.postman_environment.json new file mode 100644 index 0000000..c3e3d30 --- /dev/null +++ b/postman-tests/environments/docker-toolbox.postman_environment.json @@ -0,0 +1,16 @@ +{ + "id": "556c1331-5e87-4201-2767-8089cdb8e523", + "name": "Membrane boot2docker", + "values": [ + { + "enabled": true, + "key": "baseUrl", + "value": "http://192.168.99.100:8080", + "type": "text" + } + ], + "timestamp": 1503214232219, + "_postman_variable_scope": "environment", + "_postman_exported_at": "2017-08-20T08:06:07.385Z", + "_postman_exported_using": "Postman/5.1.3" +} \ No newline at end of file diff --git a/postman-tests/environments/localhost.postman_environment.json b/postman-tests/environments/localhost.postman_environment.json new file mode 100644 index 0000000..5dc0d0f --- /dev/null +++ b/postman-tests/environments/localhost.postman_environment.json @@ -0,0 +1,16 @@ +{ + "id": "fa99af7e-2115-254e-649e-7a2742704dbb", + "name": "Membrane local", + "values": [ + { + "enabled": true, + "key": "baseUrl", + "value": "http://localhost:8080", + "type": "text" + } + ], + "timestamp": 1503066492942, + "_postman_variable_scope": "environment", + "_postman_exported_at": "2017-08-20T08:06:12.977Z", + "_postman_exported_using": "Postman/5.1.3" +} \ No newline at end of file From 40d0564f1c60fdbc4871ea8599b8ed928ff2d2c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20S=C3=B8rensen?= Date: Sun, 20 Aug 2017 01:15:12 -0700 Subject: [PATCH 3/3] Fixed issue in assigning database name when it shouldnt be set (CouchDB) --- .../controllers/DataSourceController.java | 5 -- .../TenantInteractionScenarioTest.java | 6 +-- pom.xml | 47 ++++++++++++++++++- .../docker-toolbox.postman_environment.json | 2 +- .../localhost.postman_environment.json | 2 +- 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/apache/metamodel/membrane/controllers/DataSourceController.java b/core/src/main/java/org/apache/metamodel/membrane/controllers/DataSourceController.java index 194bbe4..7540cf5 100644 --- a/core/src/main/java/org/apache/metamodel/membrane/controllers/DataSourceController.java +++ b/core/src/main/java/org/apache/metamodel/membrane/controllers/DataSourceController.java @@ -65,11 +65,6 @@ public GetDatasourceResponse put(@PathVariable("tenant") String tenantId, map.putAll(dataContextDefinition.getProperties()); map.put(DataContextPropertiesImpl.PROPERTY_DATA_CONTEXT_TYPE, dataContextDefinition.getType()); - if (!map.containsKey(DataContextPropertiesImpl.PROPERTY_DATABASE)) { - // add the data source ID as database name if it is not already set. - map.put(DataContextPropertiesImpl.PROPERTY_DATABASE, dataSourceId); - } - final DataContextProperties properties = new DataContextPropertiesImpl(map); final String dataContextIdentifier = tenantRegistry.getTenantContext(tenantId).getDataSourceRegistry() diff --git a/core/src/test/java/org/apache/metamodel/membrane/controllers/TenantInteractionScenarioTest.java b/core/src/test/java/org/apache/metamodel/membrane/controllers/TenantInteractionScenarioTest.java index b410e01..8a56934 100644 --- a/core/src/test/java/org/apache/metamodel/membrane/controllers/TenantInteractionScenarioTest.java +++ b/core/src/test/java/org/apache/metamodel/membrane/controllers/TenantInteractionScenarioTest.java @@ -77,7 +77,7 @@ public void testScenario() throws Exception { // create datasource { final MvcResult result = mockMvc.perform(MockMvcRequestBuilders.put("/tenant1/mydata").content( - "{'type':'pojo','table-defs':'hello_world (greeting VARCHAR, who VARCHAR); foo (bar INTEGER, baz DATE);'}" + "{'type':'pojo','database':'mydata','table-defs':'hello_world (greeting VARCHAR, who VARCHAR); foo (bar INTEGER, baz DATE);'}" .replace('\'', '"')).contentType(MediaType.APPLICATION_JSON)).andExpect( MockMvcResultMatchers.status().isOk()).andReturn(); @@ -185,8 +185,8 @@ public void testScenario() throws Exception { // query metadata from information_schema { final MvcResult result = mockMvc.perform(MockMvcRequestBuilders.get("/tenant1/mydata/q?sql={sql}", - "SELECT greeting, who AS who_is_it FROM hello_world")).andExpect(MockMvcResultMatchers.status() - .isOk()).andReturn(); + "SELECT greeting, who AS who_is_it FROM hello_world")) + .andExpect(MockMvcResultMatchers.status().isOk()).andReturn(); final String content = result.getResponse().getContentAsString(); final Map map = new ObjectMapper().readValue(content, Map.class); diff --git a/pom.xml b/pom.xml index 4a9ec09..1c1c32c 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ under the License. http://metamodel.apache.org 2017 pom - + all @@ -66,6 +66,51 @@ under the License. + + + + + org.apache.rat + apache-rat-plugin + + + + ASL20 + Apache Software License, 2.0 + Single licensed ASL v2.0 + + Licensed to the Apache Software Foundation (ASF) under + one + or more contributor license agreements. + + + + false + + KEYS + **/*.md + **/*.json + **/.gitignore/** + .git/** + .gitattributes + **/.project + **/.classpath + **/.settings/** + **/.vscode/** + **/.travis.yml + **/target/** + **/*.iml/** + **/*.iws/** + **/*.ipr/** + **/.idea/** + + + + + + + diff --git a/postman-tests/environments/docker-toolbox.postman_environment.json b/postman-tests/environments/docker-toolbox.postman_environment.json index c3e3d30..e04cb2e 100644 --- a/postman-tests/environments/docker-toolbox.postman_environment.json +++ b/postman-tests/environments/docker-toolbox.postman_environment.json @@ -1,6 +1,6 @@ { "id": "556c1331-5e87-4201-2767-8089cdb8e523", - "name": "Membrane boot2docker", + "name": "Membrane docker-toolbox", "values": [ { "enabled": true, diff --git a/postman-tests/environments/localhost.postman_environment.json b/postman-tests/environments/localhost.postman_environment.json index 5dc0d0f..527d430 100644 --- a/postman-tests/environments/localhost.postman_environment.json +++ b/postman-tests/environments/localhost.postman_environment.json @@ -1,6 +1,6 @@ { "id": "fa99af7e-2115-254e-649e-7a2742704dbb", - "name": "Membrane local", + "name": "Membrane localhost", "values": [ { "enabled": true,