Search in sources :

Example 6 with NodeInstanceContainer

use of io.automatiko.engine.workflow.process.instance.NodeInstanceContainer in project automatiko-engine by automatiko-io.

the class EventSubProcessNodeInstance method nodeInstanceCompleted.

@Override
public void nodeInstanceCompleted(io.automatiko.engine.workflow.process.instance.NodeInstance nodeInstance, String outType) {
    if (nodeInstance instanceof EndNodeInstance) {
        if (getCompositeNode().isKeepActive()) {
            StartNode startNode = getCompositeNode().findStartNode();
            triggerCompleted(true);
            if (startNode.isInterrupting()) {
                String faultName = getProcessInstance().getOutcome() == null ? "" : getProcessInstance().getOutcome();
                if (startNode.getMetaData("FaultCode") != null) {
                    faultName = (String) startNode.getMetaData("FaultCode");
                }
                if (getNodeInstanceContainer() instanceof ProcessInstance) {
                    ((ProcessInstance) getProcessInstance()).setState(ProcessInstance.STATE_ABORTED, faultName);
                } else {
                    ((NodeInstanceContainer) getNodeInstanceContainer()).setState(ProcessInstance.STATE_ABORTED);
                    // to allow top level process instance in case there are no more active nodes
                    ((NodeInstanceContainer) ((ProcessInstance) getProcessInstance())).nodeInstanceCompleted(this, null);
                }
            }
        }
    } else {
        throw new IllegalArgumentException("Completing a node instance that has no outgoing connection not supported.");
    }
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance)

Example 7 with NodeInstanceContainer

use of io.automatiko.engine.workflow.process.instance.NodeInstanceContainer in project automatiko-engine by automatiko-io.

the class FaultNodeInstance method internalTrigger.

public void internalTrigger(final NodeInstance from, String type) {
    if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
        throw new IllegalArgumentException("A FaultNode only accepts default incoming connections!");
    }
    triggerTime = new Date();
    if (getProcessInstance().isFunctionFlow(this) && getNodeInstanceContainer() instanceof ProcessInstance) {
        // only when running as function flow and node is in the top level node container meaning process instance
        // and not subprocesses
        getProcessInstance().getMetaData().compute("ATK_FUNC_FLOW_NEXT", (k, v) -> {
            if (v == null) {
                v = new ArrayList<String>();
            }
            Process process = getProcessInstance().getProcess();
            String version = "";
            if (process.getVersion() != null && !process.getVersion().trim().isEmpty()) {
                version = ".v" + process.getVersion().replaceAll("\\.", "_");
            }
            String defaultNextNode = process.getPackageName() + "." + process.getId() + version + "." + getNodeName().toLowerCase();
            ((List<String>) v).add((String) getNode().getMetaData().getOrDefault("functionType", defaultNextNode));
            return v;
        });
    }
    String faultName = getFaultName();
    ExceptionScopeInstance exceptionScopeInstance = getExceptionScopeInstance(faultName);
    NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getNodeInstanceContainer();
    nodeInstanceContainer.removeNodeInstance(this);
    boolean exceptionHandled = false;
    if (getFaultNode().isTerminateParent()) {
        // events
        if (exceptionScopeInstance != null) {
            exceptionHandled = true;
            handleException(faultName, exceptionScopeInstance);
        }
        if (nodeInstanceContainer instanceof CompositeNodeInstance) {
            ((CompositeNodeInstance) nodeInstanceContainer).cancel();
        } else if (nodeInstanceContainer instanceof WorkflowProcessInstance) {
            Collection<NodeInstance> nodeInstances = ((WorkflowProcessInstance) nodeInstanceContainer).getNodeInstances();
            for (NodeInstance nodeInstance : nodeInstances) {
                ((io.automatiko.engine.workflow.process.instance.NodeInstance) nodeInstance).cancel();
            }
        }
    }
    String uniqueId = (String) getNode().getMetaData().get(UNIQUE_ID);
    if (uniqueId == null) {
        uniqueId = ((NodeImpl) getNode()).getUniqueId();
    }
    ((WorkflowProcessInstanceImpl) getProcessInstance()).addCompletedNodeId(uniqueId);
    if (exceptionScopeInstance != null) {
        if (!exceptionHandled) {
            handleException(faultName, exceptionScopeInstance);
        }
        boolean hidden = false;
        if (getNode().getMetaData().get("hidden") != null) {
            hidden = true;
        }
        if (!hidden) {
            InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
            runtime.getProcessEventSupport().fireBeforeNodeLeft(this, runtime);
        }
        ((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
        if (!hidden) {
            InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
            runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
        }
    } else {
        ((ProcessInstance) getProcessInstance()).setState(ProcessInstance.STATE_ABORTED, faultName, getFaultData());
    }
}
Also used : NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) Process(io.automatiko.engine.api.definition.process.Process) Date(java.util.Date) Collection(java.util.Collection) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) ArrayList(java.util.ArrayList) List(java.util.List) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) ExceptionScopeInstance(io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)

Example 8 with NodeInstanceContainer

use of io.automatiko.engine.workflow.process.instance.NodeInstanceContainer in project automatiko-engine by automatiko-io.

the class AbstractProcessInstance method triggerNode.

