use of io.cdap.cdap.api.workflow.WorkflowSpecification 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.api.workflow.WorkflowSpecification 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.api.workflow.WorkflowSpecification in project cdap by caskdata.
the class ProgramSystemMetadataWriter method getWorkflowNodes.
private Iterable<String> getWorkflowNodes() {
if (ProgramType.WORKFLOW != programId.getType()) {
return ImmutableSet.of();
}
Preconditions.checkArgument(programSpec instanceof WorkflowSpecification, "Expected programSpec %s to be of type WorkflowSpecification", programSpec);
WorkflowSpecification workflowSpec = (WorkflowSpecification) this.programSpec;
Set<String> workflowNodeNames = new HashSet<>();
for (Map.Entry<String, WorkflowNode> entry : workflowSpec.getNodeIdMap().entrySet()) {
WorkflowNode workflowNode = entry.getValue();
WorkflowNodeType type = workflowNode.getType();
// Fork nodes have integers as node ids. Ignore them in system metadata.
if (WorkflowNodeType.FORK == type) {
continue;
}
workflowNodeNames.add(entry.getKey());
}
return workflowNodeNames;
}
use of io.cdap.cdap.api.workflow.WorkflowSpecification in project cdap by caskdata.
the class WorkflowSpecificationCodec method deserialize.
@Override
public WorkflowSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObj = json.getAsJsonObject();
String className = jsonObj.get("className").getAsString();
String name = jsonObj.get("name").getAsString();
String description = jsonObj.get("description").getAsString();
Map<String, Plugin> plugins = deserializeMap(jsonObj.get("plugins"), context, Plugin.class);
Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class);
List<WorkflowNode> nodes = deserializeList(jsonObj.get("nodes"), context, WorkflowNode.class);
Map<String, DatasetCreationSpec> localDatasetSpec = deserializeMap(jsonObj.get("localDatasetSpecs"), context, DatasetCreationSpec.class);
return new WorkflowSpecification(className, name, description, properties, nodes, localDatasetSpec, plugins);
}
use of io.cdap.cdap.api.workflow.WorkflowSpecification in project cdap by cdapio.
the class DefaultAppConfigurer method addWorkflow.
@Override
public void addWorkflow(Workflow workflow) {
Preconditions.checkArgument(workflow != null, "Workflow cannot be null.");
DefaultWorkflowConfigurer configurer = new DefaultWorkflowConfigurer(workflow, this, deployNamespace, artifactId, pluginFinder, pluginInstantiator, runtimeInfo, getFeatureFlagsProvider());
workflow.configure(configurer);
WorkflowSpecification spec = configurer.createSpecification();
addDatasetsAndPlugins(configurer);
workflows.put(spec.getName(), spec);
}
Aggregations