use of org.iobserve.model.PCMModelHandler in project iobserve-analysis by research-iobserve.
the class AnalysisMain method createConfiguration.
@Override
protected AnalysisConfiguration createConfiguration(final Configuration configuration) throws ConfigurationException {
/**
* Configure model handling.
*/
// old model providers without neo4j
final PCMModelHandler modelFileHandler = new PCMModelHandler(this.modelInitDirectory);
final ICorrespondence correspondenceModel = modelFileHandler.getCorrespondenceModel();
/**
* initialize neo4j graphs.
*/
final GraphLoader graphLoader = new GraphLoader(this.modelDatabaseDirectory);
Graph repositoryModelGraph = graphLoader.initializeRepositoryModelGraph(modelFileHandler.getRepositoryModel());
Graph resourceEnvironmentGraph = graphLoader.initializeResourceEnvironmentModelGraph(modelFileHandler.getResourceEnvironmentModel());
Graph allocationModelGraph = graphLoader.initializeAllocationModelGraph(modelFileHandler.getAllocationModel());
Graph systemModelGraph = graphLoader.initializeSystemModelGraph(modelFileHandler.getSystemModel());
Graph usageModelGraph = graphLoader.initializeUsageModelGraph(modelFileHandler.getUsageModel());
/**
* load neo4j graphs.
*/
repositoryModelGraph = graphLoader.createRepositoryModelGraph();
resourceEnvironmentGraph = graphLoader.createResourceEnvironmentModelGraph();
allocationModelGraph = graphLoader.createAllocationModelGraph();
systemModelGraph = graphLoader.createSystemModelGraph();
usageModelGraph = graphLoader.createUsageModelGraph();
/**
* new graphModelProvider.
*/
final IModelProvider<Repository> repositoryModelProvider = new ModelProvider<>(repositoryModelGraph);
final IModelProvider<ResourceEnvironment> resourceEnvironmentModelProvider = new ModelProvider<>(resourceEnvironmentGraph);
final IModelProvider<Allocation> allocationModelProvider = new ModelProvider<>(allocationModelGraph);
final IModelProvider<org.palladiosimulator.pcm.system.System> systemModelProvider = new ModelProvider<>(systemModelGraph);
final IModelProvider<UsageModel> usageModelProvider = new ModelProvider<>(usageModelGraph);
// get systemId
final org.palladiosimulator.pcm.system.System systemModel = systemModelProvider.readOnlyRootComponent(org.palladiosimulator.pcm.system.System.class);
final String systemId = systemModel.getId();
try {
/**
* URLs for sending updates to the deployment visualization.
*/
// TODO this should be moved to the visualization sinks
final String[] sinks = configuration.getStringArrayProperty(ConfigurationKeys.CONTAINER_MANAGEMENT_SINK, ",");
if (sinks.length > 0) {
final InitializeDeploymentVisualization deploymentVisualization = new InitializeDeploymentVisualization(this.containerManagementVisualizationBaseUrl, systemId, allocationModelProvider, systemModelProvider, resourceEnvironmentModelProvider);
deploymentVisualization.initialize();
}
return new AnalysisConfiguration(configuration, repositoryModelProvider, resourceEnvironmentModelProvider, allocationModelProvider, systemModelProvider, usageModelProvider, correspondenceModel);
} catch (final MalformedURLException e) {
AbstractServiceMain.LOGGER.debug("URL construction for deployment visualization failed.", e);
return null;
} catch (final IOException e) {
AbstractServiceMain.LOGGER.debug("Deployment visualization could not connect to visualization service.", e);
return null;
}
}
use of org.iobserve.model.PCMModelHandler in project iobserve-analysis by research-iobserve.
the class ModelComparer method execute.
@Override
protected void execute(final URI element) throws Exception {
boolean equalGraphs = false;
if (this.baseAdaptationData != null) {
// TODO finish
final PCMModelHandler modelProviders = new PCMModelHandler(new File(element.toFileString()));
final GraphFactory graphFactory = new GraphFactory();
final ModelGraph runtimeGraph = graphFactory.buildGraph(modelProviders);
if (runtimeGraph.equals(this.baseAdaptationData.getReDeploymentGraph()) && this.baseAdaptationData.getReDeploymentGraph().equals(runtimeGraph)) {
equalGraphs = true;
SystemEvaluation.disableEvaluation();
}
}
this.outputPort.send(Boolean.valueOf(equalGraphs));
}
use of org.iobserve.model.PCMModelHandler in project iobserve-analysis by research-iobserve.
the class ModelModificationFactory method createNewModel.
/**
* Create a new model.
*
* @param commandLine
* command line parameters
* @throws InitializationException
* when handler do not initialize
* @throws IOException
* on io errors
*/
public static void createNewModel(final CommandLine commandLine) throws InitializationException, IOException {
ModelModificationFactory.LOGGER.info("Modifying model!");
final URI inputModels = URI.createFileURI(commandLine.getOptionValue("i"));
final URI outputLocation = URI.createFileURI(commandLine.getOptionValue("o"));
ModelModificationFactory.LOGGER.info("Copying models to new location.");
PCMModelHandler modelProviders = new PCMModelHandler(new File(inputModels.toFileString()));
final URI copyURI = ModelModificationFactory.copyRepoToOutput(outputLocation, modelProviders);
modelProviders = new PCMModelHandler(new File(copyURI.toFileString()));
final Allocation allocationModel = modelProviders.getAllocationModel();
final ResourceEnvironment resourceEnvironmentModel = modelProviders.getResourceEnvironmentModel();
final System systemModel = modelProviders.getSystemModel();
final Repository repositoryModel = modelProviders.getRepositoryModel();
final ResourceEnvironmentModification resEnvMod = new ResourceEnvironmentModification(resourceEnvironmentModel);
ModelModificationFactory.LOGGER.info("Terminating Server");
final List<ResourceContainer> terminatedResourceContainers = resEnvMod.modifyResEnvTerminate(Integer.parseInt(commandLine.getOptionValue("ac")));
ModelModificationFactory.LOGGER.info("Acquiring Server");
resEnvMod.modifyResEnvAcquire(Integer.parseInt(commandLine.getOptionValue("ac")));
ModelModificationFactory.LOGGER.info("Fixing Allocation after terminating");
AllocationModification allocMod = new AllocationModification(allocationModel, systemModel, resourceEnvironmentModel);
final int terminationMigrations = allocMod.modifyAllocationFixTerminations(terminatedResourceContainers);
ModelModificationFactory.LOGGER.info("Deallocating Components");
final SystemModification sysMod = new SystemModification(systemModel, repositoryModel);
final List<AssemblyContext> deallocatedACs = sysMod.modifySystemDeallocations(Integer.parseInt(commandLine.getOptionValue("de")));
ModelModificationFactory.LOGGER.info("Fixing Allocation after deallocating");
allocMod = new AllocationModification(allocationModel, systemModel, resourceEnvironmentModel);
allocMod.modifyAllocationFixDeallocations(deallocatedACs);
// LOG.info("Exchanging Components");
// sysMod.modifySystem_ChangeComp(Integer.parseInt(commandLine.getOptionValue("cr")));
ModelModificationFactory.LOGGER.info("Allocating new Components");
final List<AssemblyContext> allocatedACs = sysMod.modifySystemAllocate(Integer.parseInt(commandLine.getOptionValue("al")));
ModelModificationFactory.LOGGER.info("Creating Allocation for new components");
allocMod = new AllocationModification(allocationModel, systemModel, resourceEnvironmentModel);
allocMod.modifyAllocationFixAllocations(allocatedACs);
ModelModificationFactory.LOGGER.info("Creating migrations");
allocMod = new AllocationModification(allocationModel, systemModel, resourceEnvironmentModel);
final int totalMigrations = Integer.parseInt(commandLine.getOptionValue("al"));
// allocationMigrations
final int migrationsToPerform = totalMigrations - terminationMigrations;
if (migrationsToPerform > 0) {
ModelModificationFactory.LOGGER.info("Migrations to Perform: {}", migrationsToPerform);
allocMod.modifyAllocationMigrate(migrationsToPerform);
} else {
ModelModificationFactory.LOGGER.info(String.format("All migrations (%d) are already perfomed by Server-Termination (%d)!", totalMigrations, migrationsToPerform));
}
ModelModificationFactory.LOGGER.info("Saving models!");
modelProviders.save(outputLocation);
ModelModificationFactory.LOGGER.info("Modification done!");
}
use of org.iobserve.model.PCMModelHandler in project iobserve-analysis by research-iobserve.
the class PlanningMain method main.
public static void main(final String[] args) throws IOException, InitializationException, ModelHandlingErrorException {
final CommandLineParser parser = new DefaultParser();
final String workingDir;
final String perOpteryxDir;
final CommandLine commandLine;
try {
for (final String arg : args) {
if (PlanningMain.LOGGER.isInfoEnabled()) {
PlanningMain.LOGGER.info("arg: " + arg);
}
}
commandLine = parser.parse(PlanningMain.createOptions(), args);
workingDir = commandLine.getOptionValue(PlanningMain.INPUT_WORKING_DIR_OPTION);
perOpteryxDir = commandLine.getOptionValue(PlanningMain.PEROPTERYX_DIR_OPTION);
if (PlanningMain.LOGGER.isInfoEnabled()) {
PlanningMain.LOGGER.info("Working dir: " + workingDir + ", PerOpteryx dir: " + perOpteryxDir);
}
} catch (final ParseException exp) {
// LOG.error("CLI error: " + exp.getMessage());
final HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("planning", PlanningMain.createOptions());
return;
}
final URI modelURI = URI.createFileURI(workingDir);
if (PlanningMain.LOGGER.isInfoEnabled()) {
PlanningMain.LOGGER.info("modelURI: " + modelURI);
}
final URI perOpteryxURI = URI.createFileURI(perOpteryxDir);
if (PlanningMain.LOGGER.isInfoEnabled()) {
PlanningMain.LOGGER.info("perOpteryxURI: " + perOpteryxURI);
PlanningMain.LOGGER.info("lqnsURI: " + perOpteryxURI);
}
PalladioEclipseEnvironment.INSTANCE.setup();
if (!commandLine.hasOption(PlanningMain.CREATE_RESOURCEENVIRONMENT_OPTION)) {
if (PlanningMain.LOGGER.isInfoEnabled()) {
PlanningMain.LOGGER.info("Executing optimization...");
}
final AdaptationData adaptationData = new AdaptationData();
adaptationData.setRuntimeModelURI(modelURI);
final PlanningData planningData = new PlanningData();
planningData.setAdaptationData(adaptationData);
planningData.setOriginalModelDir(modelURI);
planningData.setPerOpteryxDir(perOpteryxURI);
// Process model
final ModelTransformer transformer = new ModelTransformer(planningData);
transformer.transformModel();
// Execute PerOpteryx
final int result = 0;
if (result == 0) {
if (PlanningMain.LOGGER.isInfoEnabled()) {
PlanningMain.LOGGER.info("Optimization was successful.");
}
} else {
if (PlanningMain.LOGGER.isInfoEnabled()) {
PlanningMain.LOGGER.info("Optimization failed.");
}
}
} else {
if (PlanningMain.LOGGER.isInfoEnabled()) {
PlanningMain.LOGGER.info("Creating ResourceEnvironment...");
}
final PCMModelHandler modelHandler = new PCMModelHandler(new File(workingDir));
ModelHelper.fillResourceEnvironmentFromCloudProfile(org.eclipse.emf.common.util.URI.createFileURI(workingDir), modelHandler);
if (PlanningMain.LOGGER.isInfoEnabled()) {
PlanningMain.LOGGER.info("ResourceEnvironment successfully created.");
}
}
}
use of org.iobserve.model.PCMModelHandler in project iobserve-analysis by research-iobserve.
the class PrivacyViolationDetectionServiceMain method createConfiguration.
@Override
protected PrivacyViolationDetectionConfiguration createConfiguration(final Configuration configuration) throws ConfigurationException {
/**
* load models.
*/
final PCMModelHandler modelHandler = new PCMModelHandler(this.pcmDirectory);
final GraphLoader graphLoader = new GraphLoader(this.modelDatabaseDirectory);
final Graph allocationModelGraph = graphLoader.initializeAllocationModelGraph(modelHandler.getAllocationModel());
final Graph resourceEnvironmentGraph = graphLoader.initializeResourceEnvironmentModelGraph(modelHandler.getResourceEnvironmentModel());
final Graph systemGraph = graphLoader.initializeSystemModelGraph(modelHandler.getSystemModel());
final ModelProvider<Allocation> allocationModelProvider = new ModelProvider<>(allocationModelGraph);
final ModelProvider<ResourceEnvironment> resourceEnvironmentModelProvider = new ModelProvider<>(resourceEnvironmentGraph);
final ModelProvider<System> systemModelProvider = new ModelProvider<>(systemGraph);
try {
return new PrivacyViolationDetectionConfiguration(this.inputPort, this.outputs, modelHandler.getCorrespondenceModel(), resourceEnvironmentModelProvider, allocationModelProvider, systemModelProvider, this.warningFile, this.alarmsFile);
} catch (final IOException e) {
throw new ConfigurationException(e);
}
}
Aggregations