Search in sources :

Example 1 with PCMModelHandler

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;
    }
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) MalformedURLException(java.net.MalformedURLException) IModelProvider(org.iobserve.model.provider.neo4j.IModelProvider) ModelProvider(org.iobserve.model.provider.neo4j.ModelProvider) Allocation(org.palladiosimulator.pcm.allocation.Allocation) ICorrespondence(org.iobserve.model.correspondence.ICorrespondence) AnalysisConfiguration(org.iobserve.analysis.configurations.AnalysisConfiguration) PCMModelHandler(org.iobserve.model.PCMModelHandler) IOException(java.io.IOException) Repository(org.palladiosimulator.pcm.repository.Repository) Graph(org.iobserve.model.provider.neo4j.Graph) GraphLoader(org.iobserve.model.provider.neo4j.GraphLoader) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel)

Example 2 with PCMModelHandler

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));
}
Also used : GraphFactory(org.iobserve.analysis.data.graph.GraphFactory) ModelGraph(org.iobserve.analysis.data.graph.ModelGraph) PCMModelHandler(org.iobserve.model.PCMModelHandler) File(java.io.File)

Example 3 with PCMModelHandler

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!");
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) PCMModelHandler(org.iobserve.model.PCMModelHandler) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) URI(org.eclipse.emf.common.util.URI) System(org.palladiosimulator.pcm.system.System) Repository(org.palladiosimulator.pcm.repository.Repository) Allocation(org.palladiosimulator.pcm.allocation.Allocation) File(java.io.File) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)

Example 4 with PCMModelHandler

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.");
        }
    }
}
Also used : PCMModelHandler(org.iobserve.model.PCMModelHandler) PlanningData(org.iobserve.planning.data.PlanningData) URI(org.eclipse.emf.common.util.URI) HelpFormatter(org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.commons.cli.CommandLine) ModelTransformer(org.iobserve.planning.ModelTransformer) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) AdaptationData(org.iobserve.adaptation.data.AdaptationData) File(java.io.File) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 5 with PCMModelHandler

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);
    }
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) ModelProvider(org.iobserve.model.provider.neo4j.ModelProvider) PCMModelHandler(org.iobserve.model.PCMModelHandler) IOException(java.io.IOException) System(org.palladiosimulator.pcm.system.System) Graph(org.iobserve.model.provider.neo4j.Graph) GraphLoader(org.iobserve.model.provider.neo4j.GraphLoader) Allocation(org.palladiosimulator.pcm.allocation.Allocation) ConfigurationException(org.iobserve.stages.general.ConfigurationException)

Aggregations

PCMModelHandler (org.iobserve.model.PCMModelHandler)10 File (java.io.File)8 URI (org.eclipse.emf.common.util.URI)4 Allocation (org.palladiosimulator.pcm.allocation.Allocation)4 AdaptationData (org.iobserve.adaptation.data.AdaptationData)3 GraphFactory (org.iobserve.analysis.data.graph.GraphFactory)3 ResourceEnvironment (org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment)3 System (org.palladiosimulator.pcm.system.System)3 IOException (java.io.IOException)2 CommandLine (org.apache.commons.cli.CommandLine)2 CommandLineParser (org.apache.commons.cli.CommandLineParser)2 DefaultParser (org.apache.commons.cli.DefaultParser)2 HelpFormatter (org.apache.commons.cli.HelpFormatter)2 ModelGraph (org.iobserve.analysis.data.graph.ModelGraph)2 Graph (org.iobserve.model.provider.neo4j.Graph)2 GraphLoader (org.iobserve.model.provider.neo4j.GraphLoader)2 ModelProvider (org.iobserve.model.provider.neo4j.ModelProvider)2 SnapshotBuilder (org.iobserve.model.snapshot.SnapshotBuilder)2 PlanningData (org.iobserve.planning.data.PlanningData)2 Repository (org.palladiosimulator.pcm.repository.Repository)2