@Test public void testMaxPercentFailure() throws Exception { ClusterControllerFactory factory = mock(ClusterControllerFactory.class); ClusterController controller = mock(ClusterController.class); Cluster cluster = mock(Cluster.class); when(factory.create((String) any())).thenReturn(controller); when(controller.launchCluster((ClusterSpec) any())).thenReturn(cluster); LaunchClusterCommand command = new LaunchClusterCommand(factory); Map<String, File> keys = KeyPair.generateTemporaryFiles(); int rc = command.run(null, out, null, Lists.newArrayList( "--service-name", "hadoop", "--cluster-name", "test-cluster", "--instance-templates", "1 hadoop-namenode+hadoop-jobtracker,3 hadoop-datanode+hadoop-tasktracker", "--instance-templates-max-percent-failures", "60 hadoop-datanode+hadoop-tasktracker", "--provider", "aws-ec2", "--identity", "myusername", "--credential", "mypassword", "--private-key-file", keys.get("private").getAbsolutePath(), "--version", "version-string" )); assertThat(rc, is(0)); Configuration conf = new PropertiesConfiguration(); conf.addProperty("whirr.provider", "aws-ec2"); conf.addProperty("whirr.version", "version-string"); conf.addProperty("whirr.instance-templates-max-percent-failure", "60 hadoop-datanode+hadoop-tasktracker"); ClusterSpec expectedClusterSpec = ClusterSpec.withTemporaryKeys(conf); expectedClusterSpec.setInstanceTemplates(Lists.newArrayList( InstanceTemplate.builder().numberOfInstance(1).minNumberOfInstances(1) .roles("hadoop-namenode", "hadoop-jobtracker").build(), InstanceTemplate.builder().numberOfInstance(3).minNumberOfInstances(2) .roles("hadoop-datanode", "hadoop-tasktracker").build() )); expectedClusterSpec.setServiceName("hadoop"); expectedClusterSpec.setIdentity("myusername"); expectedClusterSpec.setCredential("mypassword"); expectedClusterSpec.setClusterName("test-cluster"); expectedClusterSpec.setPrivateKey(keys.get("private")); expectedClusterSpec.setPublicKey(keys.get("public")); verify(factory).create("hadoop"); verify(controller).launchCluster(expectedClusterSpec); assertThat(outBytes.toString(), containsString("Started cluster of 0 instances")); }
@Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionSet optionSet = parser.parse(args.toArray(new String[args.size()])); if (!optionSet.nonOptionArguments().isEmpty()) { printUsage(err); return -1; } try { ClusterSpec clusterSpec = getClusterSpec(optionSet); printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -1; } }
LaunchClusterCommand extends AbstractClusterCommand { @Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionSet optionSet = parser.parse(args.toArray(new String[args.size()])); if (!optionSet.nonOptionArguments().isEmpty()) { printUsage(err); return -1; } try { ClusterSpec clusterSpec = getClusterSpec(optionSet); printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -1; } } }
LaunchClusterCommand extends AbstractClusterCommand { @Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionSet optionSet = parser.parse(args.toArray(new String[args.size()])); if (!optionSet.nonOptionArguments().isEmpty()) { printUsage(err); return -1; } try { ClusterSpec clusterSpec = getClusterSpec(optionSet); printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -1; } } LaunchClusterCommand();  LaunchClusterCommand(ClusterControllerFactory factory); }
LaunchClusterCommand extends AbstractClusterCommand { @Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionSet optionSet = parser.parse(args.toArray(new String[args.size()])); if (!optionSet.nonOptionArguments().isEmpty()) { printUsage(err); return -1; } try { ClusterSpec clusterSpec = getClusterSpec(optionSet); printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -1; } } LaunchClusterCommand();  LaunchClusterCommand(ClusterControllerFactory factory); @Override int run(InputStream in, PrintStream out, PrintStream err,
                 List<String> args); int run(InputStream in, PrintStream out, PrintStream err, ClusterSpec clusterSpec); }
LaunchClusterCommand extends AbstractClusterCommand { @Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionSet optionSet = parser.parse(args.toArray(new String[args.size()])); if (!optionSet.nonOptionArguments().isEmpty()) { printUsage(err); return -1; } try { ClusterSpec clusterSpec = getClusterSpec(optionSet); printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -1; } } LaunchClusterCommand();  LaunchClusterCommand(ClusterControllerFactory factory); @Override int run(InputStream in, PrintStream out, PrintStream err,
                 List<String> args); int run(InputStream in, PrintStream out, PrintStream err, ClusterSpec clusterSpec);  }