Search in sources :

Example 11 with ApplicationSpecification

use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class DefaultStoreTest method testLoadingProgram.

@Test
public void testLoadingProgram() throws Exception {
    ApplicationSpecification appSpec = Specifications.from(new FooApp());
    ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
    store.addApplication(appId, appSpec);
    ProgramDescriptor descriptor = store.loadProgram(appId.mr("mrJob1"));
    Assert.assertNotNull(descriptor);
    MapReduceSpecification mrSpec = descriptor.getSpecification();
    Assert.assertEquals("mrJob1", mrSpec.getName());
    Assert.assertEquals(FooMapReduceJob.class.getName(), mrSpec.getClassName());
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) MapReduceSpecification(io.cdap.cdap.api.mapreduce.MapReduceSpecification) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 12 with ApplicationSpecification

use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class DefaultStoreTest method testProgramRunCount.

@Test
public void testProgramRunCount() {
    ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
    ApplicationId appId = NamespaceId.DEFAULT.app(spec.getName());
    ArtifactId testArtifact = NamespaceId.DEFAULT.artifact("testArtifact", "1.0").toApiArtifactId();
    ProgramId workflowId = appId.workflow(AllProgramsApp.NoOpWorkflow.NAME);
    ProgramId serviceId = appId.service(AllProgramsApp.NoOpService.NAME);
    ProgramId nonExistingAppProgramId = NamespaceId.DEFAULT.app("nonExisting").workflow("test");
    ProgramId nonExistingProgramId = appId.workflow("nonExisting");
    // add the application
    store.addApplication(appId, spec);
    // add some run records to workflow and service
    for (int i = 0; i < 5; i++) {
        setStart(workflowId.run(RunIds.generate()), Collections.emptyMap(), Collections.emptyMap(), testArtifact);
        setStart(serviceId.run(RunIds.generate()), Collections.emptyMap(), Collections.emptyMap(), testArtifact);
    }
    List<RunCountResult> result = store.getProgramRunCounts(ImmutableList.of(workflowId, serviceId, nonExistingAppProgramId, nonExistingProgramId));
    // compare the result
    Assert.assertEquals(4, result.size());
    for (RunCountResult runCountResult : result) {
        ProgramId programId = runCountResult.getProgramId();
        Long count = runCountResult.getCount();
        if (programId.equals(nonExistingAppProgramId) || programId.equals(nonExistingProgramId)) {
            Assert.assertNull(count);
            Assert.assertTrue(runCountResult.getException() instanceof NotFoundException);
        } else {
            Assert.assertNotNull(count);
            Assert.assertEquals(5L, count.longValue());
        }
    }
    // remove the app should remove all run count
    store.removeApplication(appId);
    for (RunCountResult runCountResult : store.getProgramRunCounts(ImmutableList.of(workflowId, serviceId))) {
        Assert.assertNull(runCountResult.getCount());
        Assert.assertTrue(runCountResult.getException() instanceof NotFoundException);
    }
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) RunCountResult(io.cdap.cdap.proto.RunCountResult) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) NotFoundException(io.cdap.cdap.common.NotFoundException) AllProgramsApp(io.cdap.cdap.AllProgramsApp) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Test(org.junit.Test)

Example 13 with ApplicationSpecification

use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class DefaultStoreTest method testCheckDeletedWorkflow.

@Test
public void testCheckDeletedWorkflow() {
    // Deploy program with all types of programs.
    ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
    ApplicationId appId = NamespaceId.DEFAULT.app(spec.getName());
    store.addApplication(appId, spec);
    Set<String> specsToBeDeleted = Sets.newHashSet();
    specsToBeDeleted.addAll(spec.getWorkflows().keySet());
    Assert.assertEquals(1, specsToBeDeleted.size());
    // Get the spec for app that contains only flow and mapreduce - removing workflows.
    spec = Specifications.from(new DefaultStoreTestApp());
    // Get the deleted program specs by sending a spec with same name as AllProgramsApp but with no programs
    List<ProgramSpecification> deletedSpecs = store.getDeletedProgramSpecifications(appId, spec);
    Assert.assertEquals(2, deletedSpecs.size());
    for (ProgramSpecification specification : deletedSpecs) {
        // Remove the spec that is verified, to check the count later.
        specsToBeDeleted.remove(specification.getName());
    }
    // 2 specs should have been deleted and 0 should be remaining.
    Assert.assertEquals(0, specsToBeDeleted.size());
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) DefaultStoreTestApp(io.cdap.cdap.DefaultStoreTestApp) ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) AllProgramsApp(io.cdap.cdap.AllProgramsApp) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 14 with ApplicationSpecification

