use of co.cask.cdap.proto.ApplicationDetail in project cdap by caskdata.
the class UpgradeTool method upgrade.
private boolean upgrade(final ApplicationId appId) throws Exception {
ApplicationDetail appDetail = appClient.get(appId);
if (!upgrader.shouldUpgrade(appDetail.getArtifact())) {
LOG.debug("Skipping app {} since it is not an upgradeable pipeline.", appId);
return false;
}
LOG.info("Upgrading pipeline: {}", appId);
return upgrader.upgrade(appDetail.getArtifact(), appDetail.getConfiguration(), new Upgrader.UpgradeAction() {
@Override
public boolean upgrade(AppRequest<? extends ETLConfig> appRequest) {
try {
appClient.update(appId, appRequest);
return true;
} catch (Exception e) {
LOG.error("Error upgrading pipeline {}.", appId, e);
if (errorDir != null) {
File errorFile = new File(errorDir, String.format("%s-%s.json", appId.getParent(), appId.getEntityName()));
LOG.error("Writing config for pipeline {} to {} for further manual investigation.", appId, errorFile.getAbsolutePath());
try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(errorFile))) {
outputStreamWriter.write(GSON.toJson(appRequest));
} catch (IOException e1) {
LOG.error("Error writing config out for manual investigation.", e1);
}
}
return false;
}
}
});
}
use of co.cask.cdap.proto.ApplicationDetail in project cdap by caskdata.
the class ApplicationClientTestRun method testAll.
@Test
public void testAll() throws Exception {
ApplicationId app = NamespaceId.DEFAULT.app(FakeApp.NAME);
Assert.assertEquals(0, appClient.list(NamespaceId.DEFAULT).size());
// deploy app
LOG.info("Deploying app");
appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, FakeApp.NAME, "1.0.0-SNAPSHOT"));
appClient.waitForDeployed(app, 30, TimeUnit.SECONDS);
Assert.assertEquals(1, appClient.list(NamespaceId.DEFAULT).size());
try {
// check program list
LOG.info("Checking program list for app");
Map<ProgramType, List<ProgramRecord>> programs = appClient.listProgramsByType(app);
verifyProgramNames(FakeApp.FLOWS, programs.get(ProgramType.FLOW));
verifyProgramNames(FakeApp.MAPREDUCES, programs.get(ProgramType.MAPREDUCE));
verifyProgramNames(FakeApp.WORKFLOWS, programs.get(ProgramType.WORKFLOW));
verifyProgramNames(FakeApp.SERVICES, programs.get(ProgramType.SERVICE));
verifyProgramNames(FakeApp.FLOWS, appClient.listPrograms(app, ProgramType.FLOW));
verifyProgramNames(FakeApp.MAPREDUCES, appClient.listPrograms(app, ProgramType.MAPREDUCE));
verifyProgramNames(FakeApp.WORKFLOWS, appClient.listPrograms(app, ProgramType.WORKFLOW));
verifyProgramNames(FakeApp.SERVICES, appClient.listPrograms(app, ProgramType.SERVICE));
verifyProgramNames(FakeApp.FLOWS, appClient.listAllPrograms(NamespaceId.DEFAULT, ProgramType.FLOW));
verifyProgramNames(FakeApp.MAPREDUCES, appClient.listAllPrograms(NamespaceId.DEFAULT, ProgramType.MAPREDUCE));
verifyProgramNames(FakeApp.WORKFLOWS, appClient.listAllPrograms(NamespaceId.DEFAULT, ProgramType.WORKFLOW));
verifyProgramNames(FakeApp.SERVICES, appClient.listAllPrograms(NamespaceId.DEFAULT, ProgramType.SERVICE));
verifyProgramRecords(FakeApp.ALL_PROGRAMS, appClient.listAllPrograms(NamespaceId.DEFAULT));
ApplicationDetail appDetail = appClient.get(app);
ArtifactSummary expected = new ArtifactSummary(FakeApp.NAME, "1.0.0-SNAPSHOT");
Assert.assertEquals(expected, appDetail.getArtifact());
} finally {
// delete app
LOG.info("Deleting app");
appClient.delete(app);
appClient.waitForDeleted(app, 30, TimeUnit.SECONDS);
Assert.assertEquals(0, appClient.list(NamespaceId.DEFAULT).size());
}
}
use of co.cask.cdap.proto.ApplicationDetail in project cdap by caskdata.
the class ProgramLifecycleHttpHandlerTest method verifyProgramList.
private void verifyProgramList(String namespace, String appName, final ProgramType programType, int expected) throws Exception {
HttpResponse response = requestAppDetail(namespace, appName);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
String json = EntityUtils.toString(response.getEntity());
ApplicationDetail appDetail = GSON.fromJson(json, ApplicationDetail.class);
Collection<ProgramRecord> programs = Collections2.filter(appDetail.getPrograms(), new Predicate<ProgramRecord>() {
@Override
public boolean apply(@Nullable ProgramRecord record) {
return programType.getCategoryName().equals(record.getType().getCategoryName());
}
});
Assert.assertEquals(expected, programs.size());
}
use of co.cask.cdap.proto.ApplicationDetail in project cdap by caskdata.
the class ApplicationClient method get.
/**
* Get details about the specified application.
*
* @param appId the id of the application to get
* @return details about the specified application
* @throws ApplicationNotFoundException if the application with the given ID was not found
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public ApplicationDetail get(ApplicationId appId) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
String path = String.format("apps/%s/versions/%s", appId.getApplication(), appId.getVersion());
HttpResponse response = restClient.execute(HttpMethod.GET, config.resolveNamespacedURLV3(appId.getParent(), path), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ApplicationNotFoundException(appId);
}
return ObjectResponse.fromJsonBody(response, ApplicationDetail.class).getResponseObject();
}
Aggregations