use of io.cdap.cdap.internal.pipeline.StageContext in project cdap by caskdata.
the class SystemMetadataWriterStageTest method testWorkflowTags.
@Test
public void testWorkflowTags() throws Exception {
String appName = WorkflowAppWithFork.class.getSimpleName();
ApplicationId appId = NamespaceId.DEFAULT.app(appName);
ApplicationClass applicationClass = new ApplicationClass(WorkflowAppWithFork.class.getName(), appName, null);
String workflowName = WorkflowAppWithFork.WorkflowWithFork.class.getSimpleName();
ArtifactId artifactId = NamespaceId.DEFAULT.artifact(appId.getApplication(), "1.0");
ApplicationWithPrograms appWithPrograms = createAppWithWorkflow(artifactId, appId, workflowName, applicationClass);
WorkflowSpecification workflowSpec = appWithPrograms.getSpecification().getWorkflows().get(workflowName);
MetadataWriterStage systemMetadataWriterStage = new MetadataWriterStage(metadataServiceClient);
StageContext stageContext = new StageContext(Object.class);
systemMetadataWriterStage.process(stageContext);
systemMetadataWriterStage.process(appWithPrograms);
Assert.assertEquals(false, metadataStorage.read(new Read(appId.workflow(workflowName).toMetadataEntity(), MetadataScope.SYSTEM, MetadataKind.TAG)).isEmpty());
Set<String> workflowSystemTags = metadataStorage.read(new Read(appId.workflow(workflowName).toMetadataEntity())).getTags(MetadataScope.SYSTEM);
Sets.SetView<String> intersection = Sets.intersection(workflowSystemTags, getWorkflowForkNodes(workflowSpec));
Assert.assertTrue("Workflows should not be tagged with fork node names, but found the following fork nodes " + "in the workflow's system tags: " + intersection, intersection.isEmpty());
Assert.assertEquals(false, metadataStorage.read(new Read(appId.toMetadataEntity(), MetadataScope.SYSTEM, MetadataKind.PROPERTY)).isEmpty());
Map<String, String> metadataProperties = metadataStorage.read(new Read(appId.toMetadataEntity())).getProperties(MetadataScope.SYSTEM);
Assert.assertEquals(WorkflowAppWithFork.SCHED_NAME + ":testDescription", metadataProperties.get("schedule:" + WorkflowAppWithFork.SCHED_NAME));
}
use of io.cdap.cdap.internal.pipeline.StageContext in project cdap by caskdata.
the class SystemMetadataWriterStageTest method testCapabilityTags.
@Test
public void testCapabilityTags() throws Exception {
String appName = CapabilityAppWithWorkflow.class.getSimpleName();
ApplicationId appId = NamespaceId.DEFAULT.app(appName);
String[] capabilityTestNames = { "cdc", "healthcare" };
Requirements requirements = new Requirements(Collections.emptySet(), Stream.of(capabilityTestNames).collect(Collectors.toSet()));
ApplicationClass applicationClass = new ApplicationClass(CapabilityAppWithWorkflow.class.getName(), appName, null, requirements);
String workflowName = CapabilityAppWithWorkflow.SampleWorkflow.class.getSimpleName();
ArtifactId artifactId = NamespaceId.DEFAULT.artifact(appId.getApplication(), "1.0");
ApplicationWithPrograms appWithPrograms = createAppWithWorkflow(artifactId, appId, workflowName, new CapabilityAppWithWorkflow(), applicationClass);
WorkflowSpecification workflowSpec = appWithPrograms.getSpecification().getWorkflows().get(workflowName);
MetadataWriterStage systemMetadataWriterStage = new MetadataWriterStage(metadataServiceClient);
StageContext stageContext = new StageContext(Object.class);
systemMetadataWriterStage.process(stageContext);
systemMetadataWriterStage.process(appWithPrograms);
Assert.assertEquals(false, metadataStorage.read(new Read(appId.toMetadataEntity(), MetadataScope.SYSTEM, MetadataKind.PROPERTY)).isEmpty());
// Test that all test capabilities are present in the metadata
Map<String, String> metadataProperties = metadataStorage.read(new Read(appId.toMetadataEntity())).getProperties(MetadataScope.SYSTEM);
Set<String> capabilityNames = Arrays.stream(metadataProperties.get(AppSystemMetadataWriter.CAPABILITY_TAG).split(AppSystemMetadataWriter.CAPABILITY_DELIMITER)).collect(Collectors.toSet());
Assert.assertEquals(Arrays.stream(capabilityTestNames).collect(Collectors.toSet()), capabilityNames);
}
use of io.cdap.cdap.internal.pipeline.StageContext in project cdap by caskdata.
the class ProgramGenerationStageTest method testProgramGeneration.
@Test
public void testProgramGeneration() throws Exception {
cConf.set(Constants.AppFabric.OUTPUT_DIR, "programs");
LocationFactory lf = new LocalLocationFactory(TEMP_FOLDER.newFolder());
// have to do this since we are not going through the route of create namespace -> deploy application
// in real scenarios, the namespace directory would already be created
Location namespaceLocation = lf.create(DefaultId.APPLICATION.getNamespace());
Locations.mkdirsIfNotExists(namespaceLocation);
LocationFactory jarLf = new LocalLocationFactory(TEMP_FOLDER.newFolder());
Location appArchive = AppJarHelper.createDeploymentJar(jarLf, AllProgramsApp.class);
ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create();
ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
ApplicationClass applicationClass = new ApplicationClass(AllProgramsApp.class.getName(), "", null);
ProgramGenerationStage pgmStage = new ProgramGenerationStage();
// Can do better here - fixed right now to run the test.
pgmStage.process(new StageContext(Object.class));
pgmStage.process(new ApplicationDeployable(NamespaceId.DEFAULT.artifact("AllProgramApp", "1.0"), appArchive, DefaultId.APPLICATION, newSpec, null, ApplicationDeployScope.USER, applicationClass));
Assert.assertTrue(true);
}
Aggregations