diff options
Diffstat (limited to 'core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java')
-rw-r--r-- | core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java index ae1f551a4..6bb9ce2a3 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; +import org.onap.policy.apex.core.engine.EngineParameterConstants; import org.onap.policy.apex.core.engine.EngineParameters; import org.onap.policy.apex.core.engine.ExecutorParameters; import org.onap.policy.apex.core.engine.context.ApexInternalContext; @@ -34,11 +35,11 @@ import org.onap.policy.apex.core.engine.executor.TaskExecutor; import org.onap.policy.apex.core.engine.executor.TaskSelectExecutor; import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; import org.onap.policy.apex.core.engine.executor.exception.StateMachineRuntimeException; -import org.onap.policy.apex.model.basicmodel.service.ParameterService; import org.onap.policy.apex.model.policymodel.concepts.AxState; import org.onap.policy.apex.model.policymodel.concepts.AxStateFinalizerLogic; import org.onap.policy.apex.model.policymodel.concepts.AxTask; import org.onap.policy.apex.model.utilities.Assertions; +import org.onap.policy.common.parameters.ParameterService; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -53,16 +54,12 @@ public class ExecutorFactoryImpl extends ExecutorFactory { private static final XLogger LOGGER = XLoggerFactory.getXLogger(ExecutorFactoryImpl.class); // A map of logic flavours mapped to executor classes for plugins to executors for those logic flavours - private Map<String, Class<Executor<?, ?, ?, ?>>> taskExecutorPluginClassMap = - new TreeMap<String, Class<Executor<?, ?, ?, ?>>>(); - private Map<String, Class<Executor<?, ?, ?, ?>>> taskSelectionExecutorPluginClassMap = - new TreeMap<String, Class<Executor<?, ?, ?, ?>>>(); - private Map<String, Class<Executor<?, ?, ?, ?>>> stateFinalizerExecutorPluginClassMap = - new TreeMap<String, Class<Executor<?, ?, ?, ?>>>(); + private Map<String, Class<Executor<?, ?, ?, ?>>> taskExecutorPluginClassMap = new TreeMap<>(); + private Map<String, Class<Executor<?, ?, ?, ?>>> taskSelectionExecutorPluginClassMap = new TreeMap<>(); + private Map<String, Class<Executor<?, ?, ?, ?>>> stateFinalizerExecutorPluginClassMap = new TreeMap<>(); // A map of parameters for executors - private final Map<String, ExecutorParameters> implementationParameterMap = - new TreeMap<String, ExecutorParameters>(); + private final Map<String, ExecutorParameters> implementationParameterMap = new TreeMap<>(); /** * Constructor, builds the class map for executors. @@ -70,21 +67,21 @@ public class ExecutorFactoryImpl extends ExecutorFactory { * @throws StateMachineException on plugin creation errors */ public ExecutorFactoryImpl() throws StateMachineException { - final EngineParameters engineParameters = ParameterService.getParameters(EngineParameters.class); + final EngineParameters engineParameters = ParameterService.get(EngineParameterConstants.MAIN_GROUP_NAME); Assertions.argumentNotNull(engineParameters, StateMachineException.class, - "Parameter \"engineParameters\" may not be null"); + "Parameter \"engineParameters\" may not be null"); // Instantiate each executor class map entry for (final Entry<String, ExecutorParameters> executorParameterEntry : engineParameters.getExecutorParameterMap() - .entrySet()) { + .entrySet()) { // Get classes for all types of executors for this logic type taskExecutorPluginClassMap.put(executorParameterEntry.getKey(), - getExecutorPluginClass(executorParameterEntry.getValue().getTaskExecutorPluginClass())); - taskSelectionExecutorPluginClassMap.put(executorParameterEntry.getKey(), - getExecutorPluginClass(executorParameterEntry.getValue().getTaskSelectionExecutorPluginClass())); - stateFinalizerExecutorPluginClassMap.put(executorParameterEntry.getKey(), - getExecutorPluginClass(executorParameterEntry.getValue().getStateFinalizerExecutorPluginClass())); + getExecutorPluginClass(executorParameterEntry.getValue().getTaskExecutorPluginClass())); + taskSelectionExecutorPluginClassMap.put(executorParameterEntry.getKey(), getExecutorPluginClass( + executorParameterEntry.getValue().getTaskSelectionExecutorPluginClass())); + stateFinalizerExecutorPluginClassMap.put(executorParameterEntry.getKey(), getExecutorPluginClass( + executorParameterEntry.getValue().getStateFinalizerExecutorPluginClass())); // Save the executor implementation parameters implementationParameterMap.put(executorParameterEntry.getKey(), executorParameterEntry.getValue()); @@ -100,14 +97,14 @@ public class ExecutorFactoryImpl extends ExecutorFactory { */ @Override public TaskSelectExecutor getTaskSelectionExecutor(final Executor<?, ?, ?, ?> parentExecutor, final AxState state, - final ApexInternalContext context) { + final ApexInternalContext context) { if (!state.checkSetTaskSelectionLogic()) { return null; } // Create task selection executor - final TaskSelectExecutor tsExecutor = - (TaskSelectExecutor) createExecutor(state.getTaskSelectionLogic().getLogicFlavour(), + final TaskSelectExecutor tsExecutor = (TaskSelectExecutor) createExecutor( + state.getTaskSelectionLogic().getLogicFlavour(), taskSelectionExecutorPluginClassMap.get(state.getTaskSelectionLogic().getLogicFlavour()), TaskSelectExecutor.class); tsExecutor.setParameters(implementationParameterMap.get(state.getTaskSelectionLogic().getLogicFlavour())); @@ -124,10 +121,10 @@ public class ExecutorFactoryImpl extends ExecutorFactory { */ @Override public TaskExecutor getTaskExecutor(final Executor<?, ?, ?, ?> parentExecutor, final AxTask task, - final ApexInternalContext context) { + final ApexInternalContext context) { // Create task executor final TaskExecutor taskExecutor = (TaskExecutor) createExecutor(task.getTaskLogic().getLogicFlavour(), - taskExecutorPluginClassMap.get(task.getTaskLogic().getLogicFlavour()), TaskExecutor.class); + taskExecutorPluginClassMap.get(task.getTaskLogic().getLogicFlavour()), TaskExecutor.class); taskExecutor.setParameters(implementationParameterMap.get(task.getTaskLogic().getLogicFlavour())); taskExecutor.setContext(parentExecutor, task, context); @@ -144,10 +141,11 @@ public class ExecutorFactoryImpl extends ExecutorFactory { */ @Override public StateFinalizerExecutor getStateFinalizerExecutor(final Executor<?, ?, ?, ?> parentExecutor, - final AxStateFinalizerLogic logic, final ApexInternalContext context) { + final AxStateFinalizerLogic logic, final ApexInternalContext context) { // Create state finalizer executor final StateFinalizerExecutor sfExecutor = (StateFinalizerExecutor) createExecutor(logic.getLogicFlavour(), - stateFinalizerExecutorPluginClassMap.get(logic.getLogicFlavour()), StateFinalizerExecutor.class); + stateFinalizerExecutorPluginClassMap.get(logic.getLogicFlavour()), + StateFinalizerExecutor.class); sfExecutor.setParameters(implementationParameterMap.get(logic.getLogicFlavour())); sfExecutor.setContext(parentExecutor, logic, context); @@ -163,7 +161,7 @@ public class ExecutorFactoryImpl extends ExecutorFactory { */ @SuppressWarnings("unchecked") private Class<Executor<?, ?, ?, ?>> getExecutorPluginClass(final String executorClassName) - throws StateMachineException { + throws StateMachineException { // It's OK for an executor class not to be defined as long as it's not called if (executorClassName == null) { return null; @@ -176,15 +174,15 @@ public class ExecutorFactoryImpl extends ExecutorFactory { } catch (final ClassNotFoundException e) { LOGGER.error("Apex executor class not found for executor plugin \"" + executorClassName + "\"", e); throw new StateMachineException( - "Apex executor class not found for executor plugin \"" + executorClassName + "\"", e); + "Apex executor class not found for executor plugin \"" + executorClassName + "\"", e); } // Check the class is an executor if (!Executor.class.isAssignableFrom(executorPluginClass)) { - LOGGER.error("Specified Apex executor plugin class \"" + executorClassName - + "\" does not implment the Executor interface"); + LOGGER.error("Specified Apex executor plugin class \"{}\" does not implment the Executor interface", + executorClassName); throw new StateMachineException("Specified Apex executor plugin class \"" + executorClassName - + "\" does not implment the Executor interface"); + + "\" does not implment the Executor interface"); } return (Class<Executor<?, ?, ?, ?>>) executorPluginClass; @@ -199,14 +197,14 @@ public class ExecutorFactoryImpl extends ExecutorFactory { * @return The instantiated class */ private Executor<?, ?, ?, ?> createExecutor(final String logicFlavour, - final Class<Executor<?, ?, ?, ?>> executorClass, - final Class<? extends Executor<?, ?, ?, ?>> executorSuperClass) { + final Class<Executor<?, ?, ?, ?>> executorClass, + final Class<? extends Executor<?, ?, ?, ?>> executorSuperClass) { // It's OK for an executor class not to be defined but it's not all right to try and create // a non-defined // executor class if (executorClass == null) { final String errorMessage = "Executor plugin class not defined for \"" + logicFlavour - + "\" executor of type \"" + executorSuperClass.getCanonicalName() + "\""; + + "\" executor of type \"" + executorSuperClass.getCanonicalName() + "\""; LOGGER.error(errorMessage); throw new StateMachineRuntimeException(errorMessage); } @@ -217,7 +215,7 @@ public class ExecutorFactoryImpl extends ExecutorFactory { executorObject = executorClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { final String errorMessage = "Instantiation error on \"" + logicFlavour + "\" executor of type \"" - + executorClass.getCanonicalName() + "\""; + + executorClass.getCanonicalName() + "\""; LOGGER.error(errorMessage, e); throw new StateMachineRuntimeException(errorMessage, e); } @@ -225,7 +223,7 @@ public class ExecutorFactoryImpl extends ExecutorFactory { // Check the class is a Task Selection Executor if (!(executorSuperClass.isAssignableFrom(executorObject.getClass()))) { final String errorMessage = "Executor on \"" + logicFlavour + "\" of type \"" + executorClass - + "\" is not an instance of \"" + executorSuperClass.getCanonicalName() + "\""; + + "\" is not an instance of \"" + executorSuperClass.getCanonicalName() + "\""; LOGGER.error(errorMessage); throw new StateMachineRuntimeException(errorMessage); |