Repository: brooklyn-server Updated Branches: refs/heads/master 5472c1e8d -> 3ad955999
fixes BROOKLYN-250 - config is being pushed into flags, so rather than expose flags in the locations API (which we're moving away from to the catalog API), I'm now checking for the presence of a displayName parameter in flags and setting it in the LocationTransformer. Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/049c852e Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/049c852e Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/049c852e Branch: refs/heads/master Commit: 049c852ed0f48435836a061bf3f3745cdd850f8f Parents: d27d6c7 Author: John McCabe <[email protected]> Authored: Mon Apr 11 12:24:45 2016 +0100 Committer: John McCabe <[email protected]> Committed: Mon Apr 11 12:24:45 2016 +0100 ---------------------------------------------------------------------- .../rest/transform/LocationTransformer.java | 8 +- .../rest/resources/LocationResourceTest.java | 114 +++++++++++++++++++ 2 files changed, 120 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/049c852e/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/LocationTransformer.java ---------------------------------------------------------------------- diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/LocationTransformer.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/LocationTransformer.java index 3777901..a9ae1d3 100644 --- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/LocationTransformer.java +++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/LocationTransformer.java @@ -74,8 +74,12 @@ public class LocationTransformer { config = ConfigBag.newInstance(spec.getConfig()).putAll(config).getAllConfig(); } else if (level==LocationDetailLevel.LOCAL_EXCLUDING_SECRET) { // in local mode, just make sure display name is set - if (spec!=null && !explicitConfig.containsKey(LocationConfigKeys.DISPLAY_NAME) && Strings.isNonBlank(spec.getDisplayName())) { - config.put(LocationConfigKeys.DISPLAY_NAME.getName(), spec.getDisplayName()); + if (spec!=null && !explicitConfig.containsKey(LocationConfigKeys.DISPLAY_NAME) ) { + if (Strings.isNonBlank((String) spec.getFlags().get(LocationConfigKeys.DISPLAY_NAME.getName()))){ + config.put(LocationConfigKeys.DISPLAY_NAME.getName(), spec.getFlags().get(LocationConfigKeys.DISPLAY_NAME.getName())); + } else if ( Strings.isNonBlank(spec.getDisplayName()) ) { + config.put(LocationConfigKeys.DISPLAY_NAME.getName(), spec.getDisplayName()); + } } } http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/049c852e/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/LocationResourceTest.java ---------------------------------------------------------------------- diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/LocationResourceTest.java b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/LocationResourceTest.java index 78aa1e2..2a00215 100644 --- a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/LocationResourceTest.java +++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/LocationResourceTest.java @@ -29,6 +29,8 @@ import javax.annotation.Nullable; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.apache.brooklyn.core.location.LocationConfigKeys; +import org.apache.brooklyn.location.byon.FixedListMachineProvisioningLocation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; @@ -62,6 +64,10 @@ public class LocationResourceTest extends BrooklynRestResourceTest { private String locationName = "my-jungle"; private String locationVersion = "0.1.2"; + private String configDisplayName = "config_displayName"; + private String testsDisplayName = "tests_displayName"; + private String byonHostname = "10.10.10.102"; + @Test @Deprecated public void testAddLegacyLocationDefinition() { @@ -187,4 +193,112 @@ public class LocationResourceTest extends BrooklynRestResourceTest { } }); } + + + @SuppressWarnings("deprecation") + @Test + public void testDisplayNameInConfig() { + String symbolicName = "test_config_displayName_id"; + String yaml = Joiner.on("\n").join(ImmutableList.of( + "brooklyn.catalog:", + " version: " + locationVersion, + " items:", + " - id: " + symbolicName, + " itemType: location", + " item:", + " type: byon:(hosts=\"" + byonHostname + "\")", + " brooklyn.config:", + " displayName: " + configDisplayName)); + + Response response = client().path("/catalog") + .post(yaml); + + assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + + URI addedCatalogItemUri = response.getLocation(); + log.info("added, at: " + addedCatalogItemUri); + + // Ensure location definition exists + CatalogLocationSummary locationItem = client().path("/catalog/locations/"+symbolicName + "/" + locationVersion) + .get(CatalogLocationSummary.class); + log.info(" item: " + locationItem); + LocationSummary locationSummary = client().path(URI.create("/locations/"+symbolicName+"/")).get(LocationSummary.class); + log.info(" summary: " + locationSummary); + Assert.assertEquals(locationSummary.getConfig().get(LocationConfigKeys.DISPLAY_NAME.getName()), configDisplayName); + + FixedListMachineProvisioningLocation l = (FixedListMachineProvisioningLocation) getManagementContext().getLocationRegistry().getLocationManaged(symbolicName); + Assert.assertEquals(l.getDisplayName(), configDisplayName); + } + + + @SuppressWarnings("deprecation") + @Test + public void testDisplayNameInItems() { + String symbolicName = "test_items_displayName_id"; + String yaml = Joiner.on("\n").join(ImmutableList.of( + "brooklyn.catalog:", + " version: " + locationVersion, + " items:", + " - id: " + symbolicName, + " itemType: location", + " displayName: " + testsDisplayName, + " item:", + " type: byon:(hosts=\"" + byonHostname + "\")")); + + Response response = client().path("/catalog") + .post(yaml); + + assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + + URI addedCatalogItemUri = response.getLocation(); + log.info("added, at: " + addedCatalogItemUri); + + // Ensure location definition exists + CatalogLocationSummary locationItem = client().path("/catalog/locations/"+symbolicName + "/" + locationVersion) + .get(CatalogLocationSummary.class); + log.info(" item: " + locationItem); + LocationSummary locationSummary = client().path(URI.create("/locations/"+symbolicName+"/")).get(LocationSummary.class); + log.info(" summary: " + locationSummary); + Assert.assertEquals(locationSummary.getConfig().get(LocationConfigKeys.DISPLAY_NAME.getName()), testsDisplayName); + + FixedListMachineProvisioningLocation l = (FixedListMachineProvisioningLocation) getManagementContext().getLocationRegistry().getLocationManaged(symbolicName); + Assert.assertEquals(l.getDisplayName(), testsDisplayName); + } + + + @SuppressWarnings("deprecation") + @Test + public void testDisplayNameInConfigOverridesItems() { + String symbolicName = "test_config_overrides_items_displayName_id"; + String yaml = Joiner.on("\n").join(ImmutableList.of( + "brooklyn.catalog:", + " version: " + locationVersion, + " items:", + " - id: " + symbolicName, + " itemType: location", + " displayName: " + testsDisplayName, + " item:", + " type: byon:(hosts=\"" + byonHostname + "\")", + " brooklyn.config:", + " displayName: " + configDisplayName)); + + Response response = client().path("/catalog") + .post(yaml); + + assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + + URI addedCatalogItemUri = response.getLocation(); + log.info("added, at: " + addedCatalogItemUri); + + // Ensure location definition exists + CatalogLocationSummary locationItem = client().path("/catalog/locations/"+symbolicName + "/" + locationVersion) + .get(CatalogLocationSummary.class); + log.info(" item: " + locationItem); + LocationSummary locationSummary = client().path(URI.create("/locations/"+symbolicName+"/")).get(LocationSummary.class); + log.info(" summary: " + locationSummary); + Assert.assertEquals(locationSummary.getConfig().get(LocationConfigKeys.DISPLAY_NAME.getName()), configDisplayName); + + FixedListMachineProvisioningLocation l = (FixedListMachineProvisioningLocation) getManagementContext().getLocationRegistry().getLocationManaged(symbolicName); + Assert.assertEquals(l.getDisplayName(), configDisplayName); + } }
