aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-08-13 15:52:22 -0400
committerJim Hahn <jrh3@att.com>2019-08-15 09:21:28 -0400
commitfdaae76549bafb2e482c02fb26de719c69431b48 (patch)
treea3f477da55f80fe7e4bed3d959d8089cf1971438 /controlloop/common/eventmanager
parent9e8023a455633c7daf0dd291c6268986e39352d7 (diff)
Modify to work with new drools-pdp
Due to sonar fixes, drools-pdp changed in a way that requires changes to drools-applications. In the case of template.demo, lots of test cases had to be modified, so they were refactored to extract common setup and tear down code. Fixed checkstyle issues. Fixed license date. Change-Id: Ie9e0239b95916ae7ef8c1b669987f7bb07d841b9 Issue-ID: POLICY-1968 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common/eventmanager')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java22
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java40
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java14
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java32
4 files changed, 56 insertions, 52 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
index 298513619..aaccef60b 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
@@ -58,7 +58,7 @@ import org.onap.policy.controlloop.VirtualControlLoopNotification;
import org.onap.policy.controlloop.policy.FinalResult;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.processor.ControlLoopProcessor;
-import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.guard.GuardResult;
import org.onap.policy.guard.LockCallback;
import org.onap.policy.guard.PolicyGuard;
@@ -888,9 +888,9 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
try {
if (vserverName != null) {
- String aaiHostUrl = PolicyEngine.manager.getEnvironmentProperty(AAI_URL);
- String aaiUser = PolicyEngine.manager.getEnvironmentProperty(AAI_USERNAME_PROPERTY);
- String aaiPassword = PolicyEngine.manager.getEnvironmentProperty(AAI_PASS_PROPERTY);
+ String aaiHostUrl = PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_URL);
+ String aaiUser = PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_USERNAME_PROPERTY);
+ String aaiPassword = PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_PASS_PROPERTY);
String aaiGetQueryByVserver = "/aai/v11/nodes/vservers?vserver-name=";
String url = aaiHostUrl + aaiGetQueryByVserver;
logger.info("AAI Host URL by VServer: {}", url);
@@ -918,9 +918,9 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
String vnfName = event.getAai().get(GENERIC_VNF_VNF_NAME);
String vnfId = event.getAai().get(GENERIC_VNF_VNF_ID);
- String aaiHostUrl = PolicyEngine.manager.getEnvironmentProperty(AAI_URL);
- String aaiUser = PolicyEngine.manager.getEnvironmentProperty(AAI_USERNAME_PROPERTY);
- String aaiPassword = PolicyEngine.manager.getEnvironmentProperty(AAI_PASS_PROPERTY);
+ String aaiHostUrl = PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_URL);
+ String aaiUser = PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_USERNAME_PROPERTY);
+ String aaiPassword = PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_PASS_PROPERTY);
try {
if (vnfName != null) {
@@ -1024,7 +1024,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
* @return the property value
*/
private static String getPeManagerEnvProperty(String enginePropertyName) {
- String enginePropertyValue = PolicyEngine.manager.getEnvironmentProperty(enginePropertyName);
+ String enginePropertyValue = PolicyEngineConstants.getManager().getEnvironmentProperty(enginePropertyName);
if (enginePropertyValue == null) {
throw new IllegalArgumentException("The value of policy engine manager environment property \""
+ enginePropertyName + "\" may not be null");
@@ -1082,9 +1082,9 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
AaiCqResponse response = null;
String vserverId = event.getAai().get(VSERVER_VSERVER_NAME);
- String aaiHostUrl = PolicyEngine.manager.getEnvironmentProperty(AAI_URL);
- String aaiUser = PolicyEngine.manager.getEnvironmentProperty(AAI_USERNAME_PROPERTY);
- String aaiPassword = PolicyEngine.manager.getEnvironmentProperty(AAI_PASS_PROPERTY);
+ String aaiHostUrl = PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_URL);
+ String aaiUser = PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_USERNAME_PROPERTY);
+ String aaiPassword = PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_PASS_PROPERTY);
response = new AaiManager(new RestManager()).getCustomQueryResponse(aaiHostUrl, aaiUser, aaiPassword, reqId,
vserverId);
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
index cac1b8ee3..293fa43aa 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
@@ -52,7 +52,7 @@ import org.onap.policy.controlloop.actor.vfc.VfcActorServiceProvider;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.database.operationshistory.Dbao;
-import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.guard.Util;
import org.onap.policy.sdnc.SdncResponse;
import org.onap.policy.sdnr.PciResponseWrapper;
@@ -141,7 +141,7 @@ public class ControlLoopOperationManager implements Serializable {
* The target vnf-id may not be the same as the source vnf-id specified in the yaml, the target
* vnf-id is retrieved by a named query to A&AI.
*/
- if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
+ if (Boolean.valueOf(PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
GenericVnf genvnf = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset)
.getGenericVnfByModelInvariantId(policy.getTarget().getResourceID());
if (genvnf == null) {
@@ -153,9 +153,9 @@ public class ControlLoopOperationManager implements Serializable {
} else {
this.targetEntity =
AppcLcmActorServiceProvider.vnfNamedQuery(policy.getTarget().getResourceID(),
- this.targetEntity, PolicyEngine.manager.getEnvironmentProperty("aai.url"),
- PolicyEngine.manager.getEnvironmentProperty("aai.username"),
- PolicyEngine.manager.getEnvironmentProperty("aai.password"));
+ this.targetEntity, PolicyEngineConstants.getManager().getEnvironmentProperty("aai.url"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("aai.username"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("aai.password"));
}
}
}
@@ -260,7 +260,7 @@ public class ControlLoopOperationManager implements Serializable {
*/
try {
String vnfId;
- if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
+ if (Boolean.valueOf(PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
vnfId = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset).getDefaultGenericVnf()
.getVnfId();
} else {
@@ -347,7 +347,7 @@ public class ControlLoopOperationManager implements Serializable {
private Object startSoOperation(ControlLoopEvent onset, Operation operation) throws AaiException {
SoActorServiceProvider soActorSp = new SoActorServiceProvider();
- if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
+ if (Boolean.valueOf(PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
this.operationRequest =
soActorSp.constructRequestCq((VirtualControlLoopEvent) onset, operation.clOperation,
this.policy, eventManager.getCqResponse((VirtualControlLoopEvent) onset));
@@ -368,16 +368,16 @@ public class ControlLoopOperationManager implements Serializable {
private Object startVfcOperation(ControlLoopEvent onset, Operation operation) throws AaiException {
- if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
+ if (Boolean.valueOf(PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
this.operationRequest = VfcActorServiceProvider.constructRequestCq((VirtualControlLoopEvent) onset,
operation.clOperation, this.policy,
eventManager.getCqResponse((VirtualControlLoopEvent) onset));
} else {
this.operationRequest = VfcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
operation.clOperation, this.policy, this.eventManager.getVnfResponse(),
- PolicyEngine.manager.getEnvironmentProperty("vfc.url"),
- PolicyEngine.manager.getEnvironmentProperty("vfc.username"),
- PolicyEngine.manager.getEnvironmentProperty("vfc.password"));
+ PolicyEngineConstants.getManager().getEnvironmentProperty("vfc.url"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("vfc.username"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("vfc.password"));
}
this.currentOperation = operation;
if (this.operationRequest == null) {
@@ -951,7 +951,8 @@ public class ControlLoopOperationManager implements Serializable {
private void storeOperationInDataBase() {
// Only store in DB if enabled
- boolean guardEnabled = "false".equalsIgnoreCase(PolicyEngine.manager.getEnvironmentProperty("guard.disabled"));
+ boolean guardEnabled = "false"
+ .equalsIgnoreCase(PolicyEngineConstants.getManager().getEnvironmentProperty("guard.disabled"));
if (!guardEnabled) {
return;
}
@@ -959,12 +960,15 @@ public class ControlLoopOperationManager implements Serializable {
// DB Properties
Properties props = new Properties();
- if (PolicyEngine.manager.getEnvironmentProperty(Util.ONAP_KEY_URL) != null
- && PolicyEngine.manager.getEnvironmentProperty(Util.ONAP_KEY_USER) != null
- && PolicyEngine.manager.getEnvironmentProperty(Util.ONAP_KEY_PASS) != null) {
- props.put(Util.ECLIPSE_LINK_KEY_URL, PolicyEngine.manager.getEnvironmentProperty(Util.ONAP_KEY_URL));
- props.put(Util.ECLIPSE_LINK_KEY_USER, PolicyEngine.manager.getEnvironmentProperty(Util.ONAP_KEY_USER));
- props.put(Util.ECLIPSE_LINK_KEY_PASS, PolicyEngine.manager.getEnvironmentProperty(Util.ONAP_KEY_PASS));
+ if (PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_URL) != null
+ && PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_USER) != null
+ && PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_PASS) != null) {
+ props.put(Util.ECLIPSE_LINK_KEY_URL,
+ PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_URL));
+ props.put(Util.ECLIPSE_LINK_KEY_USER,
+ PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_USER));
+ props.put(Util.ECLIPSE_LINK_KEY_PASS,
+ PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_PASS));
props.put(PersistenceUnitProperties.CLASSLOADER, ControlLoopOperationManager.class.getClassLoader());
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
index b7dc1f0d9..0b27ffa49 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
@@ -65,7 +65,7 @@ import org.onap.policy.controlloop.VirtualControlLoopNotification;
import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager.NewEventStatus;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.guard.GuardResult;
import org.onap.policy.guard.PolicyGuard;
import org.onap.policy.guard.PolicyGuard.LockResult;
@@ -115,9 +115,9 @@ public class ControlLoopEventManagerTest {
public static void setUpSimulator() throws Exception {
org.onap.policy.simulators.Util.buildAaiSim();
- PolicyEngine.manager.setEnvironmentProperty(AAI_USERNAME, "AAI");
- PolicyEngine.manager.setEnvironmentProperty(AAI_PASS, "AAI");
- PolicyEngine.manager.setEnvironmentProperty(AAI_URL, "http://localhost:6666");
+ PolicyEngineConstants.getManager().setEnvironmentProperty(AAI_USERNAME, "AAI");
+ PolicyEngineConstants.getManager().setEnvironmentProperty(AAI_PASS, "AAI");
+ PolicyEngineConstants.getManager().setEnvironmentProperty(AAI_URL, "http://localhost:6666");
}
@AfterClass
@@ -141,7 +141,7 @@ public class ControlLoopEventManagerTest {
onset.getAai().put(VNF_ID, VNF_UUID);
onset.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
- PolicyEngine.manager.setEnvironmentProperty(AAI_URL, "http://localhost:6666");
+ PolicyEngineConstants.getManager().setEnvironmentProperty(AAI_URL, "http://localhost:6666");
}
@Test
@@ -1008,7 +1008,7 @@ public class ControlLoopEventManagerTest {
@Test(expected = AaiException.class)
public void testQueryAai_QueryException() throws AaiException {
// Force AAI errors
- PolicyEngine.manager.setEnvironmentProperty(AAI_URL, INVALID_URL);
+ PolicyEngineConstants.getManager().setEnvironmentProperty(AAI_URL, INVALID_URL);
makeManager(onset).queryAai(onset);
}
@@ -1231,7 +1231,7 @@ public class ControlLoopEventManagerTest {
// Force AAI error
- PolicyEngine.manager.setEnvironmentProperty(AAI_URL, INVALID_URL);
+ PolicyEngineConstants.getManager().setEnvironmentProperty(AAI_URL, INVALID_URL);
// re-create manager
manager = makeManager(onset);
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java
index 13fe72517..9b1633521 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java
@@ -68,7 +68,7 @@ import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.controlloop.policy.Target;
import org.onap.policy.controlloop.policy.TargetType;
import org.onap.policy.controlloop.processor.ControlLoopProcessor;
-import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.so.SoResponse;
import org.onap.policy.so.SoResponseWrapper;
import org.onap.policy.vfc.VfcResponse;
@@ -108,9 +108,9 @@ public class ControlLoopOperationManagerTest {
onset.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
/* Set environment properties */
- PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
- PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
- PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("aai.url", "http://localhost:6666");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("aai.username", "AAI");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("aai.password", "AAI");
}
private static EntityManagerFactory emf;
@@ -138,9 +138,9 @@ public class ControlLoopOperationManagerTest {
System.setProperty(OPERATIONS_HISTORY_PU, OPERATIONS_HISTORY_PU_TEST);
// Enter dummy props to avoid nullPointerException
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL, "a");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, "b");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "c");
+ PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL, "a");
+ PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, "b");
+ PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "c");
// Connect to in-mem db
emf = Persistence.createEntityManagerFactory(OPERATIONS_HISTORY_PU_TEST);
@@ -443,7 +443,7 @@ public class ControlLoopOperationManagerTest {
onsetEvent.getAai().remove(VNF_ID);
manager.getVnfResponse();
- if (!Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) {
+ if (!Boolean.valueOf(PolicyEngineConstants.getManager().getEnvironmentProperty("aai.customQuery"))) {
clom.getEventManager().getVnfResponse().setVnfId(VNF_ID);
assertEquals(VNF_ID, clom.getTarget(policy));
}
@@ -733,11 +733,11 @@ public class ControlLoopOperationManagerTest {
SoResponse soResponse = new SoResponse();
final SoResponseWrapper soRw = new SoResponseWrapper(soResponse, null);
- PolicyEngine.manager.setEnvironmentProperty("guard.disabled", "false");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL,
+ PolicyEngineConstants.getManager().setEnvironmentProperty("guard.disabled", "false");
+ PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL,
"http://somewhere.over.the.rainbow");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, DOROTHY);
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "Toto");
+ PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, DOROTHY);
+ PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "Toto");
assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw));
@@ -822,11 +822,11 @@ public class ControlLoopOperationManagerTest {
SoResponse soResponse = new SoResponse();
final SoResponseWrapper soRw = new SoResponseWrapper(soResponse, null);
- PolicyEngine.manager.setEnvironmentProperty("guard.disabled", "false");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL,
+ PolicyEngineConstants.getManager().setEnvironmentProperty("guard.disabled", "false");
+ PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL,
"http://somewhere.over.the.rainbow");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, DOROTHY);
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "Toto");
+ PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, DOROTHY);
+ PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "Toto");
assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw));
assertFalse(clom.isOperationRunning());