You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2016/10/03 08:30:53 UTC

[1/2] brooklyn-server git commit: Rebind when entity starting: report notUpIndicator for reason

Repository: brooklyn-server
Updated Branches:
  refs/heads/master 420ad7a4d -> b9dfdaadd


Rebind when entity starting: report notUpIndicator for reason

Entity is reported as on-fire if the starting/stopping task was
aborted due to a Brooklyn rebind. This will set the
SERVICE_NOT_IP_INDICATORS to say what the problem is.


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

Branch: refs/heads/master
Commit: 9e88ff72e576955eae700bc953d26fbfffcf615a
Parents: 2116949
Author: Aled Sage <al...@gmail.com>
Authored: Fri Sep 30 12:32:54 2016 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Sep 30 15:37:00 2016 +0100

----------------------------------------------------------------------
 .../mgmt/rebind/BasicEntityRebindSupport.java   |  4 +
 ...ftwareProcessRebindNotRunningEntityTest.java | 79 ++++++++++++--------
 2 files changed, 53 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9e88ff72/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
index 5c284bf..29a39f8 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
@@ -248,6 +248,10 @@ public class BasicEntityRebindSupport extends AbstractBrooklynObjectRebindSuppor
             LOG.warn("Entity {} goes on-fire because it was in state {} on rebind", entity, expectedState);
             LOG.warn("not-up-indicators={}", entity.getAttribute(Attributes.SERVICE_NOT_UP_INDICATORS));
             ServiceStateLogic.setExpectedState(entity, Lifecycle.ON_FIRE);
+            ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(
+                    entity, 
+                    "Task aborted on rebind", 
+                    "Set to on-fire (from previous expected state "+expectedState+") because tasks aborted on rebind");
         }
         super.instanceRebind(instance);
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9e88ff72/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessRebindNotRunningEntityTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessRebindNotRunningEntityTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessRebindNotRunningEntityTest.java
index f7e02b9..e5e7709 100644
--- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessRebindNotRunningEntityTest.java
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessRebindNotRunningEntityTest.java
@@ -19,6 +19,7 @@
 package org.apache.brooklyn.entity.software.base;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 
 import java.util.Collection;
@@ -30,6 +31,7 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.LocationSpec;
@@ -55,10 +57,13 @@ import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool.CustomRespons
 import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool.ExecParams;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.time.Duration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
@@ -70,6 +75,13 @@ import com.google.common.util.concurrent.MoreExecutors;
 
 public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixtureWithApp {
 
+    // TODO If we fail during provisioningLocation.obtain() or provisioningLocation.release(), then we
+    // should tell the user that a VM might have started being provisioned but been forgotten about; or
+    // that termination of the VM may or may not have completed.
+    // We could use the Attributes.SERVICE_NOT_UP_INDICATORS to achieve that.
+
+    private static final Logger LOG = LoggerFactory.getLogger(SoftwareProcessRebindNotRunningEntityTest.class);
+
     private ListeningExecutorService executor;
     private LocationSpec<SshMachineLocation> machineSpec;
     private FixedListMachineProvisioningLocation<?> locationProvisioner;
@@ -147,11 +159,8 @@ public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixture
         TestApplication newApp = rebind();
         final VanillaSoftwareProcess newEntity = (VanillaSoftwareProcess) Iterables.find(newApp.getChildren(), Predicates.instanceOf(VanillaSoftwareProcess.class));
 
-        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_UP, false);
-
-        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_UP, false);
+        assertMarkedAsOnfire(newEntity, Lifecycle.STARTING);
+        assertMarkedAsOnfire(newApp, Lifecycle.STARTING);
     }
 
     @Test
@@ -178,11 +187,8 @@ public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixture
         TestApplication newApp = rebind();
         final VanillaSoftwareProcess newEntity = (VanillaSoftwareProcess) Iterables.find(newApp.getChildren(), Predicates.instanceOf(VanillaSoftwareProcess.class));
 
-        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_UP, false);
-
-        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_UP, false);
+        assertMarkedAsOnfire(newEntity, Lifecycle.STARTING);
+        assertMarkedAsOnfire(newApp, Lifecycle.STARTING);
     }
 
     @Test
@@ -211,11 +217,7 @@ public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixture
         TestApplication newApp = rebind();
         final VanillaSoftwareProcess newEntity = (VanillaSoftwareProcess) Iterables.find(newApp.getChildren(), Predicates.instanceOf(VanillaSoftwareProcess.class));
 
-        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_UP, false);
-
-        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_UP, false);
+        assertMarkedAsOnfire(newEntity, Lifecycle.STOPPING);
     }
 
     @Test
@@ -239,11 +241,8 @@ public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixture
         TestApplication newApp = rebind();
         final VanillaSoftwareProcess newEntity = (VanillaSoftwareProcess) Iterables.find(newApp.getChildren(), Predicates.instanceOf(VanillaSoftwareProcess.class));
 
-        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_UP, false);
-
-        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_UP, false);
+        assertMarkedAsOnfire(newEntity, Lifecycle.STARTING);
+        assertMarkedAsOnfire(newApp, Lifecycle.STARTING);
     }
 
     @Test
