use of io.cdap.cdap.proto.ApplicationDetail in project cdap by caskdata.
the class ApplicationDetailFetcherTest method testGetApplication.
@Test
public void testGetApplication() throws Exception {
ApplicationDetailFetcher fetcher = getApplicationDetailFetcher(fetcherType);
String namespace = TEST_NAMESPACE1;
String appName = AllProgramsApp.NAME;
// Deploy the application
deploy(AllProgramsApp.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, namespace);
// Get and validate the application
ApplicationId appId = new ApplicationId(namespace, appName);
ApplicationDetail appDetail = fetcher.get(appId);
assertAllProgramAppDetail(appDetail);
// Delete the application
Assert.assertEquals(200, doDelete(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, namespace)).getResponseCode());
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by caskdata.
the class SupportBundlePipelineInfoTask method collect.
@Override
public void collect() throws IOException, NotFoundException {
for (NamespaceId namespaceId : namespaces) {
Iterable<ApplicationDetail> appDetails;
if (requestApplication == null) {
appDetails = remoteApplicationDetailFetcher.list(namespaceId.getNamespace());
} else {
try {
appDetails = Collections.singletonList(remoteApplicationDetailFetcher.get(new ApplicationId(namespaceId.getNamespace(), requestApplication)));
} catch (NotFoundException e) {
LOG.debug("Failed to find application {} ", requestApplication, e);
continue;
}
}
for (ApplicationDetail appDetail : appDetails) {
String application = appDetail.getName();
ApplicationId applicationId = new ApplicationId(namespaceId.getNamespace(), application);
File appFolderPath = new File(basePath, appDetail.getName());
DirUtils.mkdirs(appFolderPath);
try (FileWriter file = new FileWriter(new File(appFolderPath, appDetail.getName() + ".json"))) {
GSON.toJson(appDetail, file);
}
ProgramId programId = new ProgramId(namespaceId.getNamespace(), appDetail.getName(), programType, programName);
Iterable<RunRecord> runRecordList;
if (runId != null) {
ProgramRunId programRunId = new ProgramRunId(namespaceId.getNamespace(), appDetail.getName(), programType, programName, runId);
RunRecordDetail runRecordDetail = remoteProgramRunRecordFetcher.getRunRecordMeta(programRunId);
runRecordList = Collections.singletonList(runRecordDetail);
} else {
runRecordList = getRunRecords(programId);
}
SupportBundleRuntimeInfoTask supportBundleRuntimeInfoTask = new SupportBundleRuntimeInfoTask(appFolderPath, namespaceId, applicationId, programType, programId, remoteMetricsSystemClient, runRecordList, appDetail);
SupportBundlePipelineRunLogTask supportBundlePipelineRunLogTask = new SupportBundlePipelineRunLogTask(appFolderPath, programId, remoteLogsFetcher, runRecordList);
String runtimeInfoClassName = supportBundleRuntimeInfoTask.getClass().getName();
String runtimeInfoTaskName = uuid.concat(": ").concat(runtimeInfoClassName).concat(": ").concat(appDetail.getName());
supportBundleJob.executeTask(supportBundleRuntimeInfoTask, basePath.getPath(), runtimeInfoTaskName, runtimeInfoTaskName);
String runtimeLogClassName = supportBundlePipelineRunLogTask.getClass().getName();
String runtimeLogTaskName = uuid.concat(": ").concat(runtimeLogClassName).concat(": ").concat(appDetail.getName());
supportBundleJob.executeTask(supportBundlePipelineRunLogTask, basePath.getPath(), runtimeLogTaskName, runtimeLogClassName);
}
}
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by caskdata.
the class ApplicationLifecycleServiceTest method testScanApplicationsWithFailingPredicate.
@Test
public void testScanApplicationsWithFailingPredicate() throws Exception {
createNamespace("ns1");
createNamespace("ns2");
createNamespace("ns3");
deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, "ns1");
deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, "ns2");
deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, "ns3");
List<ApplicationDetail> appDetails = new ArrayList<>();
applicationLifecycleService.scanApplications(new NamespaceId("ns1"), ImmutableSet.of("name1"), "version1", d -> appDetails.add(d));
Assert.assertEquals(appDetails.size(), 0);
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by caskdata.
the class ApplicationLifecycleServiceTest method testScanApplications.
@Test
public void testScanApplications() throws Exception {
createNamespace("ns1");
createNamespace("ns2");
createNamespace("ns3");
deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, "ns1");
deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, "ns2");
deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, "ns3");
List<ApplicationDetail> appDetails = new ArrayList<>();
applicationLifecycleService.scanApplications(new NamespaceId("ns1"), ImmutableSet.of(), null, d -> appDetails.add(d));
Assert.assertEquals(appDetails.size(), 1);
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by caskdata.
the class ApplicationLifecycleServiceTest method testCreateAppDetailsArchive.
@Test
public void testCreateAppDetailsArchive() throws Exception {
createNamespace("ns1");
createNamespace("ns2");
createNamespace("ns3");
deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, "ns1");
deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, "ns2");
deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, "ns3");
File archiveFile = tmpFolder.newFile();
try (ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(archiveFile))) {
applicationLifecycleService.createAppDetailsArchive(zipOut);
}
// Validate the ZIP file content
File dir = tmpFolder.newFolder();
BundleJarUtil.unJar(archiveFile, dir);
ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
for (String ns : Arrays.asList("ns1", "ns2", "ns3")) {
File nsDir = new File(dir, ns);
Assert.assertTrue(nsDir.isDirectory());
ApplicationDetail appDetail = GSON.fromJson(Files.toString(new File(nsDir, appSpec.getName() + ".json"), StandardCharsets.UTF_8), ApplicationDetail.class);
Assert.assertEquals(appSpec.getName(), appDetail.getName());
// Check if all the programs are there
int programCount = Arrays.stream(io.cdap.cdap.api.app.ProgramType.values()).map(appSpec::getProgramsByType).mapToInt(Set::size).reduce(0, Integer::sum);
Assert.assertEquals(programCount, appDetail.getPrograms().size());
for (ProgramRecord record : appDetail.getPrograms()) {
Assert.assertTrue(appSpec.getProgramsByType(record.getType().getApiProgramType()).contains(record.getName()));
}
}
}
Aggregations