Search in sources :

Example 6 with NodeInstanceImpl

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

the class ProcessInstanceMarshaller method exportProcessInstance.

public ExportedProcessInstance<?> exportProcessInstance(ProcessInstance<?> processInstance) {
    io.automatiko.engine.api.runtime.process.ProcessInstance pi = ((AbstractProcessInstance<?>) processInstance).internalGetProcessInstance();
    if (pi == null) {
        return null;
    }
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        Map<String, Object> localEnv = new HashMap<String, Object>(env);
        localEnv.put("_export_", true);
        ProcessMarshallerWriteContext context = new ProcessMarshallerWriteContext(baos, ((io.automatiko.engine.workflow.base.instance.ProcessInstance) pi).getProcessRuntime(), null, localEnv);
        context.setProcessInstanceId(pi.getId());
        context.setState(pi.getState());
        String processType = pi.getProcess().getType();
        context.stream.writeUTF(processType);
        io.automatiko.engine.workflow.marshalling.impl.ProcessInstanceMarshaller marshaller = ProcessMarshallerRegistry.INSTANCE.getMarshaller(processType);
        Object result = marshaller.writeProcessInstance(context, pi);
        AutomatikoMessages.Header.Builder _header = AutomatikoMessages.Header.newBuilder();
        _header.setVersion(AutomatikoMessages.Version.newBuilder().setVersionMajor(1).setVersionMinor(0).setVersionRevision(0).build());
        PersisterHelper.writeStrategiesIndex(context, _header);
        String header = JsonFormat.printer().print(_header);
        context.close();
        // collect all information about timers
        Collection<io.automatiko.engine.workflow.process.instance.NodeInstance> nodes = ((WorkflowProcessInstanceImpl) pi).getNodeInstances(true);
        StringBuilder timers = new StringBuilder("[");
        for (io.automatiko.engine.workflow.process.instance.NodeInstance ni : nodes) {
            String timerId = null;
            if (ni instanceof TimerNodeInstance) {
                timerId = ((TimerNodeInstance) ni).getTimerId();
            } else if (ni instanceof StateBasedNodeInstance) {
                if (((StateBasedNodeInstance) ni).getTimerInstances() != null) {
                    ((StateBasedNodeInstance) ni).getTimerInstances().forEach(timer -> {
                        ZonedDateTime scheduledTime = context.processRuntime.getJobsService().getScheduledTime(timer);
                        timers.append("{\"timerId\":\"").append(timer).append("\",\"scheduledAt\":\"").append(scheduledTime.toString()).append("\",\"nodeInstanceId\":\"").append(ni.getId()).append("\"}");
                    });
                }
            }
            if (timerId != null) {
                ZonedDateTime scheduledTime = context.processRuntime.getJobsService().getScheduledTime(timerId);
                timers.append("{\"timerId\":\"").append(timerId).append("\",\"scheduledAt\":\"").append(scheduledTime.toString()).append("\",\"nodeInstanceId\":\"").append(ni.getId()).append("\"}");
            }
            if (((NodeInstanceImpl) ni).getRetryJobId() != null && !((NodeInstanceImpl) ni).getRetryJobId().isEmpty()) {
                ZonedDateTime scheduledTime = context.processRuntime.getJobsService().getScheduledTime(((NodeInstanceImpl) ni).getRetryJobId());
                timers.append("{\"timerId\":\"").append(((NodeInstanceImpl) ni).getRetryJobId()).append("\",\"scheduledAt\":\"").append(scheduledTime.toString()).append("\",\"nodeInstanceId\":\"").append(ni.getId()).append("\"}");
            }
        }
        timers.append("]");
        return StringExportedProcessInstance.of(header, JsonFormat.printer().print((MessageOrBuilder) result), timers.toString(), null);
    } catch (Exception e) {
        throw new RuntimeException("Error while marshalling process instance", e);
    }
}
Also used : StateBasedNodeInstance(io.automatiko.engine.workflow.process.instance.node.StateBasedNodeInstance) TimerNodeInstance(io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ProtobufRuleFlowProcessInstanceMarshaller(io.automatiko.engine.workflow.marshalling.impl.ProtobufRuleFlowProcessInstanceMarshaller) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ZonedDateTime(java.time.ZonedDateTime) ObjectInputStream(java.io.ObjectInputStream) ExpirationTime(io.automatiko.engine.api.jobs.ExpirationTime) NodeInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceImpl) HashMap(java.util.HashMap) MessageOrBuilder(com.google.protobuf.MessageOrBuilder) SerializablePlaceholderResolverStrategy(io.automatiko.engine.workflow.marshalling.impl.strategies.SerializablePlaceholderResolverStrategy) LinkedHashMap(java.util.LinkedHashMap) JobsService(io.automatiko.engine.api.jobs.JobsService) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) Process(io.automatiko.engine.api.workflow.Process) PersisterHelper(io.automatiko.engine.workflow.marshalling.impl.PersisterHelper) AbstractProcess(io.automatiko.engine.workflow.AbstractProcess) StreamCorruptedException(java.io.StreamCorruptedException) Iterator(java.util.Iterator) Model(io.automatiko.engine.api.Model) AutomatikoMessages(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages) Collection(java.util.Collection) ClassObjectMarshallingStrategyAcceptor(io.automatiko.engine.workflow.marshalling.impl.ClassObjectMarshallingStrategyAcceptor) IOException(java.io.IOException) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) MarshallerReaderContext(io.automatiko.engine.workflow.marshalling.impl.MarshallerReaderContext) ProcessMarshallerRegistry(io.automatiko.engine.workflow.marshalling.impl.ProcessMarshallerRegistry) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) StringExportedProcessInstance(io.automatiko.engine.workflow.StringExportedProcessInstance) List(java.util.List) JsonFormat(com.google.protobuf.util.JsonFormat) ObjectMarshallingStrategy(io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance) EnvironmentName(io.automatiko.engine.api.runtime.EnvironmentName) ProcessInstanceJobDescription(io.automatiko.engine.api.jobs.ProcessInstanceJobDescription) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) MessageOrBuilder(com.google.protobuf.MessageOrBuilder) ZonedDateTime(java.time.ZonedDateTime) NodeInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceImpl) StateBasedNodeInstance(io.automatiko.engine.workflow.process.instance.node.StateBasedNodeInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamCorruptedException(java.io.StreamCorruptedException) IOException(java.io.IOException) StateBasedNodeInstance(io.automatiko.engine.workflow.process.instance.node.StateBasedNodeInstance) TimerNodeInstance(io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance) TimerNodeInstance(io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance)

Example 7 with NodeInstanceImpl

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

the class AbstractProcessInstance method retriggerNodeInstance.

@Override
public void retriggerNodeInstance(String nodeInstanceId) {
    lock();
    NodeInstance nodeInstance = ((WorkflowProcessInstanceImpl) processInstance()).getNodeInstances(true).stream().filter(ni -> ni.getId().equals(nodeInstanceId)).findFirst().orElseThrow(() -> new NodeInstanceNotFoundException(this.id, nodeInstanceId));
    ((NodeInstanceImpl) nodeInstance).retrigger(true);
    removeOnFinish();
}
Also used : NodeInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceImpl) NodeInstanceNotFoundException(io.automatiko.engine.api.workflow.NodeInstanceNotFoundException) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance) LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance)

