use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException in project scylla by bptlab.
the class BatchPluginUtils method getDataViewOfInstance.
private Map<String, Object> getDataViewOfInstance(TaskBeginEvent desmojEvent, ProcessInstance processInstance, BatchActivity batchActivity) {
if (batchActivity.getGroupingCharacteristic().isEmpty()) {
return null;
} else {
// ***********
// get the value of the dataObject
// ***********
ProcessModel processModel = processInstance.getProcessModel();
ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
int nodeId = desmojEvent.getNodeId();
boolean showInTrace = desmojEvent.traceIsOn();
SimulationModel model = (SimulationModel) desmojEvent.getModel();
try {
// ***************************
// GET INPUT
// ***************************
// fetch all available data objects
Map<Integer, Object> dataObjects = (Map<Integer, Object>) desmojObjects.getExtensionDistributions().get(DataObjectPluginUtils.PLUGIN_NAME);
Map<String, Object> simulationInput = new HashMap<String, Object>();
// iterate over all available data objects
for (int dataObjectId : dataObjects.keySet()) {
// fetch all data fields
Map<String, DataObjectField> dataObjectFields = (Map<String, DataObjectField>) dataObjects.get(dataObjectId);
String dataObjectName = processModel.getDisplayNames().get(dataObjectId);
for (String fieldName : dataObjectFields.keySet()) {
// create the key by concatenating dataObjectName + fieldName and assure that the first letter is lower case
String key = dataObjectName + "." + fieldName;
// handle the distribution of every data field
DataObjectField dataObjectField = dataObjectFields.get(fieldName);
DataDistributionWrapper distWrapper = dataObjectField.getDataDistributionWrapper();
try {
simulationInput.put(key, distWrapper.getSample());
} catch (ScyllaRuntimeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Map<String, Object> dataView = new HashMap<String, Object>();
for (String dataViewElement : batchActivity.getGroupingCharacteristic()) {
dataView.put(dataViewElement, simulationInput.get(dataViewElement));
}
return dataView;
} catch (ScyllaValidationException e) {
System.err.println(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
return null;
}
}
}
use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException in project scylla by bptlab.
the class BoundaryEventPluginUtils method createTimerBoundaryEvents.
// I did not touch this for now. Hopefully could be deleted in future.
private void createTimerBoundaryEvents(SimulationModel model, BoundaryObject bo, double startOfInterval, double endOfInterval) throws ScyllaRuntimeException {
double beginTimeOfTask = bo.getBeginTimeOfTask();
ProcessSimulationComponents desmojObjects = bo.getDesmojObjects();
ProcessModel processModel = desmojObjects.getProcessModel();
Map<Integer, EventType> eventTypes = processModel.getEventTypes();
Map<Integer, Boolean> cancelActivities = processModel.getCancelActivities();
List<Integer> referenceToBoundaryEvents = bo.getReferenceToBoundaryEvents();
for (Integer nId : referenceToBoundaryEvents) {
boolean timerEventIsInterrupting = false;
EventType eventType = eventTypes.get(nId);
if (eventType == EventType.BOUNDARY) {
Map<EventDefinitionType, Map<String, String>> eventDefinitions = processModel.getEventDefinitions().get(nId);
Map<String, String> definitionAttributes = eventDefinitions.get(EventDefinitionType.TIMER);
if (definitionAttributes != null) {
// if boundary event is timer event
double timeUntilWhenTimerEventsAreCreated = bo.getTimeUntilWhenTimerEventsAreCreated();
if (definitionAttributes.get("timeDuration") != null) {
// ISO 8601 duration
String timeDuration = definitionAttributes.get("timeDuration");
if (beginTimeOfTask != timeUntilWhenTimerEventsAreCreated) {
// timer event has already been created once, skip
continue;
}
Duration javaDuration = Duration.parse(timeDuration);
double duration = javaDuration.get(ChronoUnit.SECONDS);
if (duration == 0) {
continue;
}
double timeToSchedule = beginTimeOfTask + duration;
if (timeToSchedule < endOfInterval) {
String displayName = processModel.getDisplayNames().get(nId);
if (displayName == null) {
displayName = processModel.getIdentifiers().get(nId);
}
String source = bo.getSource();
ProcessInstance processInstance = bo.getProcessInstance();
TimeInstant timeInstant = new TimeInstant(startOfInterval, TimeUnit.SECONDS);
BPMNIntermediateEvent event = new BPMNIntermediateEvent(model, source, timeInstant, desmojObjects, processInstance, nId);
bo.getBoundaryEventsToSchedule().computeIfAbsent(timeToSchedule, k -> new ArrayList<BPMNIntermediateEvent>());
bo.getBoundaryEventsToSchedule().get(timeToSchedule).add(event);
String message = "Schedule boundary timer event: " + displayName;
bo.getMessagesOfBoundaryEventsToSchedule().computeIfAbsent(timeToSchedule, k -> new ArrayList<String>());
bo.getMessagesOfBoundaryEventsToSchedule().get(timeToSchedule).add(message);
// timeUntilWhenTimerEventsAreCreated = timeToSchedule;
}
// TODO fix boundary
timeUntilWhenTimerEventsAreCreated = timeToSchedule;
} else if (definitionAttributes.get("timeCycle") != null) {
// ISO 8601 repeating time interval:
String timeCycle = definitionAttributes.get("timeCycle");
// Rn/[ISO 8601 duration] where n
// (optional) for number of
// recurrences
// ["Rn"], "[ISO 8601 duration]"]
String[] recurrencesAndDuration = timeCycle.split("/");
String recurrencesString = recurrencesAndDuration[0];
String timeDurationString = recurrencesAndDuration[1];
Integer recurrencesMax = null;
if (recurrencesString.length() > 1) {
recurrencesMax = Integer.parseInt(recurrencesString.substring(1, recurrencesString.length()));
timerEventIsInterrupting = cancelActivities.get(nId);
if (timerEventIsInterrupting) {
recurrencesMax = 1;
}
}
Duration javaDuration = Duration.parse(timeDurationString);
double duration = javaDuration.get(ChronoUnit.SECONDS);
if (duration == 0 || recurrencesMax != null && recurrencesMax == 0) {
continue;
}
double timeToSchedule = beginTimeOfTask;
int actualNumberOfOccurrences = 0;
boolean recurrencesMaxExceeded = false;
while (timeToSchedule <= timeUntilWhenTimerEventsAreCreated) {
timeToSchedule += duration;
actualNumberOfOccurrences++;
if (recurrencesMax != null && actualNumberOfOccurrences > recurrencesMax) {
recurrencesMaxExceeded = true;
break;
}
}
if (recurrencesMaxExceeded) {
continue;
}
while (timeToSchedule <= endOfInterval) {
// add as many timer events for scheduling as possible (lots of them if timer event is
// non-interrupting,
// only one if it is interrupting
String displayName = processModel.getDisplayNames().get(nId);
if (displayName == null) {
displayName = processModel.getIdentifiers().get(nId);
}
String source = bo.getSource();
ProcessInstance processInstance = bo.getProcessInstance();
TimeInstant timeInstant = new TimeInstant(startOfInterval, TimeUnit.SECONDS);
BPMNIntermediateEvent event = new BPMNIntermediateEvent(model, source, timeInstant, desmojObjects, processInstance, nId);
bo.getBoundaryEventsToSchedule().computeIfAbsent(timeToSchedule, k -> new ArrayList<BPMNIntermediateEvent>());
bo.getBoundaryEventsToSchedule().get(timeToSchedule).add(event);
String message = "Schedule boundary timer event: " + displayName;
bo.getMessagesOfBoundaryEventsToSchedule().computeIfAbsent(timeToSchedule, k -> new ArrayList<String>());
bo.getMessagesOfBoundaryEventsToSchedule().get(timeToSchedule).add(message);
actualNumberOfOccurrences++;
if (recurrencesMax != null && actualNumberOfOccurrences == recurrencesMax) {
// recurrencesMaxExceeded = true;
break;
}
timeToSchedule += duration;
}
timeUntilWhenTimerEventsAreCreated = timeToSchedule;
} else {
// TODO support timeDate attributes?
String identifier = processModel.getIdentifiers().get(nId);
DebugLogger.log("Timer event " + identifier + " has no timer definition, skip.");
continue;
}
bo.setTimeUntilWhenTimerEventsAreCreated(timeUntilWhenTimerEventsAreCreated);
}
}
}
}
use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException in project scylla by bptlab.
the class DataObjectTaskTerminate method eventRoutine.
@SuppressWarnings("unchecked")
@Override
public /* collect all fields of all dataobjects and simulate them with the given desmoj distribution. After that, pass them to the XES Logger */
void eventRoutine(TaskTerminateEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
ProcessModel processModel = processInstance.getProcessModel();
// int processInstanceId = processInstance.getId();
try {
if (processModel.getDataObjectsGraph().getNodes().containsKey(desmojEvent.getNodeId())) {
Set<Integer> refferingObjects = processModel.getDataObjectsGraph().getTargetObjects(desmojEvent.getNodeId());
Collection<Object> allFields = desmojEvent.getDesmojObjects().getExtensionDistributions().get("dataobject").values();
for (Object fields : allFields) {
Integer i = 0;
while (((Map<String, Map<Integer, DataObjectField>>) fields).values().toArray().length - i != 0) {
DataObjectField field = (DataObjectField) ((Map<String, Map<Integer, DataObjectField>>) fields).values().toArray()[i];
if (refferingObjects.contains(field.getNodeId())) {
// System.out.println(processInstance.getId() + " " + desmojEvent.getDisplayName() + " " + processModel.getDisplayNames().get(field.getNodeId()) + " " + field.getDataDistributionWrapper().getSample());
SimulationModel model = (SimulationModel) desmojEvent.getModel();
Collection<Map<Integer, java.util.List<ProcessNodeInfo>>> allProcesses = model.getProcessNodeInfos().values();
for (Map<Integer, java.util.List<ProcessNodeInfo>> process : allProcesses) {
List<ProcessNodeInfo> currentProcess = process.get(processInstance.getId());
for (ProcessNodeInfo task : currentProcess) {
// System.out.println(processModel.getDisplayNames().get(processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray()[0]) + " " + task.getTaskName());
for (Integer j = 0; j < processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray().length; j++) {
if (task.getId().equals(processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray()[j]) && task.getTransition() == ProcessNodeTransitionType.TERMINATE) {
// check all tasks and find the ones that may be looged; already logged ones will get ignored next line
if (!task.getDataObjectField().containsKey(processModel.getDisplayNames().get(field.getNodeId()) + "." + field.getFieldName())) {
// don't log if task already has this field logged
Map<String, Object> fieldSample = new HashMap<String, Object>();
Object currentSample = field.getDataDistributionWrapper().getSample();
// log Value at TaskTerminate
fieldSample.put(processModel.getDisplayNames().get(field.getNodeId()) + "." + field.getFieldName(), currentSample);
task.SetDataObjectField(fieldSample);
// set current DataObjectFieldValue
DataObjectField.addDataObjectValue(processInstance.getId(), fieldSample.keySet().toArray()[0].toString(), currentSample);
}
}
}
}
}
}
i++;
}
}
} else {
// do nothing and continue with the next task because Node has no dataobejcts
}
} catch (ScyllaRuntimeException | ScyllaValidationException | NodeNotFoundException e) {
e.printStackTrace();
}
}
use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException in project scylla by bptlab.
the class ProcessInstance method cancel.
// public double getTimeRelativeToSubProcessStart() {
// return timeRelativeToSubProcessStart;
// }
//
// public void setTimeRelativeToSubProcessStart(double timeRelativeToSubProcessStart) {
// this.timeRelativeToSubProcessStart = timeRelativeToSubProcessStart;
// }
//
// public Double getEndTimeRelativeToSubProcessStart() {
// return endTimeRelativeToSubProcessStart;
// }
//
// public void setEndTimeRelativeToSubProcessStart(Double endTimeRelativeToSubProcessStart) {
// this.endTimeRelativeToSubProcessStart = endTimeRelativeToSubProcessStart;
// }
@Override
public void cancel() {
try {
Iterator<String> iterator = children.keySet().iterator();
while (iterator.hasNext()) {
String name = iterator.next();
ProcessInstance child = children.get(name);
child.cancel();
}
if (isScheduled()) {
List<EventAbstract> scheduledEvents = getScheduledEvents();
List<ScyllaEvent> rescheduledEvents = new ArrayList<ScyllaEvent>();
for (EventAbstract e : scheduledEvents) {
if (e instanceof TaskEvent) {
TaskEvent event = (TaskEvent) e;
TaskCancelEvent cancelEvent = new TaskCancelEvent(event.getModel(), event.getSource(), event.getSimulationTimeOfSource(), event.getDesmojObjects(), this, event.getNodeId());
rescheduledEvents.add(cancelEvent);
}
}
super.cancel();
for (ScyllaEvent event : rescheduledEvents) {
TimeSpan timeSpan = new TimeSpan(0);
SimulationUtils.scheduleEvent(event, timeSpan);
}
}
if (parent != null) {
parent.removeChild(this);
}
} catch (ScyllaRuntimeException e) {
throw new RuntimeException(e);
}
}
use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException in project scylla by bptlab.
the class GatewayEvent method eventRoutine.
@Override
public void eventRoutine(ProcessInstance processInstance) throws SuspendExecution {
SimulationModel model = (SimulationModel) getModel();
ProcessModel processModel = processInstance.getProcessModel();
try {
Set<Integer> idsOfPreviousNodes = processModel.getIdsOfPreviousNodes(nodeId);
Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
String message = null;
GatewayType type = processModel.getGateways().get(nodeId);
String convergeDivergeName = "Join and Split";
if (idsOfPreviousNodes.size() == 1) {
convergeDivergeName = "Split";
} else if (idsOfNextNodes.size() == 1) {
convergeDivergeName = "Join";
}
if (type == GatewayType.DEFAULT) {
message = "Default " + convergeDivergeName + " Gateway: " + displayName;
}
if (type == GatewayType.EXCLUSIVE) {
message = "Exclusive " + convergeDivergeName + " Gateway: " + displayName;
} else if (type == GatewayType.EVENT_BASED) {
message = "Eventbased " + convergeDivergeName + " Gateway: " + displayName;
} else if (type == GatewayType.INCLUSIVE) {
message = "Inclusive " + convergeDivergeName + " Gateway: " + displayName;
} else if (type == GatewayType.PARALLEL) {
message = "Parallel " + convergeDivergeName + " Gateway: " + displayName;
} else if (type == GatewayType.COMPLEX) {
message = "Complex " + convergeDivergeName + " Gateway: " + displayName;
} else {
// TODO write to log because element not supported
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
sendTraceNote(message);
// i.e. for splits: default behavior is the one of a parallel gateway
for (Integer nextNodeId : idsOfNextNodes) {
List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(this, pSimComponents, processInstance, nextNodeId);
// next DesmoJ event occurs immediately after start event
TimeSpan timeSpan = new TimeSpan(0);
for (ScyllaEvent event : events) {
int index = getNewEventIndex();
nextEventMap.put(index, event);
timeSpanToNextEventMap.put(index, timeSpan);
}
}
GatewayEventPluggable.runPlugins(this, processInstance);
scheduleNextEvents();
} catch (NodeNotFoundException | ScyllaValidationException | ScyllaRuntimeException e) {
System.err.println(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
}
Aggregations