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);
}
}
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();
}
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;
}
Aggregations