brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drigod...@apache.org
Subject [1/4] brooklyn-server git commit: provide more detail of locations in REST calls
Date Wed, 03 May 2017 11:13:05 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master e247841dd -> a32cdd614


provide more detail of locations in REST calls

with some confused parts marked TODO


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/bfbcddd5
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/bfbcddd5
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/bfbcddd5

Branch: refs/heads/master
Commit: bfbcddd5d2088ce2cdeedc1b70e5db1edf37a0fb
Parents: 17aa622
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Sat Feb 18 00:50:28 2017 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Tue Feb 28 14:07:10 2017 +0000

----------------------------------------------------------------------
 .../location/internal/LocationInternal.java     |  1 +
 .../jclouds/JcloudsSshMachineLocation.java      |  7 ++++++
 .../rest/resources/LocationResource.java        | 14 +++++-------
 .../rest/transform/CatalogTransformer.java      | 12 +++++-----
 .../rest/transform/LocationTransformer.java     | 23 +++++++++++++++++++-
 .../rest/util/BrooklynRestResourceUtils.java    |  4 ++--
 6 files changed, 43 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bfbcddd5/core/src/main/java/org/apache/brooklyn/core/location/internal/LocationInternal.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/internal/LocationInternal.java
b/core/src/main/java/org/apache/brooklyn/core/location/internal/LocationInternal.java
index da4742e..79b8eaa 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/internal/LocationInternal.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/internal/LocationInternal.java
@@ -37,6 +37,7 @@ import com.google.common.annotations.Beta;
  */
 public interface LocationInternal extends BrooklynObjectInternal, Location {
 
+    // TODO original_spec seems to be the reference inside the named_spec -- do we really
ever want that?
     public static final ConfigKey<String> ORIGINAL_SPEC = ConfigKeys.newStringConfigKey("spec.original",
"The original spec used to instantiate a location");
     public static final ConfigKey<String> FINAL_SPEC = ConfigKeys.newStringConfigKey("spec.final",
"The actual spec (in a chain) which instantiates a location");
     public static final ConfigKey<String> NAMED_SPEC_NAME = ConfigKeys.newStringConfigKey("spec.named.name",
"The name on the (first) named spec in a chain");

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bfbcddd5/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
index dfbf63f..f69361e 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
@@ -633,7 +633,14 @@ public class JcloudsSshMachineLocation extends SshMachineLocation implements
Jcl
         putIfNotNull(builder, "provider", (parent != null) ? parent.getProvider() : null);
         putIfNotNull(builder, "account", (parent != null) ? parent.getIdentity() : null);
         putIfNotNull(builder, "region", (parent != null) ? parent.getRegion() : null);
+        putIfNotNull(builder, "endpoint", (parent != null) ? parent.getEndpoint() : null);
         putIfNotNull(builder, "serverId", getJcloudsId());
+        
+        putIfNotNull(builder, "hostname", getHostname());
+        putIfNotNull(builder, "address", getAddress()!=null ? getAddress().getHostAddress()
: null);
+        putIfNotNull(builder, "subnetHostname", getSubnetHostname());
+        putIfNotNull(builder, "subnetAddress", getSubnetIp());
+        
         putIfNotNull(builder, "imageId", getImageId());
         putIfNotNull(builder, "instanceTypeName", (hardware.isPresent() ? hardware.get().getName()
: null));
         putIfNotNull(builder, "instanceTypeId", (hardware.isPresent() ? hardware.get().getProviderId()
: null));

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bfbcddd5/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/LocationResource.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/LocationResource.java
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/LocationResource.java
index 80bd2d5..55159fa 100644
--- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/LocationResource.java
+++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/LocationResource.java
@@ -18,6 +18,8 @@
  */
 package org.apache.brooklyn.rest.resources;
 
+import static org.apache.brooklyn.rest.util.WebResourceUtils.serviceAbsoluteUriBuilder;
+
 import java.net.URI;
 import java.util.Comparator;
 import java.util.LinkedHashMap;
@@ -51,7 +53,6 @@ import com.google.common.base.Joiner;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Sets;
-import static org.apache.brooklyn.rest.util.WebResourceUtils.serviceAbsoluteUriBuilder;
 
 @SuppressWarnings("deprecation")
 @HaHotStateRequired
@@ -135,14 +136,11 @@ public class LocationResource extends AbstractBrooklynRestResource implements
Lo
 
     public LocationSummary get(String locationId, boolean fullConfig) {
         LocationDetailLevel configLevel = fullConfig ? LocationDetailLevel.FULL_EXCLUDING_SECRET
: LocationDetailLevel.LOCAL_EXCLUDING_SECRET;
-        Location l1 = mgmt().getLocationManager().getLocation(locationId);
-        if (l1!=null) {
-            return LocationTransformer.newInstance(mgmt(), l1, configLevel, ui.getBaseUriBuilder());
+        LocationSummary result = LocationTransformer.newInstance(mgmt(), locationId, configLevel,
ui.getBaseUriBuilder());
+        if (result!=null) {
+            return result;
         }
-
-        LocationDefinition l2 = brooklyn().getLocationRegistry().getDefinedLocationById(locationId);
-        if (l2==null) throw WebResourceUtils.notFound("No location matching %s", locationId);
-        return LocationTransformer.newInstance(mgmt(), l2, configLevel, ui.getBaseUriBuilder());
+        throw WebResourceUtils.notFound("No location matching %s", locationId);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bfbcddd5/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
index 5cbe16d..00051ba 100644
--- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
+++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
@@ -18,11 +18,15 @@
  */
 package org.apache.brooklyn.rest.transform;
 
+import static org.apache.brooklyn.rest.util.WebResourceUtils.serviceUriBuilder;
+
 import java.net.URI;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import javax.ws.rs.core.UriBuilder;
+
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.catalog.CatalogItem.CatalogItemType;
 import org.apache.brooklyn.api.effector.Effector;
@@ -38,6 +42,7 @@ import org.apache.brooklyn.api.sensor.Sensor;
 import org.apache.brooklyn.core.entity.EntityDynamicType;
 import org.apache.brooklyn.core.mgmt.BrooklynTags;
 import org.apache.brooklyn.core.objs.BrooklynTypes;
+import org.apache.brooklyn.rest.api.CatalogApi;
 import org.apache.brooklyn.rest.domain.CatalogEntitySummary;
 import org.apache.brooklyn.rest.domain.CatalogItemSummary;
 import org.apache.brooklyn.rest.domain.CatalogLocationSummary;
@@ -58,18 +63,11 @@ import org.slf4j.LoggerFactory;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
 
-import javax.ws.rs.core.UriBuilder;
-
-import org.apache.brooklyn.rest.api.CatalogApi;
-
-import static org.apache.brooklyn.rest.util.WebResourceUtils.serviceUriBuilder;
-
 @SuppressWarnings("deprecation")
 public class CatalogTransformer {
 
     private static final org.slf4j.Logger log = LoggerFactory.getLogger(CatalogTransformer.class);
     
-    @SuppressWarnings({ "unchecked", "rawtypes" })
     public static <T extends Entity> CatalogEntitySummary catalogEntitySummary(BrooklynRestResourceUtils
b, CatalogItem<T,EntitySpec<? extends T>> item, UriBuilder ub) {
         Set<EntityConfigSummary> config = Sets.newLinkedHashSet();
         Set<SensorSummary> sensors = Sets.newTreeSet(SummaryComparators.nameComparator());

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bfbcddd5/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 c612c6f..c083ad9 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
@@ -71,9 +71,11 @@ public class LocationTransformer {
         Map<String, Object> config = MutableMap.copyOf(explicitConfig==null ? null
: explicitConfig.getAllConfig());
         if (spec!=null && (level==LocationDetailLevel.FULL_EXCLUDING_SECRET || level==LocationDetailLevel.FULL_INCLUDING_SECRET))
{
             // full takes from any resolved spec AND from explicit config
-            config = ConfigBag.newInstance(spec.getConfig()).putAll(config).getAllConfig();
+            // TODO include flags? esp need provider, region, and endpoint
+            config = ConfigBag.newInstance(spec.getFlags()).putAll(spec.getConfig()).putAll(config).getAllConfig();
         } else if (level==LocationDetailLevel.LOCAL_EXCLUDING_SECRET) {
             // in local mode, just make sure display name is set
+            // TODO include provider, region, and endpoint ?
             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()));
@@ -146,6 +148,7 @@ public class LocationTransformer {
             // walk parent locations
             // TODO not sure this is the best strategy, or if it's needed, as the spec config
is inherited anyway... 
             if (spec==null) {
+                // TODO should be "named spec" ?
                 Maybe<Object> originalSpec = ((LocationInternal)lp).config().getRaw(LocationInternal.ORIGINAL_SPEC);
                 if (originalSpec.isPresent())
                     spec = Strings.toString(originalSpec.get());
@@ -206,4 +209,22 @@ public class LocationTransformer {
                 .addIfNotNull("spec", specUri)
                 .asUnmodifiable() );
     }
+    
+    public static LocationSummary newInstance(ManagementContext mgmt, String id, LocationDetailLevel
level, UriBuilder uriBuilder) {
+        // if it's an ID of a deployed location
+        Location l1 = mgmt.getLocationManager().getLocation(id);
+        if (l1!=null) {
+            return newInstance(mgmt, l1, level, uriBuilder);
+        }
+        
+        // a catalog item OR a legacy properties-based -- but currently goes via registry
+        LocationDefinition l2 = mgmt.getLocationRegistry().getDefinedLocationById(id);
+        if (l2!=null) {
+            return LocationTransformer.newInstance(mgmt, l2, level, uriBuilder);
+        }
+        
+        // not recognised
+        return null;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bfbcddd5/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
index 6645c5c..d9eb7ee 100644
--- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
+++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
@@ -65,9 +65,9 @@ import org.apache.brooklyn.rest.domain.ApplicationSpec;
 import org.apache.brooklyn.rest.domain.EntitySpec;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.collections.MutableSet;
-import org.apache.brooklyn.util.core.flags.TypeCoercions;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.javalang.Reflections;
+import org.apache.brooklyn.util.javalang.coerce.PrimitiveStringTypeCoercions;
 import org.apache.brooklyn.util.net.Urls;
 import org.apache.brooklyn.util.text.Strings;
 import org.slf4j.Logger;
@@ -552,7 +552,7 @@ public class BrooklynRestResourceUtils {
             }
         }
         
-        if (TypeCoercions.isPrimitiveOrBoxer(value.getClass())) return value;
+        if (PrimitiveStringTypeCoercions.isPrimitiveOrBoxer(value.getClass())) return value;
         return value.toString();
     }
 


Mime
View raw message