brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [05/18] brooklyn-server git commit: support location spec on entity spec, and deprecate methods which take concrete objects
Date Fri, 18 Mar 2016 11:06:26 GMT
support location spec on entity spec, and deprecate methods which take concrete objects


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

Branch: refs/heads/master
Commit: 2876a9e5884332c38cdd2f631d0d221de2de35c9
Parents: 515af88
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Tue Mar 15 13:27:35 2016 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Tue Mar 15 13:27:35 2016 +0000

----------------------------------------------------------------------
 .../apache/brooklyn/api/entity/EntitySpec.java  | 59 ++++++++++++++++----
 .../BrooklynComponentTemplateResolver.java      |  1 +
 .../core/mgmt/EntityManagementUtils.java        |  6 +-
 .../core/objs/proxy/InternalEntityFactory.java  |  6 +-
 .../entity/group/DynamicClusterImpl.java        | 12 ++--
 5 files changed, 65 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2876a9e5/api/src/main/java/org/apache/brooklyn/api/entity/EntitySpec.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/entity/EntitySpec.java b/api/src/main/java/org/apache/brooklyn/api/entity/EntitySpec.java
index 58cf946..9287aab 100644
--- a/api/src/main/java/org/apache/brooklyn/api/entity/EntitySpec.java
+++ b/api/src/main/java/org/apache/brooklyn/api/entity/EntitySpec.java
@@ -28,6 +28,7 @@ import javax.annotation.Nullable;
 
 import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
 import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.policy.Policy;
 import org.apache.brooklyn.api.policy.PolicySpec;
 import org.apache.brooklyn.api.sensor.Enricher;
@@ -108,6 +109,7 @@ public class EntitySpec<T extends Entity> extends AbstractBrooklynObjectSpec<T,E
     private final List<Enricher> enrichers = Lists.newArrayList();
     private final List<EnricherSpec<?>> enricherSpecs = Lists.newArrayList();
     private final List<Location> locations = Lists.newArrayList();
+    private final List<LocationSpec<?>> locationSpecs = Lists.newArrayList();
     private final Set<Class<?>> additionalInterfaces = Sets.newLinkedHashSet();
     private final List<EntityInitializer> entityInitializers = Lists.newArrayList();
     private final List<EntitySpec<?>> children = Lists.newArrayList();
@@ -131,6 +133,7 @@ public class EntitySpec<T extends Entity> extends AbstractBrooklynObjectSpec<T,E
                 .children(copyFromSpecs(otherSpec.getChildren()))
                 .members(otherSpec.getMembers())
                 .groups(otherSpec.getGroups())
+                .locationSpecs(otherSpec.getLocationSpecs())
                 .locations(otherSpec.getLocations());
         
         if (otherSpec.getParent() != null) parent(otherSpec.getParent());
@@ -207,6 +210,7 @@ public class EntitySpec<T extends Entity> extends AbstractBrooklynObjectSpec<T,E
         return policySpecs;
     }
     
+    /** @deprecated since 0.9.0 in future only {@link #getPolicySpecs()} will be supported
*/ @Deprecated
     public List<Policy> getPolicies() {
         return policies;
     }
@@ -215,10 +219,16 @@ public class EntitySpec<T extends Entity> extends AbstractBrooklynObjectSpec<T,E
         return enricherSpecs;
     }
     
+    /** @deprecated since 0.9.0 in future only {@link #getEnricherSpecs()} will be supported
*/ @Deprecated
     public List<Enricher> getEnrichers() {
         return enrichers;
     }
     
+    public List<LocationSpec<?>> getLocationSpecs() {
+        return locationSpecs;
+    }
+
+    /** @deprecated since 0.9.0 in future only {@link #getLocationSpecs()} will be supported
*/ @Deprecated
     public List<Location> getLocations() {
         return locations;
     }
@@ -311,7 +321,8 @@ public class EntitySpec<T extends Entity> extends AbstractBrooklynObjectSpec<T,E
         return this;
     }
 
-    /** adds a policy to the spec */
+    /** adds a policy to the spec 
+     * @deprecated since 0.9.0 pass a spec, using {@link #policy(EnricherSpec)} */ @Deprecated
     public <V> EntitySpec<T> policy(Policy val) {
         checkMutable();
         policies.add(checkNotNull(val, "policy"));
@@ -332,21 +343,23 @@ public class EntitySpec<T extends Entity> extends AbstractBrooklynObjectSpec<T,E
         return this;
     }
     
