Search in sources :

Example 1 with AllProgramsApp

use of co.cask.cdap.AllProgramsApp in project cdap by caskdata.

the class DefaultStoreTest method testCheckDeletedProgramSpecs.

@Test
public void testCheckDeletedProgramSpecs() throws Exception {
    // 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> specsToBeVerified = Sets.newHashSet();
    specsToBeVerified.addAll(spec.getMapReduce().keySet());
    specsToBeVerified.addAll(spec.getWorkflows().keySet());
    specsToBeVerified.addAll(spec.getFlows().keySet());
    specsToBeVerified.addAll(spec.getServices().keySet());
    specsToBeVerified.addAll(spec.getWorkers().keySet());
    specsToBeVerified.addAll(spec.getSpark().keySet());
    // Verify if there are 6 program specs in AllProgramsApp
    Assert.assertEquals(7, specsToBeVerified.size());
    // Check the diff with the same app - re-deployment scenario where programs are not removed.
    List<ProgramSpecification> deletedSpecs = store.getDeletedProgramSpecifications(appId, spec);
    Assert.assertEquals(0, deletedSpecs.size());
    // Get the spec for app that contains no programs.
    spec = Specifications.from(new NoProgramsApp());
    // Get the deleted program specs by sending a spec with same name as AllProgramsApp but with no programs
    deletedSpecs = store.getDeletedProgramSpecifications(appId, spec);
    Assert.assertEquals(7, deletedSpecs.size());
    for (ProgramSpecification specification : deletedSpecs) {
        // Remove the spec that is verified, to check the count later.
        specsToBeVerified.remove(specification.getName());
    }
    // All the 6 specs should have been deleted.
    Assert.assertEquals(0, specsToBeVerified.size());
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ProgramSpecification(co.cask.cdap.api.ProgramSpecification) NoProgramsApp(co.cask.cdap.NoProgramsApp) AllProgramsApp(co.cask.cdap.AllProgramsApp) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 2 with AllProgramsApp

use of co.cask.cdap.AllProgramsApp in project cdap by caskdata.

the class DefaultStoreTest method testRunsLimit.

@Test
public void testRunsLimit() throws Exception {
    ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
    ApplicationId appId = new ApplicationId("testRunsLimit", spec.getName());
    store.addApplication(appId, spec);
    ProgramId flowProgramId = new ProgramId("testRunsLimit", spec.getName(), ProgramType.FLOW, "NoOpFlow");
    Assert.assertNotNull(store.getApplication(appId));
    long now = System.currentTimeMillis();
    ProgramRunId flowProgramRunId = flowProgramId.run(RunIds.generate());
    setStartAndRunning(flowProgramRunId, now - 3000);
    store.setStop(flowProgramRunId, now - 100, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
    setStartAndRunning(flowProgramId.run(RunIds.generate()), now - 2000);
    // even though there's two separate run records (one that's complete and one that's active), only one should be
    // returned by the query, because the limit parameter of 1 is being passed in.
    Map<ProgramRunId, RunRecordMeta> historymap = store.getRuns(flowProgramId, ProgramRunStatus.ALL, 0, Long.MAX_VALUE, 1);
    Assert.assertEquals(1, historymap.size());
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) AllProgramsApp(co.cask.cdap.AllProgramsApp) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) Test(org.junit.Test)

Example 3 with AllProgramsApp

use of co.cask.cdap.AllProgramsApp in project cdap by caskdata.

the class DefaultStoreTest method testRuntimeArgsDeletion.

@Test
public void testRuntimeArgsDeletion() throws Exception {
    ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
    ApplicationId appId = new ApplicationId("testDeleteRuntimeArgs", spec.getName());
    store.addApplication(appId, spec);
    Assert.assertNotNull(store.getApplication(appId));
    ProgramId flowProgramId = appId.flow("NoOpFlow");
    ProgramId mapreduceProgramId = appId.mr("NoOpMR");
    ProgramId workflowProgramId = appId.workflow("NoOpWorkflow");
    String flowRunId = RunIds.generate().getId();
    String mapreduceRunId = RunIds.generate().getId();
    String workflowRunId = RunIds.generate().getId();
    ProgramRunId flowProgramRunId = flowProgramId.run(flowRunId);
    ProgramRunId mapreduceProgramRunId = mapreduceProgramId.run(mapreduceRunId);
    ProgramRunId workflowProgramRunId = workflowProgramId.run(workflowRunId);
    long nowSecs = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
    setStartAndRunning(flowProgramId.run(flowRunId), nowSecs, ImmutableMap.of("model", "click"), null);
    setStartAndRunning(mapreduceProgramId.run(mapreduceRunId), nowSecs, ImmutableMap.of("path", "/data"), null);
    setStartAndRunning(workflowProgramId.run(workflowRunId), nowSecs, ImmutableMap.of("whitelist", "cask"), null);
    Map<String, String> args = store.getRuntimeArguments(flowProgramRunId);
    Assert.assertEquals(1, args.size());
    Assert.assertEquals("click", args.get("model"));
    args = store.getRuntimeArguments(mapreduceProgramRunId);
    Assert.assertEquals(1, args.size());
    Assert.assertEquals("/data", args.get("path"));
    args = store.getRuntimeArguments(workflowProgramRunId);
    Assert.assertEquals(1, args.size());
    Assert.assertEquals("cask", args.get("whitelist"));
    // removing application
    store.removeApplication(appId);
    // Check if args are deleted.
    args = store.getRuntimeArguments(flowProgramRunId);
    Assert.assertEquals(0, args.size());
    args = store.getRuntimeArguments(mapreduceProgramRunId);
    Assert.assertEquals(0, args.size());
    args = store.getRuntimeArguments(workflowProgramRunId);
    Assert.assertEquals(0, args.size());
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) AllProgramsApp(co.cask.cdap.AllProgramsApp) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) Test(org.junit.Test)

