Search in sources :

Example 21 with ProcessInstance

use of de.hpi.bpt.scylla.simulation.ProcessInstance in project scylla by bptlab.

the class BatchPluginUtils method logTaskEventForNonResponsiblePI.

// If the execution type is parallel this makes the entry for the not really simulated process instances for tasks
void logTaskEventForNonResponsiblePI(TaskEvent event, ProcessInstance processInstance) throws ScyllaRuntimeException {
    ProcessInstance parentProcessInstance = processInstance.getParent();
    if (parentProcessInstance != null) {
        ProcessModel processModel = processInstance.getProcessModel();
        int parentNodeId = processModel.getNodeIdInParent();
        BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
        BatchCluster cluster = pluginInstance.getRunningCluster(parentProcessInstance, parentNodeId);
        if (cluster != null && cluster.getBatchActivity().getExecutionType().equals(BatchClusterExecutionType.PARALLEL)) {
            SimulationModel model = (SimulationModel) event.getModel();
            long timestamp = Math.round(model.presentTime().getTimeRounded(DateTimeUtils.getReferenceTimeUnit()));
            String taskName = event.getDisplayName();
            int nodeId = event.getNodeId();
            String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
            String source = event.getSource();
            ProcessNodeTransitionType transition;
            Set<String> resources = new HashSet<String>();
            if (event instanceof TaskEnableEvent) {
                transition = ProcessNodeTransitionType.ENABLE;
            } else if (event instanceof TaskBeginEvent) {
                transition = ProcessNodeTransitionType.BEGIN;
                Set<ResourceObject> resourceObjects = processInstance.getAssignedResources().get(source).getResourceObjects();
                for (ResourceObject res : resourceObjects) {
                    String resourceName = res.getResourceType() + "_" + res.getId();
                    resources.add(resourceName);
                }
                tasksAndResources.put(source, resources);
            } else if (event instanceof TaskCancelEvent) {
                transition = ProcessNodeTransitionType.CANCEL;
                resources = tasksAndResources.get(source);
                tasksAndResources.remove(source);
            } else if (event instanceof TaskTerminateEvent) {
                transition = ProcessNodeTransitionType.TERMINATE;
                resources = tasksAndResources.get(source);
                tasksAndResources.remove(source);
            } else {
                throw new ScyllaRuntimeException("Task event type not supported.");
            }
            int sourceSuffix = 0;
            List<ProcessInstance> processInstances = cluster.getProcessInstances();
            for (ProcessInstance pi : processInstances) {
                if (!processInstance.getParent().equals(pi)) {
                    // the source attribute comes from an event, but we did not really simulate the events for the
                    // non-responsible process instances, so we mock a source attribute value
                    String mockSource = source + "##" + ++sourceSuffix;
                    ProcessNodeInfo info;
                    info = new ProcessNodeInfo(nodeId, processScopeNodeId, mockSource, timestamp, taskName, resources, transition);
                    model.addNodeInfo(processModel, pi, info);
                }
            }
        }
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ResourceObject(de.hpi.bpt.scylla.simulation.ResourceObject) HashSet(java.util.HashSet) Set(java.util.Set) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) ProcessNodeTransitionType(de.hpi.bpt.scylla.logger.ProcessNodeTransitionType) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) HashSet(java.util.HashSet)

Example 22 with ProcessInstance

use of de.hpi.bpt.scylla.simulation.ProcessInstance in project scylla by bptlab.

the class BatchPluginUtils method logBPMNEventForNonResponsiblePI.