-    /** adds the supplied policies to the spec */
+    /** adds the supplied policies to the spec 
+     * @deprecated since 0.9.0 pass a spec, using {@link #policySpecs(Iterable)} */ @Deprecated
     public <V> EntitySpec<T> policies(Iterable<? extends Policy> val) {
         checkMutable();
         policies.addAll(MutableList.copyOf(checkNotNull(val, "policies")));
         return this;
     }
     
-    /** adds a policy to the spec */
+    /** adds an enricher to the spec 
+     * @deprecated since 0.9.0 pass a spec, using {@link #enricher(EnricherSpec)} */ @Deprecated
     public <V> EntitySpec<T> enricher(Enricher val) {
         checkMutable();
         enrichers.add(checkNotNull(val, "enricher"));
         return this;
     }
 
-    /** adds a policy to the spec */
+    /** adds an enricher to the spec */
     public <V> EntitySpec<T> enricher(EnricherSpec<?> val) {
         checkMutable();
         enricherSpecs.add(checkNotNull(val, "enricherSpec"));
@@ -360,34 +373,56 @@ public class EntitySpec<T extends Entity> extends AbstractBrooklynObjectSpec<T,E
         return this;
     }
     
-    /** adds the supplied policies to the spec */
+    /** adds the supplied policies to the spec 
+     * @deprecated since 0.9.0 pass a spec, using {@link #enricherSpecs(Iterable)} */ @Deprecated
     public <V> EntitySpec<T> enrichers(Iterable<? extends Enricher> val)
{
         checkMutable();
         enrichers.addAll(MutableList.copyOf(checkNotNull(val, "enrichers")));
         return this;
     }
     
+     /** adds a location to the spec
+      * @deprecated since 0.9.0 pass a spec, using {@link #enricherSpecs(Iterable)} */ 
+     @Deprecated
+     // there are still many places in tests where we use this;
+     // in some we want to force the use of a given location.
+     // TODO we could perhaps introduce an ExistingLocation class which can generate a spec
based on an ID to formalize this?
+     public <V> EntitySpec<T> location(Location val) {
+         checkMutable();
+         locations.add(checkNotNull(val, "location"));
+         return this;
+     }
+     
     /** adds a location to the spec */
