use of com.google.cloud.servicedirectory.v1.Namespace in project scylla by bptlab.
the class SimulationTest method setGlobalSeed.
protected void setGlobalSeed(Long seed) {
if (seed == null)
return;
if (globalConfigRoot == null)
beforeParsingGlobal.add(() -> setGlobalSeed(seed));
else {
Namespace nsp = globalConfigRoot.getNamespace();
if (globalConfigRoot.getChild("randomSeed", nsp) == null)
globalConfigRoot.addContent(new Element("randomSeed", nsp));
globalConfigRoot.getChild("randomSeed", nsp).setText(seed.toString());
}
}
use of com.google.cloud.servicedirectory.v1.Namespace in project scylla by bptlab.
the class BatchProcessModelParserPlugin method parse.
@Override
public Map<String, Object> parse(ProcessModel processModel, Element process) throws ScyllaValidationException {
Namespace bpmnNamespace = process.getNamespace();
Map<Integer, BatchActivity> batchActivities = new HashMap<Integer, BatchActivity>();
for (Element element : process.getChildren()) {
String elementName = element.getName();
if (elementName.equals("subProcess") || elementName.equals("task") || elementName.endsWith("Task")) {
String elementId = element.getAttributeValue("id");
int nodeId = processModel.getIdentifiersToNodeIds().get(elementId);
try {
parseElement(element, bpmnNamespace, nodeId).ifPresent(batchActivity -> batchActivities.put(nodeId, batchActivity));
} catch (ScyllaValidationException e) {
throw new ScyllaValidationException("Error at parsing batch region with id " + elementId + ": " + e.getMessage(), e);
}
}
}
// Not needed batchActivities.forEach((key, value) -> value.setProcessModel(processModel));
Map<String, Object> extensionAttributes = new HashMap<String, Object>();
extensionAttributes.put(BatchPluginUtils.ACTIVITIES_KEY, batchActivities);
return extensionAttributes;
}
use of com.google.cloud.servicedirectory.v1.Namespace in project scylla by bptlab.
the class BatchProcessModelParserPlugin method parseElement.
private Optional<BatchActivity> parseElement(Element element, Namespace bpmnNamespace, Integer nodeId) throws ScyllaValidationException {
Element extensions = element.getChild("extensionElements", bpmnNamespace);
// Check that only elements with extensions get parsed
if (extensions == null)
return Optional.empty();
String id = element.getAttributeValue("id");
Namespace camundaNamespace = Namespace.getNamespace("camunda", "http://camunda.org/schema/1.0/bpmn");
List<Namespace> possibleNamespaces = Arrays.asList(camundaNamespace, bpmnNamespace);
List<Element> propertyList = possibleNamespaces.stream().map(namespace -> extensions.getChild("properties", namespace)).filter(Objects::nonNull).map(propertiesElement -> propertiesElement.getChildren("property", propertiesElement.getNamespace())).flatMap(List::stream).collect(Collectors.toList());
if (propertyList.isEmpty())
return Optional.empty();
Integer maxBatchSize = null;
BatchClusterExecutionType executionType = defaultExecutionType();
ActivationRule activationRule = null;
List<BatchGroupingCharacteristic> groupingCharacteristic = new ArrayList<BatchGroupingCharacteristic>();
for (Element property : propertyList) {
// maximum batch size
switch(property.getAttributeValue("name")) {
case "maxBatchSize":
maxBatchSize = Integer.parseInt(property.getAttributeValue("value"));
break;
// execution type. if none is defined, take parallel as default
case "executionType":
executionType = parseExecutionType(property);
break;
// grouping characteristic
case "groupingCharacteristic":
groupingCharacteristic.addAll(parseGroupingCharacteristic(property));
break;
// threshold capacity (minimum batch size) & timeout of activation rule
case "activationRule":
activationRule = parseActivationRule(property);
break;
}
}
if (maxBatchSize == null) {
throw new ScyllaValidationException("You have to specify a maxBatchSize at " + id + " .");
}
/*if (groupingCharacteristic.isEmpty()){
throw new ScyllaValidationException("You have to specify at least one groupingCharacteristic at "+ id +" .");
}*/
BatchActivity ba = new BatchActivity(nodeId, maxBatchSize, executionType, activationRule, groupingCharacteristic);
return Optional.of(ba);
}
use of com.google.cloud.servicedirectory.v1.Namespace in project scylla by bptlab.
the class EventArrivalRateSCParserPlugin method parse.
/**
* Parses all occurences of event arrival rates to be stored as extension attribute.
*/
@Override
public Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
Map<Integer, TimeDistributionWrapper> arrivalRates = new HashMap<Integer, TimeDistributionWrapper>();
Namespace simNamespace = sim.getNamespace();
ProcessModel processModel = simulationInput.getProcessModel();
for (Element el : sim.getChildren()) {
String elementName = el.getName();
if (elementName.equals(EventArrivalRatePluginUtils.ELEMENT_NAME)) {
String identifier = el.getAttributeValue("id");
if (identifier == null) {
DebugLogger.log("Warning: Simulation configuration definition catch event element '" + elementName + "' does not have an identifier, skip.");
continue;
}
Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
if (nodeId == null) {
DebugLogger.log("Warning: There is no matching catch event in the process model for " + "simulation configuration definition '" + identifier + ", skip.");
continue;
}
Element elem = el.getChild("arrivalRate", simNamespace);
if (elem != null) {
TimeDistributionWrapper distribution = SimulationConfigurationParser.getTimeDistributionWrapper(elem, simNamespace);
arrivalRates.put(nodeId, distribution);
}
}
}
Map<String, Object> extensionAttributes = new HashMap<String, Object>();
extensionAttributes.put(EventArrivalRatePluginUtils.ARRIVALRATES_KEY, arrivalRates);
return extensionAttributes;
}
use of com.google.cloud.servicedirectory.v1.Namespace in project scylla by bptlab.
the class CommonProcessElementsParser method parse.
@Override
public CommonProcessElements parse(Element rootElement) throws ScyllaValidationException {
String definitionsId = rootElement.getAttributeValue("id");
Namespace bpmnNamespace = rootElement.getNamespace();
Map<String, GlobalTaskType> globalTasks = new HashMap<String, GlobalTaskType>();
Map<String, Element> globalTaskElements = new HashMap<String, Element>();
Map<String, Map<String, String>> resources = new HashMap<String, Map<String, String>>();
Map<String, Map<String, String>> messages = new HashMap<String, Map<String, String>>();
Map<String, Map<String, String>> errors = new HashMap<String, Map<String, String>>();
Map<String, Map<String, String>> escalations = new HashMap<String, Map<String, String>>();
// global tasks called by call activities
for (GlobalTaskType gtt : GlobalTaskType.values()) {
List<Element> gte = rootElement.getChildren(gtt.toString(), bpmnNamespace);
for (Element el : gte) {
String elementId = el.getAttributeValue("id");
globalTasks.put(elementId, gtt);
globalTaskElements.put(elementId, el);
}
}
// common elements: chapter 8.4 in BPMN 2.0.2 definition
List<Element> resourceElements = rootElement.getChildren("resource", bpmnNamespace);
for (Element el : resourceElements) {
Map<String, String> resource = new HashMap<String, String>();
String elementId = el.getAttributeValue("id");
String name = el.getAttributeValue("name");
if (name != null) {
resource.put("name", name);
}
resources.put(elementId, resource);
}
List<Element> messageElements = rootElement.getChildren("message", bpmnNamespace);
for (Element el : messageElements) {
Map<String, String> message = new HashMap<String, String>();
String elementId = el.getAttributeValue("id");
String name = el.getAttributeValue("name");
if (name != null) {
message.put("name", name);
}
messages.put(elementId, message);
}
List<Element> errorElements = rootElement.getChildren("error", bpmnNamespace);
for (Element el : errorElements) {
Map<String, String> error = new HashMap<String, String>();
String elementId = el.getAttributeValue("id");
String name = el.getAttributeValue("name");
if (name != null) {
error.put("name", name);
}
String errorCode = el.getAttributeValue("errorCode");
if (errorCode != null) {
error.put("errorCode", errorCode);
}
errors.put(elementId, error);
}
List<Element> escalationElements = rootElement.getChildren("escalation", bpmnNamespace);
for (Element el : escalationElements) {
Map<String, String> escalation = new HashMap<String, String>();
String elementId = el.getAttributeValue("id");
String name = el.getAttributeValue("name");
if (name != null) {
escalation.put("name", name);
}
String escalationCode = el.getAttributeValue("escalationCode");
if (escalationCode != null) {
escalation.put("escalationCode", escalationCode);
}
escalations.put(elementId, escalation);
}
CommonProcessElements commonProcessElements = new CommonProcessElements(definitionsId, globalTasks, globalTaskElements, resources, messages, errors, escalations);
return commonProcessElements;
}
Aggregations