use of org.iobserve.execution.actionscripts.ActionScriptFactory 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();
}
}
Aggregations