summaryrefslogtreecommitdiffstats
path: root/core/core-engine/src
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-08-30 09:37:29 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-08-31 19:23:41 +0100
commitf32508381ce0b555fc14978cbaa458aa4e2d91c5 (patch)
tree1cab66e5372b6467f288ae1351ce836e4eba2d03 /core/core-engine/src
parent052038c7a7e0b385462b3b653b7d06094d472df3 (diff)
Use parameter service in apex
Switch parameter handling in apex to use the ONAP PF common parameter service Change-Id: Id318d19c726b18b1a69c630fa81ca7d695355e9c Issue-ID: POLICY-954 Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'core/core-engine/src')
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/EngineParameterConstants.java37
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/EngineParameters.java32
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/ExecutorParameters.java49
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java66
4 files changed, 122 insertions, 62 deletions
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/EngineParameterConstants.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/EngineParameterConstants.java
new file mode 100644
index 000000000..1678f57c7
--- /dev/null
+++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/EngineParameterConstants.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.core.engine;
+
+/**
+ * This class holds constants used when managing engine parameter groups in apex.
+ */
+public abstract class EngineParameterConstants {
+ public static final String MAIN_GROUP_NAME = "ENGINE_PARAMETERS";
+ public static final String EXECUTOR_GROUP_NAME = "EXECUTOR_PARAMETERS";
+
+ /**
+ * Private default constructor to prevent subclassing
+ */
+ private EngineParameterConstants() {
+ // Prevents subclassing
+ }
+
+}
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/EngineParameters.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/EngineParameters.java
index 62fe6a552..e0b0349de 100644
--- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/EngineParameters.java
+++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/EngineParameters.java
@@ -24,8 +24,8 @@ import java.util.Map;
import java.util.TreeMap;
import org.onap.policy.apex.context.parameters.ContextParameters;
-import org.onap.policy.apex.model.basicmodel.service.AbstractParameters;
-import org.onap.policy.apex.model.basicmodel.service.ParameterService;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ParameterGroup;
/**
* This class holds the parameters for a single Apex engine. This parameter class holds parameters
@@ -43,19 +43,24 @@ import org.onap.policy.apex.model.basicmodel.service.ParameterService;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class EngineParameters extends AbstractParameters {
+public class EngineParameters implements ParameterGroup {
private ContextParameters contextParameters = new ContextParameters();
+ // Parameter group name
+ private String name;
+
// A map of parameters for executors of various logic types
- private Map<String, ExecutorParameters> executorParameterMap = new TreeMap<String, ExecutorParameters>();
+ private Map<String, ExecutorParameters> executorParameterMap = new TreeMap<>();
/**
* Constructor to create an engine parameters instance and register the instance with the
* parameter service.
*/
public EngineParameters() {
- super(EngineParameters.class.getCanonicalName());
- ParameterService.registerParameters(EngineParameters.class, this);
+ super();
+
+ // Set the name for the parameters
+ this.name = EngineParameterConstants.MAIN_GROUP_NAME;
}
/**
@@ -93,4 +98,19 @@ public class EngineParameters extends AbstractParameters {
public void setExecutorParameterMap(final Map<String, ExecutorParameters> executorParameterMap) {
this.executorParameterMap = executorParameterMap;
}
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ @Override
+ public GroupValidationResult validate() {
+ return new GroupValidationResult(this);
+ }
}
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/ExecutorParameters.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/ExecutorParameters.java
index 53cac399e..7de121d66 100644
--- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/ExecutorParameters.java
+++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/ExecutorParameters.java
@@ -20,8 +20,8 @@
package org.onap.policy.apex.core.engine;
-import org.onap.policy.apex.model.basicmodel.service.AbstractParameters;
-import org.onap.policy.apex.model.basicmodel.service.ParameterService;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ParameterGroup;
/**
* This class provides the executors for a logic flavour. Plugin classes for execution of task
@@ -32,7 +32,10 @@ import org.onap.policy.apex.model.basicmodel.service.ParameterService;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class ExecutorParameters extends AbstractParameters {
+public class ExecutorParameters implements ParameterGroup {
+ // Parameter group name
+ private String name;
+
// Executor Plugin classes for executors
private String taskExecutorPluginClass;
private String taskSelectionExecutorPluginClass;
@@ -43,18 +46,10 @@ public class ExecutorParameters extends AbstractParameters {
* parameter service.
*/
public ExecutorParameters() {
- super(ExecutorParameters.class.getCanonicalName());
- ParameterService.registerParameters(ExecutorParameters.class, this);
- }
+ super();
- /**
- * Constructor to create an executor parameters instance with the name of a sub class of this
- * class and register the instance with the parameter service.
- *
- * @param parameterClassName the class name of a sub class of this class
- */
- public ExecutorParameters(final String parameterClassName) {
- super(parameterClassName);
+ // Set the name for the parameters
+ this.name = EngineParameterConstants.EXECUTOR_GROUP_NAME;
}
/**
@@ -113,15 +108,25 @@ public class ExecutorParameters extends AbstractParameters {
this.stateFinalizerExecutorPluginClass = stateFinalizerExecutorPluginClass;
}
- /*
- * (non-Javadoc)
- *
- * @see org.onap.policy.apex.model.basicmodel.service.AbstractParameters#toString()
- */
@Override
public String toString() {
- return "ExecutorParameters [taskExecutorPluginClass=" + taskExecutorPluginClass
- + ", taskSelectionExecutorPluginClass=" + taskSelectionExecutorPluginClass
- + ", StateFinalizerExecutorPluginClass=" + stateFinalizerExecutorPluginClass + "]";
+ return "ExecutorParameters [name=" + name + ", taskExecutorPluginClass=" + taskExecutorPluginClass
+ + ", taskSelectionExecutorPluginClass=" + taskSelectionExecutorPluginClass
+ + ", stateFinalizerExecutorPluginClass=" + stateFinalizerExecutorPluginClass + "]";
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ @Override
+ public GroupValidationResult validate() {
+ return new GroupValidationResult(this);
}
}
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);