Search in sources :

Example 11 with WorkflowSpecification

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));
}
Also used : WorkflowAppWithFork(io.cdap.cdap.WorkflowAppWithFork) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) StageContext(io.cdap.cdap.internal.pipeline.StageContext) Read(io.cdap.cdap.spi.metadata.Read) Sets(com.google.common.collect.Sets) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 12 with WorkflowSpecification

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);
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) StageContext(io.cdap.cdap.internal.pipeline.StageContext) Requirements(io.cdap.cdap.api.plugin.Requirements) Read(io.cdap.cdap.spi.metadata.Read) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) CapabilityAppWithWorkflow(io.cdap.cdap.CapabilityAppWithWorkflow) Test(org.junit.Test)

Example 13 with WorkflowSpecification

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;
}
Also used : WorkflowNodeType(io.cdap.cdap.api.workflow.WorkflowNodeType) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) WorkflowNode(io.cdap.cdap.api.workflow.WorkflowNode) HashSet(java.util.HashSet)

Example 14 with WorkflowSpecification

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);
}
Also used : DatasetCreationSpec(io.cdap.cdap.internal.dataset.DatasetCreationSpec) JsonObject(com.google.gson.JsonObject) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) WorkflowNode(io.cdap.cdap.api.workflow.WorkflowNode) Plugin(io.cdap.cdap.api.plugin.Plugin)

Example 15 with WorkflowSpecification

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);
}
Also used : DefaultWorkflowConfigurer(io.cdap.cdap.internal.app.workflow.DefaultWorkflowConfigurer) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification)

Aggregations

WorkflowSpecification (io.cdap.cdap.api.workflow.WorkflowSpecification)50 WorkflowNode (io.cdap.cdap.api.workflow.WorkflowNode)24 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)18 WorkflowActionNode (io.cdap.cdap.api.workflow.WorkflowActionNode)18 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)18 ProgramId (io.cdap.cdap.proto.id.ProgramId)18 ScheduleProgramInfo (io.cdap.cdap.api.workflow.ScheduleProgramInfo)14 Map (java.util.Map)14 ProgramType (io.cdap.cdap.proto.ProgramType)12 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)12 DatasetCreationSpec (io.cdap.cdap.internal.dataset.DatasetCreationSpec)10 DatasetId (io.cdap.cdap.proto.id.DatasetId)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 ImmutableMap (com.google.common.collect.ImmutableMap)6 InstanceNotFoundException (io.cdap.cdap.api.dataset.InstanceNotFoundException)6 WorkflowForkNode (io.cdap.cdap.api.workflow.WorkflowForkNode)6 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)6 NotFoundException (io.cdap.cdap.common.NotFoundException)6 Path (javax.ws.rs.Path)6