Search in sources :

Example 1 with TaskTerminateEvent

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

the class BatchBPMNEEPlugin method eventRoutine.

@Override
public void eventRoutine(BPMNEndEvent event, ProcessInstance processInstance) throws ScyllaRuntimeException {
    BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
    pluginInstance.logBPMNEventForNonResponsiblePI(event, processInstance);
    // Schedule parental end events
    ProcessInstance parentProcessInstance = processInstance.getParent();
    if (parentProcessInstance != null) {
        ProcessModel processModel = processInstance.getProcessModel();
        int parentNodeId = processModel.getNodeIdInParent();
        BatchCluster cluster = pluginInstance.getRunningCluster(parentProcessInstance, parentNodeId);
        if (cluster != null) {
            cluster.setProcessInstanceToFinished();
            // Schedule them only if either all process instances has passed the last event of the batch activity or the execution type is parallel
            if (cluster.areAllProcessInstancesFinished() || cluster.hasExecutionType(BatchClusterExecutionType.PARALLEL)) {
                if (pluginInstance.isProcessInstanceCompleted(processInstance)) {
                    List<TaskTerminateEvent> parentalEndEvents = cluster.getParentalEndEvents();
                    for (TaskTerminateEvent pee : parentalEndEvents) {
                        ProcessInstance pi = pee.getProcessInstance();
                        pee.schedule(pi);
                    }
                    parentalEndEvents.clear();
                    pluginInstance.setClusterToTerminated(parentProcessInstance, parentNodeId);
                }
                // Prevent parental task terminate event from scheduling, if there is any (from subprocess plugin)
                Map<Integer, ScyllaEvent> nextEventMap = event.getNextEventMap();
                if (!nextEventMap.isEmpty()) {
                    Map<Integer, TimeSpan> timeSpanToNextEventMap = event.getTimeSpanToNextEventMap();
                    int indexOfParentalTaskTerminateEvent = 0;
                    nextEventMap.remove(indexOfParentalTaskTerminateEvent);
                    timeSpanToNextEventMap.remove(indexOfParentalTaskTerminateEvent);
                }
            } else if (cluster.hasExecutionType(BatchClusterExecutionType.SEQUENTIAL_CASEBASED)) {
                // Schedule the next start event
                pluginInstance.scheduleNextCaseInBatchProcess(cluster);
            }
        }
    }
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent)

Example 2 with TaskTerminateEvent

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

the class BatchTCPlugin method eventRoutine.

@Override
public void eventRoutine(TaskCancelEvent event, ProcessInstance processInstance) throws ScyllaRuntimeException {
    BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
    pluginInstance.logTaskEventForNonResponsiblePI(event, processInstance);
    ProcessInstance parentProcessInstance = processInstance.getParent();
    if (parentProcessInstance != null) {
        ProcessModel processModel = processInstance.getProcessModel();
        int parentNodeId = processModel.getNodeIdInParent();
        BatchCluster cluster = pluginInstance.getRunningCluster(parentProcessInstance, parentNodeId);
        if (cluster != null) {
            List<TaskTerminateEvent> parentalEndEvents = cluster.getParentalEndEvents();
            for (TaskTerminateEvent pee : parentalEndEvents) {
                TaskCancelEvent cancelEvent = new TaskCancelEvent(pee.getModel(), pee.getSource(), pee.getSimulationTimeOfSource(), pee.getDesmojObjects(), pee.getProcessInstance(), pee.getNodeId());
                cancelEvent.schedule(pee.getProcessInstance());
            }
            parentalEndEvents.clear();
            pluginInstance.setClusterToTerminated(parentProcessInstance, parentNodeId);
        }
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) TaskCancelEvent(de.hpi.bpt.scylla.simulation.event.TaskCancelEvent) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent)

Example 3 with TaskTerminateEvent

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

the class ParallelBatchCluster method logTaskEventForNonResponsiblePI.