use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class DefaultStoreTest method testScanApplicationsWithNamespace.

public void testScanApplicationsWithNamespace(Store store) {
    ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
    int count = 100;
    for (int i = 0; i < count / 2; i++) {
        String appName = "test" + (2 * i);
        store.addApplication(new ApplicationId(NamespaceId.DEFAULT.getNamespace(), appName), appSpec);
        appName = "test" + (2 * i + 1);
        store.addApplication(new ApplicationId(NamespaceId.CDAP.getNamespace(), appName), appSpec);
    }
    List<ApplicationId> apps = new ArrayList<ApplicationId>();
    ScanApplicationsRequest request = ScanApplicationsRequest.builder().setNamespaceId(NamespaceId.CDAP).build();
    store.scanApplications(request, 20, (appId, spec) -> {
        apps.add(appId);
    });
    Assert.assertEquals(count / 2, apps.size());
    // Reverse
    List<ApplicationId> reverseApps = new ArrayList<>();
    request = ScanApplicationsRequest.builder().setNamespaceId(NamespaceId.CDAP).setSortOrder(SortOrder.DESC).build();
    store.scanApplications(request, 20, (appId, spec) -> reverseApps.add(appId));
    Assert.assertEquals(Lists.reverse(apps), reverseApps);
    // Second page
    int firstPageSize = 10;
    List<ApplicationId> restartApps = new ArrayList<>();
    request = ScanApplicationsRequest.builder().setNamespaceId(NamespaceId.CDAP).setScanFrom(apps.get(firstPageSize - 1)).build();
    store.scanApplications(request, 20, (appId, spec) -> restartApps.add(appId));
    Assert.assertEquals(apps.subList(firstPageSize, apps.size()), restartApps);
}
Also used : ScanApplicationsRequest(io.cdap.cdap.app.store.ScanApplicationsRequest) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ArrayList(java.util.ArrayList) AllProgramsApp(io.cdap.cdap.AllProgramsApp) ApplicationId(io.cdap.cdap.proto.id.ApplicationId)

Example 15 with ApplicationSpecification

use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class DefaultStoreTest method testServiceDeletion.

@Test
public void testServiceDeletion() {
    // Store the application specification
    AbstractApplication app = new AppWithServices();
    ApplicationSpecification appSpec = Specifications.from(app);
    ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
    store.addApplication(appId, appSpec);
    AbstractApplication newApp = new AppWithNoServices();
    // get the delete program specs after deploying AppWithNoServices
    List<ProgramSpecification> programSpecs = store.getDeletedProgramSpecifications(appId, Specifications.from(newApp));
    // verify the result.
    Assert.assertEquals(1, programSpecs.size());
    Assert.assertEquals("NoOpService", programSpecs.get(0).getName());
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) AppWithServices(io.cdap.cdap.AppWithServices) AbstractApplication(io.cdap.cdap.api.app.AbstractApplication) AppWithNoServices(io.cdap.cdap.AppWithNoServices) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Aggregations

ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)228 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)114 ProgramId (io.cdap.cdap.proto.id.ProgramId)90 Test (org.junit.Test)90 AllProgramsApp (io.cdap.cdap.AllProgramsApp)54 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)52 ProgramType (io.cdap.cdap.proto.ProgramType)50 ArrayList (java.util.ArrayList)42 HashMap (java.util.HashMap)40 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)38 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)32 NotFoundException (io.cdap.cdap.common.NotFoundException)30 ProgramDescriptor (io.cdap.cdap.app.program.ProgramDescriptor)28 Map (java.util.Map)28 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)24 IOException (java.io.IOException)24 HashSet (java.util.HashSet)22 RunId (org.apache.twill.api.RunId)22 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)20 DefaultApplicationSpecification (io.cdap.cdap.internal.app.DefaultApplicationSpecification)20