Search in sources :

Example 61 with Namespace

use of com.google.cloud.servicedirectory.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;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) HashMap(java.util.HashMap) BranchingBehavior(de.hpi.bpt.scylla.model.configuration.BranchingBehavior) Element(org.jdom2.Element) Namespace(org.jdom2.Namespace) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)

Example 62 with Namespace

use of com.google.cloud.servicedirectory.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;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) HashMap(java.util.HashMap) BranchingBehavior(de.hpi.bpt.scylla.model.configuration.BranchingBehavior) Element(org.jdom2.Element) Namespace(org.jdom2.Namespace) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException)

Example 63 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project scylla by bptlab.

the class SimulationTest method beforeParsingSimconfig.

protected void beforeParsingSimconfig(Element simConfigRoot) {
    Namespace simNamespace = simConfigRoot.getNamespace();
    List<Element> simElements = simConfigRoot.getChildren("simulationConfiguration", simNamespace);
    for (Element simElement : simElements) {
        String id = simElement.getAttributeValue("id");
        simConfigRoots.put(id, simElement);
        beforeParsingSims.getOrDefault(id, Collections.emptyList()).forEach(Runnable::run);
    }
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Example 64 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project scylla by bptlab.

the class SimulationTest method beforeParsingModels.

protected void beforeParsingModels(Element modelRoot) {
    Namespace bpmnNamespace = modelRoot.getNamespace();
    List<Element> processElements = modelRoot.getChildren("process", bpmnNamespace);
    for (Element process : processElements) {
        String id = process.getAttributeValue("id");
        processRoots.put(id, process);
        beforeParsingModels.getOrDefault(id, Collections.emptyList()).forEach(Runnable::run);
    }
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Example 65 with Namespace

use of com.google.cloud.servicedirectory.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);
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Aggregations

Namespace (org.jdom2.Namespace)105 Element (org.jdom2.Element)87 IOException (java.io.IOException)24 XConfiguration (org.apache.oozie.util.XConfiguration)19 ArrayList (java.util.ArrayList)16 Configuration (org.apache.hadoop.conf.Configuration)15 HashMap (java.util.HashMap)14 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)14 StringReader (java.io.StringReader)13 List (java.util.List)13 Path (org.apache.hadoop.fs.Path)12 JDOMException (org.jdom2.JDOMException)10 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)9 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)9 Attribute (org.jdom2.Attribute)9 Writer (java.io.Writer)8 RegistrationServiceClient (com.google.cloud.servicedirectory.v1.RegistrationServiceClient)7 Map (java.util.Map)7 Document (org.jdom2.Document)7 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)6