Example 8 with NodeInstanceImpl

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

the class CompositeNodeInstance method getNodeInstance.

public NodeInstance getNodeInstance(final Node node) {
    if (node instanceof CompositeNode.CompositeNodeStart) {
        return buildCompositeNodeInstance(new CompositeNodeStartInstance(), node);
    }
    if (node instanceof CompositeNode.CompositeNodeEnd) {
        return buildCompositeNodeInstance(new CompositeNodeEndInstance(), node);
    }
    NodeInstanceFactory conf = NodeInstanceFactoryRegistry.getInstance().getProcessNodeInstanceFactory(node);
    if (conf == null) {
        throw new IllegalArgumentException("Illegal node type: " + node.getClass());
    }
    NodeInstanceImpl nodeInstance = (NodeInstanceImpl) conf.getNodeInstance(node, getProcessInstance(), this);
    return nodeInstance;
}
Also used : NodeInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceImpl) NodeInstanceFactory(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceFactory)

Aggregations

NodeInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.NodeInstanceImpl)8 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)4 TimerNodeInstance (io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance)4 WorkItemNodeInstance (io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance)4 JobsService (io.automatiko.engine.api.jobs.JobsService)3 CompositeContextNodeInstance (io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance)3 EventSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance)3 HumanTaskNodeInstance (io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance)3 LambdaSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance)3 Model (io.automatiko.engine.api.Model)2 ExpirationTime (io.automatiko.engine.api.jobs.ExpirationTime)2 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)2 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)2 ExportedProcessInstance (io.automatiko.engine.api.workflow.ExportedProcessInstance)2 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)2 AbstractProcess (io.automatiko.engine.workflow.AbstractProcess)2 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)2 StringExportedProcessInstance (io.automatiko.engine.workflow.StringExportedProcessInstance)2 Timer (io.automatiko.engine.workflow.base.core.timer.Timer)2 WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)2