List of usage examples for com.google.common.util.concurrent Service.State toString
public String toString()
From source file:co.cask.tigon.DistributedMain.java
public void startUp(PrintStream out) throws Exception { registerShutDownHook();/*from ww w . ja v a2 s.c o m*/ flowOperations.startAndWait(); List<String> commandList = Lists.newArrayList(); for (CLICommands cliCommand : CLICommands.values()) { commandList.add(cliCommand.toString().toLowerCase()); } consoleReader.setPrompt("tigon> "); String line; while ((line = consoleReader.readLine()) != null) { String[] args = line.split("\\s+"); String command = args[0].toUpperCase(); try { CLICommands cmd = null; try { cmd = CLICommands.valueOf(command); } catch (IllegalArgumentException e) { out.println("Available Commands : "); out.println(StringUtils.join(commandList, ", ")); continue; } if (args.length < cmd.getArgCount()) { throw new InvalidCLIArgumentException(cmd.printHelp()); } if (cmd.equals(CLICommands.START)) { Map<String, String> runtimeArgs = Maps.newHashMap(); if (args.length > cmd.getArgCount()) { try { runtimeArgs = DeployClient .fromPosixArray(Arrays.copyOfRange(args, cmd.getArgCount(), args.length)); } catch (IllegalArgumentException e) { LOG.error("Runtime Args are not in the correct format [ --key1=val1 --key2=val2 ]"); continue; } } flowOperations.startFlow(new File(args[1]), args[2], runtimeArgs); } else if (cmd.equals(CLICommands.LIST)) { out.println(StringUtils.join(flowOperations.listAllFlows(), ", ")); } else if (cmd.equals(CLICommands.STOP)) { flowOperations.stopFlow(args[1]); } else if (cmd.equals(CLICommands.DELETE)) { flowOperations.deleteFlow(args[1]); } else if (cmd.equals(CLICommands.SET)) { flowOperations.setInstances(args[1], args[2], Integer.valueOf(args[3])); } else if (cmd.equals(CLICommands.STATUS)) { Service.State state = flowOperations.getStatus(args[1]); String status = (state != null) ? state.toString() : "NOT FOUND"; out.println(status); } else if (cmd.equals(CLICommands.FLOWLETINFO)) { out.println(String.format("%-20s %s", "Flowlet Name", "Instance Count")); Map<String, Integer> flowletInfoMap = flowOperations.getFlowInfo(args[1]); for (Map.Entry<String, Integer> flowletInfo : flowletInfoMap.entrySet()) { out.println(String.format("%-20s %s", flowletInfo.getKey(), flowletInfo.getValue())); } } else if (cmd.equals(CLICommands.DISCOVER)) { for (InetSocketAddress socketAddress : flowOperations.discover(args[1], args[2])) { out.println(String.format("%s:%s", socketAddress.getHostName(), socketAddress.getPort())); } } else if (cmd.equals(CLICommands.SHOWLOGS)) { flowOperations.addLogHandler(args[1], System.out); } else if (cmd.equals(CLICommands.SERVICEINFO)) { out.println(StringUtils.join(flowOperations.getServices(args[1]), "\n")); } else if (cmd.equals(CLICommands.VERSION)) { out.println(ProjectInfo.getVersion().getBuildVersion()); } else if (cmd.equals(CLICommands.HELP)) { try { out.println(CLICommands.valueOf(args[1].toUpperCase()).printHelp()); } catch (IllegalArgumentException e) { out.println("Command Not Found"); } } else { //QUIT Command break; } } catch (InvalidCLIArgumentException e) { out.println(e.getMessage()); } } }