private void logTaskEventForNonResponsiblePI(TaskEvent event) throws ScyllaRuntimeException {
    ProcessInstance processInstance = event.getProcessInstance();
    ProcessModel processModel = processInstance.getProcessModel();
    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;
    if (event instanceof TaskEnableEvent) {
        transition = ProcessNodeTransitionType.ENABLE;
    } else if (event instanceof TaskBeginEvent) {
        transition = ProcessNodeTransitionType.BEGIN;
        ResourceObjectTuple commonResources = event.getProcessInstance().getAssignedResources().get(source);
        getParentalStartEvents().stream().forEach(each -> each.getProcessInstance().getAssignedResources().put(each.getSource(), commonResources));
    } else if (event instanceof TaskCancelEvent) {
        transition = ProcessNodeTransitionType.CANCEL;
    } else if (event instanceof TaskTerminateEvent) {
        transition = ProcessNodeTransitionType.TERMINATE;
    } else {
        throw new ScyllaRuntimeException("Task event type not supported.");
    }
    for (TaskBeginEvent beginEvent : getParentalStartEvents()) {
        if (!getResponsibleProcessInstance().equals(beginEvent.getProcessInstance())) {
            ResourceObjectTuple commonResources = beginEvent.getProcessInstance().getAssignedResources().get(beginEvent.getSource());
            Set<String> resourceStrings = commonResources.getResourceObjects().stream().map(res -> res.getResourceType() + "_" + res.getId()).collect(Collectors.toSet());
            ProcessNodeInfo info;
            info = new ProcessNodeInfo(nodeId, processScopeNodeId, beginEvent.getSource(), timestamp, taskName, resourceStrings, transition);
            model.addNodeInfo(processModel, beginEvent.getProcessInstance(), info);
        }
    }
}
Also used : SimulationUtils(de.hpi.bpt.scylla.simulation.utils.SimulationUtils) TaskEvent(de.hpi.bpt.scylla.simulation.event.TaskEvent) HashSet(java.util.HashSet) ResourceObjectTuple(de.hpi.bpt.scylla.simulation.ResourceObjectTuple) BPMNEvent(de.hpi.bpt.scylla.simulation.event.BPMNEvent) DateTimeUtils(de.hpi.bpt.scylla.simulation.utils.DateTimeUtils) TaskEnableEvent(de.hpi.bpt.scylla.simulation.event.TaskEnableEvent) BPMNIntermediateEvent(de.hpi.bpt.scylla.simulation.event.BPMNIntermediateEvent) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) TaskBeginEvent(de.hpi.bpt.scylla.simulation.event.TaskBeginEvent) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) TaskCancelEvent(de.hpi.bpt.scylla.simulation.event.TaskCancelEvent) TimeInstant(desmoj.core.simulator.TimeInstant) ProcessNodeTransitionType(de.hpi.bpt.scylla.logger.ProcessNodeTransitionType) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) Set(java.util.Set) BPMNEndEvent(de.hpi.bpt.scylla.simulation.event.BPMNEndEvent) Collectors(java.util.stream.Collectors) BPMNStartEvent(de.hpi.bpt.scylla.simulation.event.BPMNStartEvent) List(java.util.List) ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) Model(desmoj.core.simulator.Model) ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) TaskEnableEvent(de.hpi.bpt.scylla.simulation.event.TaskEnableEvent) TaskBeginEvent(de.hpi.bpt.scylla.simulation.event.TaskBeginEvent) TaskCancelEvent(de.hpi.bpt.scylla.simulation.event.TaskCancelEvent) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent) ResourceObjectTuple(de.hpi.bpt.scylla.simulation.ResourceObjectTuple) ProcessNodeTransitionType(de.hpi.bpt.scylla.logger.ProcessNodeTransitionType) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 4 with TaskTerminateEvent

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

the class BatchTBPlugin method eventRoutine.

@Override
public void eventRoutine(TaskBeginEvent event, ProcessInstance processInstance) throws ScyllaRuntimeException {
    if (BatchPluginUtils.isBatchActivityEvent(event))
        return;
    // System.out.println(event + " with display name " + event.getDisplayName() + " || " + event.getNextEventMap() + " and source " + event.getSource());
    BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
    ProcessSimulationComponents simulationComponents = event.getSimulationComponents();
    // SimulationModel model = (SimulationModel) desmojEvent.getModel();
    int nodeId = event.getNodeId();
    ProcessModel processModel = processInstance.getProcessModel();
    BatchCluster cluster = pluginInstance.getCluster(processInstance);
    if (cluster == null)
        cluster = pluginInstance.getCluster(event);
    if (cluster != null) {
        ProcessInstance parentProcessInstance = processInstance.getParent();
        // If we are the representative (first executed) process instance we add the setUp time for this task
        if (parentProcessInstance == cluster.getResponsibleProcessInstance()) {
            // therefore we fist take a sample of the setUp distribution
            double setUpTimeToAdd = simulationComponents.getSetUpDistributionSample(nodeId);
            TimeUnit unit = simulationComponents.getSetUpDistributionTimeUnit(nodeId);
            TimeSpan setUpTimeToAddAsTimeSpan = new TimeSpan(setUpTimeToAdd, unit);
            // get the old value (this will always be the entry 0 in our map, because it's always the next)
            double standardTime = event.getTimeSpanToNextEventMap().get(0).getTimeAsDouble(TimeUnit.SECONDS);
            // and overwrite the time to the next task in the timeSpanToNextEventMap (=set the calculated time as the new time)
            TimeSpan timeForTaskWithSetUp = new TimeSpan(standardTime + setUpTimeToAddAsTimeSpan.getTimeAsDouble(TimeUnit.SECONDS), TimeUnit.SECONDS);
            event.getTimeSpanToNextEventMap().put(0, timeForTaskWithSetUp);
        }
        cluster.taskBeginEvent(event);
    }
    // SimulationConfiguration simulationConfiguration = desmojObjects.getSimulationConfiguration();
    /*Map<Integer, BatchActivity> batchActivities = (Map<Integer, BatchActivity>) simulationConfiguration
                .getExtensionValue(getName(), "batchActivities");*/
    Map<Integer, BatchActivity> batchActivities = BatchPluginUtils.getBatchActivities(processModel);
    if (batchActivities.containsKey(nodeId) && processModel.getSubProcesses().containsKey(nodeId)) {
        // subprocess plugin wants to schedule BPMNStartEvents for subprocess
        // we prevent it
        Map<Integer, ScyllaEvent> nextEventMap = event.getNextEventMap();
        Map<Integer, TimeSpan> timeSpanToNextEventMap = event.getTimeSpanToNextEventMap();
        for (Integer indexOfSubprocessBPMNStartEvent : nextEventMap.keySet()) {
            ScyllaEvent eventToSchedule = nextEventMap.get(indexOfSubprocessBPMNStartEvent);
            if (eventToSchedule instanceof BPMNStartEvent || eventToSchedule instanceof TaskTerminateEvent) {
                nextEventMap.remove(indexOfSubprocessBPMNStartEvent);
                timeSpanToNextEventMap.remove(indexOfSubprocessBPMNStartEvent);
                break;
            }
        }
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent) TimeSpan(desmoj.core.simulator.TimeSpan) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) TimeUnit(java.util.concurrent.TimeUnit) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) BPMNStartEvent(de.hpi.bpt.scylla.simulation.event.BPMNStartEvent)

