You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whirr.apache.org by ab...@apache.org on 2013/07/26 19:59:39 UTC
git commit: WHIRR-724 - Add a listener to calls to
ClusterActionHandlerSupport.beforeAction and .afterAction
Updated Branches:
refs/heads/trunk 8683c88d0 -> 800e7daf5
WHIRR-724 - Add a listener to calls to ClusterActionHandlerSupport.beforeAction and .afterAction
Project: http://git-wip-us.apache.org/repos/asf/whirr/repo
Commit: http://git-wip-us.apache.org/repos/asf/whirr/commit/800e7daf
Tree: http://git-wip-us.apache.org/repos/asf/whirr/tree/800e7daf
Diff: http://git-wip-us.apache.org/repos/asf/whirr/diff/800e7daf
Branch: refs/heads/trunk
Commit: 800e7daf5392444e4e72606e76c77f6540a76d4a
Parents: 8683c88
Author: Andrew Bayer <an...@gmail.com>
Authored: Tue May 7 13:09:10 2013 -0700
Committer: Andrew Bayer <an...@gmail.com>
Committed: Thu Jul 25 16:08:08 2013 -0700
----------------------------------------------------------------------
.../main/java/org/apache/whirr/ClusterSpec.java | 15 ++++++
.../service/ClusterActionHandlerListener.java | 45 ++++++++++++++++
.../service/ClusterActionHandlerSupport.java | 2 +
.../apache/whirr/service/DryRunModuleTest.java | 56 ++++++++++++++++++++
4 files changed, 118 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/whirr/blob/800e7daf/core/src/main/java/org/apache/whirr/ClusterSpec.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/whirr/ClusterSpec.java b/core/src/main/java/org/apache/whirr/ClusterSpec.java
index d0707c5..32f1059 100644
--- a/core/src/main/java/org/apache/whirr/ClusterSpec.java
+++ b/core/src/main/java/org/apache/whirr/ClusterSpec.java
@@ -40,6 +40,7 @@ import org.apache.commons.configuration.ConfigurationUtils;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.io.IOUtils;
import org.apache.whirr.internal.ConfigToTemplateBuilderSpec;
+import org.apache.whirr.service.ClusterActionHandlerListener;
import org.jclouds.byon.Node;
import org.jclouds.compute.domain.TemplateBuilderSpec;
import org.jclouds.javax.annotation.Nullable;
@@ -330,6 +331,8 @@ public class ClusterSpec {
private Configuration config;
private Map<String,Node> byonNodes;
+
+ private ClusterActionHandlerListener handlerListener;
private boolean isQuiet;
@@ -424,6 +427,8 @@ public class ClusterSpec {
setVersion(getString(Property.VERSION));
setRunUrlBase(getString(Property.RUN_URL_BASE));
+
+ setHandlerListener(new ClusterActionHandlerListener.NoopClusterActionHandlerListener());
}
/**
@@ -483,6 +488,8 @@ public class ClusterSpec {
r.setKerberosRealm(getKerberosRealm());
r.setByonNodes(getByonNodes());
+
+ r.setHandlerListener(getHandlerListener());
return r;
}
@@ -729,6 +736,10 @@ public class ClusterSpec {
return byonNodes;
}
+ public ClusterActionHandlerListener getHandlerListener() {
+ return handlerListener;
+ }
+
public String getVersion() {
return version;
}
@@ -995,6 +1006,10 @@ public class ClusterSpec {
this.isQuiet = isQuiet;
}
+ public void setHandlerListener(ClusterActionHandlerListener handlerListener) {
+ this.handlerListener = handlerListener;
+ }
+
public void setVersion(String version) {
this.version = version;
}
http://git-wip-us.apache.org/repos/asf/whirr/blob/800e7daf/core/src/main/java/org/apache/whirr/service/ClusterActionHandlerListener.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/whirr/service/ClusterActionHandlerListener.java b/core/src/main/java/org/apache/whirr/service/ClusterActionHandlerListener.java
new file mode 100644
index 0000000..8617b63
--- /dev/null
+++ b/core/src/main/java/org/apache/whirr/service/ClusterActionHandlerListener.java
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.whirr.service;
+
+/**
+ * A listener for ClusterActionHandler event calls.
+ */
+public abstract class ClusterActionHandlerListener {
+
+ public abstract void beforeEvent(Class clazz, ClusterActionEvent event);
+
+ public abstract void afterEvent(Class clazz, ClusterActionEvent event);
+
+ public static class NoopClusterActionHandlerListener extends ClusterActionHandlerListener {
+ public NoopClusterActionHandlerListener() {
+
+ }
+
+ @Override
+ public void beforeEvent(Class clazz, ClusterActionEvent event) {
+
+ }
+
+ @Override
+ public void afterEvent(Class clazz, ClusterActionEvent event) {
+
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/whirr/blob/800e7daf/core/src/main/java/org/apache/whirr/service/ClusterActionHandlerSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/whirr/service/ClusterActionHandlerSupport.java b/core/src/main/java/org/apache/whirr/service/ClusterActionHandlerSupport.java
index 4b6ee89..9dc1a52 100644
--- a/core/src/main/java/org/apache/whirr/service/ClusterActionHandlerSupport.java
+++ b/core/src/main/java/org/apache/whirr/service/ClusterActionHandlerSupport.java
@@ -51,6 +51,7 @@ public abstract class ClusterActionHandlerSupport implements ClusterActionHandle
public void beforeAction(ClusterActionEvent event)
throws IOException, InterruptedException{
+ event.getClusterSpec().getHandlerListener().beforeEvent(getClass(), event);
if (event.getAction().equals(BOOTSTRAP_ACTION)) {
beforeBootstrap(event);
} else if (event.getAction().equals(CONFIGURE_ACTION)) {
@@ -71,6 +72,7 @@ public abstract class ClusterActionHandlerSupport implements ClusterActionHandle
public void afterAction(ClusterActionEvent event)
throws IOException, InterruptedException {
+ event.getClusterSpec().getHandlerListener().afterEvent(getClass(), event);
if (event.getAction().equals(BOOTSTRAP_ACTION)) {
afterBootstrap(event);
} else if (event.getAction().equals(CONFIGURE_ACTION)) {
http://git-wip-us.apache.org/repos/asf/whirr/blob/800e7daf/core/src/test/java/org/apache/whirr/service/DryRunModuleTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/whirr/service/DryRunModuleTest.java b/core/src/test/java/org/apache/whirr/service/DryRunModuleTest.java
index 1189a40..36552b1 100644
--- a/core/src/test/java/org/apache/whirr/service/DryRunModuleTest.java
+++ b/core/src/test/java/org/apache/whirr/service/DryRunModuleTest.java
@@ -115,6 +115,29 @@ public class DryRunModuleTest {
}
}
+ public static class MockClusterActionHandlerListener extends ClusterActionHandlerListener {
+ public MockClusterActionHandlerListener() {
+ }
+
+ public int beforeCalls = 0;
+ public int afterCalls = 0;
+
+ @Override
+ public void beforeEvent(Class clazz, ClusterActionEvent event) {
+ assertEquals("ClusterActionHandler class should be NoopClusterActionHandler",
+ clazz.getSimpleName(), "NoopClusterActionHandler");
+ beforeCalls++;
+ }
+
+ @Override
+ public void afterEvent(Class clazz, ClusterActionEvent event) {
+ assertEquals("ClusterActionHandler class should be NoopClusterActionHandler",
+ clazz.getSimpleName(), "NoopClusterActionHandler");
+ afterCalls++;
+ }
+ }
+
+
@Test
public void testExecuteOnlyBootstrapForNoop() throws Exception {
CompositeConfiguration config = new CompositeConfiguration();
@@ -141,6 +164,39 @@ public class DryRunModuleTest {
}
}
+ @Test
+ public void testExecuteOnlyBootstrapForNoopWithListener() throws Exception {
+ CompositeConfiguration config = new CompositeConfiguration();
+ config.setProperty("whirr.provider", "stub");
+ config.setProperty("whirr.cluster-name", "stub-test");
+ config.setProperty("whirr.instance-templates", "1 noop");
+ config.setProperty("whirr.state-store", "memory");
+
+ ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(config);
+ MockClusterActionHandlerListener listener = new MockClusterActionHandlerListener();
+ clusterSpec.setHandlerListener(listener);
+
+ ClusterController controller = new ClusterController();
+
+ DryRun dryRun = getDryRunInControllerForCluster(controller, clusterSpec);
+ dryRun.reset();
+
+ controller.launchCluster(clusterSpec);
+ controller.destroyCluster(clusterSpec);
+
+ ListMultimap<NodeMetadata, Statement> perNodeExecutions = dryRun.getExecutions();
+
+ for (Entry<NodeMetadata, Collection<Statement>> entry : perNodeExecutions
+ .asMap().entrySet()) {
+ assertSame("An incorrect number of scripts was executed in the node " + entry,
+ entry.getValue().size(), 1);
+ }
+
+ assertEquals("beforeCalls should be 4", listener.beforeCalls, 4);
+ assertEquals("afterCalls should be 4", listener.afterCalls, 4);
+
+ }
+
/**
* Simple test that tests dry run module and at the same time enforces clear
* separation of script execution phases.