aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java3
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java55
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/parameters/CommonTestData.java54
-rw-r--r--main/src/test/resources/parameters/MinimumParameters.json8
-rw-r--r--main/src/test/resources/parameters/PapConfigParameters.json8
-rw-r--r--main/src/test/resources/parameters/PapConfigParameters_InvalidName.json8
6 files changed, 91 insertions, 45 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java b/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java
index 21dcac0a..0690fadd 100644
--- a/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java
+++ b/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java
@@ -22,9 +22,11 @@
package org.onap.policy.pap.main.parameters;
import lombok.Getter;
+
import org.onap.policy.common.parameters.ParameterGroupImpl;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.models.provider.PolicyModelsProviderParameters;
/**
* Class to hold all parameters needed for pap component.
@@ -37,6 +39,7 @@ import org.onap.policy.common.parameters.annotations.NotNull;
public class PapParameterGroup extends ParameterGroupImpl {
private RestServerParameters restServerParameters;
private PdpParameters pdpParameters;
+ private PolicyModelsProviderParameters databaseProviderParameters;
/**
* Create the pap parameter group.
diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
index 0d078ac8..42634ee7 100644
--- a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
+++ b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
@@ -22,9 +22,9 @@
package org.onap.policy.pap.main.startstop;
import java.util.Arrays;
-import java.util.Base64;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
+
import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher;
@@ -34,7 +34,6 @@ import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.common.utils.services.ServiceManagerContainer;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.enums.PdpMessageType;
-import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.pap.main.PapConstants;
import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper;
import org.onap.policy.pap.main.PolicyPapRuntimeException;
@@ -48,14 +47,14 @@ import org.onap.policy.pap.main.rest.PapRestServer;
import org.onap.policy.pap.main.rest.PapStatisticsManager;
/**
- * This class wraps a distributor so that it can be activated as a complete service
- * together with all its pap and forwarding handlers.
+ * This class wraps a distributor so that it can be activated as a complete service together with all its pap and
+ * forwarding handlers.
*
* @author Ram Krishna Verma (ram.krishna.verma@est.tech)
*/
public class PapActivator extends ServiceManagerContainer {
- private static final String[] MSG_TYPE_NAMES = {"messageName"};
- private static final String[] REQ_ID_NAMES = {"response", "responseTo"};
+ private static final String[] MSG_TYPE_NAMES = { "messageName" };
+ private static final String[] REQ_ID_NAMES = { "response", "responseTo" };
private final PapParameterGroup papParameterGroup;
@@ -65,14 +64,14 @@ public class PapActivator extends ServiceManagerContainer {
private PapRestServer restServer;
/**
- * Listens for messages on the topic, decodes them into a {@link PdpStatus} message,
- * and then dispatches them to {@link #reqIdDispatcher}.
+ * Listens for messages on the topic, decodes them into a {@link PdpStatus} message, and then dispatches them to
+ * {@link #reqIdDispatcher}.
*/
private final MessageTypeDispatcher msgDispatcher;
/**
- * Listens for {@link PdpStatus} messages and then routes them to the listener
- * associated with the ID of the originating request.
+ * Listens for {@link PdpStatus} messages and then routes them to the listener associated with the ID of the
+ * originating request.
*/
private final RequestIdDispatcher<PdpStatus> reqIdDispatcher;
@@ -82,7 +81,7 @@ public class PapActivator extends ServiceManagerContainer {
* @param papParameterGroup the parameters for the pap service
* @param topicProperties properties used to configure the topics
*/
- public PapActivator(final PapParameterGroup papParameterGroup, Properties topicProperties) {
+ public PapActivator(final PapParameterGroup papParameterGroup, final Properties topicProperties) {
super("Policy PAP");
TopicEndpoint.manager.addTopicSinks(topicProperties);
@@ -93,25 +92,18 @@ public class PapActivator extends ServiceManagerContainer {
this.msgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES);
this.reqIdDispatcher = new RequestIdDispatcher<>(PdpStatus.class, REQ_ID_NAMES);
- } catch (RuntimeException e) {
+ } catch (final RuntimeException e) {
throw new PolicyPapRuntimeException(e);
}
papParameterGroup.getRestServerParameters().setName(papParameterGroup.getName());
- // TODO add these to the json property file
- PolicyModelsProviderParameters daoParams = new PolicyModelsProviderParameters();
- daoParams.setDatabaseUrl("jdbc:h2:mem:testdb");
- daoParams.setDatabaseUser("policy");
- daoParams.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
- daoParams.setPersistenceUnit("ToscaConceptTest");
-
final Object pdpUpdateLock = new Object();
- PdpParameters pdpParams = papParameterGroup.getPdpParameters();
- AtomicReference<Publisher> pdpPub = new AtomicReference<>();
- AtomicReference<TimerManager> pdpUpdTimers = new AtomicReference<>();
- AtomicReference<TimerManager> pdpStChgTimers = new AtomicReference<>();
- AtomicReference<PolicyModelsProviderFactoryWrapper> daoFactory = new AtomicReference<>();
+ final PdpParameters pdpParams = papParameterGroup.getPdpParameters();
+ final AtomicReference<Publisher> pdpPub = new AtomicReference<>();
+ final AtomicReference<TimerManager> pdpUpdTimers = new AtomicReference<>();
+ final AtomicReference<TimerManager> pdpStChgTimers = new AtomicReference<>();
+ final AtomicReference<PolicyModelsProviderFactoryWrapper> daoFactory = new AtomicReference<>();
// @formatter:off
addAction("PAP parameters",
@@ -119,7 +111,8 @@ public class PapActivator extends ServiceManagerContainer {
() -> ParameterService.deregister(papParameterGroup.getName()));
addAction("DAO Factory",
- () -> daoFactory.set(new PolicyModelsProviderFactoryWrapper(daoParams)),
+ () -> daoFactory.set(new PolicyModelsProviderFactoryWrapper(
+ papParameterGroup.getDatabaseProviderParameters())),
() -> daoFactory.get().close());
addAction("DAO Factory registration",
@@ -197,8 +190,8 @@ public class PapActivator extends ServiceManagerContainer {
*
* @param runner function to run in the background
*/
- private void startThread(Runnable runner) {
- Thread thread = new Thread(runner);
+ private void startThread(final Runnable runner) {
+ final Thread thread = new Thread(runner);
thread.setDaemon(true);
thread.start();
@@ -217,8 +210,8 @@ public class PapActivator extends ServiceManagerContainer {
* Registers the dispatcher with the topic source(s).
*/
private void registerMsgDispatcher() {
- for (TopicSource source : TopicEndpoint.manager
- .getTopicSources(Arrays.asList(PapConstants.TOPIC_POLICY_PDP_PAP))) {
+ for (final TopicSource source : TopicEndpoint.manager
+ .getTopicSources(Arrays.asList(PapConstants.TOPIC_POLICY_PDP_PAP))) {
source.register(msgDispatcher);
}
}
@@ -227,8 +220,8 @@ public class PapActivator extends ServiceManagerContainer {
* Unregisters the dispatcher from the topic source(s).
*/
private void unregisterMsgDispatcher() {
- for (TopicSource source : TopicEndpoint.manager
- .getTopicSources(Arrays.asList(PapConstants.TOPIC_POLICY_PDP_PAP))) {
+ for (final TopicSource source : TopicEndpoint.manager
+ .getTopicSources(Arrays.asList(PapConstants.TOPIC_POLICY_PDP_PAP))) {
source.unregister(msgDispatcher);
}
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/pap/main/parameters/CommonTestData.java
index 9d0a1abb..38d8621e 100644
--- a/main/src/test/java/org/onap/policy/pap/main/parameters/CommonTestData.java
+++ b/main/src/test/java/org/onap/policy/pap/main/parameters/CommonTestData.java
@@ -21,13 +21,16 @@
package org.onap.policy.pap.main.parameters;
+import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
+
import org.onap.policy.common.parameters.ParameterGroup;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.models.provider.PolicyModelsProviderParameters;
/**
* Class to hold/create all parameters for test cases.
@@ -53,27 +56,29 @@ public class CommonTestData {
* @param clazz class of object to be created from the map
* @return a new object represented by the map
*/
- public <T extends ParameterGroup> T toObject(Map<String, Object> source, Class<T> clazz) {
+ public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
try {
return coder.decode(coder.encode(source), clazz);
- } catch (CoderException e) {
+ } catch (final CoderException e) {
throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
}
}
/**
* Returns a property map for a PapParameterGroup map for test cases.
+ *
* @param name name of the parameters
*
* @return a property map suitable for constructing an object
*/
- public Map<String, Object> getPapParameterGroupMap(String name) {
- Map<String,Object> map = new TreeMap<>();
+ public Map<String, Object> getPapParameterGroupMap(final String name) {
+ final Map<String, Object> map = new TreeMap<>();
map.put("name", name);
map.put("restServerParameters", getRestServerParametersMap(false));
map.put("pdpParameters", getPdpParametersMap());
+ map.put("databaseProviderParameters", getPolicyModelsProviderParametersMap());
return map;
}
@@ -84,8 +89,8 @@ public class CommonTestData {
* @param isEmpty boolean value to represent that object created should be empty or not
* @return a property map suitable for constructing an object
*/
- public Map<String,Object> getRestServerParametersMap(final boolean isEmpty) {
- Map<String,Object> map = new TreeMap<>();
+ public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
+ final Map<String, Object> map = new TreeMap<>();
map.put("https", REST_SERVER_HTTPS);
map.put("aaf", REST_SERVER_AAF);
@@ -101,10 +106,11 @@ public class CommonTestData {
/**
* Returns a property map for a PdpParameters map for test cases.
+ *
* @return a property map suitable for constructing an object
*/
- public Map<String,Object> getPdpParametersMap() {
- Map<String,Object> map = new TreeMap<>();
+ public Map<String, Object> getPdpParametersMap() {
+ final Map<String, Object> map = new TreeMap<>();
map.put("updateParameters", getPdpUpdateParametersMap());
map.put("stateChangeParameters", getPdpStateChangeParametersMap());
@@ -114,26 +120,29 @@ public class CommonTestData {
/**
* Returns a property map for a PdpUpdateParameters map for test cases.
+ *
* @return a property map suitable for constructing an object
*/
- public Map<String,Object> getPdpUpdateParametersMap() {
+ public Map<String, Object> getPdpUpdateParametersMap() {
return getPdpRequestParametersMap();
}
/**
* Returns a property map for a PdpStateChangeParameters map for test cases.
+ *
* @return a property map suitable for constructing an object
*/
- public Map<String,Object> getPdpStateChangeParametersMap() {
+ public Map<String, Object> getPdpStateChangeParametersMap() {
return getPdpRequestParametersMap();
}
/**
* Returns a property map for a PdpParameters map for test cases.
+ *
* @return a property map suitable for constructing an object
*/
- public Map<String,Object> getPdpRequestParametersMap() {
- Map<String, Object> map = new HashMap<>();
+ public Map<String, Object> getPdpRequestParametersMap() {
+ final Map<String, Object> map = new HashMap<>();
map.put("maxRetryCount", "1");
map.put("maxWaitMs", "2");
@@ -145,10 +154,27 @@ public class CommonTestData {
*
* @return a property map suitable for constructing an object
*/
- public Map<String,Object> getPdpGroupDeploymentParametersMap() {
- Map<String,Object> map = new TreeMap<>();
+ public Map<String, Object> getPdpGroupDeploymentParametersMap() {
+ final Map<String, Object> map = new TreeMap<>();
map.put("waitResponseMs", "1");
return map;
}
+
+ /**
+ * Returns a property map for a PolicyModelsProviderParameters map for test cases.
+ *
+ * @return a property map suitable for constructing an object
+ */
+ public Map<String, Object> getPolicyModelsProviderParametersMap() {
+ final Map<String, Object> map = new TreeMap<>();
+ map.put("name", PolicyModelsProviderParameters.class.getSimpleName());
+ map.put("implementation", REST_SERVER_HTTPS);
+ map.put("databaseUrl", "jdbc:h2:mem:testdb");
+ map.put("databaseUser", "policy");
+ map.put("databasePassword", Base64.getEncoder().encodeToString("P01icY".getBytes()));
+ map.put("persistenceUnit", "PdpGroupTest");
+
+ return map;
+ }
}
diff --git a/main/src/test/resources/parameters/MinimumParameters.json b/main/src/test/resources/parameters/MinimumParameters.json
index b35acec5..7e7d3ee7 100644
--- a/main/src/test/resources/parameters/MinimumParameters.json
+++ b/main/src/test/resources/parameters/MinimumParameters.json
@@ -15,5 +15,13 @@
"maxRetryCount": 1,
"maxWaitMs": 1
}
+ },
+ "databaseProviderParameters": {
+ "name": "PolicyProviderParameterGroup",
+ "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
+ "databaseUrl": "jdbc:h2:mem:testdb",
+ "databaseUser": "policy",
+ "databasePassword": "P01icY",
+ "persistenceUnit": "PdpGroupTest"
}
}
diff --git a/main/src/test/resources/parameters/PapConfigParameters.json b/main/src/test/resources/parameters/PapConfigParameters.json
index a510964f..c967fdf1 100644
--- a/main/src/test/resources/parameters/PapConfigParameters.json
+++ b/main/src/test/resources/parameters/PapConfigParameters.json
@@ -16,5 +16,13 @@
"maxRetryCount": 1,
"maxWaitMs": 1
}
+ },
+ "databaseProviderParameters": {
+ "name": "PolicyProviderParameterGroup",
+ "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
+ "databaseUrl": "jdbc:h2:mem:testdb",
+ "databaseUser": "policy",
+ "databasePassword": "P01icY",
+ "persistenceUnit": "PdpGroupTest"
}
}
diff --git a/main/src/test/resources/parameters/PapConfigParameters_InvalidName.json b/main/src/test/resources/parameters/PapConfigParameters_InvalidName.json
index 7b53b880..8cb74172 100644
--- a/main/src/test/resources/parameters/PapConfigParameters_InvalidName.json
+++ b/main/src/test/resources/parameters/PapConfigParameters_InvalidName.json
@@ -15,5 +15,13 @@
"maxRetryCount": 1,
"maxWaitMs": 1
}
+ },
+ "databaseProviderParameters": {
+ "name": "PolicyProviderParameterGroup",
+ "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
+ "databaseUrl": "jdbc:h2:mem:testdb",
+ "databaseUser": "policy",
+ "databasePassword": "P01icY",
+ "persistenceUnit": "PdpGroupTest"
}
}