@Override
public void triggerNode(String nodeId) {
    lock();
    WorkflowProcessInstanceImpl wfpi = ((WorkflowProcessInstanceImpl) processInstance());
    ExecutableProcess rfp = ((ExecutableProcess) wfpi.getProcess());
    Node node = rfp.getNodesRecursively().stream().filter(ni -> nodeId.equals(ni.getMetaData().get("UniqueId"))).findFirst().orElseThrow(() -> new NodeNotFoundException(this.id, nodeId));
    Node parentNode = rfp.getParentNode(node.getId());
    NodeInstanceContainer nodeInstanceContainerNode = parentNode == null ? wfpi : ((NodeInstanceContainer) wfpi.getNodeInstance(parentNode));
    if (nodeInstanceContainerNode.getNodeInstances().isEmpty() && nodeInstanceContainerNode instanceof CompositeContextNodeInstance) {
        ((CompositeContextNodeInstance) nodeInstanceContainerNode).internalTriggerOnlyParent(null, nodeId);
    }
    nodeInstanceContainerNode.getNodeInstance(node).trigger(null, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
}
Also used : NodeNotFoundException(io.automatiko.engine.api.workflow.NodeNotFoundException) NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) Node(io.automatiko.engine.api.definition.process.Node) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)

Example 9 with NodeInstanceContainer

use of io.automatiko.engine.workflow.process.instance.NodeInstanceContainer in project automatiko-engine by automatiko-io.

the class WorkflowReuseContextInstanceFactory method getContextInstance.

public ContextInstance getContextInstance(Context context, ContextInstanceContainer contextInstanceContainer, ProcessInstance processInstance) {
    ContextInstance result = contextInstanceContainer.getContextInstance(context.getType(), context.getId());
    if (result != null) {
        return result;
    }
    try {
        AbstractContextInstance contextInstance = (AbstractContextInstance) cls.newInstance();
        contextInstance.setContextId(context.getId());
        contextInstance.setContextInstanceContainer(contextInstanceContainer);
        contextInstance.setProcessInstance(processInstance);
        contextInstanceContainer.addContextInstance(context.getType(), contextInstance);
        NodeInstanceContainer nodeInstanceContainer = null;
        if (contextInstanceContainer instanceof NodeInstanceContainer) {
            nodeInstanceContainer = (NodeInstanceContainer) contextInstanceContainer;
        } else if (contextInstanceContainer instanceof ContextInstance) {
            ContextInstanceContainer parent = ((ContextInstance) contextInstanceContainer).getContextInstanceContainer();
            while (parent != null) {
                if (parent instanceof NodeInstanceContainer) {
                    nodeInstanceContainer = (NodeInstanceContainer) parent;
                } else if (contextInstanceContainer instanceof ContextInstance) {
                    parent = ((ContextInstance) contextInstanceContainer).getContextInstanceContainer();
                } else {
                    parent = null;
                }
            }
        }
        ((WorkflowContextInstance) contextInstance).setNodeInstanceContainer(nodeInstanceContainer);
        return contextInstance;
    } catch (Exception e) {
        throw new RuntimeException("Unable to instantiate context '" + this.cls.getName() + "': " + e.getMessage());
    }
}
Also used : AbstractContextInstance(io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance) NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) AbstractContextInstance(io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance) ContextInstanceContainer(io.automatiko.engine.workflow.base.instance.ContextInstanceContainer)

Example 10 with NodeInstanceContainer

use of io.automatiko.engine.workflow.process.instance.NodeInstanceContainer in project automatiko-engine by automatiko-io.

the class CompensationEventListener method createNodeInstanceContainers.

private Stack<NodeInstance> createNodeInstanceContainers(Node toCompensateNode, boolean generalCompensation) {
    Stack<NodeContainer> nestedNodes = new Stack<NodeContainer>();
    Stack<NodeInstance> generatedInstances = new Stack<NodeInstance>();
    NodeContainer parentContainer = toCompensateNode.getParentContainer();
    while (!(parentContainer instanceof ExecutableProcess)) {
        nestedNodes.add(parentContainer);
        parentContainer = ((Node) parentContainer).getParentContainer();
    }
    NodeInstanceContainer parentInstance;
    if (nestedNodes.isEmpty()) {
        // nestedNodes is empty
        parentInstance = (NodeInstanceContainer) getProcessInstance();
    } else {
        parentInstance = (NodeInstanceContainer) ((WorkflowProcessInstanceImpl) getProcessInstance()).getNodeInstance((Node) nestedNodes.pop());
        generatedInstances.add((NodeInstance) parentInstance);
    }
    NodeInstanceContainer childInstance;
    while (!nestedNodes.isEmpty()) {
        // generate
        childInstance = (NodeInstanceContainer) parentInstance.getNodeInstance((Node) nestedNodes.pop());
        assert childInstance instanceof CompositeNodeInstance : "A node with child nodes should end up creating a CompositeNodeInstance type.";
        // track and modify
        generatedInstances.add((NodeInstance) childInstance);
        // loop
        parentInstance = childInstance;
    }
    if (generalCompensation) {
        childInstance = (NodeInstanceContainer) parentInstance.getNodeInstance(toCompensateNode);
        generatedInstances.add((NodeInstance) childInstance);
    }
    return generatedInstances;
}
Also used : NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) CompositeNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeNodeInstance) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance) CompositeNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeNodeInstance) Stack(java.util.Stack)

Aggregations

NodeInstanceContainer (io.automatiko.engine.workflow.process.instance.NodeInstanceContainer)10 WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)6 NodeInstance (io.automatiko.engine.workflow.process.instance.NodeInstance)4 Node (io.automatiko.engine.api.definition.process.Node)3 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)3 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)3 ProcessInstance (io.automatiko.engine.workflow.base.instance.ProcessInstance)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Process (io.automatiko.engine.api.definition.process.Process)2 ContextInstanceContainer (io.automatiko.engine.workflow.base.instance.ContextInstanceContainer)2 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)2 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)2 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)2 WorkflowRuntimeException (io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)2 EventNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventNodeInstance)2 EventSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance)2 Date (java.util.Date)2 Connection (io.automatiko.engine.api.definition.process.Connection)1 NodeContainer (io.automatiko.engine.api.definition.process.NodeContainer)1