Search in sources :

Example 1 with WorkflowNodeType

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

the class WorkflowNodeCodec method deserialize.

@Override
public WorkflowNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();
    WorkflowNodeType type = context.deserialize(jsonObj.get("nodeType"), WorkflowNodeType.class);
    switch(type) {
        case ACTION:
            return context.deserialize(json, WorkflowActionNode.class);
        case FORK:
            return context.deserialize(json, WorkflowForkNode.class);
        case CONDITION:
            return context.deserialize(json, WorkflowConditionNode.class);
    }
    return null;
}
Also used : WorkflowNodeType(co.cask.cdap.api.workflow.WorkflowNodeType) JsonObject(com.google.gson.JsonObject)

Example 2 with WorkflowNodeType

use of co.cask.cdap.api.workflow.WorkflowNodeType 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 WorkflowNodeType

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

the class WorkflowDriver method executeNode.

private void executeNode(ApplicationSpecification appSpec, WorkflowNode node, InstantiatorFactory instantiator, ClassLoader classLoader, WorkflowToken token) throws Exception {
    WorkflowNodeType nodeType = node.getType();
    ((BasicWorkflowToken) token).setCurrentNode(node.getNodeId());
    switch(nodeType) {
        case ACTION:
            WorkflowActionNode actionNode = (WorkflowActionNode) node;
            if (SchedulableProgramType.CUSTOM_ACTION == actionNode.getProgram().getProgramType()) {
                executeCustomAction(actionNode, instantiator, classLoader, token);
            } else {
                executeAction(actionNode, token);
            }
            break;
        case FORK:
            executeFork(appSpec, (WorkflowForkNode) node, instantiator, classLoader, token);
            break;
        case CONDITION:
            executeCondition(appSpec, (WorkflowConditionNode) node, instantiator, classLoader, token);
            break;
        default:
            break;
    }
}
Also used : WorkflowActionNode(co.cask.cdap.api.workflow.WorkflowActionNode) WorkflowNodeType(co.cask.cdap.api.workflow.WorkflowNodeType)

Example 4 with WorkflowNodeType

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

the class ApplicationVerificationStage method verifyWorkflowNode.

private void verifyWorkflowNode(ApplicationSpecification appSpec, WorkflowSpecification workflowSpec, WorkflowNode node, Set<String> existingNodeNames) {
    WorkflowNodeType nodeType = node.getType();
    // TODO CDAP-5640 Add check so that node id in the Workflow should not be same as name of the Workflow.
    if (node.getNodeId().equals(workflowSpec.getName())) {
        String msg = String.format("Node used in Workflow has same name as that of Workflow '%s'." + " This will conflict while getting the Workflow token details associated with" + " the node. Please use name for the node other than the name of the Workflow.", workflowSpec.getName());
        LOG.warn(msg);
    }
    switch(nodeType) {
        case ACTION:
            verifyWorkflowAction(appSpec, node);
            break;
        case FORK:
            verifyWorkflowFork(appSpec, workflowSpec, node, existingNodeNames);
            break;
        case CONDITION:
            verifyWorkflowCondition(appSpec, workflowSpec, node, existingNodeNames);
            break;
        default:
            break;
    }
}
Also used : WorkflowNodeType(co.cask.cdap.api.workflow.WorkflowNodeType)

Aggregations

WorkflowNodeType (co.cask.cdap.api.workflow.WorkflowNodeType)4 WorkflowActionNode (co.cask.cdap.api.workflow.WorkflowActionNode)1 WorkflowNode (co.cask.cdap.api.workflow.WorkflowNode)1 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 JsonObject (com.google.gson.JsonObject)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1