Example 4 with AllProgramsApp

use of co.cask.cdap.AllProgramsApp in project cdap by caskdata.

the class DefaultStoreTest method testCheckDeletedWorkflow.

@Test
public void testCheckDeletedWorkflow() throws Exception {
    // 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 FlowMapReduceApp());
    // 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(co.cask.cdap.api.app.ApplicationSpecification) ProgramSpecification(co.cask.cdap.api.ProgramSpecification) FlowMapReduceApp(co.cask.cdap.FlowMapReduceApp) AllProgramsApp(co.cask.cdap.AllProgramsApp) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 5 with AllProgramsApp

use of co.cask.cdap.AllProgramsApp in project cdap by caskdata.

the class DefaultStoreTest method testHistoryDeletion.

@Test
public void testHistoryDeletion() throws Exception {
    // 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 WordCountApp());
    ApplicationId appId2 = namespaceId.app(spec.getName());
    store.addApplication(appId2, spec);
    ProgramId flowProgramId1 = appId1.flow("NoOpFlow");
    ProgramId mapreduceProgramId1 = appId1.mr("NoOpMR");
    ProgramId workflowProgramId1 = appId1.workflow("NoOpWorkflow");
    ProgramId flowProgramId2 = appId2.flow("WordCountFlow");
    Assert.assertNotNull(store.getApplication(appId1));
    Assert.assertNotNull(store.getApplication(appId2));
    long now = System.currentTimeMillis();
    ProgramRunId flowProgramRunId1 = flowProgramId1.run(RunIds.generate());
    setStartAndRunning(flowProgramRunId1, now - 1000);
    store.setStop(flowProgramRunId1, now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
    ProgramRunId mapreduceProgramRunId1 = mapreduceProgramId1.run(RunIds.generate());
    setStartAndRunning(mapreduceProgramRunId1, now - 1000);
    store.setStop(mapreduceProgramRunId1, now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
    RunId runId = RunIds.generate(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(1000));
    setStartAndRunning(workflowProgramId1.run(runId.getId()), now - 1000);
    store.setStop(workflowProgramId1.run(runId.getId()), now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
    ProgramRunId flowProgramRunId2 = flowProgramId2.run(RunIds.generate());
    setStartAndRunning(flowProgramRunId2, now - 1000);
    store.setStop(flowProgramRunId2, now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
    verifyRunHistory(flowProgramId1, 1);
    verifyRunHistory(mapreduceProgramId1, 1);
    verifyRunHistory(workflowProgramId1, 1);
    verifyRunHistory(flowProgramId2, 1);
    // removing application
    store.removeApplication(appId1);
    Assert.assertNull(store.getApplication(appId1));
    Assert.assertNotNull(store.getApplication(appId2));
    verifyRunHistory(flowProgramId1, 0);
    verifyRunHistory(mapreduceProgramId1, 0);
    verifyRunHistory(workflowProgramId1, 0);
    // Check to see if the flow history of second app is not deleted
    verifyRunHistory(flowProgramId2, 1);
    // remove all
    store.removeAll(namespaceId);
    verifyRunHistory(flowProgramId2, 0);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) WordCountApp(co.cask.cdap.WordCountApp) AllProgramsApp(co.cask.cdap.AllProgramsApp) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) RunId(org.apache.twill.api.RunId) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) Test(org.junit.Test)

Aggregations

AllProgramsApp (co.cask.cdap.AllProgramsApp)5 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)5 ApplicationId (co.cask.cdap.proto.id.ApplicationId)5 Test (org.junit.Test)5 ProgramId (co.cask.cdap.proto.id.ProgramId)3 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)3 ProgramSpecification (co.cask.cdap.api.ProgramSpecification)2 FlowMapReduceApp (co.cask.cdap.FlowMapReduceApp)1 NoProgramsApp (co.cask.cdap.NoProgramsApp)1 WordCountApp (co.cask.cdap.WordCountApp)1 NamespaceId (co.cask.cdap.proto.id.NamespaceId)1 RunId (org.apache.twill.api.RunId)1