use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class DefaultStoreTest method testAddApplication.
@Test
public void testAddApplication() throws Exception {
ApplicationSpecification spec = Specifications.from(new WordCountApp());
ApplicationId appId = new ApplicationId("account1", "application1");
store.addApplication(appId, spec);
ApplicationSpecification stored = store.getApplication(appId);
assertWordCountAppSpecAndInMetadataStore(stored);
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class DefaultStoreTest method testSetFlowletInstances.
@Test
public void testSetFlowletInstances() throws Exception {
ApplicationSpecification spec = Specifications.from(new WordCountApp());
int initialInstances = spec.getFlows().get("WordCountFlow").getFlowlets().get("StreamSource").getInstances();
ApplicationId appId = NamespaceId.DEFAULT.app(spec.getName());
store.addApplication(appId, spec);
ProgramId programId = appId.flow("WordCountFlow");
store.setFlowletInstances(programId, "StreamSource", initialInstances + 5);
// checking that app spec in store was adjusted
ApplicationSpecification adjustedSpec = store.getApplication(appId);
Assert.assertNotNull(adjustedSpec);
Assert.assertEquals(initialInstances + 5, adjustedSpec.getFlows().get("WordCountFlow").getFlowlets().get("StreamSource").getInstances());
// checking that program spec in program jar was adjusted
ProgramDescriptor descriptor = store.loadProgram(programId);
Assert.assertNotNull(descriptor);
Assert.assertEquals(initialInstances + 5, descriptor.getApplicationSpecification().getFlows().get("WordCountFlow").getFlowlets().get("StreamSource").getInstances());
}
use of co.cask.cdap.api.app.ApplicationSpecification 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());
}
use of co.cask.cdap.api.app.ApplicationSpecification 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());
}
use of co.cask.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 ToyApp());
ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
store.addApplication(appId, appSpec);
ProgramDescriptor descriptor = store.loadProgram(appId.flow("ToyFlow"));
Assert.assertNotNull(descriptor);
FlowSpecification flowSpec = descriptor.getSpecification();
Assert.assertEquals("ToyFlow", flowSpec.getName());
}
Aggregations