Search in sources :

Example 11 with ScyllaRuntimeException

use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException in project scylla by bptlab.

the class DataDistributionWrapper method getSample.

/*public void setMin(double min) {
		this.min = min;
	}
	
	public void setMax(double max) {
		this.max = max;
	}*/
public Object getSample() throws ScyllaRuntimeException, ScyllaValidationException {
    if (desmojDistribution == null) {
        throw new ScyllaRuntimeException("desmojDistribution is not set.");
    }
    double value;
    /*do{
			value = desmojDistribution.sample().doubleValue();
		} while(min > value || value > max);*/
    // generate data in the given range with the given distribution, project it
    // value = min + (max-min) * ((desmojDistribution.sample().doubleValue() - Double.MAX_VALUE)/(Double.MAX_VALUE - Double.MAX_VALUE));
    value = desmojDistribution.sample().doubleValue();
    if (type == DataDistributionType.LONG) {
        return Math.round(value);
    } else // handle STRING samples
    if (type == DataDistributionType.STRING) {
        if (!(distribution instanceof EmpiricalStringDistribution)) {
            throw new ScyllaValidationException("Distribution is not an empirical string distribution, but the distribution type is String.");
        }
        EmpiricalStringDistribution es = (EmpiricalStringDistribution) distribution;
        return es.getNames().get(value);
    } else // handle BOOLEAN samples
    if (type == DataDistributionType.BOOLEAN) {
        if (!(distribution instanceof EmpiricalDistribution)) {
            throw new ScyllaValidationException("Distribution is not an empirical distribution, but the distribution type is Boolean.");
        }
        EmpiricalDistribution es = (EmpiricalDistribution) distribution;
        if (es.getEntries().size() != 2 || !es.getEntries().containsKey(1.0) || !es.getEntries().containsKey(0.0)) {
            throw new ScyllaValidationException("Distribution does not match the requirements for Boolean distribution type.");
        }
        return (value == 1.0);
    } else // handle default DOUBLE samples
    {
        return value;
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) EmpiricalDistribution(de.hpi.bpt.scylla.model.configuration.distribution.EmpiricalDistribution) EmpiricalStringDistribution(de.hpi.bpt.scylla.model.configuration.distribution.EmpiricalStringDistribution)

Example 12 with ScyllaRuntimeException

use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException in project scylla by bptlab.

the class DataObjectBPMNIntermediateEvent method eventRoutine.

@Override
public void eventRoutine(BPMNIntermediateEvent 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.EVENT_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();
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) java.util(java.util) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 13 with ScyllaRuntimeException

use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException in project scylla by bptlab.

the class DataObjectBPMNStartEvent method eventRoutine.

@Override
public void eventRoutine(BPMNStartEvent 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.EVENT_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();
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) java.util(java.util) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 14 with ScyllaRuntimeException

use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException in project scylla by bptlab.

the class EventOrderPriority method compare.

@Override
public int compare(String resourceId, ScyllaEvent e1, ScyllaEvent e2) throws ScyllaRuntimeException {
    SimulationModel model = (SimulationModel) e1.getModel();
    if (!model.equals((SimulationModel) e2.getModel())) {
        throw new ScyllaRuntimeException("New event for queue is attached to another simulation model.");
    }
    Integer priorityOfFirstEvent = null;
    Set<ResourceReference> resourceRefsOfFirstEvent = e1.getDesmojObjects().getSimulationConfiguration().getResourceReferenceSet(e1.getNodeId());
    for (ResourceReference resourceRef : resourceRefsOfFirstEvent) {
        if (resourceId.equals(resourceRef.getResourceId())) {
            String priorityString = resourceRef.getAssignmentDefinition().get("priority");
            if (priorityString == null) {
                priorityOfFirstEvent = -1;
            } else {
                priorityOfFirstEvent = Integer.parseInt(resourceRef.getAssignmentDefinition().get("priority"));
            }
        }
    }
    Integer priorityOfSecondEvent = null;
    Set<ResourceReference> resourceRefsOfSecondEvent = e2.getDesmojObjects().getSimulationConfiguration().getResourceReferenceSet(e2.getNodeId());
    for (ResourceReference resourceRef : resourceRefsOfSecondEvent) {
        if (resourceId.equals(resourceRef.getResourceId())) {
            String priorityString = resourceRef.getAssignmentDefinition().get("priority");
            if (priorityString == null) {
                priorityOfSecondEvent = -1;
            } else {
                priorityOfSecondEvent = Integer.parseInt(resourceRef.getAssignmentDefinition().get("priority"));
            }
        }
    }
    // higher value is sorted first
    return priorityOfSecondEvent - priorityOfFirstEvent;
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ResourceReference(de.hpi.bpt.scylla.model.configuration.ResourceReference) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 15 with ScyllaRuntimeException

use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException in project scylla by bptlab.

the class SubprocessBPMNEEPlugin method eventRoutine.

@Override
public void eventRoutine(BPMNEndEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    ProcessModel processModel = processInstance.getProcessModel();
    if (processModel.getParent() != null && processInstanceIsCompleted(processInstance)) {
        // works
        try {
            ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
            ProcessSimulationComponents parentDesmojObjects = desmojObjects.getParent();
            ProcessModel parentModel = processModel.getParent();
            int nodeIdInParent = processModel.getNodeIdInParent();
            ProcessInstance parentProcessInstance = processInstance.getParent();
            // behavior when sub-process sends events:
            // none -> back to normal flow
            // message -> "send it"
            // error -> to parent
            // escalation -> to parent
            // cancel -> nonono!
            // compensation -> ... not now
            // signal -> ... not now
            // terminate -> terminate sub-process (kill all events of sub-process instance (MI sub-process
            // not affected))
            // ...
            // timer -> special treatment
            Set<Integer> idsOfNextNodes = parentModel.getIdsOfNextNodes(nodeIdInParent);
            // normal flow: must not have more than one successor
            if (idsOfNextNodes.size() != 1) {
                int nodeId = desmojEvent.getNodeId();
                throw new ScyllaValidationException("Subprocess " + nodeId + " does not have 1 successor, but " + idsOfNextNodes.size() + ".");
            }
            Integer nextNodeId = idsOfNextNodes.iterator().next();
            // TODO let the parent create the next node, so remove the lines below
            List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(desmojEvent, parentDesmojObjects, parentProcessInstance, nextNodeId);
            // next event occurs immediately after start event
            TimeSpan timeSpan = new TimeSpan(0);
            String parentProcessInstanceName = parentProcessInstance.getName();
            SubprocessPluginUtils pluginInstance = SubprocessPluginUtils.getInstance();
            TaskTerminateEvent eventOfParent = pluginInstance.getEventsOnHold().get(parentProcessInstanceName).get(nodeIdInParent);
            if (eventOfParent != null) {
                events.add(eventOfParent);
                pluginInstance.getEventsOnHold().get(parentProcessInstanceName).remove(nodeIdInParent);
                pluginInstance.getNameOfEventsThatWereOnHold().add(eventOfParent.getName());
            }
            for (ScyllaEvent event : events) {
                int index = desmojEvent.getNewEventIndex();
                desmojEvent.getNextEventMap().put(index, event);
                desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
            }
        } catch (NodeNotFoundException | ScyllaValidationException | ScyllaRuntimeException e) {
            SimulationModel model = (SimulationModel) desmojEvent.getModel();
            int nodeId = desmojEvent.getNodeId();
            boolean showInTrace = model.traceIsOn();
            DebugLogger.error(e.getMessage());
            e.printStackTrace();
            SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
        }
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) 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) 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) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Aggregations

ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)24 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)21 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)18 TimeSpan (desmoj.core.simulator.TimeSpan)13 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)10 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)10 TimeInstant (desmoj.core.simulator.TimeInstant)8 HashSet (java.util.HashSet)8 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)7 Map (java.util.Map)7 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)5 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)5 ProcessNodeInfo (de.hpi.bpt.scylla.logger.ProcessNodeInfo)4 EventDefinitionType (de.hpi.bpt.scylla.model.process.node.EventDefinitionType)4 TaskType (de.hpi.bpt.scylla.model.process.node.TaskType)4 ArrayList (java.util.ArrayList)4 EventType (de.hpi.bpt.scylla.model.process.node.EventType)3 BPMNIntermediateEvent (de.hpi.bpt.scylla.simulation.event.BPMNIntermediateEvent)3 HashMap (java.util.HashMap)3 List (java.util.List)3