use of io.kubernetes.client.proto.V1.Namespace in project scylla by bptlab.
the class DataObjectSCParserPlugin method parse.
@Override
public /* pasrses the datobjects and creates the distWrapper*/
Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
Namespace simNamespace = sim.getNamespace();
ProcessModel processModel = simulationInput.getProcessModel();
Map<Integer, Map<String, DataObjectField>> dataObjects = new HashMap<Integer, Map<String, DataObjectField>>();
for (Element el : sim.getChildren()) {
String elementName = el.getName();
if (elementName.equals("dataObject") || elementName.equals("dataInput")) {
String identifier = el.getAttributeValue("id");
if (identifier == null) {
DebugLogger.log("Warning: Simulation configuration definition element '" + elementName + "' does not have an identifier, skip.");
// no matching element in process, so skip definition
continue;
}
Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
if (nodeId == null) {
DebugLogger.log("Simulation configuration definition for process element '" + identifier + "', but not available in process, skip.");
// no matching element in process, so skip definition
continue;
}
Map<String, DataObjectField> dataObjectFields = new HashMap<String, DataObjectField>();
for (Element field : el.getChildren("field", simNamespace)) {
String fieldName = field.getAttributeValue("name");
String fieldType = field.getAttributeValue("type");
DataDistributionType dataDistributionType = DataDistributionType.getEnum(fieldType);
DataDistributionWrapper distWrapper = new DataDistributionWrapper(dataDistributionType);
for (Element fieldElement : field.getChildren()) {
if (fieldElement.getName().endsWith("Distribution")) {
Distribution distribution = SimulationConfigurationParser.getDistribution(field, simNamespace, fieldType);
distWrapper.setDistribution(distribution);
}
/*else if (fieldElement.getName().equals("range")) {
try{
double min = Double.parseDouble(fieldElement.getAttributeValue("min"));
distWrapper.setMin(min);
} catch (NumberFormatException e) {
// do nothing: min was not set and is automatically -Double.MAX_VALUE
}
try{
double max = Double.parseDouble(fieldElement.getAttributeValue("max"));
distWrapper.setMax(max);
} catch (NumberFormatException e) {
// do nothing: max was not set and is automatically Double.MAX_VALUE
}
Distribution distribution = new UniformDistribution(distWrapper.getMin(), distWrapper.getMax());
distWrapper.setDistribution(distribution);
}*/
}
dataObjectFields.put(fieldName, new DataObjectField(distWrapper, nodeId, fieldName, fieldType));
}
dataObjects.put(nodeId, dataObjectFields);
}
}
// System.out.println(processModel.getDataObjectsGraph().print());
HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
extensionAttributes.put("dataObjects", dataObjects);
return extensionAttributes;
}
use of io.kubernetes.client.proto.V1.Namespace in project scylla by bptlab.
the class ExclusiveGatewaySCParserPlugin method parse.
@Override
public Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
Map<Integer, BranchingBehavior> branchingBehaviors = new HashMap<Integer, BranchingBehavior>();
Namespace simNamespace = sim.getNamespace();
ProcessModel processModel = simulationInput.getProcessModel();
for (Element el : sim.getChildren()) {
String elementName = el.getName();
if (elementName.equals("exclusiveGateway")) {
String identifier = el.getAttributeValue("id");
if (identifier == null) {
DebugLogger.log("Warning: Simulation configuration definition element '" + elementName + "' does not have an identifier, skip.");
// no matching element in process, so skip definition
continue;
}
Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
if (nodeId == null) {
DebugLogger.log("Simulation configuration definition for process element '" + identifier + "', but not available in process, skip.");
// no matching element in process, so skip definition
continue;
}
List<Element> outgoingSequenceFlows = el.getChildren("outgoingSequenceFlow", simNamespace);
if (outgoingSequenceFlows.size() > 0) {
Map<Integer, Double> branchingProbabilities = new HashMap<Integer, Double>();
Double probabilitySum = 0d;
for (Element elem : outgoingSequenceFlows) {
Integer nodeIdOfSequenceFlow = processModel.getIdentifiersToNodeIds().get(elem.getAttributeValue("id"));
if (nodeIdOfSequenceFlow != null) {
Double branchingProbability = Double.parseDouble(elem.getChildText("branchingProbability", simNamespace));
if (branchingProbability < 0 || branchingProbability > 1) {
throw new ScyllaValidationException("Exclusive gateway branching probability for " + identifier + " is out of bounds [0,1].");
}
probabilitySum += branchingProbability;
branchingProbabilities.put(nodeIdOfSequenceFlow, branchingProbability);
}
}
if (probabilitySum <= 0) {
throw new ScyllaValidationException("Simulation configuration defines branching probabilities for exclusive gateway " + identifier + ", where the sum of probabilities is negative or zero.");
}
if (probabilitySum > 1) {
// XXX imprecision by IEEE 754 floating point representation
throw new ScyllaValidationException("Simulation configuration defines branching probabilities for exclusive gateway " + identifier + ", exceeding 1 in total.");
}
// complete probabilities with the default flow probability
if (probabilitySum > 0 && probabilitySum <= 1) {
Map<String, String> gatewayAttributes = processModel.getNodeAttributes().get(nodeId);
String defaultFlowIdentifier = gatewayAttributes.get("default");
if (defaultFlowIdentifier != null) {
double probabilityOfDefaultFlow = 1 - probabilitySum;
int defaultFlowNodeId = processModel.getIdentifiersToNodeIds().get(defaultFlowIdentifier);
if (!branchingProbabilities.containsKey(defaultFlowNodeId)) {
branchingProbabilities.put(defaultFlowNodeId, probabilityOfDefaultFlow);
} else {
branchingProbabilities.put(defaultFlowNodeId, branchingProbabilities.get(defaultFlowNodeId) + probabilityOfDefaultFlow);
}
;
}
}
try {
if (branchingProbabilities.keySet().size() != processModel.getIdsOfNextNodes(nodeId).size()) {
throw new ScyllaValidationException("Number of branching probabilities defined in simulation configuration " + "does not match to number of outgoing flows of exclusive gateway " + identifier + ".");
}
} catch (NodeNotFoundException e) {
throw new ScyllaValidationException("Node not found: " + e.getMessage());
}
BranchingBehavior branchingBehavior = new BranchingBehavior(branchingProbabilities);
branchingBehaviors.put(nodeId, branchingBehavior);
}
}
}
HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
extensionAttributes.put("branchingBehaviors", branchingBehaviors);
return extensionAttributes;
}
use of io.kubernetes.client.proto.V1.Namespace in project scylla by bptlab.
the class InclusiveGatewaySCParserPlugin method parse.
@Override
public Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
Map<Integer, BranchingBehavior> branchingBehaviors = new HashMap<Integer, BranchingBehavior>();
Namespace simNamespace = sim.getNamespace();
ProcessModel processModel = simulationInput.getProcessModel();
for (Element el : sim.getChildren()) {
String elementName = el.getName();
if (elementName.equals("inclusiveGateway")) {
String identifier = el.getAttributeValue("id");
if (identifier == null) {
DebugLogger.log("Warning: Simulation configuration definition element '" + elementName + "' does not have an identifier, skip.");
// no matching element in process, so skip definition
continue;
}
Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
if (nodeId == null) {
DebugLogger.log("Simulation configuration definition for process element '" + identifier + "', but not available in process, skip.");
// no matching element in process, so skip definition
continue;
}
List<Element> outgoingSequenceFlows = el.getChildren("outgoingSequenceFlow", simNamespace);
if (outgoingSequenceFlows.size() > 0) {
Map<Integer, Double> branchingProbabilities = new HashMap<Integer, Double>();
for (Element elem : outgoingSequenceFlows) {
Integer nodeIdOfSequenceFlow = processModel.getIdentifiersToNodeIds().get(elem.getAttributeValue("id"));
if (nodeIdOfSequenceFlow != null) {
Double branchingProbability = Double.valueOf(elem.getChildText("branchingProbability", simNamespace));
if (branchingProbability < 0 || branchingProbability > 1) {
throw new ScyllaValidationException("Inclusive gateway branching probability for " + identifier + " is out of bounds [0,1].");
}
branchingProbabilities.put(nodeIdOfSequenceFlow, branchingProbability);
}
}
BranchingBehavior branchingBehavior = new BranchingBehavior(branchingProbabilities);
branchingBehaviors.put(nodeId, branchingBehavior);
}
}
}
HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
extensionAttributes.put("branchingBehaviors", branchingBehaviors);
return extensionAttributes;
}
use of io.kubernetes.client.proto.V1.Namespace in project scylla by bptlab.
the class SimulationConfigurationParserPluggable method runPlugins.
public static void runPlugins(SimulationManager simEnvironment, SimulationConfiguration simulationConfiguration, Document document) throws ScyllaValidationException {
Namespace simNamespace = document.getRootElement().getNamespace();
List<Element> simElements = document.getRootElement().getChildren("simulationConfiguration", simNamespace);
Element sim = simElements.get(0);
String processRef = sim.getAttributeValue("processRef");
ProcessModel processModel = simEnvironment.getProcessModels().get(processRef);
runPluginsPerSC(simEnvironment, simulationConfiguration, processModel, sim);
}
use of io.kubernetes.client.proto.V1.Namespace in project scylla by bptlab.
the class GlobalConfigurationParser method parse.
@Override
public GlobalConfiguration parse(Element rootElement) throws ScyllaValidationException {
System.out.println(rootElement.getNamespace());
Iterator<EventOrderType> eventOrderTypesIterator = PluginLoader.dGetPlugins(EventOrderType.class);
// ServiceLoader.load(EventOrderType.class).iterator();
// Get all event order type plugins and store them in eventOrderTypes
Map<String, EventOrderType> eventOrderTypes = new HashMap<String, EventOrderType>();
while (eventOrderTypesIterator.hasNext()) {
EventOrderType eot = eventOrderTypesIterator.next();
eventOrderTypes.put(eot.getName(), eot);
}
Namespace bsimNamespace = rootElement.getNamespace();
List<Element> globalConfigurationElements = rootElement.getChildren(null, bsimNamespace);
String globalConfId = rootElement.getAttributeValue("id");
Long randomSeed = null;
ZoneId zoneId = ZoneId.of("UTC");
Map<String, Resource> resources = new HashMap<String, Resource>();
List<EventOrderType> resourceAssignmentOrder = new ArrayList<EventOrderType>();
// resourceId:[instanceName:timetableId]
Map<String, Map<String, String>> resourcesToTimetableIds = new HashMap<String, Map<String, String>>();
Map<String, List<TimetableItem>> timetables = new HashMap<String, List<TimetableItem>>();
for (Element el : globalConfigurationElements) {
String elementName = el.getName();
if (isKnownElement(elementName)) {
if (el.getText().isEmpty()) {
continue;
}
if (elementName.equals("resourceAssignmentOrder")) {
String resourceAssignmentOrderString = el.getText();
String[] orderTypeArray = resourceAssignmentOrderString.split(",");
for (String orderTypeName : orderTypeArray) {
if (orderTypeName.isEmpty()) {
continue;
}
EventOrderType eventOrderType = eventOrderTypes.get(orderTypeName);
if (eventOrderType == null) {
throw new ScyllaValidationException("Event order type " + orderTypeName + " for resource assignment is unknown.");
}
resourceAssignmentOrder.add(eventOrderType);
}
} else if (elementName.equals("randomSeed")) {
randomSeed = Long.parseLong(el.getText());
} else if (elementName.equals("zoneOffset")) {
zoneId = ZoneId.of("GMT" + el.getText());
} else if (elementName.equals("resourceData")) {
List<Element> rDataElements = el.getChildren();
for (Element elem : rDataElements) {
String resourceId = elem.getAttributeValue("id");
String rDataElementName = elem.getName();
if (rDataElementName.equals("dynamicResource")) {
String resourceName = elem.getAttributeValue("name");
Integer defaultQuantity = Integer.valueOf(elem.getAttributeValue("defaultQuantity"));
Double defaultCost = Double.valueOf(elem.getAttributeValue("defaultCost"));
TimeUnit defaultTimeUnit = TimeUnit.valueOf(elem.getAttributeValue("defaultTimeUnit"));
DynamicResource dynamicResource = new DynamicResource(resourceId, resourceName, defaultQuantity, defaultCost, defaultTimeUnit);
String defaultTimetableId = elem.getAttributeValue("defaultTimetableId");
if (resourcesToTimetableIds.containsKey(resourceId)) {
throw new ScyllaValidationException("Multiple resource definitions: " + resourceId);
}
resourcesToTimetableIds.put(resourceId, new HashMap<String, String>());
Map<String, DynamicResourceInstance> resourceInstances = dynamicResource.getResourceInstances();
List<Element> instanceElements = elem.getChildren("instance", bsimNamespace);
// fill up list of resource instances if not explicitly defined
if (instanceElements.size() > defaultQuantity) {
throw new ScyllaValidationException("Too many instances defined for resource " + resourceId);
}
int numberOfDefaultInstances = defaultQuantity - instanceElements.size();
for (int i = 0; i < numberOfDefaultInstances; i++) {
String name = "#" + i;
DynamicResourceInstance instance = new DynamicResourceInstance(defaultCost, defaultTimeUnit);
resourceInstances.put(name, instance);
if (defaultTimetableId != null) {
resourcesToTimetableIds.get(resourceId).put(name, defaultTimetableId);
}
}
// parse defined resource instances
for (Element element : instanceElements) {
String name = element.getAttributeValue("name");
if (name == null) {
throw new ScyllaValidationException("Resource instance of type " + resourceId + " does not have name.");
}
Double cost;
if (element.getAttributeValue("cost") == null) {
cost = defaultCost;
} else {
cost = Double.valueOf(element.getAttributeValue("cost"));
}
TimeUnit timeUnit;
if (element.getAttributeValue("timeUnit") == null) {
timeUnit = defaultTimeUnit;
} else {
timeUnit = TimeUnit.valueOf(element.getAttributeValue("timeUnit"));
}
DynamicResourceInstance instance = new DynamicResourceInstance(cost, timeUnit);
if (resourceInstances.containsKey(name)) {
throw new ScyllaValidationException("Duplicate resource instance: " + name);
}
resourceInstances.put(name, instance);
String timetableId = element.getAttributeValue("timetableId");
if (timetableId != null) {
resourcesToTimetableIds.get(resourceId).put(name, timetableId);
}
}
resources.put(resourceId, dynamicResource);
} else {
DebugLogger.log("Element " + elem.getName() + " of resource data is expected to be known, but not supported.");
}
}
} else if (elementName.equals("timetables")) {
List<Element> tElements = el.getChildren("timetable", bsimNamespace);
for (Element tElement : tElements) {
String timetableId = tElement.getAttributeValue("id");
List<TimetableItem> items = new ArrayList<TimetableItem>();
List<Element> tItemElements = tElement.getChildren("timetableItem", bsimNamespace);
for (Element tItemElement : tItemElements) {
DayOfWeek weekdayFrom = DayOfWeek.valueOf(tItemElement.getAttributeValue("from"));
DayOfWeek weekdayTo = DayOfWeek.valueOf(tItemElement.getAttributeValue("to"));
LocalTime beginTime = LocalTime.parse(tItemElement.getAttributeValue("beginTime"));
LocalTime endTime = LocalTime.parse(tItemElement.getAttributeValue("endTime"));
// TODO check for overlapping timetable items and handle them
if (DateTimeUtils.compareWeekdayTime(weekdayFrom, beginTime, weekdayTo, endTime) != 0) {
if (weekdayFrom.compareTo(weekdayTo) > 0) {
// e.g. FRIDAY to MONDAY
TimetableItem item = new TimetableItem(weekdayFrom, DayOfWeek.SUNDAY, beginTime, LocalTime.MAX);
items.add(item);
item = new TimetableItem(DayOfWeek.MONDAY, weekdayTo, LocalTime.MIN, endTime);
items.add(item);
} else {
TimetableItem item = new TimetableItem(weekdayFrom, weekdayTo, beginTime, endTime);
items.add(item);
}
}
}
timetables.put(timetableId, items);
}
}
} else {
DebugLogger.log("Element " + el.getName() + " of global configuration is not supported.");
}
}
// match timetables (if any available) and resource data (if any available)s
for (String resourceId : resourcesToTimetableIds.keySet()) {
Map<String, String> resourceInstanceIdToTimetableIds = resourcesToTimetableIds.get(resourceId);
for (String resourceInstanceName : resourceInstanceIdToTimetableIds.keySet()) {
String timetableId = resourceInstanceIdToTimetableIds.get(resourceInstanceName);
if (!timetables.containsKey(timetableId)) {
DebugLogger.log("Timetable " + timetableId + " not found.");
}
List<TimetableItem> timetable = timetables.get(timetableId);
Resource resource = resources.get(resourceId);
if (resource instanceof DynamicResource) {
DynamicResource dResource = (DynamicResource) resource;
dResource.getResourceInstances().get(resourceInstanceName).setTimetable(timetable);
}
}
}
if (resources.isEmpty()) {
throw new ScyllaValidationException("No resource data definitions in file.");
}
if (randomSeed == null) {
Random random = new Random();
randomSeed = random.nextLong();
}
DebugLogger.log("Random seed for whole simulation (if not overriden by simulation configuration): " + randomSeed);
GlobalConfiguration globalConfiguration = new GlobalConfiguration(globalConfId, zoneId, randomSeed, resources, resourceAssignmentOrder);
return globalConfiguration;
}
Aggregations