From 0f4a1ac8f8688a71199cb4088f238c18be145093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C5=A0tumpf?= Date: Thu, 19 Nov 2015 18:01:16 +0100 Subject: [PATCH] FEATURE: add JDBC connection URL to Warehouse instance Conflicts: pom.xml --- src/main/java/com/gooddata/GoodData.java | 2 +- .../com/gooddata/warehouse/Warehouse.java | 42 +++++++++---------- .../gooddata/warehouse/WarehouseService.java | 31 +++----------- .../warehouse/WarehouseServiceAT.java | 2 +- .../warehouse/WarehouseServiceIT.java | 7 +++- .../com/gooddata/warehouse/WarehouseTest.java | 7 +++- .../warehouse/warehouse-null-token.json | 1 + src/test/resources/warehouse/warehouse.json | 1 + src/test/resources/warehouse/warehouses.json | 2 + 9 files changed, 41 insertions(+), 54 deletions(-) diff --git a/src/main/java/com/gooddata/GoodData.java b/src/main/java/com/gooddata/GoodData.java index 91ce4b44e..30960b150 100644 --- a/src/main/java/com/gooddata/GoodData.java +++ b/src/main/java/com/gooddata/GoodData.java @@ -185,7 +185,7 @@ protected GoodData(String hostname, String login, String password, int port, Str datasetService = new DatasetService(getRestTemplate(), dataStoreService); reportService = new ReportService(getRestTemplate()); processService = new ProcessService(getRestTemplate(), accountService, dataStoreService); - warehouseService = new WarehouseService(getRestTemplate(), hostname, port); + warehouseService = new WarehouseService(getRestTemplate()); connectorService = new ConnectorService(getRestTemplate(), projectService); } diff --git a/src/main/java/com/gooddata/warehouse/Warehouse.java b/src/main/java/com/gooddata/warehouse/Warehouse.java index e0649597d..1b2f04225 100644 --- a/src/main/java/com/gooddata/warehouse/Warehouse.java +++ b/src/main/java/com/gooddata/warehouse/Warehouse.java @@ -32,7 +32,6 @@ public class Warehouse { public static final String URI = Warehouses.URI + "/{" + ID_PARAM + "}"; public static final UriTemplate TEMPLATE = new UriTemplate(URI); - public static final UriTemplate JDBC_CONNECTION_TEMPLATE = new UriTemplate("jdbc:gdc:datawarehouse://{host}:{port}/gdc/datawarehouse/instances/{id}"); private static final String SELF_LINK = "self"; private static final String STATUS_ENABLED = "ENABLED"; @@ -48,9 +47,7 @@ public class Warehouse { private String status; private String environment; private Map links; - - private String warehouseHost; - private int warehousePort = 443; + private String connectionUrl; public Warehouse(String title, String authToken) { this(title, authToken, null); @@ -64,12 +61,13 @@ public Warehouse(String title, String authToken, String description) { @JsonCreator public Warehouse(@JsonProperty("title") String title, @JsonProperty("authorizationToken") String authToken, - @JsonProperty("description") String description, - @JsonProperty("created") @JsonDeserialize(using = ISODateTimeDeserializer.class) DateTime created, - @JsonProperty("updated") @JsonDeserialize(using = ISODateTimeDeserializer.class) DateTime updated, - @JsonProperty("createdBy") String createdBy, @JsonProperty("updatedBy") String updatedBy, - @JsonProperty("status") String status, @JsonProperty("environment") String environment, - @JsonProperty("links") Map links) { + @JsonProperty("description") String description, + @JsonProperty("created") @JsonDeserialize(using = ISODateTimeDeserializer.class) DateTime created, + @JsonProperty("updated") @JsonDeserialize(using = ISODateTimeDeserializer.class) DateTime updated, + @JsonProperty("createdBy") String createdBy, @JsonProperty("updatedBy") String updatedBy, + @JsonProperty("status") String status, @JsonProperty("environment") String environment, + @JsonProperty("connectionUrl") String connectionUrl, + @JsonProperty("links") Map links) { this(title, authToken, description); this.created = created; this.updated = updated; @@ -77,6 +75,7 @@ public Warehouse(@JsonProperty("title") String title, @JsonProperty("authorizati this.updatedBy = updatedBy; this.status = status; this.environment = environment; + this.connectionUrl = connectionUrl; this.links = links; } @@ -92,6 +91,13 @@ public String getDescription() { return description; } + /** + * Gets the JDBC connection string. + * + * @return JDBC connection string + */ + public String getConnectionUrl() { return connectionUrl; } + public void setTitle(String title) { this.title = title; } @@ -122,14 +128,6 @@ public String getStatus() { return status; } - void setWarehouseHost(String warehouseHost) { - this.warehouseHost = warehouseHost; - } - - void setWarehousePort(int warehousePort) { - this.warehousePort = warehousePort; - } - public String getEnvironment() { return environment; } @@ -149,15 +147,13 @@ public Map getLinks() { /** * Get jdbc connection string. Works only on Warehouse loaded from API (using WarehouseService). + * @deprecated Use {@link #getConnectionUrl()} instead. * @return jdbc connection string */ @JsonIgnore + @Deprecated public String getJdbcConnectionString() { - if (warehouseHost == null) { - throw new IllegalStateException("Please set warehouseHost " + - "to be able to construct jdbc connection string"); - } - return JDBC_CONNECTION_TEMPLATE.expand(warehouseHost, warehousePort, getId()).toString(); + return getConnectionUrl(); } @JsonIgnore diff --git a/src/main/java/com/gooddata/warehouse/WarehouseService.java b/src/main/java/com/gooddata/warehouse/WarehouseService.java index 5f978d8a2..a9a1037c1 100644 --- a/src/main/java/com/gooddata/warehouse/WarehouseService.java +++ b/src/main/java/com/gooddata/warehouse/WarehouseService.java @@ -10,6 +10,7 @@ import com.gooddata.collections.PageableList; import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; +import org.springframework.util.StringUtils; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -25,21 +26,14 @@ */ public class WarehouseService extends AbstractService { - private final String warehouseHost; - private final int warehousePort; - /** * Sets RESTful HTTP Spring template. Should be called from constructor of concrete service extending * this abstract one. * * @param restTemplate RESTful HTTP Spring template - * @param warehouseHost host to connect warehouses - * @param warehousePort port to connect warehouses */ - public WarehouseService(RestTemplate restTemplate, String warehouseHost, int warehousePort) { + public WarehouseService(RestTemplate restTemplate) { super(restTemplate); - this.warehouseHost = notNull(warehouseHost, "warehouseHost"); - this.warehousePort = warehousePort; } /** @@ -80,7 +74,7 @@ protected void onFinish() { public void handlePollResult(WarehouseTask pollResult) { try { final Warehouse warehouse = restTemplate.getForObject(pollResult.getWarehouseLink(), Warehouse.class); - setResult(setWarehouseConnection(warehouse)); + setResult(warehouse); } catch (GoodDataException | RestClientException e) { throw new GoodDataException("Warehouse creation finished, but can't get created warehouse, uri: " + pollResult.getWarehouseLink(), e); @@ -116,7 +110,7 @@ public void removeWarehouse(Warehouse warehouse) { public Warehouse getWarehouseByUri(String uri) { notEmpty(uri, "uri"); try { - return setWarehouseConnection(restTemplate.getForObject(uri, Warehouse.class)); + return restTemplate.getForObject(uri, Warehouse.class); } catch (GoodDataRestException e) { if (HttpStatus.NOT_FOUND.value() == e.getStatusCode()) { throw new WarehouseNotFoundException(uri, e); @@ -171,7 +165,7 @@ private PageableList listWarehouses(final URI uri) { if (result == null) { return new PageableList<>(); } - return setWarehouseConnection(result); + return result; } catch (GoodDataException | RestClientException e) { throw new GoodDataException("Unable to list Warehouses", e); } @@ -257,19 +251,4 @@ public Warehouse updateWarehouse(Warehouse toUpdate) { return getWarehouseByUri(toUpdate.getUri()); } - - private Warehouse setWarehouseConnection(Warehouse warehouse) { - notNull(warehouse, "warehouse"); - warehouse.setWarehouseHost(warehouseHost); - warehouse.setWarehousePort(warehousePort); - return warehouse; - } - - private PageableList setWarehouseConnection(PageableList warehouses) { - notNull(warehouses, "warehouses"); - for (Warehouse warehouse : warehouses) { - setWarehouseConnection(warehouse); - } - return warehouses; - } } diff --git a/src/test/java/com/gooddata/warehouse/WarehouseServiceAT.java b/src/test/java/com/gooddata/warehouse/WarehouseServiceAT.java index fac69398b..56c8c15f6 100644 --- a/src/test/java/com/gooddata/warehouse/WarehouseServiceAT.java +++ b/src/test/java/com/gooddata/warehouse/WarehouseServiceAT.java @@ -39,7 +39,7 @@ public void createWarehouse() throws Exception { final Warehouse wh = new Warehouse(title, warehouseToken); wh.setEnvironment(Environment.TESTING); warehouse = service.createWarehouse(wh).get(); - String jdbc = warehouse.getJdbcConnectionString(); + String jdbc = warehouse.getConnectionUrl(); } @Test(groups = "warehouse", dependsOnMethods = "createWarehouse") diff --git a/src/test/java/com/gooddata/warehouse/WarehouseServiceIT.java b/src/test/java/com/gooddata/warehouse/WarehouseServiceIT.java index f3d42e372..e7ef9e1d7 100644 --- a/src/test/java/com/gooddata/warehouse/WarehouseServiceIT.java +++ b/src/test/java/com/gooddata/warehouse/WarehouseServiceIT.java @@ -34,6 +34,8 @@ public class WarehouseServiceIT extends AbstractGoodDataIT { private static final String WAREHOUSE_URI = Warehouse.TEMPLATE.expand(WAREHOUSE_ID).toString(); private static final String WAREHOUSE_USER_URI = WarehouseUsers.TEMPLATE.expand(WAREHOUSE_ID).toString(); + private static final String CONNECTION_URL = "CONNECTION_URL"; + private WarehouseTask pollingTask; private WarehouseTask finishedTask; private Warehouse warehouse; @@ -71,7 +73,7 @@ public void shouldCreateWarehouse() throws Exception { final Warehouse created = gd.getWarehouseService().createWarehouse(new Warehouse(TITLE, "{Token}", "Storage")).get(); assertThat(created, notNullValue()); assertThat(created.getTitle(), is(TITLE)); - assertThat(created.getJdbcConnectionString(), is("jdbc:gdc:datawarehouse://localhost:" + port() + WAREHOUSE_URI)); + assertThat(created.getConnectionUrl(), is(CONNECTION_URL)); } @Test(expectedExceptions = GoodDataException.class) @@ -103,6 +105,8 @@ public void shouldListWarehouses() throws Exception { final PageableList list = gd.getWarehouseService().listWarehouses(); assertThat(list, notNullValue()); assertThat(list, hasSize(2)); + assertThat(list.get(0).getConnectionUrl(), notNullValue()); + assertThat(list.get(1).getConnectionUrl(), notNullValue()); } @Test @@ -128,6 +132,7 @@ public void shouldGetWarehouse() throws Exception { final Warehouse warehouse = gd.getWarehouseService().getWarehouseById(WAREHOUSE_ID); assertThat(warehouse, notNullValue()); assertThat(warehouse.getTitle(), is(TITLE)); + assertThat(warehouse.getConnectionUrl(), notNullValue()); } @Test diff --git a/src/test/java/com/gooddata/warehouse/WarehouseTest.java b/src/test/java/com/gooddata/warehouse/WarehouseTest.java index 2d92784fd..7f548ace0 100644 --- a/src/test/java/com/gooddata/warehouse/WarehouseTest.java +++ b/src/test/java/com/gooddata/warehouse/WarehouseTest.java @@ -26,6 +26,7 @@ public class WarehouseTest { public static final String CREATED_BY = "/gdc/account/profile/createdBy"; public static final String UPDATED_BY = "/gdc/account/profile/updatedBy"; public static final String STATUS = "ENABLED"; + public static final String CONNECTION_URL = "CONNECTION_URL"; public static final Map LINKS = new LinkedHashMap() {{ put("self", "/gdc/datawarehouse/instances/instanceId"); put("parent", "/gdc/datawarehouse/instances"); @@ -42,13 +43,13 @@ public void testSerializationForInstanceCreation() throws Exception { @Test public void testSerialization() throws Exception { - final Warehouse warehouse = new Warehouse(TITLE, TOKEN, DESCRIPTION, CREATED, UPDATED, CREATED_BY, UPDATED_BY, STATUS, ENVIRONMENT, LINKS); + final Warehouse warehouse = new Warehouse(TITLE, TOKEN, DESCRIPTION, CREATED, UPDATED, CREATED_BY, UPDATED_BY, STATUS, ENVIRONMENT, CONNECTION_URL, LINKS); assertThat(warehouse, serializesToJson("/warehouse/warehouse.json")); } @Test public void testSerializationWithNullToken() throws Exception { - final Warehouse warehouse = new Warehouse(TITLE, null, DESCRIPTION, CREATED, UPDATED, CREATED_BY, UPDATED_BY, STATUS, ENVIRONMENT, LINKS); + final Warehouse warehouse = new Warehouse(TITLE, null, DESCRIPTION, CREATED, UPDATED, CREATED_BY, UPDATED_BY, STATUS, ENVIRONMENT, CONNECTION_URL, LINKS); assertThat(warehouse, serializesToJson("/warehouse/warehouse-null-token.json")); } @@ -67,6 +68,7 @@ public void testDeserialization() throws Exception { assertThat(warehouse.getUpdated(), is(UPDATED)); assertThat(warehouse.getStatus(), is(STATUS)); assertThat(warehouse.getLinks(), is(LINKS)); + assertThat(warehouse.getConnectionUrl(), is(CONNECTION_URL)); } @Test @@ -84,5 +86,6 @@ public void testDeserializationWithNullToken() throws Exception { assertThat(warehouse.getUpdated(), is(UPDATED)); assertThat(warehouse.getStatus(), is(STATUS)); assertThat(warehouse.getLinks(), is(LINKS)); + assertThat(warehouse.getConnectionUrl(), is(CONNECTION_URL)); } } diff --git a/src/test/resources/warehouse/warehouse-null-token.json b/src/test/resources/warehouse/warehouse-null-token.json index 708b11db6..4bafa4c50 100644 --- a/src/test/resources/warehouse/warehouse-null-token.json +++ b/src/test/resources/warehouse/warehouse-null-token.json @@ -8,6 +8,7 @@ "createdBy" : "/gdc/account/profile/createdBy", "updatedBy" : "/gdc/account/profile/updatedBy", "environment" : "TESTING", + "connectionUrl" : "CONNECTION_URL", "links" : { "self" : "/gdc/datawarehouse/instances/instanceId", "parent" : "/gdc/datawarehouse/instances", diff --git a/src/test/resources/warehouse/warehouse.json b/src/test/resources/warehouse/warehouse.json index 29deb45e5..971150215 100644 --- a/src/test/resources/warehouse/warehouse.json +++ b/src/test/resources/warehouse/warehouse.json @@ -9,6 +9,7 @@ "createdBy" : "/gdc/account/profile/createdBy", "updatedBy" : "/gdc/account/profile/updatedBy", "environment" : "TESTING", + "connectionUrl" : "CONNECTION_URL", "links" : { "self" : "/gdc/datawarehouse/instances/instanceId", "parent" : "/gdc/datawarehouse/instances", diff --git a/src/test/resources/warehouse/warehouses.json b/src/test/resources/warehouse/warehouses.json index 919eca8ef..f9deee1f8 100644 --- a/src/test/resources/warehouse/warehouses.json +++ b/src/test/resources/warehouse/warehouses.json @@ -10,6 +10,7 @@ "updated" : "2014-03-17T13:02:41.000Z", "createdBy" : "/gdc/account/profile/{profile-id}", "updatedBy" : "/gdc/account/profile/{profile-id}", + "connectionUrl" : "test", "links" : { "self" : "/gdc/datawarehouse/instances/{instance-id}", "parent" : "/gdc/datawarehouse/instances", @@ -27,6 +28,7 @@ "updated" : "2014-04-09T22:10:26.000Z", "createdBy" : "/gdc/account/profile/{profile-id}", "updatedBy" : "/gdc/account/profile/{profile-id}", + "connectionUrl" : "test", "links" : { "self" : "/gdc/datawarehouse/instances/{instance-id}", "parent" : "/gdc/datawarehouse/instances",