@Test public void testDestroyInstanceById() throws Exception { ClusterControllerFactory factory = mock(ClusterControllerFactory.class); ClusterController controller = mock(ClusterController.class); when(factory.create((String) any())).thenReturn(controller); DestroyInstanceCommand command = new DestroyInstanceCommand(factory); Map<String, File> keys = KeyPair.generateTemporaryFiles(); int rc = command.run(null, out, null, Lists.newArrayList( "--instance-templates", "1 noop", "--instance-id", "region/instanceid", "--service-name", "test-service", "--cluster-name", "test-cluster", "--provider", "rackspace", "--identity", "myusername", "--credential", "mypassword", "--private-key-file", keys.get("private").getAbsolutePath(), "--version", "version-string" )); assertThat(rc, is(0)); verify(controller).destroyInstance((ClusterSpec) any(), eq("region/instanceid")); }
@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 { if (!optionSet.hasArgument(instanceOption)) { throw new IllegalArgumentException("--instance-id is a mandatory argument"); } ClusterSpec clusterSpec = getClusterSpec(optionSet); String instanceId = optionSet.valueOf(instanceOption); printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec, instanceId); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -1; } }
DestroyInstanceCommand 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 { if (!optionSet.hasArgument(instanceOption)) { throw new IllegalArgumentException("--instance-id is a mandatory argument"); } ClusterSpec clusterSpec = getClusterSpec(optionSet); String instanceId = optionSet.valueOf(instanceOption); printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec, instanceId); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -1; } } }
DestroyInstanceCommand 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 { if (!optionSet.hasArgument(instanceOption)) { throw new IllegalArgumentException("--instance-id is a mandatory argument"); } ClusterSpec clusterSpec = getClusterSpec(optionSet); String instanceId = optionSet.valueOf(instanceOption); printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec, instanceId); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -1; } } DestroyInstanceCommand();  DestroyInstanceCommand(ClusterControllerFactory factory); }
DestroyInstanceCommand 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 { if (!optionSet.hasArgument(instanceOption)) { throw new IllegalArgumentException("--instance-id is a mandatory argument"); } ClusterSpec clusterSpec = getClusterSpec(optionSet); String instanceId = optionSet.valueOf(instanceOption); printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec, instanceId); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -1; } } DestroyInstanceCommand();  DestroyInstanceCommand(ClusterControllerFactory factory); @Override int run(InputStream in, PrintStream out,
                 PrintStream err, List<String> args); int run(InputStream in, PrintStream out, PrintStream err,
                 ClusterSpec clusterSpec, String instanceId); @Override void printUsage(PrintStream stream); }
DestroyInstanceCommand 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 { if (!optionSet.hasArgument(instanceOption)) { throw new IllegalArgumentException("--instance-id is a mandatory argument"); } ClusterSpec clusterSpec = getClusterSpec(optionSet); String instanceId = optionSet.valueOf(instanceOption); printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec, instanceId); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -1; } } DestroyInstanceCommand();  DestroyInstanceCommand(ClusterControllerFactory factory); @Override int run(InputStream in, PrintStream out,
                 PrintStream err, List<String> args); int run(InputStream in, PrintStream out, PrintStream err,
                 ClusterSpec clusterSpec, String instanceId); @Override void printUsage(PrintStream stream);  }