Search in sources :

Example 21 with WorkflowProcessInstanceImpl

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

the class ProcessMetricsEventListener method afterNodeInstanceFailed.

@Override
public void afterNodeInstanceFailed(ProcessNodeInstanceFailedEvent event) {
    final WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) event.getProcessInstance();
    // Displays total count of process instances that failed during execution - failure of given node
    Counter counter = registry.counter("automatiko.process.errored.count", Arrays.asList(Tag.of("application", application.orElse("")), Tag.of("version", version.orElse("")), Tag.of("processId", processInstance.getProcessId()), Tag.of("processVersion", processInstance.getProcess().getVersion() == null ? "unknown" : processInstance.getProcess().getVersion()), Tag.of("nodeName", event.getNodeInstance().getNodeName())));
    counter.increment();
}
Also used : Counter(io.micrometer.core.instrument.Counter) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)

Example 22 with WorkflowProcessInstanceImpl

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

the class ProcessMetricsEventListener method afterProcessSignaled.

@Override
public void afterProcessSignaled(ProcessSignaledEvent event) {
    final WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) event.getProcessInstance();
    // Displays total count of process instance's signals
    Counter counter = registry.counter("automatiko.process.signals.count", Arrays.asList(Tag.of("application", application.orElse("")), Tag.of("version", version.orElse("")), Tag.of("processId", processInstance.getProcessId()), Tag.of("processVersion", processInstance.getProcess().getVersion() == null ? "unknown" : processInstance.getProcess().getVersion()), Tag.of("signal", event.getSignal())));
    counter.increment();
}
Also used : Counter(io.micrometer.core.instrument.Counter) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)

Example 23 with WorkflowProcessInstanceImpl

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

the class ProcessMetricsEventListener method afterProcessStarted.

@Override
public void afterProcessStarted(ProcessStartedEvent event) {
    final WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) event.getProcessInstance();
    // "Total count of started process instances"
    Counter counter = registry.counter("automatiko.process.started.count", Arrays.asList(Tag.of("application", application.orElse("")), Tag.of("version", version.orElse("")), Tag.of("processId", processInstance.getProcessId()), Tag.of("processVersion", processInstance.getProcess().getVersion() == null ? "unknown" : processInstance.getProcess().getVersion())));
    counter.increment();
}
Also used : Counter(io.micrometer.core.instrument.Counter) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)

Example 24 with WorkflowProcessInstanceImpl

use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl 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 25 with WorkflowProcessInstanceImpl

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

the class AbstractProtobufProcessInstanceMarshaller method writeProcessInstance.

