Search in sources :

Example 51 with ApplicationDetail

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())));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) Location(org.apache.twill.filesystem.Location) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) URL(java.net.URL) HttpResponse(io.cdap.common.http.HttpResponse) Test(org.junit.Test) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) LocationFactory(org.apache.twill.filesystem.LocationFactory) ProgramType(io.cdap.cdap.proto.ProgramType) HttpRequestConfig(io.cdap.common.http.HttpRequestConfig) AppJarHelper(io.cdap.cdap.common.test.AppJarHelper) Gson(com.google.gson.Gson) ContentProvider(io.cdap.common.ContentProvider) HttpRequests(io.cdap.common.http.HttpRequests) URI(java.net.URI) AllProgramsApp(io.cdap.cdap.AllProgramsApp) Assert(org.junit.Assert) HttpRequest(io.cdap.common.http.HttpRequest) InputStream(java.io.InputStream) ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) HttpResponse(io.cdap.common.http.HttpResponse) Gson(com.google.gson.Gson) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) HttpRequestConfig(io.cdap.common.http.HttpRequestConfig) AllProgramsApp(io.cdap.cdap.AllProgramsApp) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) URI(java.net.URI) URL(java.net.URL) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 52 with ApplicationDetail

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());
}
Also used : SupportBundleTaskStatus(io.cdap.cdap.support.status.SupportBundleTaskStatus) Reader(java.io.Reader) JsonObject(com.google.gson.JsonObject) SupportBundleConfiguration(io.cdap.cdap.support.status.SupportBundleConfiguration) ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) SupportBundlePipelineInfoTask(io.cdap.cdap.support.task.SupportBundlePipelineInfoTask) SupportBundleStatus(io.cdap.cdap.support.status.SupportBundleStatus) SupportBundleJob(io.cdap.cdap.support.job.SupportBundleJob) File(java.io.File) Test(org.junit.Test)

Aggregations

ApplicationDetail (io.cdap.cdap.proto.ApplicationDetail)52 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)30 Test (org.junit.Test)30 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)26 File (java.io.File)20 ArrayList (java.util.ArrayList)20 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)16 HttpResponse (io.cdap.common.http.HttpResponse)16 HashSet (java.util.HashSet)16 Gson (com.google.gson.Gson)14 Constants (io.cdap.cdap.common.conf.Constants)14 ProgramId (io.cdap.cdap.proto.id.ProgramId)14 HashMap (java.util.HashMap)14 List (java.util.List)14 Map (java.util.Map)14 Assert (org.junit.Assert)14 ImmutableMap (com.google.common.collect.ImmutableMap)12 ImmutableSet (com.google.common.collect.ImmutableSet)12 RunRecord (io.cdap.cdap.proto.RunRecord)12 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)12