use of io.cdap.cdap.proto.BatchProgramResult in project cdap by caskdata.
the class StartProgramsCommand method runBatchCommand.
@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);
}
use of io.cdap.cdap.proto.BatchProgramResult in project cdap by caskdata.
the class StopProgramsCommand method runBatchCommand.
@Override
protected void runBatchCommand(PrintStream printStream, Args<BatchProgram> args) throws Exception {
List<BatchProgramResult> results = programClient.stop(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);
}
use of io.cdap.cdap.proto.BatchProgramResult in project cdap by caskdata.
the class ProgramClient method start.
/**
* Starts a batch of programs in the same call.
*
* @param namespace the namespace of the programs
* @param programs the programs to start, including any runtime arguments to start them with
* @return the result of starting each program
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<BatchProgramResult> start(NamespaceId namespace, List<BatchProgramStart> programs) throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(namespace, "start");
HttpRequest request = HttpRequest.builder(HttpMethod.POST, url).withBody(GSON.toJson(programs), Charsets.UTF_8).build();
HttpResponse response = restClient.execute(request, config.getAccessToken());
return ObjectResponse.<List<BatchProgramResult>>fromJsonBody(response, BATCH_RESULTS_TYPE, GSON).getResponseObject();
}
use of io.cdap.cdap.proto.BatchProgramResult in project cdap by caskdata.
the class ProgramClient method stop.
/**
* Stops a batch of programs in the same call.
*
* @param namespace the namespace of the programs
* @param programs the programs to stop
* @return the result of stopping each program
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<BatchProgramResult> stop(NamespaceId namespace, List<BatchProgram> programs) throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(namespace, "stop");
HttpRequest request = HttpRequest.builder(HttpMethod.POST, url).withBody(GSON.toJson(programs), Charsets.UTF_8).build();
HttpResponse response = restClient.execute(request, config.getAccessToken());
return ObjectResponse.<List<BatchProgramResult>>fromJsonBody(response, BATCH_RESULTS_TYPE, GSON).getResponseObject();
}
use of io.cdap.cdap.proto.BatchProgramResult in project cdap by caskdata.
the class ProgramClientTestRun method testBatchProgramCalls.
@Test
public void testBatchProgramCalls() throws Exception {
final NamespaceId namespace = NamespaceId.DEFAULT;
final ApplicationId appId = namespace.app(FakeApp.NAME);
BatchProgram pingService = new BatchProgram(FakeApp.NAME, ProgramType.SERVICE, PingService.NAME);
BatchProgram writerService = new BatchProgram(FakeApp.NAME, ProgramType.SERVICE, DatasetWriterService.NAME);
BatchProgram missing = new BatchProgram(FakeApp.NAME, ProgramType.SERVICE, "not" + PingService.NAME);
appClient.deploy(namespace, createAppJarFile(FakeApp.class));
try {
// make a batch call to start multiple programs, one of which does not exist
List<BatchProgramStart> programStarts = ImmutableList.of(new BatchProgramStart(pingService), new BatchProgramStart(writerService), new BatchProgramStart(missing));
List<BatchProgramResult> results = programClient.start(namespace, programStarts);
// check that we got a 200 for programs that exist, and a 404 for the one that doesn't
for (BatchProgramResult result : results) {
if (missing.getProgramId().equals(result.getProgramId())) {
Assert.assertEquals(404, result.getStatusCode());
} else {
Assert.assertEquals(200, result.getStatusCode());
}
}
// wait for all programs to be in RUNNING status
assertProgramRuns(programClient, namespace.app(pingService.getAppId()).service(pingService.getProgramId()), ProgramRunStatus.RUNNING, 1, 10);
assertProgramRuns(programClient, namespace.app(writerService.getAppId()).service(writerService.getProgramId()), ProgramRunStatus.RUNNING, 1, 10);
// make a batch call for status of programs, one of which does not exist
List<BatchProgram> programs = ImmutableList.of(pingService, writerService, missing);
List<BatchProgramStatus> statusList = programClient.getStatus(namespace, programs);
// check status is running for programs that exist, and that we get a 404 for the one that doesn't
for (BatchProgramStatus status : statusList) {
if (missing.getProgramId().equals(status.getProgramId())) {
Assert.assertEquals(404, status.getStatusCode());
} else {
Assert.assertEquals(200, status.getStatusCode());
Assert.assertEquals("RUNNING", status.getStatus());
}
}
// make a batch call to stop programs, one of which does not exist
results = programClient.stop(namespace, programs);
// check that we got a 200 for programs that exist, and a 404 for the one that doesn't
for (BatchProgramResult result : results) {
if (missing.getProgramId().equals(result.getProgramId())) {
Assert.assertEquals(404, result.getStatusCode());
} else {
Assert.assertEquals(200, result.getStatusCode());
}
}
// check programs are in stopped state
final List<BatchProgram> stoppedPrograms = ImmutableList.of(pingService, writerService);
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
List<BatchProgramStatus> statusList = programClient.getStatus(namespace, stoppedPrograms);
for (BatchProgramStatus status : statusList) {
if (status.getStatusCode() != 200) {
return false;
}
if (status.getStatus().equals("RUNNING")) {
return false;
}
}
return true;
}
}, 10, TimeUnit.SECONDS);
} finally {
try {
appClient.delete(appId);
} catch (Exception e) {
LOG.error("Error deleting app {} during test cleanup.", appId, e);
}
}
}
Aggregations