// If the execution type is parallel this makes the entry for the not really simulated process instances for events
void logBPMNEventForNonResponsiblePI(BPMNEvent event, ProcessInstance processInstance) {
    ProcessInstance parentProcessInstance = processInstance.getParent();
    if (parentProcessInstance != null) {
        ProcessModel processModel = processInstance.getProcessModel();
        int parentNodeId = processModel.getNodeIdInParent();
        BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
        BatchCluster cluster = pluginInstance.getRunningCluster(parentProcessInstance, parentNodeId);
        if (cluster != null && cluster.hasExecutionType(BatchClusterExecutionType.PARALLEL)) {
            SimulationModel model = (SimulationModel) event.getModel();
            long timestamp = Math.round(model.presentTime().getTimeRounded(DateTimeUtils.getReferenceTimeUnit()));
            Set<String> resources = new HashSet<String>();
            String taskName = event.getDisplayName();
            int nodeId = event.getNodeId();
            String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
            String source = event.getSource();
            int sourceSuffix = 0;
            List<ProcessInstance> processInstances = cluster.getProcessInstances();
            for (ProcessInstance pi : processInstances) {
                if (!processInstance.getParent().equals(pi)) {
                    // the source attribute comes from an event, but we did not really simulate the events for the
                    // non-responsible process instances, so we mock a source attribute value
                    String mockSource = source + "##" + ++sourceSuffix;
                    ProcessNodeInfo info;
                    info = new ProcessNodeInfo(nodeId, processScopeNodeId, mockSource, timestamp, taskName, resources, ProcessNodeTransitionType.EVENT_BEGIN);
                    model.addNodeInfo(processModel, pi, info);
                    info = new ProcessNodeInfo(nodeId, processScopeNodeId, mockSource, timestamp, taskName, resources, ProcessNodeTransitionType.EVENT_TERMINATE);
                    model.addNodeInfo(processModel, pi, info);
                }
            }
        }
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) HashSet(java.util.HashSet)

Example 23 with ProcessInstance

use of de.hpi.bpt.scylla.simulation.ProcessInstance in project scylla by bptlab.

the class BoundaryEventPluginUtils method scheduleBoundaryEvents.

private void scheduleBoundaryEvents(SimulationModel model, double startOfInterval, double endOfInterval) {
    Set<String> boundaryObjectsToRemove = new HashSet<>();
    for (String taskEnableEventName : boundaryObjects.keySet()) {
        // boolean isInterruptingEvent = false;
        BoundaryObject bo = boundaryObjects.get(taskEnableEventName);
        TreeMap<Double, List<BPMNIntermediateEvent>> boundaryEventsToSchedule = bo.getBoundaryEventsToSchedule();
        Iterator<Double> iterator = boundaryEventsToSchedule.keySet().iterator();
        Set<Double> elementsToRemove = new HashSet<>();
        ProcessInstance processInstance = bo.getProcessInstance();
        while (iterator.hasNext()) {
            Double timeToSchedule = iterator.next();
            if (timeToSchedule > endOfInterval) {
                // We will not have prepared events for scheduling which are beyond endOfInterval.
                break;
            }
            List<BPMNIntermediateEvent> events = boundaryEventsToSchedule.get(timeToSchedule);
            // Now take all events and schedule them.
            for (BPMNIntermediateEvent event : events) {
                double durationRelativeToEventStart = timeToSchedule - startOfInterval;
                if (durationRelativeToEventStart < 0)
                    continue;
                TimeUnit unit = TimeUnit.SECONDS;
                TimeSpan timeSpan = new TimeSpan(durationRelativeToEventStart, unit);
                // Schedule the event.
                try {
                    SimulationUtils.scheduleEvent(event, timeSpan);
                } catch (ScyllaRuntimeException exception) {
                    exception.printStackTrace();
                }
            /*ProcessModel processModel = processInstance.getProcessModel();
                    int nodeId = event.getNodeId();
                    boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
                    if (cancelActivity) {
                        isInterruptingEvent = true;
                    }*/
            }
            // TreeMap<Double, List<String>> messagesOfBoundaryEventsToSchedule = bo.getMessagesOfBoundaryEventsToSchedule();
            // Took this out, see rest in createNonTimerBoundaryEvents.
            /*List<String> messages = messagesOfBoundaryEventsToSchedule.get(timeToSchedule);
                for (String message : messages) {
                    model.sendTraceNote(message);
                }*/
            // clean up
            elementsToRemove.add(timeToSchedule);
        // Not needed anymore, alreday done in creation.
        /*if (isInterruptingEvent) {
                    boundaryObjectsToRemove.add(taskEnableEventName);
                    // if (bo.getSource().equals(desmojEvent.getSource())) {
                    // normalBehavior = false;
                    // }
                    // processInstance.cancel();
                    break;
                }*/
        }
        for (Double timeToSchedule : elementsToRemove) {
            boundaryEventsToSchedule.remove(timeToSchedule);
            // messagesOfBoundaryEventsToSchedule.remove(timeToSchedule);
            if (boundaryEventsToSchedule.isEmpty()) {
                boundaryObjectsToRemove.add(taskEnableEventName);
            }
        }
    }
    // Delete all boudnaryObjects, which are compeltetly scheduled.
    for (String taskEnableEventName : boundaryObjectsToRemove) {
        boundaryObjects.remove(taskEnableEventName);
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) BPMNIntermediateEvent(de.hpi.bpt.scylla.simulation.event.BPMNIntermediateEvent) TimeSpan(desmoj.core.simulator.TimeSpan) TimeUnit(java.util.concurrent.TimeUnit) ArrayList(java.util.ArrayList) List(java.util.List) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) HashSet(java.util.HashSet)

Example 24 with ProcessInstance

use of de.hpi.bpt.scylla.simulation.ProcessInstance in project scylla by bptlab.

the class BPMNErrorBPMNEEPlugin method eventRoutine.

@Override
public void eventRoutine(BPMNEndEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    SimulationModel model = (SimulationModel) desmojEvent.getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    int nodeId = desmojEvent.getNodeId();
    Map<EventDefinitionType, Map<String, String>> definitions = processModel.getEventDefinitions().get(nodeId);
    ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
    boolean showInTrace = model.traceIsOn();
    try {
        for (EventDefinitionType definition : definitions.keySet()) {
            if (definition == EventDefinitionType.ERROR) {
                if (processModel.getParent() != null) {
                    Map<String, String> eventAttributes = processModel.getEventDefinitions().get(nodeId).get(definition);
                    String errorRef = eventAttributes.get("errorRef");
                    // Map<String, Map<String, String>> errors = model.getCommonProcessElements().getErrors();
                    // Map<String, String> error = errors.get("errorRef");
                    ProcessSimulationComponents parentDesmojObjects = desmojObjects.getParent();
                    ProcessModel parentModel = processModel.getParent();
                    int nodeIdInParent = processModel.getNodeIdInParent();
                    Integer nextNodeId = null;
                    // find boundary event of parentModel which has the same errorRef
                    List<Integer> referencesToBoundaryEvents = parentModel.getReferencesToBoundaryEvents().get(nodeIdInParent);
                    for (int nId : referencesToBoundaryEvents) {
                        Map<EventDefinitionType, Map<String, String>> boundaryEventDefinitions = parentModel.getEventDefinitions().get(nId);
                        Map<String, String> boundaryErrorEventDefinition = boundaryEventDefinitions.get(EventDefinitionType.ERROR);
                        if (boundaryErrorEventDefinition != null) {
                            if (errorRef.equals(boundaryErrorEventDefinition.get("errorRef"))) {
                                nextNodeId = nId;
                                break;
                            }
                        }
                    }
                    if (nextNodeId == null) {
                        DebugLogger.error("Could not find referenced error " + errorRef + ".");
                        SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
                        return;
                    }
                    ProcessInstance parentProcessInstance = processInstance.getParent();
                    List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(desmojEvent, parentDesmojObjects, parentProcessInstance, nextNodeId);
                    TimeSpan timeSpan = new TimeSpan(0);
                    /**
                     * first event in the map is the node that comes after the subprocess when normal behavior
                     * applies, so remove it;
                     */
                    int indexOfTaskTerminateEvent = 0;
                    desmojEvent.getNextEventMap().remove(indexOfTaskTerminateEvent);
                    desmojEvent.getTimeSpanToNextEventMap().remove(indexOfTaskTerminateEvent);
                    for (ScyllaEvent event : events) {
                        int index = desmojEvent.getNewEventIndex();
                        desmojEvent.getNextEventMap().put(index, event);
                        desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
                    }
                    processInstance.cancel();
                }
            }
        }
    } catch (NodeNotFoundException | ScyllaValidationException e) {
        DebugLogger.error(e.getMessage());
        e.printStackTrace();
        SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) EventDefinitionType(de.hpi.bpt.scylla.model.process.node.EventDefinitionType) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) Map(java.util.Map) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Aggregations

ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)24 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)18 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)12 TimeSpan (desmoj.core.simulator.TimeSpan)12 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)11 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)8 TimeInstant (desmoj.core.simulator.TimeInstant)8 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)7 TimeUnit (java.util.concurrent.TimeUnit)7 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)6 TaskTerminateEvent (de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Map (java.util.Map)4 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)3 ProcessNodeInfo (de.hpi.bpt.scylla.logger.ProcessNodeInfo)3 MultipleStartNodesException (de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException)3 NoStartNodeException (de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)3 EventDefinitionType (de.hpi.bpt.scylla.model.process.node.EventDefinitionType)3