Search in sources :

Example 1 with WorkflowNode

use of co.cask.cdap.api.workflow.WorkflowNode 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, 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);
}
Also used : DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) JsonObject(com.google.gson.JsonObject) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) WorkflowNode(co.cask.cdap.api.workflow.WorkflowNode)

Example 2 with WorkflowNode

use of co.cask.cdap.api.workflow.WorkflowNode 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(co.cask.cdap.api.workflow.WorkflowNodeType) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) WorkflowNode(co.cask.cdap.api.workflow.WorkflowNode) HashSet(java.util.HashSet)

Example 3 with WorkflowNode

use of co.cask.cdap.api.workflow.WorkflowNode in project cdap by caskdata.

the class ApplicationVerificationStage method verifyWorkflowNodeList.

private void verifyWorkflowNodeList(ApplicationSpecification appSpec, WorkflowSpecification workflowSpec, List<WorkflowNode> nodeList, Set<String> existingNodeNames) {
    for (WorkflowNode n : nodeList) {
        if (existingNodeNames.contains(n.getNodeId())) {
            throw new RuntimeException(String.format("Node '%s' already exists in workflow '%s'.", n.getNodeId(), workflowSpec.getName()));
        }
        existingNodeNames.add(n.getNodeId());
        verifyWorkflowNode(appSpec, workflowSpec, n, existingNodeNames);
    }
}
Also used : WorkflowNode(co.cask.cdap.api.workflow.WorkflowNode)

Example 4 with WorkflowNode

use of co.cask.cdap.api.workflow.WorkflowNode in project cdap by caskdata.

the class WorkflowVerificationTest method verifyWorkflowWithLocalDatasetSpecification.

private void verifyWorkflowWithLocalDatasetSpecification(ApplicationSpecification appSpec) {
    WorkflowSpecification spec = appSpec.getWorkflows().get("WorkflowWithLocalDatasets");
    List<WorkflowNode> nodes = spec.getNodes();
    Assert.assertTrue(nodes.size() == 2);
    WorkflowNode node = nodes.get(0);
    Assert.assertTrue(node.getType() == WorkflowNodeType.ACTION);
    WorkflowActionNode actionNode = (WorkflowActionNode) node;
    Assert.assertTrue(actionNode.getProgram().equals(new ScheduleProgramInfo(SchedulableProgramType.MAPREDUCE, "MR1")));
    node = nodes.get(1);
    Assert.assertTrue(node.getType() == WorkflowNodeType.ACTION);
    actionNode = (WorkflowActionNode) node;
    Assert.assertTrue(actionNode.getProgram().equals(new ScheduleProgramInfo(SchedulableProgramType.SPARK, "SP1")));
    Map<String, DatasetCreationSpec> localDatasetSpecs = spec.getLocalDatasetSpecs();
    Assert.assertEquals(5, localDatasetSpecs.size());
    DatasetCreationSpec datasetCreationSpec = localDatasetSpecs.get("mytable");
    Assert.assertEquals(Table.class.getName(), datasetCreationSpec.getTypeName());
    Assert.assertEquals(0, datasetCreationSpec.getProperties().getProperties().size());
    datasetCreationSpec = localDatasetSpecs.get("myfile");
    Assert.assertEquals(FileSet.class.getName(), datasetCreationSpec.getTypeName());
    Assert.assertEquals(0, datasetCreationSpec.getProperties().getProperties().size());
    datasetCreationSpec = localDatasetSpecs.get("myfile_with_properties");
    Assert.assertEquals(FileSet.class.getName(), datasetCreationSpec.getTypeName());
    Assert.assertEquals("prop_value", datasetCreationSpec.getProperties().getProperties().get("prop_key"));
    datasetCreationSpec = localDatasetSpecs.get("mytablefromtype");
    Assert.assertEquals(Table.class.getName(), datasetCreationSpec.getTypeName());
    Assert.assertEquals(0, datasetCreationSpec.getProperties().getProperties().size());
    datasetCreationSpec = localDatasetSpecs.get("myfilefromtype");
    Assert.assertEquals(FileSet.class.getName(), datasetCreationSpec.getTypeName());
    Assert.assertEquals("another_prop_value", datasetCreationSpec.getProperties().getProperties().get("another_prop_key"));
    // Check if the application specification has correct modules
    Map<String, String> datasetModules = appSpec.getDatasetModules();
    Assert.assertEquals(2, datasetModules.size());
    Assert.assertTrue(datasetModules.containsKey(FileSet.class.getName()));
    Assert.assertTrue(datasetModules.containsKey(Table.class.getName()));
}
Also used : Table(co.cask.cdap.api.dataset.table.Table) FileSet(co.cask.cdap.api.dataset.lib.FileSet) WorkflowActionNode(co.cask.cdap.api.workflow.WorkflowActionNode) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) ScheduleProgramInfo(co.cask.cdap.api.workflow.ScheduleProgramInfo) WorkflowNode(co.cask.cdap.api.workflow.WorkflowNode)

Example 5 with WorkflowNode

use of co.cask.cdap.api.workflow.WorkflowNode in project cdap by caskdata.

the class WorkflowDriver method executeAll.

private void executeAll(Iterator<WorkflowNode> iterator, ApplicationSpecification appSpec, InstantiatorFactory instantiator, ClassLoader classLoader, WorkflowToken token) {
    while (iterator.hasNext() && runningThread != null) {
        try {
            blockIfSuspended();
            WorkflowNode node = iterator.next();
            executeNode(appSpec, node, instantiator, classLoader, token);
        } catch (Throwable t) {
            Throwable rootCause = Throwables.getRootCause(t);
            if (rootCause instanceof InterruptedException) {
                LOG.debug("Workflow '{}' with run id '{}' aborted", workflowSpec.getName(), workflowRunId.getRun());
                basicWorkflowContext.setState(new ProgramState(ProgramStatus.KILLED, rootCause.getMessage()));
                break;
            }
            basicWorkflowContext.setState(new ProgramState(ProgramStatus.FAILED, rootCause.getMessage()));
            throw Throwables.propagate(rootCause);
        }
    }
}
Also used : BasicThrowable(co.cask.cdap.proto.BasicThrowable) ProgramState(co.cask.cdap.api.ProgramState) WorkflowNode(co.cask.cdap.api.workflow.WorkflowNode)

Aggregations

WorkflowNode (co.cask.cdap.api.workflow.WorkflowNode)15 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)7 WorkflowActionNode (co.cask.cdap.api.workflow.WorkflowActionNode)5 ScheduleProgramInfo (co.cask.cdap.api.workflow.ScheduleProgramInfo)4 WorkflowForkNode (co.cask.cdap.api.workflow.WorkflowForkNode)4 Map (java.util.Map)3 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)2 SchedulableProgramType (co.cask.cdap.api.schedule.SchedulableProgramType)2 WorkflowConditionNode (co.cask.cdap.api.workflow.WorkflowConditionNode)2 DatasetCreationSpec (co.cask.cdap.internal.dataset.DatasetCreationSpec)2 ProgramType (co.cask.cdap.proto.ProgramType)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ProgramState (co.cask.cdap.api.ProgramState)1 Resources (co.cask.cdap.api.Resources)1 TransactionControl (co.cask.cdap.api.annotation.TransactionControl)1 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)1 FileSet (co.cask.cdap.api.dataset.lib.FileSet)1 Table (co.cask.cdap.api.dataset.table.Table)1 AbstractCondition (co.cask.cdap.api.workflow.AbstractCondition)1 Condition (co.cask.cdap.api.workflow.Condition)1