-    public <V> EntitySpec<T> location(Location val) {
+    public <V> EntitySpec<T> location(LocationSpec<?> val) {
         checkMutable();
-        locations.add(checkNotNull(val, "location"));
+        locationSpecs.add(checkNotNull(val, "location"));
         return this;
     }
     
-    /** clears locations defined in the spec */
-    public <V> EntitySpec<T> clearLocations() {
+    /** adds the supplied locations to the spec */
+    public <V> EntitySpec<T> locationSpecs(Iterable<? extends LocationSpec<?>>
val) {
         checkMutable();
-        locations.clear();
-        return this;        
+        locationSpecs.addAll(MutableList.copyOf(checkNotNull(val, "locations")));
+        return this;
     }
     
-    /** adds the supplied locations to the spec */
+    /** adds the supplied locations to the spec
+     * @deprecated since 0.9.0 pass a spec, using {@link #locationSpecs(Iterable)} */ @Deprecated
     public <V> EntitySpec<T> locations(Iterable<? extends Location> val)
{
         checkMutable();
         locations.addAll(MutableList.copyOf(checkNotNull(val, "locations")));
         return this;
     }
 
+    /** clears locations defined in the spec */
+    public <V> EntitySpec<T> clearLocations() {
+        checkMutable();
+        locationSpecs.clear();
+        locations.clear();
+        return this;        
+    }
+    
     /** "seals" this spec, preventing any future changes */
     public EntitySpec<T> immutable() {
         immutable = true;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2876a9e5/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
index fdc2559..9757063 100644
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
+++ b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
@@ -224,6 +224,7 @@ public class BrooklynComponentTemplateResolver {
         if (planId != null)
             spec.configure(BrooklynCampConstants.PLAN_ID, planId);
 
+        // XXX use location spec
         List<Location> locations = new BrooklynYamlLocationResolver(mgmt).resolveLocations(attrs.getAllConfig(),
true);
         if (locations != null) {
             // override locations defined in the type if locations are specified here

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2876a9e5/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java
index 2f37e7c..d5c31ee 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java
@@ -249,6 +249,7 @@ public class EntityManagementUtils {
             wrappedChild.displayName(wrapperParent.getDisplayName());
         }
         
+        wrappedChild.locationSpecs(wrapperParent.getLocationSpecs());
         wrappedChild.locations(wrapperParent.getLocations());
         
         if (!wrapperParent.getParameters().isEmpty())
@@ -310,8 +311,9 @@ public class EntityManagementUtils {
             spec.getInitializers().isEmpty() &&
             spec.getPolicies().isEmpty() &&
             spec.getPolicySpecs().isEmpty() &&
-            // these items prevent merge only if they are defined at both levels
-            (spec.getLocations().isEmpty() || Iterables.getOnlyElement(spec.getChildren()).getLocations().isEmpty())
+            // prevent merge only if a location is defined at both levels
+            ((spec.getLocations().isEmpty() && spec.getLocationSpecs().isEmpty())
|| 
+                (Iterables.getOnlyElement(spec.getChildren()).getLocations().isEmpty()) &&
Iterables.getOnlyElement(spec.getChildren()).getLocationSpecs().isEmpty())
             // TODO what should we do with parameters? currently clobbers due to EntitySpec.parameters(...)
behaviour.
 //            && (spec.getParameters().isEmpty() || Iterables.getOnlyElement(spec.getChildren()).getParameters().isEmpty())
             ;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2876a9e5/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalEntityFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalEntityFactory.java
b/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalEntityFactory.java
index e55d6d9..96516f0 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalEntityFactory.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalEntityFactory.java
@@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkState;
 
 import java.lang.reflect.InvocationTargetException;
 import java.util.Collection;
-import java.util.List;
 import java.util.Map;
 import java.util.Queue;
 import java.util.Set;
@@ -34,6 +33,7 @@ import org.apache.brooklyn.api.entity.EntityLocal;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.entity.EntityTypeRegistry;
 import org.apache.brooklyn.api.entity.Group;
+import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.objs.SpecParameter;
 import org.apache.brooklyn.api.policy.Policy;
 import org.apache.brooklyn.api.policy.PolicySpec;
@@ -326,6 +326,10 @@ public class InternalEntityFactory extends InternalFactory {
             public void run() {
                 ((AbstractEntity)entity).init();
 
+                for (LocationSpec<?> locationSpec : spec.getLocationSpecs()) {
+                    ((AbstractEntity)entity).addLocations(MutableList.of(
+                        managementContext.getLocationManager().createLocation(locationSpec)));
+                }
                 ((AbstractEntity)entity).addLocations(spec.getLocations());
 
                 for (EntityInitializer initializer: spec.getInitializers()) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2876a9e5/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java
index dc604dc..db263d7 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java
@@ -728,15 +728,19 @@ public class DynamicClusterImpl extends AbstractGroupImpl implements
DynamicClus
 
         // choose locations to be deployed to
         List<Location> chosenLocations;
-        List<Location> memberLocations = getMemberSpec() == null ? null : getMemberSpec().getLocations();
-        if (memberLocations != null && memberLocations.size() > 0) {
+
+        EntitySpec<?> memberSpec = getMemberSpec();
+        boolean memberSpecHasLocation = memberSpec!=null && (!memberSpec.getLocationSpecs().isEmpty()
|| !memberSpec.getLocations().isEmpty());
+        if (memberSpecHasLocation) {
             // The memberSpec overrides the location passed to cluster.start(); use
             // the location defined on the member.
             if (isAvailabilityZoneEnabled()) {
                 LOG.warn("Cluster {} has availability-zone enabled, but memberSpec overrides
location with {}; using "
-                        + "memberSpec's location; availability-zone behaviour will not apply",
this, memberLocations);
+                        + "memberSpec's location; availability-zone behaviour will not apply",
this, 
+                        ""+memberSpec.getLocationSpecs()+"+"+memberSpec.getLocations());
             }
-            chosenLocations = Collections.nCopies(delta, memberLocations.get(0));
+            // null means create an instance but don't set a location
+            chosenLocations = Collections.nCopies(delta, null);
         } else if (isAvailabilityZoneEnabled()) {
             List<Location> subLocations = getNonFailedSubLocations();
             Multimap<Location, Entity> membersByLocation = getMembersByLocation();


Mime
View raw message