Search in sources :

Example 31 with ApplicationDetail

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());
}
Also used : ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 32 with ApplicationDetail

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);
        }
    }
}
Also used : FileWriter(java.io.FileWriter) RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) NotFoundException(io.cdap.cdap.common.NotFoundException) ProgramId(io.cdap.cdap.proto.id.ProgramId) RunRecord(io.cdap.cdap.proto.RunRecord) ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) File(java.io.File)

Example 33 with ApplicationDetail

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);
}
Also used : ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) ArrayList(java.util.ArrayList) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 34 with ApplicationDetail

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);
}
Also used : ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) ArrayList(java.util.ArrayList) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 35 with ApplicationDetail

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()));
        }
    }
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) ProgramRecord(io.cdap.cdap.proto.ProgramRecord) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) AllProgramsApp(io.cdap.cdap.AllProgramsApp) 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