@@ -269,11 +268,7 @@ public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixture
         TestApplication newApp = rebind();
         final VanillaSoftwareProcess newEntity = (VanillaSoftwareProcess) Iterables.find(newApp.getChildren(), Predicates.instanceOf(VanillaSoftwareProcess.class));
 
-        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_UP, false);
-
-        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_UP, false);
+        assertMarkedAsOnfire(newEntity, Lifecycle.STOPPING);
     }
 
     @Test
@@ -301,11 +296,8 @@ public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixture
         TestApplication newApp = hotStandby();
         final VanillaSoftwareProcess newEntity = (VanillaSoftwareProcess) Iterables.find(newApp.getChildren(), Predicates.instanceOf(VanillaSoftwareProcess.class));
 
-        EntityAsserts.assertAttributeEqualsContinually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STARTING);
-        assertEquals(newEntity.getAttribute(Attributes.SERVICE_STATE_EXPECTED).getState(), Lifecycle.STARTING);
-        
-        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STARTING);
-        assertEquals(newApp.getAttribute(Attributes.SERVICE_STATE_EXPECTED).getState(), Lifecycle.STARTING);
+        assertNotMarkedOnfire(newEntity, Lifecycle.STARTING);
+        assertNotMarkedOnfire(newApp, Lifecycle.STARTING);
     }
 
     protected ListenableFuture<Void> startAsync(final Startable entity, final Collection<? extends Location> locs) {
@@ -335,11 +327,38 @@ public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixture
         return result;
     }
 
+    protected void assertMarkedAsOnfire(final Entity entity, final Lifecycle previousState) throws Exception {
+        EntityAsserts.assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+        EntityAsserts.assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, false);
+        EntityAsserts.assertAttributeEventually(entity, Attributes.SERVICE_NOT_UP_INDICATORS, new Predicate<Map<?,?>>() {
+            @Override
+            public boolean apply(Map<?, ?> input) {
+                if (input == null) return false;
+                String expectedKey = "Task aborted on rebind";
+                String expectedVal = "Set to on-fire (from previous expected state "+previousState+") because tasks aborted on rebind";
+                for (Map.Entry<?, ?> entry : input.entrySet()) {
+                    boolean keyMatches = expectedKey.equals(entry.getKey());
+                    boolean valueMatches = expectedVal.equals(entry.getValue());
+                    if (keyMatches && valueMatches) return true;
+                }
+                LOG.info("entity "+entity+" not-up-indicators: "+input);
+                return false;
+            }});
+    }
+
+    protected void assertNotMarkedOnfire(final Entity entity, final Lifecycle expectedState) throws Exception {
+        assertEquals(entity.getAttribute(Attributes.SERVICE_STATE_ACTUAL), expectedState);
+        Map<String, Object> indicators = entity.getAttribute(Attributes.SERVICE_NOT_UP_INDICATORS);
+        assertFalse(indicators.keySet().contains("Task aborted on rebind"), "indicators="+indicators);
+    }
+
     public static class MyProvisioningLocation extends AbstractLocation implements MachineProvisioningLocation<SshMachineLocation> {
         public static final ConfigKey<CountDownLatch> OBTAIN_CALLED_LATCH = ConfigKeys.newConfigKey(CountDownLatch.class, "obtainCalledLatch");
         public static final ConfigKey<CountDownLatch> OBTAIN_BLOCKED_LATCH = ConfigKeys.newConfigKey(CountDownLatch.class, "obtainBlockedLatch");
         public static final ConfigKey<CountDownLatch> RELEASE_CALLED_LATCH = ConfigKeys.newConfigKey(CountDownLatch.class, "releaseCalledLatch");
         public static final ConfigKey<CountDownLatch> RELEASE_BLOCKED_LATCH = ConfigKeys.newConfigKey(CountDownLatch.class, "releaseBlockedLatch");
+        
+        @SuppressWarnings("serial")
         public static final ConfigKey<LocationSpec<SshMachineLocation>> MACHINE_SPEC = ConfigKeys.newConfigKey(
                 new TypeToken<LocationSpec<SshMachineLocation>>() {},
                 "machineSpec");


[2/2] brooklyn-server git commit: Closes #364

Posted by sv...@apache.org.
Closes #364

Rebind when entity starting: report notUpIndicator for reason

Entity is reported as on-fire if the starting/stopping task was
aborted due to a Brooklyn rebind. This will set the
SERVICE_NOT_IP_INDICATORS to say what the problem is.


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

Branch: refs/heads/master
Commit: b9dfdaadd46b2581d38b22be7248d84b9b6fbd7d
Parents: 420ad7a 9e88ff7
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Mon Oct 3 10:30:35 2016 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Mon Oct 3 10:30:35 2016 +0200

----------------------------------------------------------------------
 .../mgmt/rebind/BasicEntityRebindSupport.java   |  4 +
 ...ftwareProcessRebindNotRunningEntityTest.java | 79 ++++++++++++--------
 2 files changed, 53 insertions(+), 30 deletions(-)
----------------------------------------------------------------------