/** * Starts a program using the stored runtime arguments. * * @param program the program to start * @throws IOException if a network error occurred * @throws ProgramNotFoundException if the program with the specified name could not be found * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public void start(ProgramId program, boolean debug) throws IOException, ProgramNotFoundException, UnauthenticatedException, UnauthorizedException { start(program, debug, null); }
/** * Starts a program using the stored runtime arguments. * * @param program the program to start * @throws IOException if a network error occurred * @throws ProgramNotFoundException if the program with the specified name could not be found * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public void start(ProgramId program) throws IOException, ProgramNotFoundException, UnauthenticatedException, UnauthorizedException { start(program, false, null); }
@Override public void startProgram(ProgramId programId, Map<String, String> arguments) { try { programClient.start(programId, false, arguments); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override protected void runBatchCommand(PrintStream printStream, Args<BatchProgram> args) throws Exception { NamespaceId namespace = args.appId.getParent(); printStream.print("Stopping programs...\n"); programClient.stop(namespace, args.programs); printStream.print("Starting programs...\n"); List<BatchProgramStart> startList = new ArrayList<>(args.programs.size()); for (BatchProgram program : args.programs) { startList.add(new BatchProgramStart(program)); } programClient.start(namespace, startList); }
@Override protected void runBatchCommand(PrintStream printStream, Args<BatchProgram> args) throws Exception { NamespaceId namespace = args.appId.getParent(); printStream.print("Stopping programs...\n"); programClient.stop(namespace, args.programs); printStream.print("Starting programs...\n"); List<BatchProgramStart> startList = new ArrayList<>(args.programs.size()); for (BatchProgram program : args.programs) { startList.add(new BatchProgramStart(program)); } programClient.start(namespace, startList); }
@Override public void perform(Arguments arguments, PrintStream output) throws Exception { String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\."); if (programIdParts.length < 2) { throw new CommandInputError(this); } ProgramId programId = parseProgramId(arguments, elementType); String appName = programId.getApplication(); String appVersion = programId.getVersion(); String programName = programId.getProgram(); String runtimeArgsString = arguments.getOptional(ArgumentName.RUNTIME_ARGS.toString(), ""); if (runtimeArgsString == null || runtimeArgsString.isEmpty()) { // run with stored runtime args programClient.start(programId, isDebug, null); runtimeArgsString = SPACE_EQUALS_JOINER.join(programClient.getRuntimeArgs(programId)); output.printf("Successfully started %s '%s' of application '%s.%s' with stored runtime arguments '%s'\n", elementType.getName(), programName, appName, appVersion, runtimeArgsString); } else { // run with user-provided runtime args Map<String, String> runtimeArgs = ArgumentParser.parseMap(runtimeArgsString, ArgumentName.RUNTIME_ARGS.toString()); programClient.start(programId, isDebug, runtimeArgs); output.printf("Successfully started %s '%s' of application '%s.%s' with provided runtime arguments '%s'\n", elementType.getName(), programName, appName, appVersion, runtimeArgsString); } }
@Override public void perform(Arguments arguments, PrintStream output) throws Exception { String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\."); if (programIdParts.length < 2) { throw new CommandInputError(this); } ProgramId programId = parseProgramId(arguments, elementType); String appName = programId.getApplication(); String appVersion = programId.getVersion(); String programName = programId.getProgram(); String runtimeArgsString = arguments.getOptional(ArgumentName.RUNTIME_ARGS.toString(), ""); if (runtimeArgsString == null || runtimeArgsString.isEmpty()) { // run with stored runtime args programClient.start(programId, isDebug, null); runtimeArgsString = SPACE_EQUALS_JOINER.join(programClient.getRuntimeArgs(programId)); output.printf("Successfully started %s '%s' of application '%s.%s' with stored runtime arguments '%s'\n", elementType.getName(), programName, appName, appVersion, runtimeArgsString); } else { // run with user-provided runtime args Map<String, String> runtimeArgs = ArgumentParser.parseMap(runtimeArgsString, ArgumentName.RUNTIME_ARGS.toString()); programClient.start(programId, isDebug, runtimeArgs); output.printf("Successfully started %s '%s' of application '%s.%s' with provided runtime arguments '%s'\n", elementType.getName(), programName, appName, appVersion, runtimeArgsString); } }
@Override protected void runBatchCommand(PrintStream printStream, Args<BatchProgramStart> args) throws Exception { List<BatchProgramResult> results = programClient.start(args.appId.getParent(), args.programs); Table table = Table.builder() .setHeader("name", "type", "error") .setRows(results, new RowMaker<BatchProgramResult>() { @Override public List<?> makeRow(BatchProgramResult result) { return Lists.newArrayList( result.getProgramId(), result.getProgramType(), result.getError()); } }).build(); cliConfig.getTableRenderer().render(cliConfig, printStream, table); }
@Override protected void runBatchCommand(PrintStream printStream, Args<BatchProgramStart> args) throws Exception { List<BatchProgramResult> results = programClient.start(args.appId.getParent(), args.programs); Table table = Table.builder() .setHeader("name", "type", "error") .setRows(results, new RowMaker<BatchProgramResult>() { @Override public List<?> makeRow(BatchProgramResult result) { return Lists.newArrayList( result.getProgramId(), result.getProgramType(), result.getError()); } }).build(); cliConfig.getTableRenderer().render(cliConfig, printStream, table); }
public void programClient() throws Exception { // Construct the client used to interact with CDAP ProgramClient programClient = new ProgramClient(clientConfig); // Start a service in the WordCount example programClient.start(NamespaceId.DEFAULT.app("WordCount").service("RetrieveCounts")); // Fetch live information from the HelloWorld example // Live info includes the address of an component’s container host and the container’s debug port, // formatted in JSON programClient.getLiveInfo(NamespaceId.DEFAULT.app("HelloWorld").service("greet")); // Fetch program logs in the WordCount example programClient.getProgramLogs(NamespaceId.DEFAULT.app("WordCount").service("RetrieveCounts"), 0, Long.MAX_VALUE); // Scale a service in the HelloWorld example programClient.setServiceInstances(NamespaceId.DEFAULT.app("HelloWorld").service("greet"), 3); // Stop a service in the HelloWorld example programClient.stop(NamespaceId.DEFAULT.app("HelloWorld").service("greet")); }