From e87b2f7632dedf0067ea2417fb1157a8638df101 Mon Sep 17 00:00:00 2001 From: mmis Date: Mon, 23 Jul 2018 12:22:07 +0100 Subject: Copy policy-endpoints from drools-pdp to common Replaced references to classes deleted from drools-pdp with references to the corresponding in policy-common Issue-ID: POLICY-967 Change-Id: Ia9d2ac704e6b7c434e5a9e7aee6d7dcf9198e4f2 Signed-off-by: mmis --- controlloop/common/actors/actor.appc/pom.xml | 6 + .../actor/appc/AppcServiceProviderTest.java | 2 +- controlloop/common/actors/actor.appclcm/pom.xml | 6 + .../actor/appclcm/AppcLcmServiceProviderTest.java | 2 +- controlloop/common/actors/actor.so/pom.xml | 6 + .../actor/so/TestSOActorServiceProvider.java | 2 +- controlloop/common/actors/actor.vfc/pom.xml | 6 + .../actor/vfc/TestVFCActorServiceProvider.java | 2 +- controlloop/common/eventmanager/pom.xml | 6 + .../eventmanager/ControlLoopEventManagerTest.java | 8 +- .../ControlLoopOperationManagerTest.java | 2 +- .../common/feature-controlloop-trans/pom.xml | 6 + .../feature/trans/ControlLoopMetricsFeature.java | 8 +- .../trans/ControlLoopMetricsFeatureTest.java | 35 +-- .../common/feature-controlloop-utils/pom.xml | 6 + .../feature/utils/ControlLoopUtilsFeatureTest.java | 2 +- controlloop/common/guard/pom.xml | 6 + .../onap/policy/guard/PolicyGuardXacmlHelper.java | 2 +- .../policy/guard/PolicyGuardXacmlHelperTest.java | 2 +- controlloop/common/model-impl/aai/pom.xml | 2 +- .../main/java/org/onap/policy/aai/AaiManager.java | 2 +- controlloop/common/model-impl/so/pom.xml | 6 + .../main/java/org/onap/policy/so/SOManager.java | 107 ++++---- controlloop/common/model-impl/vfc/pom.xml | 6 + .../main/java/org/onap/policy/vfc/VFCManager.java | 280 +++++++++++---------- controlloop/common/simulators/pom.xml | 2 +- .../main/java/org/onap/policy/simulators/Util.java | 4 +- .../onap/policy/simulators/AaiSimulatorTest.java | 2 +- .../onap/policy/simulators/GuardSimulatorTest.java | 2 +- .../onap/policy/simulators/SoSimulatorTest.java | 2 +- .../onap/policy/simulators/VfcSimulatorTest.java | 2 +- controlloop/templates/template.demo/pom.xml | 6 + .../template/demo/ControlLoopFailureTest.java | 14 +- .../java/org/onap/policy/template/demo/Util.java | 2 +- .../policy/template/demo/VCPEControlLoopTest.java | 14 +- .../policy/template/demo/VDNSControlLoopTest.java | 14 +- .../policy/template/demo/VFCControlLoopTest.java | 14 +- .../policy/template/demo/VFWControlLoopTest.java | 14 +- 38 files changed, 350 insertions(+), 260 deletions(-) (limited to 'controlloop') diff --git a/controlloop/common/actors/actor.appc/pom.xml b/controlloop/common/actors/actor.appc/pom.xml index f8dde7572..4ed4d0aa2 100644 --- a/controlloop/common/actors/actor.appc/pom.xml +++ b/controlloop/common/actors/actor.appc/pom.xml @@ -75,6 +75,12 @@ ${project.version} test + + org.onap.policy.common + policy-endpoints + ${project.version} + provided + org.onap.policy.drools-pdp policy-management diff --git a/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java b/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java index f081e8105..5130276e2 100644 --- a/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java +++ b/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java @@ -36,6 +36,7 @@ import org.onap.policy.appc.Request; import org.onap.policy.appc.Response; import org.onap.policy.appc.ResponseCode; import org.onap.policy.appc.util.Serialization; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.ControlLoopTargetType; @@ -43,7 +44,6 @@ import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.controlloop.policy.Target; import org.onap.policy.controlloop.policy.TargetType; -import org.onap.policy.drools.http.server.HttpServletServer; import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.simulators.Util; import org.slf4j.Logger; diff --git a/controlloop/common/actors/actor.appclcm/pom.xml b/controlloop/common/actors/actor.appclcm/pom.xml index 0cc110266..ecd98ffb6 100644 --- a/controlloop/common/actors/actor.appclcm/pom.xml +++ b/controlloop/common/actors/actor.appclcm/pom.xml @@ -63,6 +63,12 @@ ${project.version} provided + + org.onap.policy.common + policy-endpoints + ${project.version} + provided + org.onap.policy.drools-pdp policy-management diff --git a/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java b/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java index 4fb6ac4b9..48c613dce 100644 --- a/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java +++ b/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java @@ -38,6 +38,7 @@ import org.onap.policy.appclcm.LcmRequest; import org.onap.policy.appclcm.LcmRequestWrapper; import org.onap.policy.appclcm.LcmResponse; import org.onap.policy.appclcm.LcmResponseWrapper; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.ControlLoopTargetType; @@ -46,7 +47,6 @@ import org.onap.policy.controlloop.policy.Policy; 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.drools.http.server.HttpServletServer; import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.simulators.Util; import org.slf4j.Logger; diff --git a/controlloop/common/actors/actor.so/pom.xml b/controlloop/common/actors/actor.so/pom.xml index e91de19b6..1b59de8c3 100644 --- a/controlloop/common/actors/actor.so/pom.xml +++ b/controlloop/common/actors/actor.so/pom.xml @@ -68,6 +68,12 @@ 2.5 provided + + org.onap.policy.common + policy-endpoints + ${project.version} + provided + org.onap.policy.drools-pdp policy-management diff --git a/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java index 9d5ff6f77..5333be58d 100644 --- a/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java +++ b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java @@ -30,10 +30,10 @@ import java.util.UUID; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.policy.Policy; -import org.onap.policy.drools.http.server.HttpServletServer; import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.simulators.Util; import org.onap.policy.so.SORequest; diff --git a/controlloop/common/actors/actor.vfc/pom.xml b/controlloop/common/actors/actor.vfc/pom.xml index 4474e96b6..c0d9bbb71 100644 --- a/controlloop/common/actors/actor.vfc/pom.xml +++ b/controlloop/common/actors/actor.vfc/pom.xml @@ -56,6 +56,12 @@ ${project.version} provided + + org.onap.policy.common + policy-endpoints + ${project.version} + provided + org.onap.policy.drools-pdp policy-management diff --git a/controlloop/common/actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/TestVFCActorServiceProvider.java b/controlloop/common/actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/TestVFCActorServiceProvider.java index 86b0aeef7..65425b01e 100644 --- a/controlloop/common/actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/TestVFCActorServiceProvider.java +++ b/controlloop/common/actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/TestVFCActorServiceProvider.java @@ -31,10 +31,10 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.aai.AaiGetVnfResponse; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.policy.Policy; -import org.onap.policy.drools.http.server.HttpServletServer; import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.simulators.Util; import org.onap.policy.vfc.VFCRequest; diff --git a/controlloop/common/eventmanager/pom.xml b/controlloop/common/eventmanager/pom.xml index 99c13e7ae..1f35d1c41 100644 --- a/controlloop/common/eventmanager/pom.xml +++ b/controlloop/common/eventmanager/pom.xml @@ -160,6 +160,12 @@ 4.5.5 provided + + org.onap.policy.common + policy-endpoints + ${project.version} + provided + org.onap.policy.drools-pdp policy-management 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 0c626e247..711848167 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 @@ -48,6 +48,7 @@ import org.onap.policy.aai.RelationshipData; import org.onap.policy.aai.RelationshipDataItem; import org.onap.policy.aai.RelationshipList; import org.onap.policy.aai.util.AaiException; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopException; import org.onap.policy.controlloop.ControlLoopNotificationType; @@ -57,7 +58,6 @@ import org.onap.policy.controlloop.VirtualControlLoopNotification; import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager.NEW_EVENT_STATUS; import org.onap.policy.controlloop.policy.ControlLoopPolicy; import org.onap.policy.controlloop.policy.PolicyResult; -import org.onap.policy.drools.http.server.HttpServletServer; import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.guard.GuardResult; import org.onap.policy.guard.PolicyGuard; @@ -461,7 +461,7 @@ public class ControlLoopEventManagerTest { public void testMethods() { UUID requestId = UUID.randomUUID(); ControlLoopEventManager clem = new ControlLoopEventManager("MyClosedLoopName", requestId); - + assertEquals("MyClosedLoopName", clem.getClosedLoopControlName()); assertEquals(requestId, clem.getRequestID()); @@ -959,9 +959,9 @@ public class ControlLoopEventManagerTest { // repeat query with same manager manager.queryAai(onsetEvent); - + // remaining queries each use their own manager so they will be re-executed - + makeManager(onsetEvent).queryAai(onsetEvent); onsetEvent.getAai().put("generic-vnf.is-closed-loop-disabled", "true"); 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 fd4405d61..cd541cf66 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 @@ -50,6 +50,7 @@ import org.onap.policy.appclcm.LcmRequest; import org.onap.policy.appclcm.LcmRequestWrapper; import org.onap.policy.appclcm.LcmResponse; import org.onap.policy.appclcm.LcmResponseWrapper; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopException; import org.onap.policy.controlloop.ControlLoopNotificationType; @@ -63,7 +64,6 @@ 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.http.server.HttpServletServer; import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.so.SOResponse; import org.onap.policy.so.SOResponseWrapper; diff --git a/controlloop/common/feature-controlloop-trans/pom.xml b/controlloop/common/feature-controlloop-trans/pom.xml index e76a7a756..3dd7b9572 100644 --- a/controlloop/common/feature-controlloop-trans/pom.xml +++ b/controlloop/common/feature-controlloop-trans/pom.xml @@ -96,6 +96,12 @@ events ${project.version} + + org.onap.policy.common + policy-endpoints + ${project.version} + provided + org.onap.policy.drools-pdp policy-management diff --git a/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeature.java b/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeature.java index 29630e33c..b15fb1479 100644 --- a/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeature.java +++ b/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeature.java @@ -20,8 +20,8 @@ package org.onap.policy.drools.apps.controlloop.feature.trans; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.controlloop.VirtualControlLoopNotification; -import org.onap.policy.drools.event.comm.Topic.CommInfrastructure; import org.onap.policy.drools.features.PolicyControllerFeatureAPI; import org.onap.policy.drools.system.PolicyController; import org.slf4j.Logger; @@ -51,7 +51,8 @@ public class ControlLoopMetricsFeature implements PolicyControllerFeatureAPI { /** * transaction timeout in minutes */ - public static final String CL_CACHE_TRANS_TIMEOUT_SECONDS_PROPERTY = "controllop.cache.transactions.timeout.seconds"; + public static final String CL_CACHE_TRANS_TIMEOUT_SECONDS_PROPERTY = + "controllop.cache.transactions.timeout.seconds"; public static final long CL_CACHE_TRANS_TIMEOUT_SECONDS_DEFAULT = 1L * 60 * 60; @Override @@ -75,8 +76,9 @@ public class ControlLoopMetricsFeature implements PolicyControllerFeatureAPI { */ @Override public boolean beforeDeliver(PolicyController controller, CommInfrastructure protocol, String topic, Object event) { - if (event instanceof VirtualControlLoopNotification) + if (event instanceof VirtualControlLoopNotification) { ControlLoopMetrics.manager.transactionEvent(controller, (VirtualControlLoopNotification) event); + } /* do not take ownership */ return false; 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 4c113aca7..df93c7a5e 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 @@ -20,23 +20,24 @@ package org.onap.policy.drools.apps.controlloop.feature.trans; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.nio.file.Path; import java.util.UUID; + import org.junit.AfterClass; import org.junit.BeforeClass; 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.event.comm.Topic.CommInfrastructure; import org.onap.policy.drools.persistence.SystemPersistence; import org.onap.policy.drools.system.PolicyController; import org.onap.policy.drools.system.PolicyEngine; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - /** * ControlLoopMetrics Tests */ @@ -48,9 +49,8 @@ public class ControlLoopMetricsFeatureTest { @BeforeClass public static void setUp() { SystemPersistence.manager.setConfigurationDir("src/test/resources"); - testController = - PolicyEngine.manager.createPolicyController - ("metrics", SystemPersistence.manager.getControllerProperties("metrics")); + testController = PolicyEngine.manager.createPolicyController("metrics", + SystemPersistence.manager.getControllerProperties("metrics")); } @AfterClass @@ -96,7 +96,7 @@ public class ControlLoopMetricsFeatureTest { /* let the entries expire */ try { - Thread.sleep((ControlLoopMetrics.manager.getTransactionTimeout()+5)*1000L); + Thread.sleep((ControlLoopMetrics.manager.getTransactionTimeout() + 5) * 1000L); } catch (InterruptedException e) { /* nothing to do */ } @@ -108,11 +108,13 @@ public class ControlLoopMetricsFeatureTest { @Test public void reset() { VirtualControlLoopNotification notification = this.generateNotification(); - new ControlLoopMetricsFeature().beforeDeliver(testController, CommInfrastructure.DMAAP, "POLICY-CL-MGT", notification); + new ControlLoopMetricsFeature().beforeDeliver(testController, CommInfrastructure.DMAAP, "POLICY-CL-MGT", + notification); assertNotNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestId())); - ControlLoopMetrics.manager.resetCache(ControlLoopMetrics.manager.getCacheSize(), ControlLoopMetrics.manager.getTransactionTimeout()); + ControlLoopMetrics.manager.resetCache(ControlLoopMetrics.manager.getCacheSize(), + ControlLoopMetrics.manager.getTransactionTimeout()); assertNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestId())); this.cacheDefaults(); } @@ -132,7 +134,7 @@ public class ControlLoopMetricsFeatureTest { @Test public void eviction() { ControlLoopMetricsFeature feature = new ControlLoopMetricsFeature(); - for (int i=0; i < ControlLoopMetrics.manager.getCacheSize(); i++) { + for (int i = 0; i < ControlLoopMetrics.manager.getCacheSize(); i++) { VirtualControlLoopNotification notification = generateNotification(); feature.beforeDeliver(testController, CommInfrastructure.DMAAP, "POLICY-CL-MGT", notification); assertNotNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestId())); @@ -151,13 +153,14 @@ public class ControlLoopMetricsFeatureTest { /* let the entries expire */ try { - Thread.sleep((ControlLoopMetrics.manager.getTransactionTimeout()+5)*1000L); + Thread.sleep((ControlLoopMetrics.manager.getTransactionTimeout() + 5) * 1000L); } catch (InterruptedException e) { /* nothing to do */ } ControlLoopMetrics.manager.refresh(); - assertTrue(ControlLoopMetrics.manager.getTransactionIds().size() == ControlLoopMetrics.manager.getCacheOccupancy()); + assertTrue(ControlLoopMetrics.manager.getTransactionIds().size() == ControlLoopMetrics.manager + .getCacheOccupancy()); assertFalse(ControlLoopMetrics.manager.getCacheOccupancy() == ControlLoopMetrics.manager.getCacheSize()); assertTrue(ControlLoopMetrics.manager.getTransactionIds().isEmpty()); assertTrue(ControlLoopMetrics.manager.getTransactions().isEmpty()); @@ -178,4 +181,4 @@ public class ControlLoopMetricsFeatureTest { ControlLoopMetricsFeature feature = new ControlLoopMetricsFeature(); assertTrue(feature.getSequenceNumber() == ControlLoopMetricsFeature.FEATURE_SEQUENCE_PRIORITY); } -} \ No newline at end of file +} diff --git a/controlloop/common/feature-controlloop-utils/pom.xml b/controlloop/common/feature-controlloop-utils/pom.xml index 018f22a8b..b5cc09128 100644 --- a/controlloop/common/feature-controlloop-utils/pom.xml +++ b/controlloop/common/feature-controlloop-utils/pom.xml @@ -101,6 +101,12 @@ ${project.version} provided + + org.onap.policy.common + policy-endpoints + ${project.version} + provided + org.onap.policy.drools-pdp policy-endpoints 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 bb058262f..07b999e56 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 @@ -23,7 +23,7 @@ package org.onap.policy.drools.apps.controlloop.feature.utils; import static org.junit.Assert.assertNotNull; import org.junit.Test; -import org.onap.policy.drools.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.drools.utils.logging.LoggerUtil; import org.onap.policy.simulators.Util; diff --git a/controlloop/common/guard/pom.xml b/controlloop/common/guard/pom.xml index 86c00283a..232dfbc20 100644 --- a/controlloop/common/guard/pom.xml +++ b/controlloop/common/guard/pom.xml @@ -79,6 +79,12 @@ 2.7.0 provided + + org.onap.policy.common + policy-endpoints + ${project.version} + provided + org.onap.policy.drools-pdp policy-management 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 777240fea..321d80ce2 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 @@ -49,7 +49,7 @@ import org.slf4j.LoggerFactory; public class PolicyGuardXacmlHelper { private static final Logger logger = LoggerFactory.getLogger(PolicyGuardXacmlHelper.class); private static final Logger netLogger = - LoggerFactory.getLogger(org.onap.policy.drools.event.comm.Topic.NETWORK_LOGGER); + LoggerFactory.getLogger(org.onap.policy.common.endpoints.event.comm.Topic.NETWORK_LOGGER); // Constant for the systme line separator private static final String SYSTEM_LS = System.lineSeparator(); 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 628bfedc2..867c05d2f 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 @@ -54,7 +54,7 @@ import java.util.UUID; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.policy.drools.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.drools.utils.logging.LoggerUtil; diff --git a/controlloop/common/model-impl/aai/pom.xml b/controlloop/common/model-impl/aai/pom.xml index 93f7dad61..2a885ec2f 100644 --- a/controlloop/common/model-impl/aai/pom.xml +++ b/controlloop/common/model-impl/aai/pom.xml @@ -61,7 +61,7 @@ test - org.onap.policy.drools-pdp + org.onap.policy.common policy-endpoints ${project.version} provided diff --git a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java index 4aa231cb8..56f79d378 100644 --- a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java +++ b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java @@ -45,7 +45,7 @@ public final class AaiManager { /** The Constant netLogger. */ private static final Logger netLogger = - LoggerFactory.getLogger(org.onap.policy.drools.event.comm.Topic.NETWORK_LOGGER); + LoggerFactory.getLogger(org.onap.policy.common.endpoints.event.comm.Topic.NETWORK_LOGGER); /** The rest manager. */ // The REST manager used for processing REST calls for this AAI manager diff --git a/controlloop/common/model-impl/so/pom.xml b/controlloop/common/model-impl/so/pom.xml index ddbc4f231..0780a3970 100644 --- a/controlloop/common/model-impl/so/pom.xml +++ b/controlloop/common/model-impl/so/pom.xml @@ -53,6 +53,12 @@ rest ${project.version} + + org.onap.policy.common + policy-endpoints + ${project.version} + provided + org.onap.policy.drools-pdp policy-management diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java index 8190b1a54..ae43f5bd9 100644 --- a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java @@ -40,14 +40,15 @@ import org.slf4j.LoggerFactory; /** - * This class handles the interface towards SO (Service Orchestrator) for the ONAP Policy Framework. The SO - * API is defined at this link: + * This class handles the interface towards SO (Service Orchestrator) for the ONAP Policy Framework. + * The SO API is defined at this link: * http://onap.readthedocs.io/en/latest/submodules/so.git/docs/SO_R1_Interface.html#get-orchestration-request - * + * */ public final class SOManager { private static final Logger logger = LoggerFactory.getLogger(SOManager.class); - private static final Logger netLogger = LoggerFactory.getLogger(org.onap.policy.drools.event.comm.Topic.NETWORK_LOGGER); + private static final Logger netLogger = + LoggerFactory.getLogger(org.onap.policy.common.endpoints.event.comm.Topic.NETWORK_LOGGER); private static ExecutorService executors = Executors.newCachedThreadPool(); private static final int SO_RESPONSE_ERROR = 999; @@ -55,7 +56,7 @@ public final class SOManager { private static final String LINE_SEPARATOR = System.lineSeparator(); // REST get timeout value in milliseconds - private static final int GET_REQUESTS_BEFORE_TIMEOUT = 20; + private static final int GET_REQUESTS_BEFORE_TIMEOUT = 20; private static final long GET_REQUEST_WAIT_INTERVAL = 20000; // The REST manager used for processing REST calls for this VFC manager @@ -72,6 +73,7 @@ public final class SOManager { /** * Create a service instance in SO. + * * @param url the SO URL * @param urlBase the base URL * @param username user name on SO @@ -79,24 +81,28 @@ public final class SOManager { * @param request the request to issue to SO * @return */ - public SOResponse createModuleInstance(final String url, final String urlBase, final String username, final String password, final SORequest request) { + public SOResponse createModuleInstance(final String url, final String urlBase, final String username, + final String password, final SORequest request) { // Issue the HTTP POST request to SO to create the service instance String requestJson = Serialization.gsonPretty.toJson(request); - netLogger.info("[OUT|{}|{}|{}|{}|{}|{}|]{}{}", "SO", url, username, password, createSimpleHeaders(), MEDIA_TYPE, LINE_SEPARATOR, requestJson); - Pair httpResponse = restManager.post(url, username, password, createSimpleHeaders(), MEDIA_TYPE, requestJson); + netLogger.info("[OUT|{}|{}|{}|{}|{}|{}|]{}{}", "SO", url, username, password, createSimpleHeaders(), MEDIA_TYPE, + LINE_SEPARATOR, requestJson); + Pair httpResponse = + restManager.post(url, username, password, createSimpleHeaders(), MEDIA_TYPE, requestJson); // Process the response from SO - SOResponse response = waitForSOOperationCompletion(urlBase, username, password, url, httpResponse); + SOResponse response = waitForSOOperationCompletion(urlBase, username, password, url, httpResponse); if (SO_RESPONSE_ERROR != response.getHttpResponseCode()) { return response; - } - else { + } else { return null; } } - + /** - * This method makes an asynchronous Rest call to MSO and inserts the response into Drools working memory. + * This method makes an asynchronous Rest call to MSO and inserts the response into Drools + * working memory. + * * @param wm the Drools working memory * @param url the URL to use on the POST request * @param urlBase the SO base URL @@ -105,7 +111,8 @@ public final class SOManager { * @param request the SO request * @return a concurrent Future for the thread that handles the request */ - public Future asyncSORestCall(final String requestID, final WorkingMemory wm, final String serviceInstanceId, final String vnfInstanceId, final SORequest request) { + public Future asyncSORestCall(final String requestID, final WorkingMemory wm, + final String serviceInstanceId, final String vnfInstanceId, final SORequest request) { return executors.submit(new AsyncSORestCallThread(requestID, wm, serviceInstanceId, vnfInstanceId, request)); } @@ -121,13 +128,15 @@ public final class SOManager { /** * Constructor, sets the context of the request. + * * @param requestID The request ID * @param wm reference to the Drools working memory * @param serviceInstanceId the service instance in SO to use * @param vnfInstanceId the VNF instance that is the subject of the request * @param request the request itself */ - private AsyncSORestCallThread(final String requestID, final WorkingMemory wm, final String serviceInstanceId, final String vnfInstanceId, final SORequest request) { + private AsyncSORestCallThread(final String requestID, final WorkingMemory wm, final String serviceInstanceId, + final String vnfInstanceId, final SORequest request) { this.requestID = requestID; this.wm = wm; this.serviceInstanceId = serviceInstanceId; @@ -145,37 +154,39 @@ public final class SOManager { String password = PolicyEngine.manager.getEnvironmentProperty("so.password"); // The URL of the request we will POST - String url = urlBase + "/serviceInstances/v5/" + serviceInstanceId + "/vnfs/" - + vnfInstanceId + "/vfModules"; + String url = + urlBase + "/serviceInstances/v5/" + serviceInstanceId + "/vnfs/" + vnfInstanceId + "/vfModules"; // Create a JSON representation of the request String soJson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create().toJson(request); netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, LINE_SEPARATOR, soJson); - Pair httpResponse = restManager.post(url, username, password, createSimpleHeaders(), MEDIA_TYPE, soJson); + Pair httpResponse = + restManager.post(url, username, password, createSimpleHeaders(), MEDIA_TYPE, soJson); // Process the response from SO - SOResponse response = waitForSOOperationCompletion(urlBase, username, password, url, httpResponse); - + SOResponse response = waitForSOOperationCompletion(urlBase, username, password, url, httpResponse); + // Return the response to Drools in its working memory SOResponseWrapper soWrapper = new SOResponseWrapper(response, requestID); wm.insert(soWrapper); - + return response; } } /** * Wait for the SO operation we have ordered to complete. - * @param urlBaseSO The base URL for SO + * + * @param urlBaseSO The base URL for SO * @param username user name on SO * @param password password on SO * @param initialRequestURL The URL of the initial HTTP request * @param initialHTTPResponse The initial HTTP message returned from SO - * @return The parsed final response of SO to the request + * @return The parsed final response of SO to the request */ - private SOResponse waitForSOOperationCompletion(final String urlBaseSO, final String username, final String password, - final String initialRequestURL, final Pair initialHTTPResponse) { + private SOResponse waitForSOOperationCompletion(final String urlBaseSO, final String username, + final String password, final String initialRequestURL, final Pair initialHTTPResponse) { // Process the initial response from SO, the response to a post SOResponse response = processSOResponse(initialRequestURL, initialHTTPResponse); if (SO_RESPONSE_ERROR == response.getHttpResponseCode()) { @@ -190,7 +201,8 @@ public final class SOManager { // Wait for the response from SO for (int attemptsLeft = GET_REQUESTS_BEFORE_TIMEOUT; attemptsLeft >= 0; attemptsLeft--) { - // The SO request may have completed even on the first request so we check the response here before + // The SO request may have completed even on the first request so we check the response + // here before // issuing any other requests if (isRequestStateFinished(latestHTTPResponse, response)) { return response; @@ -199,16 +211,16 @@ public final class SOManager { // Wait for the defined interval before issuing a get try { Thread.sleep(restGetTimeout); - } - catch (InterruptedException e) { + } catch (InterruptedException e) { logger.error("Interrupted exception: ", e); Thread.currentThread().interrupt(); response.setHttpResponseCode(SO_RESPONSE_ERROR); return response; } - + // Issue a GET to find the current status of our request - netLogger.info("[OUT|{}|{}|{}|{}|{}|{}|]{}", "SO", urlGet, username, password, createSimpleHeaders(), MEDIA_TYPE, LINE_SEPARATOR); + netLogger.info("[OUT|{}|{}|{}|{}|{}|{}|]{}", "SO", urlGet, username, password, createSimpleHeaders(), + MEDIA_TYPE, LINE_SEPARATOR); Pair httpResponse = restManager.get(urlGet, username, password, createSimpleHeaders()); // Get our response @@ -216,11 +228,11 @@ public final class SOManager { if (SO_RESPONSE_ERROR == response.getHttpResponseCode()) { return response; } - + // Our latest HTTP response code latestHTTPResponse = httpResponse; } - + // We have timed out on the SO request response.setHttpResponseCode(SO_RESPONSE_ERROR); return response; @@ -228,14 +240,16 @@ public final class SOManager { /** * Parse the response message from SO into a SOResponse object. - * @param requestURL The URL of the HTTP request + * + * @param requestURL The URL of the HTTP request * @param httpDetails The HTTP message returned from SO * @return The parsed response */ private SOResponse processSOResponse(final String requestURL, final Pair httpResponse) { SOResponse response = new SOResponse(); - // A null httpDetails indicates a HTTP problem, a valid response from SO must be either 200 or 202 + // A null httpDetails indicates a HTTP problem, a valid response from SO must be either 200 + // or 202 if (!httpResultIsNullFree(httpResponse) || (httpResponse.a != 200 && httpResponse.a != 202)) { logger.error("Invalid HTTP response received from SO"); response.setHttpResponseCode(SO_RESPONSE_ERROR); @@ -245,8 +259,7 @@ public final class SOManager { // Parse the JSON of the response into our POJO try { response = Serialization.gsonPretty.fromJson(httpResponse.b, SOResponse.class); - } - catch (JsonSyntaxException e) { + } catch (JsonSyntaxException e) { logger.error("Failed to deserialize HTTP response into SOResponse: ", e); response.setHttpResponseCode(SO_RESPONSE_ERROR); return response; @@ -254,9 +267,9 @@ public final class SOManager { // Set the HTTP response code of the response if needed if (response.getHttpResponseCode() == 0) { - response.setHttpResponseCode(httpResponse.a); + response.setHttpResponseCode(httpResponse.a); } - + netLogger.info("[IN|{}|{}|]{}{}", "SO", requestURL, LINE_SEPARATOR, httpResponse.b); if (logger.isDebugEnabled()) { @@ -268,7 +281,8 @@ public final class SOManager { } /** - * Method to allow tuning of REST get timeout. + * Method to allow tuning of REST get timeout. + * * @param restGetTimeout the timeout value */ protected void setRestGetTimeout(final long restGetTimeout) { @@ -277,19 +291,19 @@ public final class SOManager { /** * Check that the request state of a response is defined. + * * @param response The response to check * @return true if the request for the response is defined */ private boolean isRequestStateDefined(final SOResponse response) { - return response != null && - response.getRequest() != null && - response.getRequest().getRequestStatus() != null && - response.getRequest().getRequestStatus().getRequestState() != null; + return response != null && response.getRequest() != null && response.getRequest().getRequestStatus() != null + && response.getRequest().getRequestStatus().getRequestState() != null; } /** * Check that the request state of a response is finished. - * @param latestHTTPDetails the HTTP details of the response + * + * @param latestHTTPDetails the HTTP details of the response * @param response The response to check * @return true if the request for the response is finished */ @@ -297,14 +311,14 @@ public final class SOManager { if (latestHTTPDetails != null && 200 == latestHTTPDetails.a && isRequestStateDefined(response)) { String requestState = response.getRequest().getRequestStatus().getRequestState(); return "COMPLETE".equalsIgnoreCase(requestState) || "FAILED".equalsIgnoreCase(requestState); - } - else { + } else { return false; } } /** * Check that a HTTP operation result has no nulls. + * * @param httpOperationResult the result to check * @return true if no nulls are found */ @@ -314,6 +328,7 @@ public final class SOManager { /** * Create simple HTTP headers for unauthenticated requests to SO. + * * @return the HTTP headers */ private Map createSimpleHeaders() { diff --git a/controlloop/common/model-impl/vfc/pom.xml b/controlloop/common/model-impl/vfc/pom.xml index 8f9a4553c..1b20630c2 100644 --- a/controlloop/common/model-impl/vfc/pom.xml +++ b/controlloop/common/model-impl/vfc/pom.xml @@ -57,6 +57,12 @@ 6.5.0.Final provided + + org.onap.policy.common + policy-endpoints + ${project.version} + provided + org.onap.policy.drools-pdp policy-management diff --git a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java index 9a7bf8894..e5c9f5db9 100644 --- a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java +++ b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java @@ -18,154 +18,158 @@ package org.onap.policy.vfc; +import com.google.gson.JsonSyntaxException; + import java.util.HashMap; import java.util.Map; import org.drools.core.WorkingMemory; -import org.onap.policy.vfc.util.Serialization; import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.rest.RESTManager; import org.onap.policy.rest.RESTManager.Pair; +import org.onap.policy.vfc.util.Serialization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.JsonSyntaxException; - public final class VFCManager implements Runnable { - private static final String SYSTEM_LS = System.lineSeparator(); - - private String vfcUrlBase; - private String username; - private String password; - private VFCRequest vfcRequest; - private WorkingMemory workingMem; - private static final Logger logger = LoggerFactory.getLogger(VFCManager.class); - private static final Logger netLogger = LoggerFactory.getLogger(org.onap.policy.drools.event.comm.Topic.NETWORK_LOGGER); - - // The REST manager used for processing REST calls for this VFC manager - private RESTManager restManager; - - public VFCManager(WorkingMemory wm, VFCRequest request) { - if (wm == null || request == null) { - throw new IllegalArgumentException("the parameters \"wm\" and \"request\" on the VFCManager constructor may not be null"); - } - workingMem = wm; - vfcRequest = request; - - restManager = new RESTManager(); - - // use getPEManagerEnvProperty() for required properties; others are optional + private static final String SYSTEM_LS = System.lineSeparator(); + + private String vfcUrlBase; + private String username; + private String password; + private VFCRequest vfcRequest; + private WorkingMemory workingMem; + private static final Logger logger = LoggerFactory.getLogger(VFCManager.class); + private static final Logger netLogger = + LoggerFactory.getLogger(org.onap.policy.common.endpoints.event.comm.Topic.NETWORK_LOGGER); + + // The REST manager used for processing REST calls for this VFC manager + private RESTManager restManager; + + public VFCManager(WorkingMemory wm, VFCRequest request) { + if (wm == null || request == null) { + throw new IllegalArgumentException( + "the parameters \"wm\" and \"request\" on the VFCManager constructor may not be null"); + } + workingMem = wm; + vfcRequest = request; + + restManager = new RESTManager(); + + // use getPEManagerEnvProperty() for required properties; others are optional setVFCParams(getPEManagerEnvProperty("vfc.url"), PolicyEngine.manager.getEnvironmentProperty("vfc.username"), - PolicyEngine.manager.getEnvironmentProperty("vfc.password")); - } - - public void setVFCParams(String baseUrl, String name, String pwd) { - vfcUrlBase = baseUrl + "/api/nslcm/v1"; - username = name; - password = pwd; - } - - @Override - public void run() { - Map headers = new HashMap<>(); - Pair httpDetails; - - VFCResponse responseError = new VFCResponse(); - responseError.setResponseDescriptor(new VFCResponseDescriptor()); - responseError.getResponseDescriptor().setStatus("error"); - - headers.put("Accept", "application/json"); - String vfcUrl = vfcUrlBase + "/ns/" + vfcRequest.getNSInstanceId() + "/heal"; - try { - String vfcRequestJson = Serialization.gsonPretty.toJson(vfcRequest); - netLogger.info("[OUT|{}|{}|]{}{}", "VFC", vfcUrl, SYSTEM_LS, vfcRequestJson); - - httpDetails = restManager.post(vfcUrl, username, password, headers, "application/json", vfcRequestJson); - } catch (Exception e) { - logger.error(e.getMessage(), e); - workingMem.insert(responseError); - return; - } - - if (httpDetails == null) { - workingMem.insert(responseError); - return; - } - - if (httpDetails.a != 202) { - logger.warn("VFC Heal Restcall failed"); - return; - } - - try { - VFCResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, VFCResponse.class); - netLogger.info("[IN|{}|{}|]{}{}", "VFC", vfcUrl, SYSTEM_LS, httpDetails.b); - String body = Serialization.gsonPretty.toJson(response); - logger.debug("Response to VFC Heal post:"); - logger.debug(body); - - String jobId = response.getJobId(); - int attemptsLeft = 20; - - String urlGet = vfcUrlBase + "/jobs/" + jobId; - VFCResponse responseGet = null; - - while (attemptsLeft-- > 0) { - netLogger.info("[OUT|{}|{}|]", "VFC", urlGet); - Pair httpDetailsGet = restManager.get(urlGet, username, password, headers); - responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.b, VFCResponse.class); - netLogger.info("[IN|{}|{}|]{}{}", "VFC", urlGet, SYSTEM_LS, httpDetailsGet.b); - responseGet.setRequestId(vfcRequest.getRequestId().toString()); - body = Serialization.gsonPretty.toJson(responseGet); - logger.debug("Response to VFC Heal get:"); - logger.debug(body); - - String responseStatus = responseGet.getResponseDescriptor().getStatus(); - if (httpDetailsGet.a == 200 && ("finished".equalsIgnoreCase(responseStatus) || "error".equalsIgnoreCase(responseStatus))) { - logger.debug("VFC Heal Status {}", responseGet.getResponseDescriptor().getStatus()); - workingMem.insert(responseGet); - break; - } - Thread.sleep(20000); - } - if ((attemptsLeft <= 0) - && (responseGet != null) - && (responseGet.getResponseDescriptor() != null) - && (responseGet.getResponseDescriptor().getStatus() != null) - && (!responseGet.getResponseDescriptor().getStatus().isEmpty())) { - logger.debug("VFC timeout. Status: ({})", responseGet.getResponseDescriptor().getStatus()); - workingMem.insert(responseGet); - } - } catch (JsonSyntaxException e) { - logger.error("Failed to deserialize into VFCResponse {}", e.getLocalizedMessage(), e); - } catch (InterruptedException e) { - logger.error("Interrupted exception: {}", e.getLocalizedMessage(), e); - Thread.currentThread().interrupt(); - } catch (Exception e) { - logger.error("Unknown error deserializing into VFCResponse {}", e.getLocalizedMessage(), e); - } - } - - /** - * Protected setter for rest manager to allow mocked rest manager to be used for testing - * @param restManager the test REST manager - */ - protected void setRestManager(final RESTManager restManager) { - this.restManager = restManager; - } - - /** - * This method reads and validates environmental properties coming from the policy engine. Null properties cause - * an {@link IllegalArgumentException} runtime exception to be thrown - * @param string the name of the parameter to retrieve - * @return the property value - */ - - private String getPEManagerEnvProperty(String enginePropertyName) { - String enginePropertyValue = PolicyEngine.manager.getEnvironmentProperty(enginePropertyName); - if (enginePropertyValue == null) { - throw new IllegalArgumentException("The value of policy engine manager environment property \"" + enginePropertyName + "\" may not be null"); - } - return enginePropertyValue; - } + PolicyEngine.manager.getEnvironmentProperty("vfc.password")); + } + + public void setVFCParams(String baseUrl, String name, String pwd) { + vfcUrlBase = baseUrl + "/api/nslcm/v1"; + username = name; + password = pwd; + } + + @Override + public void run() { + Map headers = new HashMap<>(); + Pair httpDetails; + + VFCResponse responseError = new VFCResponse(); + responseError.setResponseDescriptor(new VFCResponseDescriptor()); + responseError.getResponseDescriptor().setStatus("error"); + + headers.put("Accept", "application/json"); + String vfcUrl = vfcUrlBase + "/ns/" + vfcRequest.getNSInstanceId() + "/heal"; + try { + String vfcRequestJson = Serialization.gsonPretty.toJson(vfcRequest); + netLogger.info("[OUT|{}|{}|]{}{}", "VFC", vfcUrl, SYSTEM_LS, vfcRequestJson); + + httpDetails = restManager.post(vfcUrl, username, password, headers, "application/json", vfcRequestJson); + } catch (Exception e) { + logger.error(e.getMessage(), e); + workingMem.insert(responseError); + return; + } + + if (httpDetails == null) { + workingMem.insert(responseError); + return; + } + + if (httpDetails.a != 202) { + logger.warn("VFC Heal Restcall failed"); + return; + } + + try { + VFCResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, VFCResponse.class); + netLogger.info("[IN|{}|{}|]{}{}", "VFC", vfcUrl, SYSTEM_LS, httpDetails.b); + String body = Serialization.gsonPretty.toJson(response); + logger.debug("Response to VFC Heal post:"); + logger.debug(body); + + String jobId = response.getJobId(); + int attemptsLeft = 20; + + String urlGet = vfcUrlBase + "/jobs/" + jobId; + VFCResponse responseGet = null; + + while (attemptsLeft-- > 0) { + netLogger.info("[OUT|{}|{}|]", "VFC", urlGet); + Pair httpDetailsGet = restManager.get(urlGet, username, password, headers); + responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.b, VFCResponse.class); + netLogger.info("[IN|{}|{}|]{}{}", "VFC", urlGet, SYSTEM_LS, httpDetailsGet.b); + responseGet.setRequestId(vfcRequest.getRequestId().toString()); + body = Serialization.gsonPretty.toJson(responseGet); + logger.debug("Response to VFC Heal get:"); + logger.debug(body); + + String responseStatus = responseGet.getResponseDescriptor().getStatus(); + if (httpDetailsGet.a == 200 + && ("finished".equalsIgnoreCase(responseStatus) || "error".equalsIgnoreCase(responseStatus))) { + logger.debug("VFC Heal Status {}", responseGet.getResponseDescriptor().getStatus()); + workingMem.insert(responseGet); + break; + } + Thread.sleep(20000); + } + if ((attemptsLeft <= 0) && (responseGet != null) && (responseGet.getResponseDescriptor() != null) + && (responseGet.getResponseDescriptor().getStatus() != null) + && (!responseGet.getResponseDescriptor().getStatus().isEmpty())) { + logger.debug("VFC timeout. Status: ({})", responseGet.getResponseDescriptor().getStatus()); + workingMem.insert(responseGet); + } + } catch (JsonSyntaxException e) { + logger.error("Failed to deserialize into VFCResponse {}", e.getLocalizedMessage(), e); + } catch (InterruptedException e) { + logger.error("Interrupted exception: {}", e.getLocalizedMessage(), e); + Thread.currentThread().interrupt(); + } catch (Exception e) { + logger.error("Unknown error deserializing into VFCResponse {}", e.getLocalizedMessage(), e); + } + } + + /** + * Protected setter for rest manager to allow mocked rest manager to be used for testing + * + * @param restManager the test REST manager + */ + protected void setRestManager(final RESTManager restManager) { + this.restManager = restManager; + } + + /** + * This method reads and validates environmental properties coming from the policy engine. Null + * properties cause an {@link IllegalArgumentException} runtime exception to be thrown + * + * @param string the name of the parameter to retrieve + * @return the property value + */ + + private String getPEManagerEnvProperty(String enginePropertyName) { + String enginePropertyValue = PolicyEngine.manager.getEnvironmentProperty(enginePropertyName); + if (enginePropertyValue == null) { + throw new IllegalArgumentException("The value of policy engine manager environment property \"" + + enginePropertyName + "\" may not be null"); + } + return enginePropertyValue; + } } diff --git a/controlloop/common/simulators/pom.xml b/controlloop/common/simulators/pom.xml index 7160548a1..93ea62372 100644 --- a/controlloop/common/simulators/pom.xml +++ b/controlloop/common/simulators/pom.xml @@ -32,7 +32,7 @@ - org.onap.policy.drools-pdp + org.onap.policy.common policy-endpoints ${project.version} diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java index fc9a9320e..58aae6267 100644 --- a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java +++ b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java @@ -22,8 +22,8 @@ package org.onap.policy.simulators; import java.io.IOException; -import org.onap.policy.drools.http.server.HttpServletServer; -import org.onap.policy.drools.utils.NetworkUtil; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; +import org.onap.policy.common.utils.network.NetworkUtil; public class Util { private Util() { diff --git a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/AaiSimulatorTest.java b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/AaiSimulatorTest.java index 07ec6ac28..606db6cf7 100644 --- a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/AaiSimulatorTest.java +++ b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/AaiSimulatorTest.java @@ -39,7 +39,7 @@ import org.onap.policy.aai.AaiNqNamedQuery; import org.onap.policy.aai.AaiNqQueryParameters; import org.onap.policy.aai.AaiNqRequest; import org.onap.policy.aai.AaiNqResponse; -import org.onap.policy.drools.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.drools.utils.logging.LoggerUtil; import org.onap.policy.rest.RESTManager; diff --git a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java index 9c44bc9de..cebf5f7fe 100644 --- a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java +++ b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java @@ -27,7 +27,7 @@ import static org.junit.Assert.fail; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.policy.drools.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.drools.utils.logging.LoggerUtil; import org.onap.policy.rest.RESTManager; import org.onap.policy.rest.RESTManager.Pair; diff --git a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java index 28620d59d..837c52cd6 100644 --- a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java +++ b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java @@ -29,7 +29,7 @@ import java.util.UUID; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.policy.drools.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.drools.utils.logging.LoggerUtil; import org.onap.policy.rest.RESTManager; import org.onap.policy.rest.RESTManager.Pair; diff --git a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/VfcSimulatorTest.java b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/VfcSimulatorTest.java index 4e61d4b72..8a7afb959 100644 --- a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/VfcSimulatorTest.java +++ b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/VfcSimulatorTest.java @@ -29,7 +29,7 @@ import java.util.HashMap; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.policy.drools.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.drools.utils.logging.LoggerUtil; import org.onap.policy.rest.RESTManager; import org.onap.policy.rest.RESTManager.Pair; diff --git a/controlloop/templates/template.demo/pom.xml b/controlloop/templates/template.demo/pom.xml index 9c75357bc..767af56ab 100644 --- a/controlloop/templates/template.demo/pom.xml +++ b/controlloop/templates/template.demo/pom.xml @@ -196,6 +196,12 @@ [1.4.186,) test + + org.onap.policy.common + policy-endpoints + ${project.version} + provided + org.onap.policy.drools-applications.controlloop.common simulators diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java index 686b3805f..584a8e349 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java @@ -42,17 +42,17 @@ import org.onap.policy.appclcm.LcmRequest; import org.onap.policy.appclcm.LcmRequestWrapper; import org.onap.policy.appclcm.LcmResponse; import org.onap.policy.appclcm.LcmResponseWrapper; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.event.comm.TopicEndpoint; +import org.onap.policy.common.endpoints.event.comm.TopicListener; +import org.onap.policy.common.endpoints.event.comm.TopicSink; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopNotificationType; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.VirtualControlLoopNotification; import org.onap.policy.controlloop.policy.ControlLoopPolicy; -import org.onap.policy.drools.event.comm.Topic.CommInfrastructure; -import org.onap.policy.drools.event.comm.TopicEndpoint; -import org.onap.policy.drools.event.comm.TopicListener; -import org.onap.policy.drools.event.comm.TopicSink; -import org.onap.policy.drools.http.server.HttpServletServer; -import org.onap.policy.drools.properties.PolicyProperties; import org.onap.policy.drools.protocol.coders.EventProtocolCoder; import org.onap.policy.drools.protocol.coders.JsonProtocolFilter; import org.onap.policy.drools.system.PolicyController; @@ -85,7 +85,7 @@ public class ControlLoopFailureTest implements TopicListener { PolicyEngine.manager.configure(new Properties()); assertTrue(PolicyEngine.manager.start()); Properties noopSinkProperties = new Properties(); - noopSinkProperties.put(PolicyProperties.PROPERTY_NOOP_SINK_TOPICS, "APPC-LCM-READ,POLICY-CL-MGT"); + noopSinkProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, "APPC-LCM-READ,POLICY-CL-MGT"); noopSinkProperties.put("noop.sink.topics.APPC-LCM-READ.events", "org.onap.policy.appclcm.LcmRequestWrapper"); noopSinkProperties.put("noop.sink.topics.APPC-LCM-READ.events.custom.gson", "org.onap.policy.appclcm.util.Serialization,gson"); diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java index 2149bc779..b69369181 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java @@ -46,7 +46,7 @@ import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieSession; import org.onap.policy.controlloop.policy.ControlLoopPolicy; import org.onap.policy.controlloop.policy.guard.ControlLoopGuard; -import org.onap.policy.drools.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.guard.PolicyGuardYamlToXacml; import org.slf4j.Logger; diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java index 9c3410fcb..19c33ace3 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java @@ -42,18 +42,18 @@ import org.onap.policy.appclcm.LcmRequest; import org.onap.policy.appclcm.LcmRequestWrapper; import org.onap.policy.appclcm.LcmResponse; import org.onap.policy.appclcm.LcmResponseWrapper; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.event.comm.TopicEndpoint; +import org.onap.policy.common.endpoints.event.comm.TopicListener; +import org.onap.policy.common.endpoints.event.comm.TopicSink; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopNotificationType; import org.onap.policy.controlloop.ControlLoopTargetType; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.VirtualControlLoopNotification; import org.onap.policy.controlloop.policy.ControlLoopPolicy; -import org.onap.policy.drools.event.comm.Topic.CommInfrastructure; -import org.onap.policy.drools.event.comm.TopicEndpoint; -import org.onap.policy.drools.event.comm.TopicListener; -import org.onap.policy.drools.event.comm.TopicSink; -import org.onap.policy.drools.http.server.HttpServletServer; -import org.onap.policy.drools.properties.PolicyProperties; import org.onap.policy.drools.protocol.coders.EventProtocolCoder; import org.onap.policy.drools.protocol.coders.JsonProtocolFilter; import org.onap.policy.drools.system.PolicyController; @@ -85,7 +85,7 @@ public class VCPEControlLoopTest implements TopicListener { PolicyEngine.manager.configure(new Properties()); assertTrue(PolicyEngine.manager.start()); Properties noopSinkProperties = new Properties(); - noopSinkProperties.put(PolicyProperties.PROPERTY_NOOP_SINK_TOPICS, "APPC-LCM-READ,POLICY-CL-MGT"); + noopSinkProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, "APPC-LCM-READ,POLICY-CL-MGT"); noopSinkProperties.put("noop.sink.topics.APPC-LCM-READ.events", "org.onap.policy.appclcm.LcmRequestWrapper"); noopSinkProperties.put("noop.sink.topics.APPC-LCM-READ.events.custom.gson", "org.onap.policy.appclcm.util.Serialization,gson"); diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java index 493316915..2785e3d55 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java @@ -38,17 +38,17 @@ import org.junit.BeforeClass; import org.junit.Test; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.event.comm.TopicEndpoint; +import org.onap.policy.common.endpoints.event.comm.TopicListener; +import org.onap.policy.common.endpoints.event.comm.TopicSink; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopNotificationType; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.VirtualControlLoopNotification; import org.onap.policy.controlloop.policy.ControlLoopPolicy; -import org.onap.policy.drools.event.comm.Topic.CommInfrastructure; -import org.onap.policy.drools.event.comm.TopicEndpoint; -import org.onap.policy.drools.event.comm.TopicListener; -import org.onap.policy.drools.event.comm.TopicSink; -import org.onap.policy.drools.http.server.HttpServletServer; -import org.onap.policy.drools.properties.PolicyProperties; import org.onap.policy.drools.protocol.coders.EventProtocolCoder; import org.onap.policy.drools.protocol.coders.JsonProtocolFilter; import org.onap.policy.drools.system.PolicyController; @@ -82,7 +82,7 @@ public class VDNSControlLoopTest implements TopicListener { PolicyEngine.manager.configure(new Properties()); assertTrue(PolicyEngine.manager.start()); Properties noopSinkProperties = new Properties(); - noopSinkProperties.put(PolicyProperties.PROPERTY_NOOP_SINK_TOPICS, "POLICY-CL-MGT"); + noopSinkProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, "POLICY-CL-MGT"); noopSinkProperties.put("noop.sink.topics.POLICY-CL-MGT.events", "org.onap.policy.controlloop.VirtualControlLoopNotification"); noopSinkProperties.put("noop.sink.topics.POLICY-CL-MGT.events.custom.gson", diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java index eedd09ba0..5db0e3f56 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java @@ -38,18 +38,18 @@ import org.junit.BeforeClass; import org.junit.Test; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.event.comm.TopicEndpoint; +import org.onap.policy.common.endpoints.event.comm.TopicListener; +import org.onap.policy.common.endpoints.event.comm.TopicSink; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopNotificationType; import org.onap.policy.controlloop.ControlLoopTargetType; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.VirtualControlLoopNotification; import org.onap.policy.controlloop.policy.ControlLoopPolicy; -import org.onap.policy.drools.event.comm.Topic.CommInfrastructure; -import org.onap.policy.drools.event.comm.TopicEndpoint; -import org.onap.policy.drools.event.comm.TopicListener; -import org.onap.policy.drools.event.comm.TopicSink; -import org.onap.policy.drools.http.server.HttpServletServer; -import org.onap.policy.drools.properties.PolicyProperties; import org.onap.policy.drools.protocol.coders.EventProtocolCoder; import org.onap.policy.drools.protocol.coders.JsonProtocolFilter; import org.onap.policy.drools.system.PolicyController; @@ -84,7 +84,7 @@ public class VFCControlLoopTest implements TopicListener { PolicyEngine.manager.configure(new Properties()); assertTrue(PolicyEngine.manager.start()); Properties noopSinkProperties = new Properties(); - noopSinkProperties.put(PolicyProperties.PROPERTY_NOOP_SINK_TOPICS, "POLICY-CL-MGT"); + noopSinkProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, "POLICY-CL-MGT"); noopSinkProperties.put("noop.sink.topics.POLICY-CL-MGT.events", "org.onap.policy.controlloop.VirtualControlLoopNotification"); noopSinkProperties.put("noop.sink.topics.POLICY-CL-MGT.events.custom.gson", diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java index 9c0cbd716..756fb202f 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java @@ -41,17 +41,17 @@ import org.kie.api.runtime.rule.FactHandle; import org.onap.policy.appc.Request; import org.onap.policy.appc.Response; import org.onap.policy.appc.ResponseCode; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.event.comm.TopicEndpoint; +import org.onap.policy.common.endpoints.event.comm.TopicListener; +import org.onap.policy.common.endpoints.event.comm.TopicSink; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopNotificationType; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.VirtualControlLoopNotification; import org.onap.policy.controlloop.policy.ControlLoopPolicy; -import org.onap.policy.drools.event.comm.Topic.CommInfrastructure; -import org.onap.policy.drools.event.comm.TopicEndpoint; -import org.onap.policy.drools.event.comm.TopicListener; -import org.onap.policy.drools.event.comm.TopicSink; -import org.onap.policy.drools.http.server.HttpServletServer; -import org.onap.policy.drools.properties.PolicyProperties; import org.onap.policy.drools.protocol.coders.EventProtocolCoder; import org.onap.policy.drools.protocol.coders.JsonProtocolFilter; import org.onap.policy.drools.system.PolicyController; @@ -83,7 +83,7 @@ public class VFWControlLoopTest implements TopicListener { PolicyEngine.manager.configure(new Properties()); assertTrue(PolicyEngine.manager.start()); Properties noopSinkProperties = new Properties(); - noopSinkProperties.put(PolicyProperties.PROPERTY_NOOP_SINK_TOPICS, "APPC-CL,POLICY-CL-MGT"); + noopSinkProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, "APPC-CL,POLICY-CL-MGT"); noopSinkProperties.put("noop.sink.topics.APPC-CL.events", "org.onap.policy.appc.Response"); noopSinkProperties.put("noop.sink.topics.APPC-CL.events.custom.gson", "org.onap.policy.appc.util.Serialization,gsonPretty"); -- cgit 1.2.3-korg