brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [16/16] git commit: don't sweat it too much if shutdown fails when node is already shutdown (fixes failing unit test BrooklynNodeTest)
Date Fri, 19 Sep 2014 11:31:32 GMT
don't sweat it too much if shutdown fails when node is already shutdown (fixes failing unit
test BrooklynNodeTest)


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

Branch: refs/heads/master
Commit: 6ca7d456f9631f673fd04ca8de38d2f1f8b4b229
Parents: 0e2d29d
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Wed Sep 17 21:54:40 2014 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri Sep 19 12:30:14 2014 +0100

----------------------------------------------------------------------
 .../entity/brooklynnode/BrooklynNode.java       |  4 ++--
 .../entity/brooklynnode/BrooklynNodeImpl.java   | 23 ++++++++++++++++----
 .../brooklynnode/EntityHttpClientImpl.java      |  5 ++++-
 3 files changed, 25 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6ca7d456/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNode.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNode.java b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNode.java
index 5ac63e2..51cc62b 100644
--- a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNode.java
+++ b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNode.java
@@ -245,7 +245,7 @@ public interface BrooklynNode extends SoftwareProcess, UsesJava {
     public interface StopNodeButLeaveAppsEffector {
         ConfigKey<Duration> TIMEOUT = ConfigKeys.newConfigKey(Duration.class, "timeout",
"How long to wait before giving up on stopping the node", Duration.ONE_HOUR);
         Effector<Void> STOP_NODE_BUT_LEAVE_APPS = Effectors.effector(Void.class, "stopNodeButLeaveApps")
-                .description("Stop the node without stopping the running applications")
+                .description("Stop the node but if it was managing other applications, leave
them running")
                 .parameter(TIMEOUT)
                 .buildAbstract();
     }
@@ -255,7 +255,7 @@ public interface BrooklynNode extends SoftwareProcess, UsesJava {
     public interface StopNodeAndKillAppsEffector {
         ConfigKey<Duration> TIMEOUT = ConfigKeys.newConfigKey(Duration.class, "timeout",
"How long to wait before giving up on stopping the node", Duration.ONE_HOUR);
         Effector<Void> STOP_NODE_AND_KILL_APPS = Effectors.effector(Void.class, "stopNodeAndKillApps")
-                .description("Stop all apps running on the node and shutdown the node")
+                .description("Stop all apps managed by the node and shutdown the node")
                 .parameter(TIMEOUT)
                 .buildAbstract();
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6ca7d456/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
index c1294b2..78c9991 100644
--- a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
+++ b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
@@ -32,6 +32,8 @@ import brooklyn.entity.Effector;
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.Attributes;
 import brooklyn.entity.basic.ServiceStateLogic.ServiceNotUpLogic;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.Lifecycle;
 import brooklyn.entity.basic.SoftwareProcessImpl;
 import brooklyn.entity.effector.EffectorBody;
 import brooklyn.entity.effector.Effectors;
@@ -43,10 +45,13 @@ import brooklyn.management.TaskAdaptable;
 import brooklyn.util.collections.Jsonya;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.exceptions.PropagatedRuntimeException;
 import brooklyn.util.http.HttpToolResponse;
 import brooklyn.util.javalang.JavaClassNames;
 import brooklyn.util.task.DynamicTasks;
 import brooklyn.util.task.TaskTags;
+import brooklyn.util.task.Tasks;
 import brooklyn.util.text.Strings;
 import brooklyn.util.time.Duration;
 
@@ -174,10 +179,20 @@ public class BrooklynNodeImpl extends SoftwareProcessImpl implements
BrooklynNod
                     .addIfNotNull("shutdownTimeout", toNullableString(parameters.get(SHUTDOWN_TIMEOUT)))
                     .addIfNotNull("requestTimeout", toNullableString(parameters.get(REQUEST_TIMEOUT)))
                     .addIfNotNull("delayForHttpReturn", toNullableString(parameters.get(DELAY_FOR_HTTP_RETURN)));
-            HttpToolResponse resp = ((BrooklynNode)entity()).http()
-                .post("/v1/server/shutdown", MutableMap.<String, String>of(), formParams);
-            if (resp.getResponseCode() != HttpStatus.SC_NO_CONTENT) {
-                throw new IllegalStateException("Remote node shutdown failed.");
+            try {
+                HttpToolResponse resp = ((BrooklynNode)entity()).http()
+                    .post("/v1/server/shutdown", MutableMap.<String, String>of(), formParams);
+                if (resp.getResponseCode() != HttpStatus.SC_NO_CONTENT) {
+                    throw new IllegalStateException("Response code "+resp.getResponseCode());
+                }
+            } catch (Exception e) {
+                Exceptions.propagateIfFatal(e);
+                Lifecycle state = entity().getAttribute(Attributes.SERVICE_STATE_ACTUAL);
+                if (state!=Lifecycle.RUNNING) {
+                    // ignore failure in this task if the node is not currently running
+                    Tasks.markInessential();
+                }
+                throw new PropagatedRuntimeException("Error shutting down remote node "+entity()+"
(in state "+state+"): "+Exceptions.collapseText(e), e);
             }
             ServiceNotUpLogic.updateNotUpIndicator(entity(), "brooklynnode.shutdown", "Shutdown
of remote node has completed successfuly");
             return null;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6ca7d456/software/base/src/main/java/brooklyn/entity/brooklynnode/EntityHttpClientImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/brooklynnode/EntityHttpClientImpl.java
b/software/base/src/main/java/brooklyn/entity/brooklynnode/EntityHttpClientImpl.java
index 262c485..76d2ede 100644
--- a/software/base/src/main/java/brooklyn/entity/brooklynnode/EntityHttpClientImpl.java
+++ b/software/base/src/main/java/brooklyn/entity/brooklynnode/EntityHttpClientImpl.java
@@ -35,6 +35,8 @@ import brooklyn.util.net.Urls;
 import brooklyn.util.stream.Streams;
 import brooklyn.util.task.Tasks;
 
+import com.google.common.base.Preconditions;
+
 public class EntityHttpClientImpl implements EntityHttpClient {
     private static final Logger LOG = LoggerFactory.getLogger(EntityHttpClientImpl.class);
 
@@ -68,7 +70,8 @@ public class EntityHttpClientImpl implements EntityHttpClient {
     }
 
     protected HttpToolResponse exec(String path, HttpCall httpCall) {
-        HttpClient client = getHttpClientForBrooklynNode().build();
+        HttpClient client = Preconditions.checkNotNull(getHttpClientForBrooklynNode(), "No
address info for "+node)
+            .build();
         URI baseUri = node.getAttribute(BrooklynNode.WEB_CONSOLE_URI);
         URI uri = URI.create(Urls.mergePaths(baseUri.toString(), path));
 


Mime
View raw message