You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2016/01/19 16:51:16 UTC
[2/3] incubator-brooklyn git commit: tidy several other places
start(Collection) is assuming locations are always passed in,
not inherited
tidy several other places start(Collection<Location>) is assuming locations are always passed in, not inherited
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/ba8bb7f6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/ba8bb7f6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/ba8bb7f6
Branch: refs/heads/master
Commit: ba8bb7f6dba6553888a669bd9cc1d4e3f27cb3dd
Parents: e3da35d
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Jan 19 13:52:09 2016 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Jan 19 14:40:46 2016 +0000
----------------------------------------------------------------------
.../entity/messaging/kafka/KafkaClusterImpl.java | 6 +++++-
.../webapp/ControlledDynamicWebAppClusterImpl.java | 7 +++++--
.../core/location/BasicLocationRegistry.java | 4 +++-
.../brooklyn/entity/group/DynamicClusterImpl.java | 14 +++++++-------
.../brooklyn/entity/stock/BasicStartableImpl.java | 3 ++-
.../brooklyn/entity/stock/DataEntityImpl.java | 1 +
.../brooklyn/entity/group/DynamicClusterTest.java | 16 ++++++++--------
.../entity/software/base/SameServerEntityImpl.java | 7 ++++++-
.../test/framework/ParallelTestCaseImpl.java | 2 +-
9 files changed, 38 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ba8bb7f6/brooklyn-library/software/messaging/src/main/java/org/apache/brooklyn/entity/messaging/kafka/KafkaClusterImpl.java
----------------------------------------------------------------------
diff --git a/brooklyn-library/software/messaging/src/main/java/org/apache/brooklyn/entity/messaging/kafka/KafkaClusterImpl.java b/brooklyn-library/software/messaging/src/main/java/org/apache/brooklyn/entity/messaging/kafka/KafkaClusterImpl.java
index 8f4e7fb..a95adf9 100644
--- a/brooklyn-library/software/messaging/src/main/java/org/apache/brooklyn/entity/messaging/kafka/KafkaClusterImpl.java
+++ b/brooklyn-library/software/messaging/src/main/java/org/apache/brooklyn/entity/messaging/kafka/KafkaClusterImpl.java
@@ -28,6 +28,7 @@ import org.apache.brooklyn.core.entity.AbstractEntity;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.trait.Startable;
import org.apache.brooklyn.core.feed.ConfigToAttributes;
+import org.apache.brooklyn.core.location.Locations;
import org.apache.brooklyn.enricher.stock.Enrichers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -104,11 +105,14 @@ public class KafkaClusterImpl extends AbstractEntity implements KafkaCluster {
@Override
public void start(Collection<? extends Location> locations) {
if (isLegacyConstruction()) {
+ // TODO should no longer be needed?
init();
}
- if (locations.isEmpty()) locations = getLocations();
+ locations = MutableList.copyOf(Locations.getLocationsCheckingAncestors(locations, this));
+
Iterables.getOnlyElement(locations); // Assert just one
+ // set it; here we don't allow changing locations
addLocations(locations);
List<Entity> childrenToStart = MutableList.<Entity>of(getCluster());
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ba8bb7f6/brooklyn-library/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/ControlledDynamicWebAppClusterImpl.java
----------------------------------------------------------------------
diff --git a/brooklyn-library/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/ControlledDynamicWebAppClusterImpl.java b/brooklyn-library/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/ControlledDynamicWebAppClusterImpl.java
index 78898bd..8c52746 100644
--- a/brooklyn-library/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/ControlledDynamicWebAppClusterImpl.java
+++ b/brooklyn-library/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/ControlledDynamicWebAppClusterImpl.java
@@ -38,6 +38,7 @@ import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic;
import org.apache.brooklyn.core.entity.trait.Startable;
import org.apache.brooklyn.core.entity.trait.StartableMethods;
import org.apache.brooklyn.core.feed.ConfigToAttributes;
+import org.apache.brooklyn.core.location.Locations;
import org.apache.brooklyn.enricher.stock.Enrichers;
import org.apache.brooklyn.entity.group.DynamicGroupImpl;
import org.apache.brooklyn.entity.proxy.LoadBalancer;
@@ -207,7 +208,8 @@ public class ControlledDynamicWebAppClusterImpl extends DynamicGroupImpl impleme
init();
}
- if (locations.isEmpty()) locations = getLocations();
+ locations = Locations.getLocationsCheckingAncestors(locations, this);
+ // store inherited locations
addLocations(locations);
LoadBalancer loadBalancer = getController();
@@ -229,7 +231,8 @@ public class ControlledDynamicWebAppClusterImpl extends DynamicGroupImpl impleme
}
}
- Entities.invokeEffectorList(this, childrenToStart, Startable.START, ImmutableMap.of("locations", locations)).get();
+ // don't propagate start locations
+ Entities.invokeEffectorList(this, childrenToStart, Startable.START, ImmutableMap.of("locations", MutableList.of())).get();
if (startControllerTask != null) {
startControllerTask.get();
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ba8bb7f6/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
index 4954393..60fb061 100644
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
+++ b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
@@ -430,7 +430,9 @@ public class BasicLocationRegistry implements LocationRegistry {
public List<Location> resolve(Iterable<?> spec) {
List<Location> result = new ArrayList<Location>();
for (Object id : spec) {
- if (id instanceof String) {
+ if (id==null) {
+ // drop a null entry
+ } if (id instanceof String) {
result.add(resolve((String) id));
} else if (id instanceof Location) {
result.add((Location) id);
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ba8bb7f6/brooklyn-server/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java
index e1dffa8..f434fcf 100644
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java
+++ b/brooklyn-server/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java
@@ -314,14 +314,14 @@ public class DynamicClusterImpl extends AbstractGroupImpl implements DynamicClus
private Location getLocation(boolean required) {
Collection<? extends Location> ll = Locations.getLocationsCheckingAncestors(getLocations(), this);
- try {
- if (!required && ll.isEmpty()) return null;
- return Iterables.getOnlyElement(ll);
- } catch (Exception e) {
- Exceptions.propagateIfFatal(e);
- if (ll.isEmpty()) throw new IllegalStateException("No location available for "+this);
- else throw new IllegalStateException("Ambiguous location for "+this+"; expected one but had "+ll);
+ if (ll.isEmpty()) {
+ if (!required) return null;
+ throw new IllegalStateException("No location available for "+this);
+ }
+ if (ll.size()>1) {
+ throw new IllegalStateException("Ambiguous location for "+this+"; expected one but had "+ll);
}
+ return Iterables.getOnlyElement(ll);
}
protected boolean isAvailabilityZoneEnabled() {
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ba8bb7f6/brooklyn-server/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartableImpl.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartableImpl.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartableImpl.java
index b5a8616..54be703 100644
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartableImpl.java
+++ b/brooklyn-server/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartableImpl.java
@@ -48,11 +48,12 @@ public class BasicStartableImpl extends AbstractEntity implements BasicStartable
@Override
public void start(Collection<? extends Location> locations) {
- log.info("Starting entity "+this+" at "+locations);
try {
ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);
addLocations(locations);
+ locations = Locations.getLocationsCheckingAncestors(locations, this);
+ log.info("Starting entity "+this+" at "+locations);
// essentially does StartableMethods.start(this, locations),
// but optionally filters locations for each child
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ba8bb7f6/brooklyn-server/core/src/main/java/org/apache/brooklyn/entity/stock/DataEntityImpl.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/entity/stock/DataEntityImpl.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/entity/stock/DataEntityImpl.java
index 9ee3b28..cc6d8d7 100644
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/entity/stock/DataEntityImpl.java
+++ b/brooklyn-server/core/src/main/java/org/apache/brooklyn/entity/stock/DataEntityImpl.java
@@ -38,6 +38,7 @@ public class DataEntityImpl extends AbstractEntity implements DataEntity {
@Override
public void start(Collection<? extends Location> locations) {
+ addLocations(locations);
connectSensors();
sensors().set(SERVICE_UP, Boolean.TRUE);
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ba8bb7f6/brooklyn-server/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java b/brooklyn-server/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
index f58ac90..b58c630 100644
--- a/brooklyn-server/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
+++ b/brooklyn-server/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
@@ -110,9 +110,9 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
try {
app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
.configure("factory", "error"));
- fail();
+ Asserts.shouldHaveFailedPreviously();
} catch (Exception e) {
- if (Exceptions.getFirstThrowableOfType(e, IllegalArgumentException.class) == null) throw e;
+ Asserts.expectedFailure(e);
}
}
@@ -121,9 +121,9 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
DynamicCluster c = app.createAndManageChild(EntitySpec.create(DynamicCluster.class));
try {
c.start(ImmutableList.of(loc));
- fail();
+ Asserts.shouldHaveFailedPreviously();
} catch (Exception e) {
- if (Exceptions.getFirstThrowableOfType(e, IllegalStateException.class) == null) throw e;
+ Asserts.expectedFailureOfType(e, IllegalStateException.class);
}
}
@@ -135,9 +135,9 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
cluster.start(ImmutableList.of(loc));
cluster.stop();
cluster.start(ImmutableList.of(loc2));
- fail();
+ Asserts.shouldHaveFailedPreviously();
} catch (Exception e) {
- if (Exceptions.getFirstThrowableOfType(e, IllegalStateException.class) == null) throw e;
+ Asserts.expectedFailureOfType(e, IllegalStateException.class);
}
}
@@ -147,9 +147,9 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
.configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class)));
try {
cluster.start(ImmutableList.of(loc, loc2));
- fail();
+ Asserts.shouldHaveFailedPreviously();
} catch (Exception e) {
- if (Exceptions.getFirstThrowableOfType(e, IllegalArgumentException.class) == null) throw e;
+ Asserts.expectedFailureContainsIgnoreCase(e, "ambiguous");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ba8bb7f6/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SameServerEntityImpl.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SameServerEntityImpl.java b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SameServerEntityImpl.java
index c24201a..8da252f 100644
--- a/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SameServerEntityImpl.java
+++ b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SameServerEntityImpl.java
@@ -21,6 +21,7 @@ package org.apache.brooklyn.entity.software.base;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collection;
+import java.util.List;
import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.api.mgmt.Task;
@@ -28,6 +29,7 @@ import org.apache.brooklyn.core.entity.AbstractEntity;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic;
import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ComputeServiceIndicatorsFromChildrenAndMembers;
+import org.apache.brooklyn.core.location.Locations;
import org.apache.brooklyn.entity.software.base.lifecycle.MachineLifecycleEffectorTasks;
import org.apache.brooklyn.util.collections.QuorumCheck;
import org.apache.brooklyn.util.core.config.ConfigBag;
@@ -68,7 +70,10 @@ public class SameServerEntityImpl extends AbstractEntity implements SameServerEn
* Subclasses should override {@link #doStart} to customise behaviour.
*/
@Override
- public final void start(final Collection<? extends Location> locations) {
+ public final void start(Collection<? extends Location> locsO) {
+ addLocations(locsO);
+ final Collection<? extends Location> locations = Locations.getLocationsCheckingAncestors(locsO, this);
+
checkNotNull(locations, "locations");
if (DynamicTasks.getTaskQueuingContext() != null) {
doStart(locations);
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ba8bb7f6/brooklyn-server/test-framework/src/main/java/org/apache/brooklyn/test/framework/ParallelTestCaseImpl.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/test-framework/src/main/java/org/apache/brooklyn/test/framework/ParallelTestCaseImpl.java b/brooklyn-server/test-framework/src/main/java/org/apache/brooklyn/test/framework/ParallelTestCaseImpl.java
index 469bc3d..3ded474 100644
--- a/brooklyn-server/test-framework/src/main/java/org/apache/brooklyn/test/framework/ParallelTestCaseImpl.java
+++ b/brooklyn-server/test-framework/src/main/java/org/apache/brooklyn/test/framework/ParallelTestCaseImpl.java
@@ -49,7 +49,7 @@ public class ParallelTestCaseImpl extends TargetableTestComponentImpl implements
try {
// Get an unsubmitted task for starting all the children of this entity in parallel,
// at the same location as this entity.
- final TaskAdaptable<?> taskAdaptable = StartableMethods.startingChildren(this);
+ final TaskAdaptable<?> taskAdaptable = StartableMethods.startingChildren(this, locations);
logger.trace("{}, TaskAdaptable: {}", this, taskAdaptable);
// Submit the task to the ExecutionManager so that they actually get started