Search in sources :

Example 1 with AppWithServices

use of io.cdap.cdap.AppWithServices 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)

Example 2 with AppWithServices

use of io.cdap.cdap.AppWithServices in project cdap by caskdata.

the class DefaultStoreTest method testHistoryDeletion.

@Test
public void testHistoryDeletion() {
    // Deploy two apps, write some history for programs
    // Remove application using accountId, AppId and verify
    // Remove all from accountId and verify
    ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
    NamespaceId namespaceId = new NamespaceId("testDeleteAll");
    ApplicationId appId1 = namespaceId.app(spec.getName());
    store.addApplication(appId1, spec);
    spec = Specifications.from(new AppWithServices());
    ApplicationId appId2 = namespaceId.app(spec.getName());
    store.addApplication(appId2, spec);
    ProgramId mapreduceProgramId1 = appId1.mr("NoOpMR");
    ProgramId workflowProgramId1 = appId1.workflow("NoOpWorkflow");
    ArtifactId artifactId = appId1.getNamespaceId().artifact("testArtifact", "1.0").toApiArtifactId();
    ProgramId serviceId = appId2.service(AppWithServices.SERVICE_NAME);
    Assert.assertNotNull(store.getApplication(appId1));
    Assert.assertNotNull(store.getApplication(appId2));
    long now = System.currentTimeMillis();
    ProgramRunId mapreduceProgramRunId1 = mapreduceProgramId1.run(RunIds.generate(now - 1000));
    setStartAndRunning(mapreduceProgramRunId1, artifactId);
    store.setStop(mapreduceProgramRunId1, now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
    RunId runId = RunIds.generate(now - 1000);
    setStartAndRunning(workflowProgramId1.run(runId.getId()), artifactId);
    store.setStop(workflowProgramId1.run(runId.getId()), now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
    ProgramRunId serviceRunId = serviceId.run(RunIds.generate(now - 1000));
    setStartAndRunning(serviceRunId, artifactId);
    store.setStop(serviceRunId, now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
    verifyRunHistory(mapreduceProgramId1, 1);
    verifyRunHistory(workflowProgramId1, 1);
    verifyRunHistory(serviceId, 1);
    // removing application
    store.removeApplication(appId1);
    Assert.assertNull(store.getApplication(appId1));
    Assert.assertNotNull(store.getApplication(appId2));
    verifyRunHistory(mapreduceProgramId1, 0);
    verifyRunHistory(workflowProgramId1, 0);
    // Check to see if the history of second app is not deleted
    verifyRunHistory(serviceId, 1);
    // remove all
    store.removeAll(namespaceId);
    verifyRunHistory(serviceId, 0);
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) AppWithServices(io.cdap.cdap.AppWithServices) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) AllProgramsApp(io.cdap.cdap.AllProgramsApp) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) RunId(org.apache.twill.api.RunId) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Test(org.junit.Test)

Example 3 with AppWithServices

use of io.cdap.cdap.AppWithServices in project cdap by caskdata.

the class DefaultStoreTest method testServiceInstances.

@Test
public void testServiceInstances() {
    ApplicationSpecification appSpec = Specifications.from(new AppWithServices());
    ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
    store.addApplication(appId, appSpec);
    // Test setting of service instances
    ProgramId programId = appId.program(ProgramType.SERVICE, "NoOpService");
    int count = store.getServiceInstances(programId);
    Assert.assertEquals(1, count);
    store.setServiceInstances(programId, 10);
    count = store.getServiceInstances(programId);
    Assert.assertEquals(10, count);
    ApplicationSpecification newSpec = store.getApplication(appId);
    Assert.assertNotNull(newSpec);
    Map<String, ServiceSpecification> services = newSpec.getServices();
    Assert.assertEquals(1, services.size());
    ServiceSpecification serviceSpec = services.get("NoOpService");
    Assert.assertEquals(10, serviceSpec.getInstances());
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification) AppWithServices(io.cdap.cdap.AppWithServices) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Test(org.junit.Test)

Aggregations

AppWithServices (io.cdap.cdap.AppWithServices)3 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)3 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)3 Test (org.junit.Test)3 ProgramId (io.cdap.cdap.proto.id.ProgramId)2 AllProgramsApp (io.cdap.cdap.AllProgramsApp)1 AppWithNoServices (io.cdap.cdap.AppWithNoServices)1 ProgramSpecification (io.cdap.cdap.api.ProgramSpecification)1 AbstractApplication (io.cdap.cdap.api.app.AbstractApplication)1 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)1 ServiceSpecification (io.cdap.cdap.api.service.ServiceSpecification)1 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)1 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)1 RunId (org.apache.twill.api.RunId)1