Example 5 with TaskTerminateEvent

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

the class BatchPluginUtils method setClusterToRunning.

void setClusterToRunning(BatchCluster bc) {
    // BatchActivity activity = bc.getBatchActivity();
    // String processId = activity.getProcessModel().getId();
    // int nodeId = activity.getNodeId();
    // List<BatchCluster> clusters= batchClusters.get(processId).get(nodeId);
    // // remove from not started
    // BatchActivity activity = bc.getBatchActivity();
    // String processId = activity.getProcessModel().getId();
    // int nodeId = activity.getNodeId();
    // batchClustersNotStarted.get(processId).get(nodeId).remove(bc);
    // 
    // // move to running
    // 
    bc.setState(BatchClusterState.RUNNING);
    bc.setStartTime(bc.presentTime());
    // 
    // Map<Integer, List<BatchCluster>> batchClustersOfProcess = batchClustersRunning.get(processId);
    // if (batchClustersOfProcess == null) {
    // batchClustersOfProcess = batchClustersRunning.put(processId, new HashMap<Integer, List<BatchCluster>>());
    // List<BatchCluster> clusters = batchClustersOfProcess.get(nodeId);
    // if (clusters == null) {
    // clusters = batchClustersOfProcess.put(nodeId, new ArrayList<BatchCluster>());
    // }
    // }
    // create parental subprocess end events and put them on hold
    List<TaskBeginEvent> parentalStartEvents = bc.getParentalStartEvents();
    for (TaskBeginEvent pse : parentalStartEvents) {
        TaskTerminateEvent taskTerminateEvent = new TaskTerminateEvent(pse.getModel(), pse.getSource(), pse.getSimulationTimeOfSource(), pse.getSimulationComponents(), pse.getProcessInstance(), pse.getNodeId());
        bc.getParentalEndEvents().add(taskTerminateEvent);
    }
// parentalStartEvents.clear();
// batchClustersOfProcess.get(nodeId).add(bc);
}
Also used : TaskBeginEvent(de.hpi.bpt.scylla.simulation.event.TaskBeginEvent) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent)

Aggregations

TaskTerminateEvent (de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent)10 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)8 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)7 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)6 TimeSpan (desmoj.core.simulator.TimeSpan)6 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)4 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)4 TaskCancelEvent (de.hpi.bpt.scylla.simulation.event.TaskCancelEvent)4 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)3 BPMNStartEvent (de.hpi.bpt.scylla.simulation.event.BPMNStartEvent)3 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)2 TaskBeginEvent (de.hpi.bpt.scylla.simulation.event.TaskBeginEvent)2 TimeInstant (desmoj.core.simulator.TimeInstant)2 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)1 ProcessNodeInfo (de.hpi.bpt.scylla.logger.ProcessNodeInfo)1 ProcessNodeTransitionType (de.hpi.bpt.scylla.logger.ProcessNodeTransitionType)1 MultipleStartNodesException (de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException)1 NoStartNodeException (de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)1 ResourceObjectTuple (de.hpi.bpt.scylla.simulation.ResourceObjectTuple)1 BPMNEndEvent (de.hpi.bpt.scylla.simulation.event.BPMNEndEvent)1