Search in sources :

Example 1 with CommonProcessElements

use of de.hpi.bpt.scylla.model.process.CommonProcessElements 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;
}
Also used : CommonProcessElements(de.hpi.bpt.scylla.model.process.CommonProcessElements) GlobalTaskType(de.hpi.bpt.scylla.model.process.node.GlobalTaskType) HashMap(java.util.HashMap) Element(org.jdom2.Element) Map(java.util.Map) HashMap(java.util.HashMap) Namespace(org.jdom2.Namespace)

Example 2 with CommonProcessElements

use of de.hpi.bpt.scylla.model.process.CommonProcessElements in project scylla by bptlab.

the class SimulationManager method run.

/**
 * parses input, runs DesmoJ simulation experiment, writes BPS output logs
 */
public String run() {
    try {
        SAXBuilder builder = new SAXBuilder();
        if (globalConfigurationFilename == null || globalConfigurationFilename.isEmpty()) {
            throw new ScyllaValidationException("No global configuration provided.");
        } else {
            // parse global configuration XML
            Document gcDoc = builder.build(globalConfigurationFilename);
            Element gcRootElement = gcDoc.getRootElement();
            GlobalConfigurationParser globalConfigurationParser = new GlobalConfigurationParser(this);
            globalConfiguration = globalConfigurationParser.parse(gcDoc.getRootElement());
            String fileNameWithoutExtension = // filename.lastIndexOf("\\") +
            globalConfigurationFilename.substring(// 1,
            globalConfigurationFilename.lastIndexOf(Scylla.FILEDELIM) + 1, globalConfigurationFilename.lastIndexOf(".xml"));
            globalConfiguration.setFileNameWithoutExtension(fileNameWithoutExtension);
            // plugins to parse global configuration
            GlobalConfigurationParserPluggable.runPlugins(this, globalConfiguration, gcRootElement);
            DateTimeUtils.setZoneId(globalConfiguration.getZoneId());
        }
        CommonProcessElementsParser cpeParser = new CommonProcessElementsParser(this);
        for (String filename : processModelFilenames) {
            Document pmDoc = builder.build(filename);
            Element pmRootElement = pmDoc.getRootElement();
            // parse common process elements from XML (BPMN)
            CommonProcessElements commonProcessElementsFromFile = cpeParser.parse(pmRootElement);
            String fileNameWithoutExtension = // filename.lastIndexOf("\\") + 1,
            filename.substring(filename.lastIndexOf(Scylla.FILEDELIM) + 1, filename.lastIndexOf(".bpmn"));
            commonProcessElementsFromFile.setBpmnFileNameWithoutExtension(fileNameWithoutExtension);
            // plugins to parse common process elements
            CommonProcessElementsParserPluggable.runPlugins(this, commonProcessElementsFromFile, pmRootElement);
            // parse process model(s) from XML (BPMN)
            ProcessModelParser pmParser = new ProcessModelParser(this);
            pmParser.setCommonProcessElements(commonProcessElementsFromFile);
            ProcessModel processModelFromFile = pmParser.parse(pmDoc.getRootElement());
            String processId = processModelFromFile.getId();
            if (processModels.containsKey(processId)) {
                throw new ScyllaValidationException("Duplicate process model with id " + processId + ".");
            }
            // plugins to parse process model(s)
            ProcessModelParserPluggable.runPlugins(this, processModelFromFile, pmRootElement);
            processModels.put(processId, processModelFromFile);
            commonProcessElements.put(processId, commonProcessElementsFromFile);
        }
        SimulationConfigurationParser simParser = new SimulationConfigurationParser(this);
        // parse each simulation configuration XML
        for (String filename : simulationConfigurationFilenames) {
            Document scDoc = builder.build(filename);
            SimulationConfiguration simulationConfigurationFromFile = simParser.parse(scDoc.getRootElement());
            String processId = simulationConfigurationFromFile.getProcessModel().getId();
            if (simulationConfigurations.containsKey(processId)) {
                throw new ScyllaValidationException("Multiple simulation configurations for process with id " + processId + ".");
            }
            // plugins to parse simulation configuration
            SimulationConfigurationParserPluggable.runPlugins(this, simulationConfigurationFromFile, scDoc);
            simulationConfigurations.put(processId, simulationConfigurationFromFile);
        }
    } catch (JDOMException | IOException | ScyllaValidationException e) {
        DebugLogger.error(e.getMessage());
        e.printStackTrace();
    }
    // TODO validate resources in process models (i.e. check if they are all covered in resource data)
    TimeUnit epsilon = TimeUnit.SECONDS;
    DateTimeUtils.setReferenceTimeUnit(epsilon);
    String experimentName = Long.toString((new Date()).getTime());
    Experiment.setEpsilon(epsilon);
    Experiment exp = new Experiment(experimentName, experimentOutputFolder);
    exp.setShowProgressBar(false);
    // XXX each simulation configuration may have its own seed
    Long randomSeed = globalConfiguration.getRandomSeed();
    if (randomSeed != null) {
        exp.setSeedGenerator(randomSeed);
    } else {
        exp.setSeedGenerator((new Random()).nextLong());
    }
    SimulationModel sm = new SimulationModel(null, globalConfiguration, commonProcessElements, processModels, simulationConfigurations, enableBpsLogging, enableDesLogging);
    sm.connectToExperiment(exp);
    int lambda = 1;
    if (sm.getEndDateTime() != null) {
        // have to use time which is slightly after intended end time (epsilon)
        // otherwise the AbortProcessSimulationEvent(s) may not fire
        long simulationDuration = DateTimeUtils.getDuration(sm.getStartDateTime(), sm.getEndDateTime());
        TimeInstant simulationTimeInstant = new TimeInstant(simulationDuration + lambda, epsilon);
        exp.stop(simulationTimeInstant);
        exp.tracePeriod(new TimeInstant(0), simulationTimeInstant);
        exp.debugPeriod(new TimeInstant(0), simulationTimeInstant);
    } else {
        exp.traceOn(new TimeInstant(0));
        exp.debugOn(new TimeInstant(0));
    }
    if (!enableDesLogging) {
        exp.debugOff(new TimeInstant(0));
        exp.traceOff(new TimeInstant(0));
    }
    exp.start();
    exp.report();
    exp.finish();
    try {
        // log process execution
        // log resources, process, tasks
        StringBuilder strb = new StringBuilder(globalConfigurationFilename.substring(0, globalConfigurationFilename.lastIndexOf(Scylla.FILEDELIM) + 1));
        outputPath = strb.substring(0, strb.lastIndexOf(Scylla.FILEDELIM) + 1) + "output_" + new SimpleDateFormat("yy_MM_dd_HH_mm_ss").format(new Date()) + Scylla.FILEDELIM;
        File outputPathFolder = new File(outputPath);
        if (!outputPathFolder.exists())
            outputPathFolder.mkdir();
        OutputLoggerPluggable.runPlugins(sm, outputPath);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return outputPath;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) Element(org.jdom2.Element) Document(org.jdom2.Document) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) Random(java.util.Random) TimeUnit(java.util.concurrent.TimeUnit) SimulationConfigurationParser(de.hpi.bpt.scylla.parser.SimulationConfigurationParser) CommonProcessElements(de.hpi.bpt.scylla.model.process.CommonProcessElements) SAXBuilder(org.jdom2.input.SAXBuilder) Experiment(desmoj.core.simulator.Experiment) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) CommonProcessElementsParser(de.hpi.bpt.scylla.parser.CommonProcessElementsParser) Date(java.util.Date) SimulationConfiguration(de.hpi.bpt.scylla.model.configuration.SimulationConfiguration) ProcessModelParser(de.hpi.bpt.scylla.parser.ProcessModelParser) GlobalConfigurationParser(de.hpi.bpt.scylla.parser.GlobalConfigurationParser) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) TimeInstant(desmoj.core.simulator.TimeInstant)

Aggregations

CommonProcessElements (de.hpi.bpt.scylla.model.process.CommonProcessElements)2 Element (org.jdom2.Element)2 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)1 SimulationConfiguration (de.hpi.bpt.scylla.model.configuration.SimulationConfiguration)1 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)1 GlobalTaskType (de.hpi.bpt.scylla.model.process.node.GlobalTaskType)1 CommonProcessElementsParser (de.hpi.bpt.scylla.parser.CommonProcessElementsParser)1 GlobalConfigurationParser (de.hpi.bpt.scylla.parser.GlobalConfigurationParser)1 ProcessModelParser (de.hpi.bpt.scylla.parser.ProcessModelParser)1 SimulationConfigurationParser (de.hpi.bpt.scylla.parser.SimulationConfigurationParser)1 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)1 Experiment (desmoj.core.simulator.Experiment)1 TimeInstant (desmoj.core.simulator.TimeInstant)1 File (java.io.File)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1