You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2016/03/07 11:42:09 UTC
[2/6] brooklyn-server git commit: Added start latch to BasicStartable
and StartableApplication
Added start latch to BasicStartable and StartableApplication
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/a5660eae
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/a5660eae
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/a5660eae
Branch: refs/heads/master
Commit: a5660eae10a4c64b09028402f2c85ae5ff7862a5
Parents: 975a599
Author: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Authored: Wed Feb 24 08:30:54 2016 +0000
Committer: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Committed: Fri Mar 4 17:57:47 2016 +0000
----------------------------------------------------------------------
.../core/entity/AbstractApplication.java | 27 ++++++++++++--------
.../core/entity/StartableApplication.java | 6 ++++-
.../entity/stock/BasicApplicationImpl.java | 4 +--
.../brooklyn/entity/stock/BasicEntityImpl.java | 7 ++---
.../brooklyn/entity/stock/BasicStartable.java | 14 +++++++---
.../entity/stock/BasicStartableImpl.java | 17 +++++++-----
6 files changed, 45 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a5660eae/core/src/main/java/org/apache/brooklyn/core/entity/AbstractApplication.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractApplication.java b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractApplication.java
index 18a79cd..db2cd9f 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractApplication.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractApplication.java
@@ -21,6 +21,11 @@ package org.apache.brooklyn.core.entity;
import java.util.Collection;
import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.ImmutableSet;
+
import org.apache.brooklyn.api.entity.Application;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.location.Location;
@@ -35,10 +40,6 @@ import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.exceptions.RuntimeInterruptedException;
import org.apache.brooklyn.util.text.Strings;
import org.apache.brooklyn.util.time.Time;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.ImmutableSet;
/**
* Users can extend this to define the entities in their application, and the relationships between
@@ -132,12 +133,12 @@ public abstract class AbstractApplication extends AbstractEntity implements Star
@Override
protected void initEnrichers() {
super.initEnrichers();
-
+
// default app logic; easily overridable by adding a different enricher with the same tag
ServiceStateLogic.newEnricherFromChildren().checkChildrenAndMembers().addTo(this);
ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL, "Application created but not yet started, at "+Time.makeDateString());
}
-
+
/**
* Default start will start all Startable children (child.start(Collection<? extends Location>)),
* calling preStart(locations) first and postStart(locations) afterwards.
@@ -152,15 +153,19 @@ public abstract class AbstractApplication extends AbstractEntity implements Star
setExpectedStateAndRecordLifecycleEvent(Lifecycle.STARTING);
try {
preStart(locationsToUse);
- // if there are other items which should block service_up, they should be done in preStart
- ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL);
-
+
+ // Opportunity to block startup until other dependent components are available
+ Object val = config().get(START_LATCH);
+ if (val != null) log.debug("{} finished waiting for start-latch; continuing...", this);
+
doStart(locationsToUse);
postStart(locationsToUse);
+
+ ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL);
} catch (Exception e) {
// TODO should probably remember these problems then clear? if so, do it here ... or on all effectors?
-// ServiceProblemsLogic.updateProblemsIndicator(this, START, e);
-
+ // ServiceProblemsLogic.updateProblemsIndicator(this, START, e);
+
recordApplicationEvent(Lifecycle.ON_FIRE);
// no need to log here; the effector invocation should do that
throw Exceptions.propagate(e);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a5660eae/core/src/main/java/org/apache/brooklyn/core/entity/StartableApplication.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/StartableApplication.java b/core/src/main/java/org/apache/brooklyn/core/entity/StartableApplication.java
index cf806c3..bdd4f2f 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/StartableApplication.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/StartableApplication.java
@@ -22,11 +22,15 @@ import org.apache.brooklyn.api.entity.Application;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.util.core.flags.SetFromFlag;
public interface StartableApplication extends Application, Startable {
ConfigKey<Boolean> DESTROY_ON_STOP = ConfigKeys.newBooleanConfigKey("application.stop.shouldDestroy",
"Whether the app should be removed from management after a successful stop (if it is a root); "
+ "true by default.", true);
-
+
+ @SetFromFlag("startLatch")
+ ConfigKey<Boolean> START_LATCH = BrooklynConfigKeys.START_LATCH;
+
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a5660eae/core/src/main/java/org/apache/brooklyn/entity/stock/BasicApplicationImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/stock/BasicApplicationImpl.java b/core/src/main/java/org/apache/brooklyn/entity/stock/BasicApplicationImpl.java
index ed74746..3c7e097 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/stock/BasicApplicationImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/stock/BasicApplicationImpl.java
@@ -20,10 +20,8 @@ package org.apache.brooklyn.entity.stock;
import org.apache.brooklyn.core.entity.AbstractApplication;
-
-
public class BasicApplicationImpl extends AbstractApplication implements BasicApplication {
-
+
@Override
public void init() {
super.init();
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a5660eae/core/src/main/java/org/apache/brooklyn/entity/stock/BasicEntityImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/stock/BasicEntityImpl.java b/core/src/main/java/org/apache/brooklyn/entity/stock/BasicEntityImpl.java
index 1d282ad..98b6f59 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/stock/BasicEntityImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/stock/BasicEntityImpl.java
@@ -20,11 +20,8 @@ package org.apache.brooklyn.entity.stock;
import org.apache.brooklyn.core.entity.AbstractEntity;
+public class BasicEntityImpl extends AbstractEntity implements BasicEntity {
+ public BasicEntityImpl() { }
-
-public class BasicEntityImpl extends AbstractEntity implements BasicEntity {
-
- public BasicEntityImpl() {
- }
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a5660eae/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartable.java b/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartable.java
index 2e56fab..12ad993 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartable.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartable.java
@@ -20,15 +20,17 @@ package org.apache.brooklyn.entity.stock;
import java.util.List;
+import com.google.common.collect.ImmutableList;
+
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.ImplementedBy;
import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
import org.apache.brooklyn.core.entity.trait.Startable;
import org.apache.brooklyn.core.location.Locations;
-
-import com.google.common.collect.ImmutableList;
+import org.apache.brooklyn.util.core.flags.SetFromFlag;
/**
* Provides a pass-through Startable entity used for keeping hierarchies tidy.
@@ -36,6 +38,12 @@ import com.google.common.collect.ImmutableList;
@ImplementedBy(BasicStartableImpl.class)
public interface BasicStartable extends Entity, Startable {
+ @SetFromFlag("startLatch")
+ ConfigKey<Boolean> START_LATCH = BrooklynConfigKeys.START_LATCH;
+
+ ConfigKey<Locations.LocationsFilter> LOCATIONS_FILTER = ConfigKeys.newConfigKey(Locations.LocationsFilter.class,
+ "brooklyn.locationsFilter", "Provides a hook for customizing locations to be used for a given context");
+
/** @deprecated since 0.7.0; use {@link Locations#LocationFilter} */
@Deprecated
public interface LocationsFilter extends Locations.LocationsFilter {
@@ -51,6 +59,4 @@ public interface BasicStartable extends Entity, Startable {
};
}
- public static final ConfigKey<Locations.LocationsFilter> LOCATIONS_FILTER = ConfigKeys.newConfigKey(Locations.LocationsFilter.class,
- "brooklyn.locationsFilter", "Provides a hook for customizing locations to be used for a given context");
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a5660eae/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartableImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartableImpl.java b/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartableImpl.java
index 54be703..6ca6190 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartableImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartableImpl.java
@@ -22,6 +22,13 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.api.mgmt.Task;
@@ -35,12 +42,6 @@ import org.apache.brooklyn.core.entity.trait.Startable;
import org.apache.brooklyn.core.entity.trait.StartableMethods;
import org.apache.brooklyn.core.location.Locations;
import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Predicates;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
public class BasicStartableImpl extends AbstractEntity implements BasicStartable {
@@ -51,6 +52,10 @@ public class BasicStartableImpl extends AbstractEntity implements BasicStartable
try {
ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);
+ // Opportunity to block startup until other dependent components are available
+ Object val = config().get(START_LATCH);
+ if (val != null) log.debug("{} finished waiting for start-latch; continuing...", this);
+
addLocations(locations);
locations = Locations.getLocationsCheckingAncestors(locations, this);
log.info("Starting entity "+this+" at "+locations);