You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ge...@apache.org on 2017/12/11 15:50:08 UTC
[1/2] brooklyn-server git commit: BROOKLYN-549: fix policy rebind's
execution context
Repository: brooklyn-server
Updated Branches:
refs/heads/master 770ca3498 -> ebf450e25
BROOKLYN-549: fix policy rebind's execution context
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/b2dd25cb
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/b2dd25cb
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/b2dd25cb
Branch: refs/heads/master
Commit: b2dd25cbb1788bf978f359236e68e65036e0b7f7
Parents: 770ca34
Author: Aled Sage <al...@gmail.com>
Authored: Thu Nov 9 12:54:04 2017 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Dec 11 10:42:43 2017 +0000
----------------------------------------------------------------------
.../camp/brooklyn/DslAndRebindYamlTest.java | 84 ++++++++++++++++++++
.../mgmt/rebind/RebindExceptionHandlerImpl.java | 10 +++
.../core/mgmt/rebind/RebindIteration.java | 33 +++++---
3 files changed, 117 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b2dd25cb/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
index 44dcbca..680140e 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
@@ -18,6 +18,8 @@
*/
package org.apache.brooklyn.camp.brooklyn;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.List;
@@ -31,6 +33,7 @@ import java.util.regex.Pattern;
import org.apache.brooklyn.api.entity.Application;
import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntityLocal;
import org.apache.brooklyn.api.mgmt.ha.MementoCopyMode;
import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoRawData;
import org.apache.brooklyn.api.sensor.AttributeSensor;
@@ -44,9 +47,14 @@ import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.EntityAsserts;
import org.apache.brooklyn.core.entity.EntityInternal;
import org.apache.brooklyn.core.mgmt.persist.BrooklynPersistenceUtils;
+import org.apache.brooklyn.core.mgmt.rebind.RebindOptions;
+import org.apache.brooklyn.core.mgmt.rebind.RecordingRebindExceptionHandler;
+import org.apache.brooklyn.core.policy.AbstractPolicy;
import org.apache.brooklyn.core.sensor.Sensors;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.entity.group.DynamicCluster;
+import org.apache.brooklyn.entity.stock.BasicApplication;
+import org.apache.brooklyn.policy.ha.ServiceReplacer;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.core.task.Tasks;
import org.apache.brooklyn.util.exceptions.Exceptions;
@@ -58,6 +66,7 @@ import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@@ -638,4 +647,79 @@ public class DslAndRebindYamlTest extends AbstractYamlRebindTest {
" test.confName: $brooklyn:template(\"${config['test.sourceName']}\")");
}
+ // See https://issues.apache.org/jira/browse/BROOKLYN-549
+ @Test
+ public void testDslInServiceReplacerPolicy() throws Exception {
+ RecordingRebindExceptionHandler exceptionHandler = new RecordingRebindExceptionHandler(RecordingRebindExceptionHandler.builder()
+ .strict());
+
+ Entity app = createAndStartApplication(
+ "services:",
+ "- type: "+DynamicCluster.class.getName(),
+ " brooklyn.config:",
+ " initialSize: 0",
+ " brooklyn.policies:",
+ " - type: "+ServiceReplacer.class.getName(),
+ " brooklyn.config:",
+ " failureSensorToMonitor: $brooklyn:sensor(\"ha.entityFailed\")");
+ waitForApplicationTasks(app);
+ DynamicCluster cluster = (DynamicCluster) Iterables.getOnlyElement(app.getChildren());
+ ServiceReplacer policy = (ServiceReplacer) Iterables.find(cluster.policies(), Predicates.instanceOf(ServiceReplacer.class));
+ Sensor<?> sensor = policy.config().get(ServiceReplacer.FAILURE_SENSOR_TO_MONITOR);
+ assertEquals(sensor.getName(), "ha.entityFailed");
+
+ rebind(RebindOptions.create().exceptionHandler(exceptionHandler));
+
+ Entity newApp = mgmt().getEntityManager().getEntity(app.getId());
+ DynamicCluster newCluster = (DynamicCluster) Iterables.getOnlyElement(newApp.getChildren());
+ ServiceReplacer newPolicy = (ServiceReplacer) Iterables.find(newCluster.policies(), Predicates.instanceOf(ServiceReplacer.class));
+
+ Sensor<?> newSensor2 = ((EntityInternal)newCluster).getExecutionContext().submit("get-policy-config", new Callable<Sensor<?>>() {
+ public Sensor<?> call() {
+ return newPolicy.config().get(ServiceReplacer.FAILURE_SENSOR_TO_MONITOR);
+ }})
+ .get();
+ assertEquals(newSensor2.getName(), "ha.entityFailed");
+ }
+
+ // See https://issues.apache.org/jira/browse/BROOKLYN-549
+ // Similar to testDslInServiceReplacerPolicy, but with a simple test policy (so test will always
+ // be here, even if someone changes the implementation of ServiceReplacer).
+ @Test
+ public void testDslInPolicy() throws Exception {
+ RecordingRebindExceptionHandler exceptionHandler = new RecordingRebindExceptionHandler(RecordingRebindExceptionHandler.builder()
+ .strict());
+
+ Entity app = createAndStartApplication(
+ "services:",
+ "- type: "+BasicApplication.class.getName(),
+ " brooklyn.config:",
+ " myentity.myconfig: myval",
+ " brooklyn.policies:",
+ " - type: "+MyPolicy.class.getName(),
+ " brooklyn.config:",
+ " mypolicy.myconfig: $brooklyn:config(\"myentity.myconfig\")");
+ waitForApplicationTasks(app);
+ MyPolicy policy = (MyPolicy) Iterables.find(app.policies(), Predicates.instanceOf(MyPolicy.class));
+ assertEquals(policy.resolvedVal, "myval");
+
+ rebind(RebindOptions.create().exceptionHandler(exceptionHandler));
+
+ Entity newApp = mgmt().getEntityManager().getEntity(app.getId());
+ MyPolicy newPolicy = (MyPolicy) Iterables.find(newApp.policies(), Predicates.instanceOf(MyPolicy.class));
+ assertEquals(newPolicy.resolvedVal, "myval");
+ }
+
+ public static class MyPolicy extends AbstractPolicy {
+ public static final ConfigKey<String> MY_CONFIG = ConfigKeys.newStringConfigKey("mypolicy.myconfig");
+
+ public String resolvedVal;
+
+ @Override
+ @SuppressWarnings("deprecation")
+ public void setEntity(EntityLocal entity) {
+ super.setEntity(entity);
+ resolvedVal = checkNotNull(getConfig(MY_CONFIG), "myconfig");
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b2dd25cb/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
index 54564a8..a705748 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
@@ -42,6 +42,7 @@ import org.apache.brooklyn.api.typereg.ManagedBundle;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.util.collections.MutableList;
import org.apache.brooklyn.util.collections.QuorumCheck;
+import org.apache.brooklyn.util.collections.QuorumCheck.QuorumChecks;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.text.Strings;
import org.slf4j.Logger;
@@ -94,6 +95,15 @@ public class RebindExceptionHandlerImpl implements RebindExceptionHandler {
private RebindManager.RebindFailureMode deserializePolicyFailureMode = RebindManager.RebindFailureMode.CONTINUE;
private QuorumCheck danglingRefsQuorumRequiredHealthy = RebindManagerImpl.DANGLING_REFERENCES_MIN_REQUIRED_HEALTHY.getDefaultValue();
+ public Builder strict() {
+ danglingRefFailureMode = RebindManager.RebindFailureMode.FAIL_AT_END;
+ rebindFailureMode = RebindManager.RebindFailureMode.FAIL_AT_END;
+ addConfigFailureMode = RebindManager.RebindFailureMode.FAIL_AT_END;
+ addPolicyFailureMode = RebindManager.RebindFailureMode.FAIL_AT_END;
+ deserializePolicyFailureMode = RebindManager.RebindFailureMode.FAIL_AT_END;
+ danglingRefsQuorumRequiredHealthy = QuorumChecks.all();
+ return this;
+ }
public Builder danglingRefFailureMode(RebindManager.RebindFailureMode val) {
danglingRefFailureMode = val;
return this;
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b2dd25cb/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
index a9b08b0..21c5677 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
@@ -41,6 +41,7 @@ import org.apache.brooklyn.api.catalog.CatalogItem;
import org.apache.brooklyn.api.entity.Application;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.mgmt.ExecutionContext;
import org.apache.brooklyn.api.mgmt.classloading.BrooklynClassLoadingContext;
import org.apache.brooklyn.api.mgmt.ha.ManagementNodeState;
import org.apache.brooklyn.api.mgmt.rebind.RebindContext;
@@ -107,6 +108,8 @@ import org.apache.brooklyn.util.collections.MutableList;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.core.ClassLoaderUtils;
import org.apache.brooklyn.util.core.flags.FlagUtils;
+import org.apache.brooklyn.util.core.task.BasicExecutionContext;
+import org.apache.brooklyn.util.core.task.Tasks;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.guava.Maybe;
import org.apache.brooklyn.util.javalang.Reflections;
@@ -653,16 +656,26 @@ public abstract class RebindIteration {
// usually because of creation-failure, when not using fail-fast
exceptionHandler.onNotFound(BrooklynObjectType.ENTITY, entityMemento.getId());
} else {
- try {
- entityMemento.injectTypeClass(entity.getClass());
- // TODO these call to the entity which in turn sets the entity on the underlying feeds and enrichers;
- // that is taken as the cue to start, but it should not be. start should be a separate call.
- ((EntityInternal)entity).getRebindSupport().addPolicies(rebindContext, entityMemento);
- ((EntityInternal)entity).getRebindSupport().addEnrichers(rebindContext, entityMemento);
- ((EntityInternal)entity).getRebindSupport().addFeeds(rebindContext, entityMemento);
- } catch (Exception e) {
- exceptionHandler.onRebindFailed(BrooklynObjectType.ENTITY, entity, e);
- }
+ // Must execute in entity's context, so policy.setEntity can resolve config (BROOKLYN-549).
+ Runnable body = new Runnable() {
+ public void run() {
+ try {
+ entityMemento.injectTypeClass(entity.getClass());
+ // TODO these call to the entity which in turn sets the entity on the underlying feeds and enrichers;
+ // that is taken as the cue to start, but it should not be. start should be a separate call.
+ ((EntityInternal)entity).getRebindSupport().addPolicies(rebindContext, entityMemento);
+ ((EntityInternal)entity).getRebindSupport().addEnrichers(rebindContext, entityMemento);
+ ((EntityInternal)entity).getRebindSupport().addFeeds(rebindContext, entityMemento);
+ } catch (Exception e) {
+ exceptionHandler.onRebindFailed(BrooklynObjectType.ENTITY, entity, e);
+ }
+ }
+ };
+ ((EntityInternal)entity).getExecutionContext().get(Tasks.<Void>builder()
+ .displayName("rebind-adjuncts-"+entity.getId())
+ .dynamic(false)
+ .body(body)
+ .build());
}
}
}
[2/2] brooklyn-server git commit: Closes #888
Posted by ge...@apache.org.
Closes #888
BROOKLYN-549: fix policy rebind's execution context
Adds test, marked as "Broken" so not run by jenkins, which demonstrates the bug reported at https://issues.apache.org/jira/browse/BROOKLYN-549
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/ebf450e2
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/ebf450e2
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/ebf450e2
Branch: refs/heads/master
Commit: ebf450e2546b62baf67659a1b1098f82f8093ddd
Parents: 770ca34 b2dd25c
Author: Geoff Macartney <ge...@cloudsoftcorp.com>
Authored: Mon Dec 11 15:49:54 2017 +0000
Committer: Geoff Macartney <ge...@cloudsoftcorp.com>
Committed: Mon Dec 11 15:49:54 2017 +0000
----------------------------------------------------------------------
.../camp/brooklyn/DslAndRebindYamlTest.java | 84 ++++++++++++++++++++
.../mgmt/rebind/RebindExceptionHandlerImpl.java | 10 +++
.../core/mgmt/rebind/RebindIteration.java | 33 +++++---
3 files changed, 117 insertions(+), 10 deletions(-)
----------------------------------------------------------------------