// Output methods
public AutomatikoMessages.ProcessInstance writeProcessInstance(MarshallerWriteContext context, ProcessInstance processInstance) throws IOException {
    WorkflowProcessInstanceImpl workFlow = (WorkflowProcessInstanceImpl) processInstance;
    AutomatikoMessages.ProcessInstance.Builder _instance = AutomatikoMessages.ProcessInstance.newBuilder().setId(workFlow.getId()).setProcessId(workFlow.getProcessId()).setState(workFlow.getState()).setProcessType(workFlow.getProcess().getType()).setSignalCompletion(workFlow.isSignalCompletion()).setSlaCompliance(workFlow.getSlaCompliance()).setStartDate(workFlow.getStartDate().getTime());
    if (workFlow.getProcessXml() != null) {
        _instance.setProcessXml(workFlow.getProcessXml());
    }
    if (workFlow.getDescription() != null) {
        _instance.setDescription(workFlow.getDescription());
    }
    if (workFlow.getInitiator() != null) {
        _instance.setInitiator(workFlow.getInitiator());
    }
    _instance.addAllCompletedNodeIds(workFlow.getCompletedNodeIds());
    if (workFlow.getCorrelationKey() != null) {
        _instance.setCorrelationKey(workFlow.getCorrelationKey());
    }
    if (workFlow.getSlaDueDate() != null) {
        _instance.setSlaDueDate(workFlow.getSlaDueDate().getTime());
    }
    if (workFlow.getSlaTimerId() != null) {
        _instance.setSlaTimerId(workFlow.getSlaTimerId());
    }
    if (workFlow.getParentProcessInstanceId() != null) {
        _instance.setParentProcessInstanceId(workFlow.getParentProcessInstanceId());
    }
    if (workFlow.getRootProcessInstanceId() != null) {
        _instance.setRootProcessInstanceId(workFlow.getRootProcessInstanceId());
    }
    if (workFlow.getRootProcessId() != null) {
        _instance.setRootProcessId(workFlow.getRootProcessId());
    }
    if (workFlow.getReferenceFromRoot() != null) {
        _instance.setReferenceFromRoot(workFlow.getReferenceFromRoot());
    }
    if (workFlow.getProcess().getVersion() != null) {
        _instance.setProcessVersion(workFlow.getProcess().getVersion());
    }
    List<ExecutionsErrorInfo> errors = workFlow.errors();
    if (errors != null) {
        for (ExecutionsErrorInfo error : errors) {
            _instance.addErrors(AutomatikoMessages.ProcessInstance.Error.newBuilder().setErrorNodeId(error.getFailedNodeId()).setErrorId(error.getErrorId()).setErrorMessage(error.getErrorMessage() == null ? "" : error.getErrorMessage()).setErrorDetails(error.getErrorDetails() == null ? "" : error.getErrorDetails()));
        }
    }
    if (workFlow.getReferenceId() != null) {
        _instance.setReferenceId(workFlow.getReferenceId());
    }
    Map<String, List<String>> children = workFlow.getChildren();
    if (children != null) {
        for (Entry<String, List<String>> entry : children.entrySet()) {
            _instance.addChildren(AutomatikoMessages.ProcessInstance.ProcessInstanchChildren.newBuilder().setProcessId(entry.getKey()).addAllIds(entry.getValue()).build());
        }
    }
    Collection<Tag> tags = workFlow.getTags();
    if (tags != null) {
        for (Tag tag : tags) {
            _instance.addTags(AutomatikoMessages.ProcessInstance.Tag.newBuilder().setId(tag.getId()).setValue(tag.getValue()));
        }
    }
    SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) workFlow.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
    if (swimlaneContextInstance != null) {
        Map<String, String> swimlaneActors = swimlaneContextInstance.getSwimlaneActors();
        for (Map.Entry<String, String> entry : swimlaneActors.entrySet()) {
            _instance.addSwimlaneContext(AutomatikoMessages.ProcessInstance.SwimlaneContextInstance.newBuilder().setSwimlane(entry.getKey()).setActorId(entry.getValue()).build());
        }
    }
    List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(workFlow.getNodeInstances());
    Collections.sort(nodeInstances, new Comparator<NodeInstance>() {

        public int compare(NodeInstance o1, NodeInstance o2) {
            return (int) (o1.getId().compareTo(o2.getId()));
        }
    });
    for (NodeInstance nodeInstance : nodeInstances) {
        _instance.addNodeInstance(writeNodeInstance(context, nodeInstance));
    }
    List<ContextInstance> exclusiveGroupInstances = workFlow.getContextInstances(ExclusiveGroup.EXCLUSIVE_GROUP);
    if (exclusiveGroupInstances != null) {
        for (ContextInstance contextInstance : exclusiveGroupInstances) {
            AutomatikoMessages.ProcessInstance.ExclusiveGroupInstance.Builder _exclusive = AutomatikoMessages.ProcessInstance.ExclusiveGroupInstance.newBuilder();
            ExclusiveGroupInstance exclusiveGroupInstance = (ExclusiveGroupInstance) contextInstance;
            Collection<NodeInstance> groupNodeInstances = exclusiveGroupInstance.getNodeInstances();
            for (NodeInstance nodeInstance : groupNodeInstances) {
                _exclusive.addGroupNodeInstanceId(nodeInstance.getId());
            }
            _instance.addExclusiveGroup(_exclusive.build());
        }
    }
    if (!(boolean) context.env.getOrDefault("_ignore_vars_", false)) {
        writeVariableScope(context, workFlow, _instance);
    }
    List<Map.Entry<String, Integer>> iterationlevels = new ArrayList<Map.Entry<String, Integer>>(workFlow.getIterationLevels().entrySet());
    Collections.sort(iterationlevels, new Comparator<Map.Entry<String, Integer>>() {

        public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
            return o1.getKey().compareTo(o2.getKey());
        }
    });
    for (Map.Entry<String, Integer> level : iterationlevels) {
        if (level.getValue() != null) {
            _instance.addIterationLevels(AutomatikoMessages.IterationLevel.newBuilder().setId(level.getKey()).setLevel(level.getValue()));
        }
    }
    return _instance.build();
}
Also used : ExecutionsErrorInfo(io.automatiko.engine.api.workflow.ExecutionsErrorInfo) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList) Entry(java.util.Map.Entry) List(java.util.List) ArrayList(java.util.ArrayList) ExclusiveGroupInstance(io.automatiko.engine.workflow.base.instance.context.exclusive.ExclusiveGroupInstance) SwimlaneContextInstance(io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance) SwimlaneContextInstance(io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) Tag(io.automatiko.engine.api.workflow.Tag) Map(java.util.Map) HashMap(java.util.HashMap) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) StateNodeInstance(io.automatiko.engine.workflow.process.instance.node.StateNodeInstance) ForEachNodeInstance(io.automatiko.engine.workflow.process.instance.node.ForEachNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) TimerNodeInstance(io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance) MilestoneNodeInstance(io.automatiko.engine.workflow.process.instance.node.MilestoneNodeInstance) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) SubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.SubProcessNodeInstance) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) DynamicNodeInstance(io.automatiko.engine.workflow.process.instance.node.DynamicNodeInstance) LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) RuleSetNodeInstance(io.automatiko.engine.workflow.process.instance.node.RuleSetNodeInstance) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance)

Aggregations

WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)36 ArrayList (java.util.ArrayList)10 EventSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance)8 Node (io.automatiko.engine.api.definition.process.Node)7 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)7 HumanTaskNodeInstance (io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance)7 Process (io.automatiko.engine.api.definition.process.Process)6 NodeInstance (io.automatiko.engine.workflow.process.instance.NodeInstance)6 CompositeContextNodeInstance (io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Map (java.util.Map)6 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)5 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)5 NodeInstanceContainer (io.automatiko.engine.workflow.process.instance.NodeInstanceContainer)5 LambdaSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance)5 WorkItemNodeInstance (io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance)5 Date (java.util.Date)5 ExpirationTime (io.automatiko.engine.api.jobs.ExpirationTime)4 JobsService (io.automatiko.engine.api.jobs.JobsService)4