private static List<Command> generateCommands(ProgramClient programClient, CLIConfig cliConfig) { List<Command> commands = Lists.newArrayList(); for (ElementType elementType : ElementType.values()) { if (elementType.canStop()) { commands.add(new StopProgramCommand(elementType, programClient, cliConfig)); } } return commands; }
@Override @SuppressWarnings("deprecation") public void perform(Arguments arguments, PrintStream output) throws Exception { String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\."); String appId = programIdParts[0]; int instances; switch (elementType) { case FLOWLET: if (programIdParts.length < 3) { throw new CommandInputError(this); } String flowId = programIdParts[1]; String flowletId = programIdParts[2]; instances = programClient.getFlowletInstances(appId, flowId, flowletId); break; case WORKER: if (programIdParts.length < 2) { throw new CommandInputError(this); } String workerId = programIdParts[1]; instances = programClient.getWorkerInstances(appId, workerId); break; case SERVICE: if (programIdParts.length < 2) { throw new CommandInputError(this); } String service = programIdParts[1]; instances = programClient.getServiceInstances(appId, service); break; default: // TODO: remove this throw new IllegalArgumentException( "Unrecognized program element type for scaling: " + elementType); } output.println(instances); }
@Override public String getDescription() { return String.format( "Gets the instances of %s.", Fragment.of(Article.A, elementType.getTitleName())); }
@Override public String getPattern() { return String.format( "get %s instances <%s>", elementType.getName(), elementType.getArgumentName()); }