private void runExperimentSeries( ScenarioInstance scenarioInstance, Map<MeasurementSpecification, List<ExperimentSeriesDefinition>> experimentSeries) { boolean mecAcquired = false; try { experimentController.acquireMEController(); mecAcquired = true; for (MeasurementSpecification measSpec : experimentSeries.keySet()) { experimentController.initialize( EngineTools.getConstantParameterValues(measSpec.getInitializationAssignemts()), scenarioInstance.getScenarioDefinition().getMeasurementEnvironmentDefinition()); for (ExperimentSeriesDefinition esd : experimentSeries.get(measSpec)) { ExperimentSeries series = scenarioInstance.getExperimentSeries(esd.getName()); if (series == null) { series = EntityFactory.createExperimentSeries(esd); scenarioInstance.getExperimentSeriesList().add(series); series.setScenarioInstance(scenarioInstance); persistenceProvider.store(series); } experimentSeriesManager.runExperimentSeries(series); } } } catch (Exception e) { throw new RuntimeException("Failed executing experiments!", e); } finally { if (mecAcquired) { experimentController.releaseMEController(); } } }
private ScenarioInstance createNewScenarioInstance(ScenarioDefinition scenarioDefinition) { ScenarioInstance scenarioInstance = EntityFactory.createScenarioInstance( scenarioDefinition, getConfiguration().getMeasurementControllerURIAsStr()); persistenceProvider.store(scenarioInstance); LOGGER.debug("Created new ScenarioInstance {}", scenarioInstance); return scenarioInstance; }
@Override public ScenarioInstance run( ScenarioDefinition scenarioDefinition, Collection<String> experimentSeriesNames) { if (experimentSeriesNames == null || experimentSeriesNames.isEmpty()) { throw new RuntimeException("List of experiment series names is empty or null!"); } ScenarioInstance scenarioInstance = retrieveScenarioInstance(scenarioDefinition); scenarioInstance.getScenarioDefinition().getAllExperimentSeriesDefinitions(); Map<MeasurementSpecification, List<ExperimentSeriesDefinition>> experimentSeries = new HashMap<MeasurementSpecification, List<ExperimentSeriesDefinition>>(); for (MeasurementSpecification ms : scenarioDefinition.getMeasurementSpecifications()) { List<ExperimentSeriesDefinition> currentExpSeriesList = new ArrayList<ExperimentSeriesDefinition>(); for (ExperimentSeriesDefinition esd : ms.getExperimentSeriesDefinitions()) { for (String expSeriesName : experimentSeriesNames) { if ((ms.getName() + "." + esd.getName()).equals(expSeriesName)) { currentExpSeriesList.add(esd); } } } if (!currentExpSeriesList.isEmpty()) { experimentSeries.put(ms, currentExpSeriesList); } } runExperimentSeries(scenarioInstance, experimentSeries); try { ScenarioInstance loadedScenario = persistenceProvider.loadScenarioInstance(scenarioInstance.getPrimaryKey()); return loadedScenario; } catch (DataNotFoundException e) { LOGGER.error( "Cannot load the scenario from the persistnce provider. Something is seriously gone wrong."); throw new RuntimeException("Something went wrong"); } }
private ScenarioInstance retrieveScenarioInstance(ScenarioDefinition scenarioDefinition) { ScenarioInstance scenarioInstance = null; try { scenarioInstance = persistenceProvider.loadScenarioInstance( scenarioDefinition.getScenarioName(), getConfiguration().getMeasurementControllerURIAsStr()); LOGGER.debug("Loaded ScenarioInstance {} from database", scenarioInstance); LOGGER.debug( "Compare Scenario definition defined in the specification with the one loaded from database"); } catch (DataNotFoundException e) { scenarioInstance = createNewScenarioInstance(scenarioDefinition); } if (scenarioInstance == null) { throw new RuntimeException("Failed to retrieve scenario instance!"); } return scenarioInstance; }