diff options
author | Jim Hahn <jrh3@att.com> | 2019-08-13 15:52:22 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-08-15 09:21:28 -0400 |
commit | fdaae76549bafb2e482c02fb26de719c69431b48 (patch) | |
tree | a3f477da55f80fe7e4bed3d959d8089cf1971438 /controlloop/common | |
parent | 9e8023a455633c7daf0dd291c6268986e39352d7 (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')
14 files changed, 134 insertions, 124 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()); diff --git a/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/apps/controlloop/feature/management/ControlLoopManagementFeature.java b/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/apps/controlloop/feature/management/ControlLoopManagementFeature.java index 3b5792a42..ae19b914e 100644 --- a/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/apps/controlloop/feature/management/ControlLoopManagementFeature.java +++ b/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/apps/controlloop/feature/management/ControlLoopManagementFeature.java @@ -24,6 +24,7 @@ import java.util.stream.Stream; import org.onap.policy.controlloop.params.ControlLoopParams; import org.onap.policy.drools.features.PolicyEngineFeatureApi; import org.onap.policy.drools.system.PolicyController; +import org.onap.policy.drools.system.PolicyControllerConstants; /** * Control Loop Management Feature. @@ -100,7 +101,7 @@ public class ControlLoopManagementFeature implements PolicyEngineFeatureApi { */ public static class Factory { public PolicyController getController(String controllerName) { - return PolicyController.factory.get(controllerName); + return PolicyControllerConstants.getFactory().get(controllerName); } } } diff --git a/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java b/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java index 4b62e489a..08b218dd6 100644 --- a/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java +++ b/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java @@ -47,8 +47,8 @@ import org.onap.policy.controlloop.params.ControlLoopParams; import org.onap.policy.controlloop.processor.ControlLoopProcessor; import org.onap.policy.drools.apps.controlloop.feature.management.ControlLoopManagementFeature; import org.onap.policy.drools.controller.DroolsController; -import org.onap.policy.drools.system.PolicyController; -import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.drools.system.PolicyControllerConstants; +import org.onap.policy.drools.system.PolicyEngineConstants; import org.onap.policy.rest.RestManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -206,7 +206,7 @@ public class RestControlLoopManager { .build(); } - DroolsController controller = PolicyController.factory.get(controllerName).getDrools(); + DroolsController controller = PolicyControllerConstants.getFactory().get(controllerName).getDrools(); controlLoop = new ControlLoopParams(); controlLoop.setPolicyScope(controller.getGroupId()); @@ -240,9 +240,13 @@ public class RestControlLoopManager { return Response .status(Status.OK) .entity(new AaiManager(new RestManager()) - .getCustomQueryResponse(PolicyEngine.manager.getEnvironmentProperty(ControlLoopEventManager.AAI_URL), - PolicyEngine.manager.getEnvironmentProperty(ControlLoopEventManager.AAI_USERNAME_PROPERTY), - PolicyEngine.manager.getEnvironmentProperty(ControlLoopEventManager.AAI_PASS_PROPERTY), + .getCustomQueryResponse( + PolicyEngineConstants.getManager() + .getEnvironmentProperty(ControlLoopEventManager.AAI_URL), + PolicyEngineConstants.getManager().getEnvironmentProperty( + ControlLoopEventManager.AAI_USERNAME_PROPERTY), + PolicyEngineConstants.getManager().getEnvironmentProperty( + ControlLoopEventManager.AAI_PASS_PROPERTY), UUID.randomUUID(), vserverId)) .build(); @@ -261,9 +265,13 @@ public class RestControlLoopManager { return Response .status(Status.OK) .entity(new AaiManager(new RestManager()) - .postQuery(PolicyEngine.manager.getEnvironmentProperty(ControlLoopEventManager.AAI_URL), - PolicyEngine.manager.getEnvironmentProperty(ControlLoopEventManager.AAI_USERNAME_PROPERTY), - PolicyEngine.manager.getEnvironmentProperty(ControlLoopEventManager.AAI_PASS_PROPERTY), + .postQuery( + PolicyEngineConstants.getManager() + .getEnvironmentProperty(ControlLoopEventManager.AAI_URL), + PolicyEngineConstants.getManager().getEnvironmentProperty( + ControlLoopEventManager.AAI_USERNAME_PROPERTY), + PolicyEngineConstants.getManager().getEnvironmentProperty( + ControlLoopEventManager.AAI_PASS_PROPERTY), ControlLoopEventManager.getAaiNqRequest(vserverId), UUID.randomUUID())) .build(); diff --git a/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java index ae14a64b7..833adfb69 100644 --- a/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java +++ b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java @@ -46,10 +46,10 @@ import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager; -import org.onap.policy.drools.persistence.SystemPersistence; -import org.onap.policy.drools.properties.DroolsProperties; -import org.onap.policy.drools.system.PolicyController; -import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.drools.persistence.SystemPersistenceConstants; +import org.onap.policy.drools.properties.DroolsPropertyConstants; +import org.onap.policy.drools.system.PolicyControllerConstants; +import org.onap.policy.drools.system.PolicyEngineConstants; import org.onap.policy.drools.util.KieUtils; import org.onap.policy.drools.utils.logging.LoggerUtil; import org.onap.policy.simulators.Util; @@ -97,22 +97,23 @@ public class RestControlLoopManagerTest { System.setProperty("kie.maven.settings.custom", "src/test/resources/settings.xml"); LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "WARN"); - SystemPersistence.manager.setConfigurationDir("src/test/resources"); - PolicyEngine.manager.configure(PolicyEngine.manager.defaultTelemetryConfig()); + SystemPersistenceConstants.getManager().setConfigurationDir("src/test/resources"); + PolicyEngineConstants.getManager().configure(PolicyEngineConstants.getManager().defaultTelemetryConfig()); ReleaseId releaseId = KieUtils.installArtifact(Paths.get(KMODULE_PATH).toFile(), Paths.get(KMODULE_POM_PATH).toFile(), KJAR_DRL_PATH, Paths.get(KMODULE_DRL_PATH).toFile()); Properties controllerProperties = new Properties(); - controllerProperties.put(DroolsProperties.RULES_GROUPID, releaseId.getGroupId()); - controllerProperties.put(DroolsProperties.RULES_ARTIFACTID, releaseId.getArtifactId()); - controllerProperties.put(DroolsProperties.RULES_VERSION, releaseId.getVersion()); + controllerProperties.put(DroolsPropertyConstants.RULES_GROUPID, releaseId.getGroupId()); + controllerProperties.put(DroolsPropertyConstants.RULES_ARTIFACTID, releaseId.getArtifactId()); + controllerProperties.put(DroolsPropertyConstants.RULES_VERSION, releaseId.getVersion()); - PolicyEngine.manager.createPolicyController(CONTROLLER, controllerProperties); - PolicyEngine.manager.start(); + PolicyEngineConstants.getManager().createPolicyController(CONTROLLER, controllerProperties); + PolicyEngineConstants.getManager().start(); - HttpClientFactoryInstance.getClientFactory().build(SystemPersistence.manager.getProperties(CLIENT_CONFIG)); + HttpClientFactoryInstance.getClientFactory() + .build(SystemPersistenceConstants.getManager().getProperties(CLIENT_CONFIG)); if (!NetworkUtil.isTcpPortOpen("localhost", 9696, 6, 10000L)) { throw new IllegalStateException("cannot connect to port 9696"); @@ -120,9 +121,9 @@ public class RestControlLoopManagerTest { await().atMost(1, TimeUnit.MINUTES).until(isContainerAlive()); - PolicyEngine.manager.setEnvironmentProperty(ControlLoopEventManager.AAI_URL, "http://localhost:6666"); - PolicyEngine.manager.setEnvironmentProperty(ControlLoopEventManager.AAI_USERNAME_PROPERTY, "AAI"); - PolicyEngine.manager.setEnvironmentProperty(ControlLoopEventManager.AAI_PASS_PROPERTY, "AAI"); + PolicyEngineConstants.getManager().setEnvironmentProperty(ControlLoopEventManager.AAI_URL, "http://localhost:6666"); + PolicyEngineConstants.getManager().setEnvironmentProperty(ControlLoopEventManager.AAI_USERNAME_PROPERTY, "AAI"); + PolicyEngineConstants.getManager().setEnvironmentProperty(ControlLoopEventManager.AAI_PASS_PROPERTY, "AAI"); Util.buildAaiSim(); } @@ -132,14 +133,14 @@ public class RestControlLoopManagerTest { */ @AfterClass public static void tearDown() { - PolicyController.factory.get(CONTROLLER).stop(); + PolicyControllerConstants.getFactory().get(CONTROLLER).stop(); await().atMost(1, TimeUnit.MINUTES).until(isContainerAlive(), equalTo(Boolean.FALSE)); - PolicyEngine.manager.removePolicyController(CONTROLLER); - PolicyEngine.manager.stop(); + PolicyEngineConstants.getManager().removePolicyController(CONTROLLER); + PolicyEngineConstants.getManager().stop(); final Path controllerPath = - Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), CONTROLLER_FILE); + Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), CONTROLLER_FILE); try { Files.deleteIfExists(controllerPath); } catch (Exception ignored) { @@ -147,7 +148,7 @@ public class RestControlLoopManagerTest { } Path controllerBakPath = - Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), CONTROLLER_FILE_BAK); + Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), CONTROLLER_FILE_BAK); try { Files.deleteIfExists(controllerBakPath); @@ -230,6 +231,6 @@ public class RestControlLoopManagerTest { * @return if the container is alive. */ private static Callable<Boolean> isContainerAlive() { - return () -> PolicyController.factory.get(CONTROLLER).getDrools().getContainer().isAlive(); + return () -> PolicyControllerConstants.getFactory().get(CONTROLLER).getDrools().getContainer().isAlive(); } } diff --git a/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/CacheBasedControlLoopMetricsManager.java b/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/CacheBasedControlLoopMetricsManager.java index b2a82a29e..9dc4c5ad3 100644 --- a/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/CacheBasedControlLoopMetricsManager.java +++ b/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/CacheBasedControlLoopMetricsManager.java @@ -24,7 +24,6 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.cache.RemovalListener; - import java.time.Instant; import java.time.ZonedDateTime; import java.util.ArrayList; @@ -32,10 +31,9 @@ import java.util.List; import java.util.Properties; import java.util.UUID; import java.util.concurrent.TimeUnit; - import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.VirtualControlLoopNotification; -import org.onap.policy.drools.persistence.SystemPersistence; +import org.onap.policy.drools.persistence.SystemPersistenceConstants; import org.onap.policy.drools.system.PolicyController; import org.onap.policy.drools.utils.logging.MdcTransaction; import org.slf4j.Logger; @@ -57,8 +55,8 @@ class CacheBasedControlLoopMetricsManager implements ControlLoopMetrics { public CacheBasedControlLoopMetricsManager() { - Properties properties = - SystemPersistence.manager.getProperties(ControlLoopMetricsFeature.CONFIGURATION_PROPERTIES_NAME); + Properties properties = SystemPersistenceConstants.getManager() + .getProperties(ControlLoopMetricsFeature.CONFIGURATION_PROPERTIES_NAME); /* cache size */ diff --git a/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java b/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java index bbbcc132f..b416736ab 100644 --- a/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java +++ b/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java @@ -36,9 +36,9 @@ import org.junit.Test; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.controlloop.ControlLoopNotificationType; import org.onap.policy.controlloop.VirtualControlLoopNotification; -import org.onap.policy.drools.persistence.SystemPersistence; +import org.onap.policy.drools.persistence.SystemPersistenceConstants; import org.onap.policy.drools.system.PolicyController; -import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.drools.system.PolicyEngineConstants; /** * ControlLoopMetrics Tests. @@ -46,7 +46,7 @@ import org.onap.policy.drools.system.PolicyEngine; public class ControlLoopMetricsFeatureTest { private static final String POLICY_CL_MGT = "POLICY-CL-MGT"; - private static final Path configPath = SystemPersistence.manager.getConfigurationPath(); + private static final Path configPath = SystemPersistenceConstants.getManager().getConfigurationPath(); private static PolicyController testController; /** @@ -54,14 +54,14 @@ public class ControlLoopMetricsFeatureTest { */ @BeforeClass public static void setUp() { - SystemPersistence.manager.setConfigurationDir("src/test/resources"); - testController = PolicyEngine.manager.createPolicyController("metrics", - SystemPersistence.manager.getControllerProperties("metrics")); + SystemPersistenceConstants.getManager().setConfigurationDir("src/test/resources"); + testController = PolicyEngineConstants.getManager().createPolicyController("metrics", + SystemPersistenceConstants.getManager().getControllerProperties("metrics")); } @AfterClass public static void tearDown() { - SystemPersistence.manager.setConfigurationDir(configPath.toString()); + SystemPersistenceConstants.getManager().setConfigurationDir(configPath.toString()); } @Test diff --git a/controlloop/common/feature-controlloop-utils/src/test/java/org/onap/policy/drools/apps/controlloop/feature/utils/ControlLoopUtilsFeatureTest.java b/controlloop/common/feature-controlloop-utils/src/test/java/org/onap/policy/drools/apps/controlloop/feature/utils/ControlLoopUtilsFeatureTest.java index 899b7ce8e..3999797a9 100644 --- a/controlloop/common/feature-controlloop-utils/src/test/java/org/onap/policy/drools/apps/controlloop/feature/utils/ControlLoopUtilsFeatureTest.java +++ b/controlloop/common/feature-controlloop-utils/src/test/java/org/onap/policy/drools/apps/controlloop/feature/utils/ControlLoopUtilsFeatureTest.java @@ -24,7 +24,7 @@ import static org.junit.Assert.assertNotNull; import org.junit.Test; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; -import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.drools.system.PolicyEngineConstants; import org.onap.policy.drools.utils.logging.LoggerUtil; import org.onap.policy.simulators.Util; @@ -38,7 +38,7 @@ public class ControlLoopUtilsFeatureTest { LoggerUtil.setLevel("ROOT", "INFO"); LoggerUtil.setLevel("org.eclipse.jetty", "WARN"); final ControlLoopUtilsFeature feature = new ControlLoopUtilsFeature(); - feature.afterStart(PolicyEngine.manager); + feature.afterStart(PolicyEngineConstants.getManager()); assertNotNull(HttpServletServerFactoryInstance.getServerFactory().get(Util.AAISIM_SERVER_PORT)); assertNotNull(HttpServletServerFactoryInstance.getServerFactory().get(Util.SOSIM_SERVER_PORT)); assertNotNull(HttpServletServerFactoryInstance.getServerFactory().get(Util.SOSIM_SERVER_PORT)); diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java index 22fce1999..611dd2d8b 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java @@ -66,7 +66,7 @@ public class CallGuardTask implements Runnable { private PolicyGuardResponse guardResponse; /** - * Guard url is grabbed from PolicyEngine.manager properties + * Guard url is grabbed from PolicyEngine manager properties. */ public CallGuardTask(WorkingMemory wm, String cl, String act, String rec, String tar, String reqId, Supplier<Integer> vfcnt) { diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java index 53f1cea4b..ed6cd6c5f 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java @@ -24,13 +24,12 @@ package org.onap.policy.guard; import java.util.HashMap; import java.util.Map; import java.util.UUID; - import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.utils.NetLoggerUtil; import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.drools.system.PolicyEngineConstants; import org.onap.policy.models.decisions.concepts.DecisionRequest; import org.onap.policy.models.decisions.concepts.DecisionResponse; import org.onap.policy.rest.RestManager; @@ -50,9 +49,9 @@ public class PolicyGuardXacmlHelper { * Constructor. */ public PolicyGuardXacmlHelper() { - this.url = PolicyEngine.manager.getEnvironmentProperty("guard.url"); - this.user = PolicyEngine.manager.getEnvironmentProperty("pdpx.username"); - this.pwd = PolicyEngine.manager.getEnvironmentProperty("pdpx.password"); + this.url = PolicyEngineConstants.getManager().getEnvironmentProperty("guard.url"); + this.user = PolicyEngineConstants.getManager().getEnvironmentProperty("pdpx.username"); + this.pwd = PolicyEngineConstants.getManager().getEnvironmentProperty("pdpx.password"); } /** diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java index d859fbe09..717ca3f45 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java @@ -25,11 +25,10 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; - import org.apache.commons.io.IOUtils; import org.onap.policy.controlloop.policy.ControlLoopPolicy; import org.onap.policy.controlloop.policy.guard.ControlLoopGuard; -import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.drools.system.PolicyEngineConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.yaml.snakeyaml.Yaml; @@ -135,16 +134,16 @@ public final class Util { * <p>see /guard/src/test/java/org/onap/policy/guard/UtilTest.java for setting test properties */ public static void setGuardEnvProps(String url, String username, String password) { - PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_URL, url); - PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_USER, username); - PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_PASS, password); + PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_URL, url); + PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_USER, username); + PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_PASS, password); } public static void setGuardEnvProp(String key, String value) { - PolicyEngine.manager.setEnvironmentProperty(key, value); + PolicyEngineConstants.getManager().setEnvironmentProperty(key, value); } public static String getGuardProp(String propName) { - return PolicyEngine.manager.getEnvironmentProperty(propName); + return PolicyEngineConstants.getManager().getEnvironmentProperty(propName); } } diff --git a/controlloop/common/guard/src/test/java/org/onap/policy/guard/PolicyGuardXacmlHelperTest.java b/controlloop/common/guard/src/test/java/org/onap/policy/guard/PolicyGuardXacmlHelperTest.java index 9d252b9f1..d0194da38 100644 --- a/controlloop/common/guard/src/test/java/org/onap/policy/guard/PolicyGuardXacmlHelperTest.java +++ b/controlloop/common/guard/src/test/java/org/onap/policy/guard/PolicyGuardXacmlHelperTest.java @@ -28,7 +28,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; -import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.drools.system.PolicyEngineConstants; import org.onap.policy.drools.utils.logging.LoggerUtil; public class PolicyGuardXacmlHelperTest { @@ -106,45 +106,45 @@ public class PolicyGuardXacmlHelperTest { @Test public void testInit() { - final Properties savedEnvironment = (Properties) PolicyEngine.manager.getEnvironment().clone(); + final Properties savedEnvironment = (Properties) PolicyEngineConstants.getManager().getEnvironment().clone(); assertNotNull(new PolicyGuardXacmlHelper()); - PolicyEngine.manager.getEnvironment().setProperty(GUARD_URL, + PolicyEngineConstants.getManager().getEnvironment().setProperty(GUARD_URL, "http://localhost:6669/pdp/api/getDecision,Dorothy"); assertNotNull(new PolicyGuardXacmlHelper()); - PolicyEngine.manager.getEnvironment().setProperty(GUARD_URL, + PolicyEngineConstants.getManager().getEnvironment().setProperty(GUARD_URL, "http://localhost:6669/pdp/api/getDecision,Dorothy,Toto"); assertNotNull(new PolicyGuardXacmlHelper()); - PolicyEngine.manager.getEnvironment().setProperty(GUARD_URL, + PolicyEngineConstants.getManager().getEnvironment().setProperty(GUARD_URL, "http://localhost:6969/policy/pdpx/v1/decision"); - PolicyEngine.manager.getEnvironment().setProperty("pdpx.timeout", "thisIsNotANumber"); + PolicyEngineConstants.getManager().getEnvironment().setProperty("pdpx.timeout", "thisIsNotANumber"); assertNotNull(new PolicyGuardXacmlHelper()); - PolicyEngine.manager.getEnvironment().setProperty("pdpx.timeout", "1000"); + PolicyEngineConstants.getManager().getEnvironment().setProperty("pdpx.timeout", "1000"); assertNotNull(new PolicyGuardXacmlHelper()); - PolicyEngine.manager.getEnvironment().remove("pdpx.password"); + PolicyEngineConstants.getManager().getEnvironment().remove("pdpx.password"); assertNotNull(new PolicyGuardXacmlHelper()); - PolicyEngine.manager.getEnvironment().setProperty("pdpx.username", "python"); + PolicyEngineConstants.getManager().getEnvironment().setProperty("pdpx.username", "python"); assertNotNull(new PolicyGuardXacmlHelper()); - PolicyEngine.manager.getEnvironment().setProperty(GUARD_URL, "///"); + PolicyEngineConstants.getManager().getEnvironment().setProperty(GUARD_URL, "///"); assertNotNull(new PolicyGuardXacmlHelper()); - PolicyEngine.manager.getEnvironment().setProperty("guard.disabled", ""); + PolicyEngineConstants.getManager().getEnvironment().setProperty("guard.disabled", ""); assertNotNull(new PolicyGuardXacmlHelper()); - PolicyEngine.manager.getEnvironment().setProperty("guard.disabled", "true"); + PolicyEngineConstants.getManager().getEnvironment().setProperty("guard.disabled", "true"); assertNotNull(new PolicyGuardXacmlHelper()); - PolicyEngine.manager.getEnvironment().clear(); + PolicyEngineConstants.getManager().getEnvironment().clear(); assertNotNull(new PolicyGuardXacmlHelper()); - PolicyEngine.manager.setEnvironment(savedEnvironment); + PolicyEngineConstants.getManager().setEnvironment(savedEnvironment); } } |