brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject 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 flags
Date Thu, 28 Apr 2016 13:44:12 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/0.9.x 0b371e34b -> a80b1dfdd


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/a80b1dfd
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/a80b1dfd
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/a80b1dfd

Branch: refs/heads/0.9.x
Commit: a80b1dfddc146c874d81ba92388bbbf78d3bcf03
Parents: 0b371e3
Author: John McCabe <john@johnmccabe.net>
Authored: Mon Apr 11 12:24:45 2016 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Thu Apr 28 14:43:51 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/a80b1dfd/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/a80b1dfd/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);
+    }
 }


Mime
View raw message