Search in sources :

Example 1 with AdaptationData

use of org.iobserve.adaptation.data.AdaptationData 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 2 with AdaptationData

use of org.iobserve.adaptation.data.AdaptationData in project iobserve-analysis by research-iobserve.

the class AdaptationExecution method execute.

@Override
protected void execute(final AdaptationData element) throws Exception {
    AdaptationExecution.LOGGER.info("Executing adaptation");
    element.setDeployablesFolderURI(this.deployablesFolderURI);
    final List<AbstractActionScript> notAutoSupported = new ArrayList<>();
    final List<AbstractActionScript> actionScripts = new ArrayList<>();
    final ActionScriptFactory actionFactory = new ActionScriptFactory(element);
    // TODO Finish, by adding execution. Maybe Async?
    for (final Action action : element.getExecutionOrder()) {
        final AbstractActionScript script = actionFactory.getExecutionScript(action);
        actionScripts.add(script);
        if (!script.isAutoExecutable()) {
            notAutoSupported.add(script);
        }
    }
    if (notAutoSupported.size() > 0) {
        if (this.listener == null) {
            final String unsupportedActionsDesc = notAutoSupported.stream().map(script -> script.getDescription()).collect(Collectors.joining("\n"));
            throw new IllegalStateException("Could not execute all actions automatically, aborting.\n Not supported actions were:\n" + unsupportedActionsDesc);
        }
        this.listener.notifyUnsupportedActionsFound(notAutoSupported);
    }
    SystemEvaluation.enableEvaluation(element);
    try {
        actionScripts.forEach(script -> {
            try {
                script.execute();
            } catch (final Exception e) {
                if (this.listener == null) {
                    throw new IllegalStateException("Could not execute action script '" + script.getDescription() + "' automatically and no listener was present. Aborting!");
                }
                this.listener.notifyExecutionError(script, e);
            }
        });
    } finally {
        SystemEvaluation.disableEvaluation();
    }
}
Also used : AbstractTransformation(teetime.stage.basic.AbstractTransformation) List(java.util.List) AbstractActionScript(org.iobserve.execution.actionscripts.AbstractActionScript) Logger(org.slf4j.Logger) URI(org.eclipse.emf.common.util.URI) AdaptationData(org.iobserve.adaptation.data.AdaptationData) ActionScriptFactory(org.iobserve.execution.actionscripts.ActionScriptFactory) Action(org.iobserve.planning.systemadaptation.Action) LoggerFactory(org.slf4j.LoggerFactory) SystemEvaluation(org.iobserve.evaluation.SystemEvaluation) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ActionScriptFactory(org.iobserve.execution.actionscripts.ActionScriptFactory) Action(org.iobserve.planning.systemadaptation.Action) ArrayList(java.util.ArrayList) AbstractActionScript(org.iobserve.execution.actionscripts.AbstractActionScript)

Example 3 with AdaptationData

use of org.iobserve.adaptation.data.AdaptationData in project iobserve-analysis by research-iobserve.

the class CandidateProcessing method execute.

@Override
protected void execute(final PlanningData element) throws Exception {
    CandidateGeneration.LOG.info("Candiate Processing");
    final AdaptationData adapdationData = element.getAdaptationData();
    final GraphFactory factory = new GraphFactory();
    final File directory = new File(adapdationData.getReDeploymentURI().toFileString());
    final ModelGraph graph = factory.buildGraph(new PCMModelHandler(directory));
    element.getAdaptationData().setReDeploymentGraph(graph);
    this.outputPort.send(element.getAdaptationData());
}
Also used : GraphFactory(org.iobserve.analysis.data.graph.GraphFactory) ModelGraph(org.iobserve.analysis.data.graph.ModelGraph) PCMModelHandler(org.iobserve.model.PCMModelHandler) AdaptationData(org.iobserve.adaptation.data.AdaptationData) File(java.io.File)

Example 4 with AdaptationData

use of org.iobserve.adaptation.data.AdaptationData in project iobserve-analysis by research-iobserve.

the class ModelProcessing method execute.

@Override
protected void execute(final URI element) throws Exception {
    CandidateGeneration.LOG.info("Model Processing");
    final PlanningData planningData = new PlanningData();
    final AdaptationData adaptationData = new AdaptationData();
    adaptationData.setRuntimeModelURI(element);
    planningData.setAdaptationData(adaptationData);
    planningData.setPerOpteryxDir(this.perOpteryxDir);
    planningData.setOriginalModelDir(element);
    planningData.setLqnsDir(this.lqnsDir);
    final File directory = new File(adaptationData.getReDeploymentURI().toFileString());
    final PCMModelHandler models = new PCMModelHandler(directory);
    final SnapshotBuilder snapshotBuilder = new SnapshotBuilder(ModelProcessing.PROCESSED_MODEL_FOLDER, models);
    final URI snapshotLocation = snapshotBuilder.createSnapshot();
    planningData.setProcessedModelDir(snapshotLocation);
    final ModelTransformer modelTransformer = new ModelTransformer(planningData);
    modelTransformer.transformModel();
    this.outputPort.send(planningData);
}
Also used : SnapshotBuilder(org.iobserve.model.snapshot.SnapshotBuilder) PCMModelHandler(org.iobserve.model.PCMModelHandler) PlanningData(org.iobserve.planning.data.PlanningData) AdaptationData(org.iobserve.adaptation.data.AdaptationData) File(java.io.File) URI(org.eclipse.emf.common.util.URI)

Aggregations

AdaptationData (org.iobserve.adaptation.data.AdaptationData)4 File (java.io.File)3 URI (org.eclipse.emf.common.util.URI)3 PCMModelHandler (org.iobserve.model.PCMModelHandler)3 PlanningData (org.iobserve.planning.data.PlanningData)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 ParseException (org.apache.commons.cli.ParseException)1 GraphFactory (org.iobserve.analysis.data.graph.GraphFactory)1 ModelGraph (org.iobserve.analysis.data.graph.ModelGraph)1 SystemEvaluation (org.iobserve.evaluation.SystemEvaluation)1 AbstractActionScript (org.iobserve.execution.actionscripts.AbstractActionScript)1 ActionScriptFactory (org.iobserve.execution.actionscripts.ActionScriptFactory)1 SnapshotBuilder (org.iobserve.model.snapshot.SnapshotBuilder)1 ModelTransformer (org.iobserve.planning.ModelTransformer)1