Skip to content

Commit

Permalink
WHIRR-172. Log warning for unrecognized service names.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/incubator/whirr/trunk@1092389 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
tomwhite committed Apr 14, 2011
1 parent 676ed20 commit 1bf7fa1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Trunk (unreleased changes)

WHIRR-274. Add wagon-ssh-external as a maven build extension. (asavu)

WHIRR-172. Log warning for unrecognized service names. (tomwhite)

Release 0.4.0 - 2011-03-15

NEW FEATURES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@
import org.apache.whirr.ClusterControllerFactory;
import org.apache.whirr.ClusterSpec;
import org.apache.whirr.ClusterSpec.Property;
import org.apache.whirr.actions.BootstrapClusterAction;
import org.apache.whirr.cli.Command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* An abstract command for interacting with clusters.
*/
public abstract class AbstractClusterSpecCommand extends Command {

private static final Logger LOG =
LoggerFactory.getLogger(AbstractClusterSpecCommand.class);

protected ClusterControllerFactory factory;

Expand Down Expand Up @@ -105,13 +111,12 @@ protected ClusterSpec getClusterSpec(OptionSet optionSet) throws ConfigurationEx

/**
* Create the specified service
* @throws IllegalArgumentException if serviceName is not found
*/
protected ClusterController createClusterController(String serviceName) {
ClusterController controller = factory.create(serviceName);
if (controller == null) {
throw new IllegalArgumentException("Unable to find service "
+ serviceName + ", exiting");
LOG.warn("Unable to find service {}, using default.", serviceName);
controller = factory.create(null);
}
return controller;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public int run(InputStream in, PrintStream out, PrintStream err,
}

/**
* Ensure that an invalid service name causes failure
* Ensure that an invalid service name uses the default (after logging a
* warning).
*/
@Test(expected=IllegalArgumentException.class)
public void testCreateServerWithInvalidClusterControllerName() throws Exception {
AbstractClusterSpecCommand clusterSpecCommand = new AbstractClusterSpecCommand("name",
"description", new ClusterControllerFactory()) {
Expand All @@ -79,7 +79,7 @@ public int run(InputStream in, PrintStream out, PrintStream err,
"--private-key-file", keys.get("private").getAbsolutePath()
);
ClusterSpec clusterSpec = clusterSpecCommand.getClusterSpec(optionSet);
// this should fail - non-existent service
// following should not fail
clusterSpecCommand.createClusterController("bar");
}
}

0 comments on commit 1bf7fa1

Please sign in to comment.