Return-Path: X-Original-To: apmail-brooklyn-commits-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D8B2019F39 for ; Wed, 20 Apr 2016 16:00:28 +0000 (UTC) Received: (qmail 90190 invoked by uid 500); 20 Apr 2016 16:00:28 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 90161 invoked by uid 500); 20 Apr 2016 16:00:28 -0000 Mailing-List: contact commits-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list commits@brooklyn.apache.org Received: (qmail 90151 invoked by uid 99); 20 Apr 2016 16:00:28 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Apr 2016 16:00:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A8FB6DFB8E; Wed, 20 Apr 2016 16:00:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: svet@apache.org To: commits@brooklyn.apache.org Date: Wed, 20 Apr 2016 16:00:28 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] brooklyn-server git commit: 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 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 Authored: Mon Apr 11 12:24:45 2016 +0100 Committer: John McCabe 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); + } }