Permalink
Browse files

Increase unit test coverage

  • Loading branch information...
1 parent 35830ff commit e1b9cbad402e1935a52a4ba18ee3ad7706ef77fc @ggear ggear committed Oct 19, 2012
View
@@ -54,7 +54,7 @@ Download the Whirr CM plugun source, build and install into the lib directory of
```bash
git clone https://github.com/cloudera/whirr-cm.git
cd whirr-cm
-mvn clean install
+mvn clean install -Dmaven.test.skip=true
cp -rvf target/whirr-cm-*.jar $WHIRR_HOME/lib
```
@@ -34,11 +34,13 @@
public abstract class BaseHandler extends ClusterActionHandlerSupport {
- protected final static String CM_CONFIG_IMPORT_FILE = "collect_existing_service_data.py";
- protected final static String CM_CONFIG_IMPORT_PATH = "functions/cmf/";
+ protected final static String CONFIG_IMPORT_FILE = "collect_existing_service_data.py";
+ protected final static String CONFIG_IMPORT_PATH = "functions/cmf/";
+
+ private final static String PROPERTIES_FILE = "whirr-cm-default.properties";
protected Configuration getConfiguration(ClusterSpec spec) throws IOException {
- return getConfiguration(spec, "whirr-cm-default.properties");
+ return getConfiguration(spec, PROPERTIES_FILE);
}
@Override
@@ -59,10 +61,10 @@ protected void beforeConfigure(ClusterActionEvent event) throws IOException,
addStatement(
event,
createOrOverwriteFile(
- "/tmp/" + CM_CONFIG_IMPORT_FILE,
+ "/tmp/" + CONFIG_IMPORT_FILE,
Splitter.on('\n').split(
- CharStreams.toString(Resources.newReaderSupplier(Resources
- .getResource(CM_CONFIG_IMPORT_PATH + CM_CONFIG_IMPORT_FILE),
+ CharStreams.toString(Resources.newReaderSupplier(
+ Resources.getResource(CONFIG_IMPORT_PATH + CONFIG_IMPORT_FILE),
Charsets.UTF_8)))));
}
@@ -17,14 +17,6 @@
*/
package com.cloudera.whirr.cm;
-import static org.apache.whirr.RolePredicates.role;
-
-import java.io.IOException;
-
-import org.apache.whirr.Cluster;
-import org.apache.whirr.Cluster.Instance;
-import org.apache.whirr.service.ClusterActionEvent;
-
public class CdhClientHandler extends BaseHandler {
public static final String ROLE = "cdhclient";
@@ -34,14 +26,4 @@ public String getRole() {
return ROLE;
}
- @Override
- protected void afterConfigure(ClusterActionEvent event) throws IOException,
- InterruptedException {
- Cluster cluster = event.getCluster();
- Instance client = cluster.getInstanceMatching(role(ROLE));
- String clientAddress = client.getPublicAddress().getHostName();
- System.out.printf("CDH client machine available at %s over SSH.\n",
- clientAddress);
- }
-
}
@@ -21,18 +21,12 @@
import static org.jclouds.scriptbuilder.domain.Statements.call;
import java.io.IOException;
-import java.util.List;
-import java.util.NoSuchElementException;
import org.apache.whirr.service.ClusterActionEvent;
-import org.apache.whirr.service.FirewallManager.Rule;
-public class CmAgentHandler extends BaseHandler {
-
- private static final String CM_SERVER_PORT = "7182";
+public class CmAgentHandler extends CmNodeHandler {
public static final String ROLE = "cmagent";
- private static final String PORTS = "cmagent.ports";
@Override
public String getRole() {
@@ -42,32 +36,19 @@ public String getRole() {
@Override
protected void beforeBootstrap(ClusterActionEvent event) throws IOException {
super.beforeBootstrap(event);
- addStatement(event, call("install_cm"));
addStatement(event, call("install_cm_agent"));
}
@Override
protected void beforeConfigure(ClusterActionEvent event) throws IOException,
InterruptedException {
super.beforeConfigure(event);
- try {
- addStatement(
- event,
- call("configure_cm_agent", "-h", event.getCluster()
- .getInstanceMatching(role(CmServerHandler.ROLE)).getPublicHostName(),
- "-p", CM_SERVER_PORT));
- } catch (NoSuchElementException e) {
- addStatement(event,
- call("configure_cm_agent", "-h", "localhost", "-p", CM_SERVER_PORT));
- }
- List<?> ports = getConfiguration(event.getClusterSpec()).getList(PORTS);
- if (ports != null) {
- for (Object port : ports) {
- event.getFirewallManager().addRule(
- Rule.create().destination(role(ROLE))
- .port(Integer.parseInt(port.toString())));
- }
- }
+ addStatement(
+ event,
+ call("configure_cm_agent", "-h",
+ event.getCluster().getInstanceMatching(role(CmServerHandler.ROLE))
+ .getPublicHostName(), "-p", getConfiguration(event.getClusterSpec())
+ .getString(CmServerHandler.PROPERTY_PORT_COMMS)));
}
}
@@ -21,15 +21,15 @@
import static org.jclouds.scriptbuilder.domain.Statements.call;
import java.io.IOException;
-import java.util.List;
import org.apache.whirr.service.ClusterActionEvent;
import org.apache.whirr.service.FirewallManager.Rule;
public class CmNodeHandler extends BaseHandler {
public static final String ROLE = "cmnode";
- private static final String PORTS = "cmnode.ports";
+
+ private static final String PROPERTY_PORTS = "cmnode.ports";
@Override
public String getRole() {
@@ -46,13 +46,12 @@ protected void beforeBootstrap(ClusterActionEvent event) throws IOException {
protected void beforeConfigure(ClusterActionEvent event) throws IOException,
InterruptedException {
super.beforeConfigure(event);
- List<?> ports = getConfiguration(event.getClusterSpec()).getList(PORTS);
- if (ports != null) {
- for (Object port : ports) {
+ for (Object port : getConfiguration(event.getClusterSpec()).getList(
+ PROPERTY_PORTS)) {
+ if (port != null && !"".equals(port))
event.getFirewallManager().addRule(
Rule.create().destination(role(ROLE))
.port(Integer.parseInt(port.toString())));
- }
}
}
@@ -22,6 +22,8 @@
import static org.jclouds.scriptbuilder.domain.Statements.createOrOverwriteFile;
import java.io.IOException;
+import java.net.URL;
+import java.util.List;
import java.util.Set;
import org.apache.whirr.Cluster;
@@ -42,7 +44,9 @@
public static final String LICENSE_FILE = "cm-license.txt";
public static final String CONFIG_FILE = "cm-config.json";
- private static final int CLIENT_PORT = 7180;
+ public static final String PROPERTY_PORTS = "cmserver.ports";
+ public static final String PROPERTY_PORT_WEB = "cmserver.port.web";
+ public static final String PROPERTY_PORT_COMMS = "cmserver.port.comms";
@Override
public String getRole() {
@@ -60,42 +64,54 @@ protected void beforeBootstrap(ClusterActionEvent event) throws IOException {
protected void beforeConfigure(ClusterActionEvent event) throws IOException,
InterruptedException {
super.beforeConfigure(event);
- try {
+ URL licenceConfigUri = null;
+ if ((licenceConfigUri = CmServerHandler.class.getClassLoader().getResource(
+ LICENSE_FILE)) != null) {
addStatement(
event,
createOrOverwriteFile(
"/tmp/" + LICENSE_FILE,
Splitter.on('\n').split(
- CharStreams.toString(Resources.newReaderSupplier(
- Resources.getResource(LICENSE_FILE), Charsets.UTF_8)))));
- } catch (IllegalArgumentException e) {
-
+ CharStreams.toString(Resources.newReaderSupplier(licenceConfigUri,
+ Charsets.UTF_8)))));
}
- try {
+ URL configFileUri = null;
+ if ((configFileUri = CmServerHandler.class.getClassLoader().getResource(
+ CONFIG_FILE)) != null) {
addStatement(
event,
createOrOverwriteFile(
"/tmp/" + CONFIG_FILE,
Splitter.on('\n').split(
- CharStreams.toString(Resources.newReaderSupplier(
- Resources.getResource(CONFIG_FILE), Charsets.UTF_8)))));
- } catch (IllegalArgumentException e) {
-
+ CharStreams.toString(Resources.newReaderSupplier(configFileUri,
+ Charsets.UTF_8)))));
}
addStatement(event, call("configure_cm_server"));
- event.getFirewallManager().addRule(
- Rule.create().destination(role(ROLE)).port(CLIENT_PORT));
+ @SuppressWarnings("unchecked")
+ List<String> ports = getConfiguration(event.getClusterSpec()).getList(
+ PROPERTY_PORTS);
+ ports.add(getConfiguration(event.getClusterSpec()).getString(
+ PROPERTY_PORT_WEB));
+ ports.add(getConfiguration(event.getClusterSpec()).getString(
+ PROPERTY_PORT_COMMS));
+ for (String port : ports) {
+ if (port != null && !"".equals(port))
+ event.getFirewallManager().addRule(
+ Rule.create().destination(role(ROLE)).port(Integer.parseInt(port)));
+ }
}
@Override
protected void afterConfigure(ClusterActionEvent event) throws IOException,
InterruptedException {
+ super.afterConfigure(event);
Cluster cluster = event.getCluster();
Instance master = cluster.getInstanceMatching(role(ROLE));
String masterAddress = master.getPublicAddress().getHostName();
System.out.printf(
"Cloudera Manager Admin Console available at http://%s:%s\n",
- masterAddress, CLIENT_PORT);
+ masterAddress,
+ getConfiguration(event.getClusterSpec()).getString(PROPERTY_PORT_WEB));
System.out
.println("Nodes in cluster (copy into text area when setting up the cluster):");
@@ -15,5 +15,7 @@
# limitations under the License.
#
+cmserver.port.web=7180
+cmserver.port.comms=7182
+cmserver.ports=
cmnode.ports=8088,8888,50030,50060,50070,50090,60010,60030
-cmagent.ports=7182,9000
@@ -39,8 +39,14 @@
@Override
protected Predicate<CharSequence> bootstrapPredicate() {
- return and(containsPattern("install_cm"),
- containsPattern("install_cm_server"));
+ return and(
+ containsPattern("configure_hostnames"),
+ and(
+ containsPattern("install_cdh_hadoop"),
+ and(
+ containsPattern("install_cm_config_import"),
+ and(containsPattern("install_cm"),
+ containsPattern("install_cm_server")))));
}
@Override
@@ -49,11 +55,11 @@
}
@Test
- public void testChefWithDefaultRecipe() throws Exception {
+ public void testDefaultConfiguration() throws Exception {
DryRun dryRun = launchWithClusterSpec(newClusterSpecForProperties(ImmutableMap
.of("whirr.instance-templates", "1 cmserver")));
- assertScriptPredicateOnPhase(dryRun, "bootstrap", bootstrapPredicate());
- assertScriptPredicateOnPhase(dryRun, "configure", configurePredicate());
+ assertScriptPredicateOnPhase(dryRun, "configure",
+ containsPattern(CmServerHandler.CONFIG_IMPORT_FILE));
}
}

0 comments on commit e1b9cba

Please sign in to comment.