Search in sources :

Example 1 with Action

use of org.iobserve.planning.systemadaptation.Action 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)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 URI (org.eclipse.emf.common.util.URI)1 AdaptationData (org.iobserve.adaptation.data.AdaptationData)1 SystemEvaluation (org.iobserve.evaluation.SystemEvaluation)1 AbstractActionScript (org.iobserve.execution.actionscripts.AbstractActionScript)1 ActionScriptFactory (org.iobserve.execution.actionscripts.ActionScriptFactory)1 Action (org.iobserve.planning.systemadaptation.Action)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 AbstractTransformation (teetime.stage.basic.AbstractTransformation)1