use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.
the class AppFabricServiceMainTest method testAppFabricService.
@Test
public void testAppFabricService() throws Exception {
// Query the system services endpoint
URL url = getRouterBaseURI().resolve("/v3/system/services").toURL();
HttpResponse response = HttpRequests.execute(HttpRequest.get(url).build(), new DefaultHttpRequestConfig(false));
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
// Deploy an app
LocationFactory locationFactory = new LocalLocationFactory(TEMP_FOLDER.newFolder());
Location deploymentJar = AppJarHelper.createDeploymentJar(locationFactory, AllProgramsApp.class);
URI baseURI = getRouterBaseURI().resolve("/v3/namespaces/default/");
url = baseURI.resolve("apps").toURL();
HttpRequestConfig requestConfig = new HttpRequestConfig(0, 0, false);
response = HttpRequests.execute(HttpRequest.post(url).withBody((ContentProvider<? extends InputStream>) deploymentJar::getInputStream).addHeader("X-Archive-Name", AllProgramsApp.class.getSimpleName() + "-1.0-SNAPSHOT.jar").build(), requestConfig);
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
// Get the application
url = baseURI.resolve("apps/" + AllProgramsApp.NAME).toURL();
response = HttpRequests.execute(HttpRequest.get(url).build(), requestConfig);
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
ApplicationDetail appDetail = new Gson().fromJson(response.getResponseBodyAsString(), ApplicationDetail.class);
// Do some basic validation only.
Assert.assertEquals(AllProgramsApp.NAME, appDetail.getName());
Assert.assertTrue(appDetail.getPrograms().stream().filter(r -> r.getType() == ProgramType.WORKFLOW).anyMatch(r -> AllProgramsApp.NoOpWorkflow.NAME.equals(r.getName())));
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.
the class SupportBundlePipelineInfoTaskTest method testSupportBundlePipelineInfo.
// Contains two sub-task supportBundleRuntimeInfo and supportBundlePipelineRunLog
// So we will test all three files together
@Test
public void testSupportBundlePipelineInfo() throws Exception {
String runId = generateWorkflowLog();
SupportBundleConfiguration supportBundleConfiguration = new SupportBundleConfiguration(namespaceId.getNamespace(), application, runId, programType, workflowName, 1);
String uuid = UUID.randomUUID().toString();
File tempFolder = new File(configuration.get(Constants.SupportBundle.LOCAL_DATA_DIR));
File uuidFile = new File(tempFolder, uuid);
SupportBundleStatus supportBundleStatus = SupportBundleStatus.builder().setBundleId(uuid).setStartTimestamp(System.currentTimeMillis()).setParameters(supportBundleConfiguration).setStatus(CollectionState.IN_PROGRESS).build();
SupportBundleJob supportBundleJob = new SupportBundleJob(supportBundleTaskFactorySet, executorService, configuration, supportBundleStatus);
SupportBundlePipelineInfoTask supportBundlePipelineInfoTask = new SupportBundlePipelineInfoTask(uuid, Collections.singletonList(namespaceId), application, null, uuidFile, remoteApplicationDetailFetcher, remoteProgramRunRecordsFetcher, remoteLogsFetcher, programType, workflowName, remoteMetricsSystemClient, supportBundleJob, 1, remoteProgramRunRecordFetcher);
supportBundlePipelineInfoTask.collect();
Set<SupportBundleTaskStatus> supportBundleTaskStatusList = supportBundleStatus.getTasks();
for (SupportBundleTaskStatus supportBundleTaskStatus : supportBundleTaskStatusList) {
if (!supportBundleTaskStatus.getName().endsWith("SupportBundleSystemLogTask") && !supportBundleTaskStatus.getName().endsWith("SupportBundlePipelineInfoTask")) {
Assert.assertEquals(CollectionState.FINISHED, supportBundleTaskStatus.getStatus());
}
}
File pipelineFolder = new File(uuidFile, AppWithWorkflow.NAME);
File[] pipelineFiles = pipelineFolder.listFiles((dir, name) -> !name.startsWith(".") && !dir.isHidden() && dir.isDirectory());
Assert.assertEquals(3, pipelineFiles.length);
File pipelineInfoFile = new File(pipelineFolder, AppWithWorkflow.NAME + ".json");
try (Reader reader = Files.newBufferedReader(pipelineInfoFile.toPath(), StandardCharsets.UTF_8)) {
ApplicationDetail pipelineInfo = GSON.fromJson(reader, ApplicationDetail.class);
Assert.assertEquals(AppWithWorkflow.NAME, pipelineInfo.getName());
Assert.assertEquals("-SNAPSHOT", pipelineInfo.getAppVersion());
Assert.assertEquals("Sample application", pipelineInfo.getDescription());
} catch (Exception e) {
LOG.error("Can not read pipelineInfo file ", e);
Assert.fail();
}
File runInfoFile = new File(pipelineFolder, runId + ".json");
try (Reader reader = Files.newBufferedReader(runInfoFile.toPath(), StandardCharsets.UTF_8)) {
JsonObject runInfo = GSON.fromJson(reader, JsonObject.class);
Assert.assertEquals("COMPLETED", runInfo.get("status").getAsString());
} catch (Exception e) {
LOG.error("Can not read status file ", e);
Assert.fail();
}
File runLogFile = new File(pipelineFolder, runId + SupportBundleFileNames.LOG_SUFFIX_NAME);
Assert.assertTrue(runLogFile.exists());
}
Aggregations