diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2019-04-05 21:07:07 -0400 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2019-04-08 10:42:22 -0400 |
commit | ada55be1b59899e461dc5177782e381f89cbc407 (patch) | |
tree | 7bdb3eb5fe44e166a75a3333bf81f2293a3585de | |
parent | eb7127ac85b3df30a09277721a5f9271033843e7 (diff) |
Remove drools PDP dependency
Removing working memory and use of PolicyEngine from
drools in these classes.
Cleaned up some unused imports and checkstyle.
Issue-ID: POLICY-1264
Change-Id: Id059da9689a721b0eafc6b310adcbdad43574ce7
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
33 files changed, 235 insertions, 808 deletions
diff --git a/models-interactions/model-actors/actor.appc/pom.xml b/models-interactions/model-actors/actor.appc/pom.xml index a6da5ee23..c9f7dc144 100644 --- a/models-interactions/model-actors/actor.appc/pom.xml +++ b/models-interactions/model-actors/actor.appc/pom.xml @@ -76,11 +76,5 @@ <version>${policy.common.version}</version> <scope>provided</scope> </dependency> - <dependency> - <groupId>org.onap.policy.drools-pdp</groupId> - <artifactId>policy-management</artifactId> - <version>${policy.drools-pdp.version}</version> - <scope>provided</scope> - </dependency> </dependencies> </project> diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java index e1fdd395a..fc57d50ef 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java @@ -45,7 +45,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.system.PolicyEngine; import org.onap.policy.simulators.Util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -95,11 +94,6 @@ public class AppcServiceProviderTest { policy.setRetry(2); policy.setTimeout(300); - /* Set environment properties */ - PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666"); - PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI"); - PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI"); - } /** diff --git a/models-interactions/model-actors/actor.appclcm/pom.xml b/models-interactions/model-actors/actor.appclcm/pom.xml index fd62e70fb..0fa3498a3 100644 --- a/models-interactions/model-actors/actor.appclcm/pom.xml +++ b/models-interactions/model-actors/actor.appclcm/pom.xml @@ -66,10 +66,9 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>org.onap.policy.drools-pdp</groupId> - <artifactId>policy-management</artifactId> - <version>${policy.drools-pdp.version}</version> - <scope>provided</scope> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <version>3.8.1</version> </dependency> <dependency> <groupId>org.onap.policy.models.policy-models-interactions</groupId> diff --git a/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java b/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java index 5768cd12a..21cce2fd6 100644 --- a/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java +++ b/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java @@ -24,7 +24,6 @@ package org.onap.policy.controlloop.actor.appclcm; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; - import java.util.AbstractMap; import java.util.AbstractMap.SimpleEntry; import java.util.Collections; @@ -32,7 +31,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; - import org.onap.policy.aai.AaiManager; import org.onap.policy.aai.AaiNqInstanceFilters; import org.onap.policy.aai.AaiNqInventoryResponseItem; @@ -52,7 +50,6 @@ import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.controlloop.policy.PolicyResult; -import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.rest.RestManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -144,7 +141,8 @@ public class AppcLcmActorServiceProvider implements Actor { * @return the target entities vnf id to act upon * @throws AaiException it an error occurs */ - public static String vnfNamedQuery(String resourceId, String sourceVnfId) throws AaiException { + public static String vnfNamedQuery(String resourceId, String sourceVnfId, String aaiUrl, + String aaiUser, String aaiPassword) throws AaiException { // TODO: This request id should not be hard coded in future releases UUID requestId = UUID.fromString("a93ac487-409c-4e8c-9e5f-334ae8f99087"); @@ -163,9 +161,8 @@ public class AppcLcmActorServiceProvider implements Actor { aaiRequest.setInstanceFilters(new AaiNqInstanceFilters()); aaiRequest.getInstanceFilters().getInstanceFilter().add(filter); - AaiNqResponse aaiResponse = new AaiManager(new RestManager()).postQuery(getPeManagerEnvProperty("aai.url"), - getPeManagerEnvProperty("aai.username"), getPeManagerEnvProperty("aai.password"), aaiRequest, - requestId); + AaiNqResponse aaiResponse = new AaiManager(new RestManager()).postQuery(aaiUrl, + aaiUser, aaiPassword, aaiRequest, requestId); if (aaiResponse == null) { throw new AaiException("The named query response was null"); @@ -341,20 +338,4 @@ public class AppcLcmActorServiceProvider implements Actor { } return new AbstractMap.SimpleEntry<>(result, message); } - - /** - * This method reads and validates environmental properties coming from the policy engine. Null - * properties cause an {@link IllegalArgumentException} runtime exception to be thrown - * - * @param enginePropertyName the name of the parameter to retrieve - * @return the property value - */ - private static 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/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatter.java b/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatter.java index daf1af711..61394f2ab 100644 --- a/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatter.java +++ b/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatter.java @@ -24,7 +24,7 @@ package org.onap.policy.controlloop.actor.appclcm; import com.google.common.collect.Lists; import java.util.stream.Collectors; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; class AppcLcmRecipeFormatter { diff --git a/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProviderTest.java b/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProviderTest.java index 39cdc43ab..da95611d4 100644 --- a/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProviderTest.java +++ b/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProviderTest.java @@ -49,7 +49,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.system.PolicyEngine; import org.onap.policy.simulators.Util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -116,11 +115,6 @@ public class AppcLcmActorServiceProviderTest { dmaapResponse.setRpcName(policy.getRecipe().toLowerCase()); dmaapResponse.setType("response"); - /* Set environment properties */ - PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666"); - PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI"); - PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI"); - /* A sample APPC LCM request. */ LcmRequest appcRequest = new LcmRequest(); @@ -317,7 +311,8 @@ public class AppcLcmActorServiceProviderTest { String resourceId = "82194af1-3c2c-485a-8f44-420e22a9eaa4"; String targetVnfId = null; try { - targetVnfId = AppcLcmActorServiceProvider.vnfNamedQuery(resourceId, "vnf01"); + targetVnfId = AppcLcmActorServiceProvider.vnfNamedQuery(resourceId, "vnf01", + "http://localhost:6666", "AAI", "AAI"); } catch (AaiException e) { logger.warn(e.toString()); fail("no vnf-id found"); diff --git a/models-interactions/model-actors/actor.sdnc/pom.xml b/models-interactions/model-actors/actor.sdnc/pom.xml index 225ba0d76..b4e68c480 100644 --- a/models-interactions/model-actors/actor.sdnc/pom.xml +++ b/models-interactions/model-actors/actor.sdnc/pom.xml @@ -61,12 +61,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>org.onap.policy.drools-pdp</groupId> - <artifactId>policy-management</artifactId> - <version>${policy.drools-pdp.version}</version> - <scope>provided</scope> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java index 4de3ed96b..26e3f4e1e 100644 --- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java +++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java @@ -24,12 +24,9 @@ package org.onap.policy.controlloop.actor.sdnc; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; - import java.util.Collections; import java.util.List; import java.util.UUID; - -import org.onap.policy.aai.AaiGetVnfResponse; import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; @@ -43,9 +40,7 @@ import org.onap.policy.sdnc.SdncHealVfModuleParameter; import org.onap.policy.sdnc.SdncHealVfModuleParametersInfo; import org.onap.policy.sdnc.SdncHealVfModuleRequestInput; import org.onap.policy.sdnc.SdncHealVnfInfo; - import org.onap.policy.sdnc.SdncRequest; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProviderTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProviderTest.java index 7288ec126..c80a38d77 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProviderTest.java +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProviderTest.java @@ -33,12 +33,10 @@ import java.util.UUID; 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.system.PolicyEngine; import org.onap.policy.sdnc.SdncRequest; import org.onap.policy.simulators.Util; @@ -75,16 +73,12 @@ public class SdncActorServiceProviderTest { onset.getAai().put("network-information.network-id", "network-5555"); assertNull(provider.constructRequest(onset, operation, policy)); - PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666"); - PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI"); - PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI"); assertNull(provider.constructRequest(onset, operation, policy)); UUID requestId = UUID.randomUUID(); onset.setRequestId(requestId); assertNull(provider.constructRequest(onset, operation, policy)); - PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI"); assertNull(provider.constructRequest(onset, operation, policy)); onset.getAai().put("service-instance.service-instance-id", "service-instance-01"); diff --git a/models-interactions/model-actors/actor.sdnr/pom.xml b/models-interactions/model-actors/actor.sdnr/pom.xml index 0cb696063..95248bc39 100644 --- a/models-interactions/model-actors/actor.sdnr/pom.xml +++ b/models-interactions/model-actors/actor.sdnr/pom.xml @@ -70,11 +70,5 @@ <version>${policy.common.version}</version> <scope>provided</scope> </dependency> - <dependency> - <groupId>org.onap.policy.drools-pdp</groupId> - <artifactId>policy-management</artifactId> - <version>${policy.drools-pdp.version}</version> - <scope>provided</scope> - </dependency> </dependencies> </project> diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java index a6212d3ab..226c3da47 100644 --- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java +++ b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java @@ -23,16 +23,12 @@ package org.onap.policy.controlloop.actor.sdnr; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.time.Instant; import java.util.HashMap; 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.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.ControlLoopTargetType; @@ -40,11 +36,9 @@ 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.system.PolicyEngine; import org.onap.policy.sdnr.PciRequest; import org.onap.policy.sdnr.PciResponse; import org.onap.policy.sdnr.util.Serialization; -import org.onap.policy.simulators.Util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/models-interactions/model-actors/actor.so/pom.xml b/models-interactions/model-actors/actor.so/pom.xml index f8d91a6f9..0af56bbbc 100644 --- a/models-interactions/model-actors/actor.so/pom.xml +++ b/models-interactions/model-actors/actor.so/pom.xml @@ -55,12 +55,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>org.drools</groupId> - <artifactId>drools-core</artifactId> - <version>6.5.0.Final</version> - <scope>provided</scope> - </dependency> - <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <scope>provided</scope> @@ -72,12 +66,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>org.onap.policy.drools-pdp</groupId> - <artifactId>policy-management</artifactId> - <version>${policy.drools-pdp.version}</version> - <scope>provided</scope> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java index eef6e7c12..2a14bb19a 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java @@ -28,7 +28,6 @@ import java.lang.reflect.Type; import java.util.Collections; import java.util.List; import java.util.Map; -import org.drools.core.WorkingMemory; import org.onap.policy.aai.AaiNqExtraProperty; import org.onap.policy.aai.AaiNqInventoryResponseItem; import org.onap.policy.aai.AaiNqResponseWrapper; @@ -374,12 +373,16 @@ public class SoActorServiceProvider implements Actor { * in the asyncSORestCall. * * @param requestId the request Id - * @param wm the working memory + * @param callback callback method * @param request the request + * @param url SO REST URL + * @param user username + * @param password password */ - public static void sendRequest(String requestId, WorkingMemory wm, Object request) { - SoManager soManager = new SoManager(); - soManager.asyncSoRestCall(requestId, wm, lastServiceItemServiceInstanceId, lastVNFItemVnfId, + public static void sendRequest(String requestId, SoManager.SoCallback callback, Object request, + String url, String user, String password) { + SoManager soManager = new SoManager(url, user, password); + soManager.asyncSoRestCall(requestId, callback, lastServiceItemServiceInstanceId, lastVNFItemVnfId, lastVfModuleItemVfModuleInstanceId, (SoRequest) request); } @@ -406,7 +409,7 @@ public class SoActorServiceProvider implements Actor { private void buildRequestParameters(Policy policy, SoRequestDetails request) { // assume null until proven otherwise request.setRequestParameters(null); - + if (policy.getPayload() == null) { return; } @@ -428,7 +431,7 @@ public class SoActorServiceProvider implements Actor { private void buildConfigurationParameters(Policy policy, SoRequestDetails request) { // assume null until proven otherwise request.setConfigurationParameters(null); - + if (policy.getPayload() == null) { return; } diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java index d0eab120c..a7bdf1a76 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java @@ -145,7 +145,7 @@ public class SoActorServiceProviderTest { @Test public void testSendRequest() { try { - SoActorServiceProvider.sendRequest(UUID.randomUUID().toString(), null, null); + SoActorServiceProvider.sendRequest(UUID.randomUUID().toString(), null, null, null, null, null); } catch (Exception e) { fail("Test should not throw an exception"); } diff --git a/models-interactions/model-actors/actor.vfc/pom.xml b/models-interactions/model-actors/actor.vfc/pom.xml index 7dfeb201b..10ef89f5f 100644 --- a/models-interactions/model-actors/actor.vfc/pom.xml +++ b/models-interactions/model-actors/actor.vfc/pom.xml @@ -61,12 +61,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>org.onap.policy.drools-pdp</groupId> - <artifactId>policy-management</artifactId> - <version>${policy.drools-pdp.version}</version> - <scope>provided</scope> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> diff --git a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProvider.java b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProvider.java index 52902cb61..23eb71996 100644 --- a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProvider.java +++ b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProvider.java @@ -33,7 +33,6 @@ import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; import org.onap.policy.controlloop.policy.Policy; -import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.rest.RestManager; import org.onap.policy.vfc.VfcHealActionVmInfo; import org.onap.policy.vfc.VfcHealAdditionalParams; @@ -88,7 +87,7 @@ public class VfcActorServiceProvider implements Actor { * @return the constructed request */ public static VfcRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, - Policy policy, AaiGetVnfResponse vnfResponse) { + Policy policy, AaiGetVnfResponse vnfResponse, String aaiUrl, String aaiUsername, String aaiPassword) { // Construct an VFC request VfcRequest request = new VfcRequest(); @@ -97,7 +96,7 @@ public class VfcActorServiceProvider implements Actor { AaiGetVnfResponse tempVnfResp = vnfResponse; if (tempVnfResp == null) { // if the response is null, we haven't queried // This does the AAI query since we haven't already - tempVnfResp = getAaiServiceInstance(onset); + tempVnfResp = getAaiServiceInstance(onset, aaiUrl, aaiUsername, aaiPassword); if (tempVnfResp == null) { return null; } @@ -124,14 +123,12 @@ public class VfcActorServiceProvider implements Actor { return request; } - private static AaiGetVnfResponse getAaiServiceInstance(VirtualControlLoopEvent event) { + private static AaiGetVnfResponse getAaiServiceInstance(VirtualControlLoopEvent event, String aaiUrl, + String aaiUsername, String aaiPassword) { AaiGetVnfResponse response = null; UUID requestId = event.getRequestId(); String vnfName = event.getAai().get("generic-vnf.vnf-name"); String vnfId = event.getAai().get("generic-vnf.vnf-id"); - String aaiUrl = PolicyEngine.manager.getEnvironmentProperty("aai.url"); - String aaiUsername = PolicyEngine.manager.getEnvironmentProperty("aai.username"); - String aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password"); try { if (vnfName != null) { String url = aaiUrl + "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name="; diff --git a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProviderTest.java b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProviderTest.java index 5d4447b8b..80ec3476e 100644 --- a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProviderTest.java +++ b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProviderTest.java @@ -38,7 +38,6 @@ 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.system.PolicyEngine; import org.onap.policy.simulators.Util; import org.onap.policy.vfc.VfcRequest; @@ -69,37 +68,32 @@ public class VfcActorServiceProviderTest { Policy policy = new Policy(); policy.setRecipe("GoToOz"); - assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null)); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null, null, null, null)); onset.getAai().put("generic-vnf.vnf-id", "dorothy.gale.1939"); - assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null)); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null, null, null, null)); - PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666"); - PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI"); - PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI"); - assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null)); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null, "http://localhost:6666", "AAI", "AAI")); UUID requestId = UUID.randomUUID(); onset.setRequestId(requestId); - assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null)); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null, "http://localhost:6666", "AAI", "AAI")); onset.getAai().put("generic-vnf.vnf-name", "Dorothy"); - PolicyEngine.manager.getEnvironment().remove("aai.password"); - assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null)); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null, "http://localhost:6666", "AAI", null)); - PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI"); - assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null)); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null, "http://localhost:6666", "AAI", "AAI")); onset.getAai().put("service-instance.service-instance-id", ""); - assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null)); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null, "http://localhost:6666", "AAI", "AAI")); - assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse())); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse(), "http://localhost:6666", "AAI", "AAI")); policy.setRecipe("Restart"); - assertNotNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse())); + assertNotNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse(), "http://localhost:6666", "AAI", "AAI")); VfcRequest request = - VfcActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse()); + VfcActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse(), "http://localhost:6666", "AAI", "AAI"); assertEquals(requestId, Objects.requireNonNull(request).getRequestId()); assertEquals("dorothy.gale.1939", request.getHealRequest().getVnfInstanceId()); diff --git a/models-interactions/model-impl/sdnc/pom.xml b/models-interactions/model-impl/sdnc/pom.xml index 8bc0776e4..6a0a38720 100644 --- a/models-interactions/model-impl/sdnc/pom.xml +++ b/models-interactions/model-impl/sdnc/pom.xml @@ -52,22 +52,10 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>org.drools</groupId> - <artifactId>drools-core</artifactId> - <version>6.5.0.Final</version> - <scope>provided</scope> - </dependency> - <dependency> <groupId>org.onap.policy.common</groupId> <artifactId>policy-endpoints</artifactId> <version>${policy.common.version}</version> <scope>provided</scope> </dependency> - <dependency> - <groupId>org.onap.policy.drools-pdp</groupId> - <artifactId>policy-management</artifactId> - <version>${policy.drools-pdp.version}</version> - <scope>provided</scope> - </dependency> </dependencies> </project> diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java index 864ddf506..3679625ec 100644 --- a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java +++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java @@ -22,17 +22,14 @@ package org.onap.policy.sdnc; - import com.google.gson.JsonSyntaxException; import java.util.HashMap; import java.util.Map; -import org.drools.core.WorkingMemory; 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.drools.system.PolicyEngine; import org.onap.policy.rest.RestManager; import org.onap.policy.rest.RestManager.Pair; import org.onap.policy.sdnc.util.Serialization; @@ -46,31 +43,41 @@ public final class SdncManager implements Runnable { private String username; private String password; private SdncRequest sdncRequest; - private WorkingMemory workingMem; + private SdncCallback callback; private static final Logger logger = LoggerFactory.getLogger(SdncManager.class); // The REST manager used for processing REST calls for this Sdnc manager private RestManager restManager; + public interface SdncCallback { + public void onCallback(SdncResponse response); + } + /** * Constructor. * - * @param wm Drools working memory + * @param cb Callback method * @param request request */ - public SdncManager(WorkingMemory wm, SdncRequest request) { - if (wm == null || request == null) { + public SdncManager(SdncCallback cb, SdncRequest request, String url, + String user, String password) { + if (cb == null || request == null) { throw new IllegalArgumentException( - "the parameters \"wm\" and \"request\" on the SdncManager constructor may not be null" + "the parameters \"callback\" and \"request\" on the SdncManager constructor may not be null" ); } - workingMem = wm; - sdncRequest = request; + this.callback = cb; + this.sdncRequest = request; + if (url == null) { + throw new IllegalArgumentException( + "the \"url\" parameter on the SdncManager constructor may not be null" + ); + } + this.sdncUrlBase = url; + this.username = user; + this.password = password; restManager = new RestManager(); - - setSdncParams(getPeManagerEnvProperty("sdnc.url"), getPeManagerEnvProperty("sdnc.username"), - getPeManagerEnvProperty("sdnc.password")); } /** @@ -108,12 +115,12 @@ public final class SdncManager implements Runnable { sdncRequestJson); } catch (Exception e) { logger.info(e.getMessage(), e); - workingMem.insert(responseError); + this.callback.onCallback(responseError); return; } if (httpDetails == null) { - workingMem.insert(responseError); + this.callback.onCallback(responseError); return; } @@ -132,7 +139,7 @@ public final class SdncManager implements Runnable { ); } - workingMem.insert(response); + this.callback.onCallback(response); } catch (JsonSyntaxException e) { logger.info("Failed to deserialize into SdncResponse {}", e.getLocalizedMessage(), e); } catch (Exception e) { @@ -147,22 +154,4 @@ public final class SdncManager implements Runnable { 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 enginePropertyName 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/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java index 53be3382b..1c18d9c8f 100644 --- a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java @@ -19,8 +19,6 @@ package org.onap.policy.sdnc; -import java.util.LinkedList; - import org.junit.Test; import org.onap.policy.sdnc.util.Serialization; diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java index ca6df0d0b..2a1cc6984 100644 --- a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java @@ -25,34 +25,24 @@ package org.onap.policy.sdnc; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; - import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.endsWith; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.startsWith; - import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.util.ArrayList; -import java.util.List; import java.util.UUID; - -import org.drools.core.WorkingMemory; -import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.rest.RestManager; import org.onap.policy.rest.RestManager.Pair; +import org.onap.policy.sdnc.SdncManager.SdncCallback; import org.onap.policy.sdnc.util.Serialization; -public class SdncManagerTest { - private static WorkingMemory mockedWorkingMemory; - +public class SdncManagerTest implements SdncCallback { private RestManager mockedRestManager; private Pair<Integer, String> httpResponsePutOk; @@ -65,7 +55,6 @@ public class SdncManagerTest { @BeforeClass public static void beforeTestSdncManager() { - mockedWorkingMemory = mock(WorkingMemory.class); } /** @@ -74,13 +63,13 @@ public class SdncManagerTest { @Before public void setupMockedRest() { mockedRestManager = mock(RestManager.class); - + httpResponsePutOk = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(response)); httpResponseGetOk = mockedRestManager.new Pair<>(200, Serialization.gsonPretty.toJson(response)); httpResponseBadResponse = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(null)); httpResponseErr = mockedRestManager.new Pair<>(200, null); } - + /** * Create the request and response before. */ @@ -92,7 +81,7 @@ public class SdncManagerTest { SdncHealRequestHeaderInfo additionalParams = new SdncHealRequestHeaderInfo(); additionalParams.setSvcAction("Go Home"); additionalParams.setSvcRequestId("My Request"); - + SdncHealRequest healRequest = new SdncHealRequest(); healRequest.setRequestHeaderInfo(additionalParams); healRequest.setServiceInfo(serviceInfo); @@ -112,87 +101,48 @@ public class SdncManagerTest { response.setRequestId(request.getRequestId().toString()); response.setResponseOutput(responseDescriptor); } - - /** - * After Test clean up. - */ - @After - public void afterTestSdncManager() throws InterruptedException { - PolicyEngine.manager.getEnvironment().remove("sdnc.password"); - PolicyEngine.manager.getEnvironment().remove("sdnc.username"); - PolicyEngine.manager.getEnvironment().remove("sdnc.url"); - } @Test public void testSdncInitiation() throws InterruptedException { try { - new SdncManager(null, null); + new SdncManager(null, null, null, null, null); fail("test should throw an exception here"); } catch (IllegalArgumentException e) { assertEquals( - "the parameters \"wm\" and \"request\" on the SdncManager constructor may not be null", + "the parameters \"callback\" and \"request\" on the SdncManager constructor may not be null", e.getMessage() ); } - - try { - new SdncManager(mockedWorkingMemory, null); - fail("test should throw an exception here"); - } - catch (IllegalArgumentException e) { - assertEquals( - "the parameters \"wm\" and \"request\" on the SdncManager constructor may not be null", - e.getMessage() - ); - } - - try { - new SdncManager(mockedWorkingMemory, request); - fail("test should throw an exception here"); - } - catch (IllegalArgumentException e) { - assertEquals( - "The value of policy engine manager environment property \"sdnc.url\" may not be null", - e.getMessage() - ); - } - - PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow"); + try { - new SdncManager(mockedWorkingMemory, request); + new SdncManager(this, null, null, null, null); fail("test should throw an exception here"); } catch (IllegalArgumentException e) { assertEquals( - "The value of policy engine manager environment property \"sdnc.username\" may not be null", + "the parameters \"callback\" and \"request\" on the SdncManager constructor may not be null", e.getMessage() ); } - - PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy"); + try { - new SdncManager(mockedWorkingMemory, request); + new SdncManager(this, request, null, null, null); fail("test should throw an exception here"); } catch (IllegalArgumentException e) { assertEquals( - "The value of policy engine manager environment property \"sdnc.password\" may not be null", + "the \"url\" parameter on the SdncManager constructor may not be null", e.getMessage() ); } - - PolicyEngine.manager.getEnvironment().put("sdnc.password", "Toto"); - new SdncManager(mockedWorkingMemory, request); + + new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Toto"); } @Test public void testSdncExecutionException() throws InterruptedException { - PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow"); - PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy"); - PolicyEngine.manager.getEnvironment().put("sdnc.password", "Exception"); - - SdncManager manager = new SdncManager(mockedWorkingMemory, request); + SdncManager manager = new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Exception"); manager.setRestManager(mockedRestManager); Thread managerThread = new Thread(manager); @@ -200,85 +150,76 @@ public class SdncManagerTest { when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Exception"), anyMap(), anyString(), anyString())) .thenThrow(new RuntimeException("OzException")); - + managerThread.join(100); } - + @Test public void testSdncExecutionNull() throws InterruptedException { - PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow"); - PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy"); - PolicyEngine.manager.getEnvironment().put("sdnc.password", "Null"); - - SdncManager manager = new SdncManager(mockedWorkingMemory, request); + SdncManager manager = new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Null"); manager.setRestManager(mockedRestManager); Thread managerThread = new Thread(manager); managerThread.start(); - + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString())) .thenReturn(null); - + managerThread.join(100); } @Test public void testSdncExecutionError0() throws InterruptedException { - PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow"); - PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy"); - PolicyEngine.manager.getEnvironment().put("sdnc.password", "Error0"); - - SdncManager manager = new SdncManager(mockedWorkingMemory, request); + SdncManager manager = new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Error0"); manager.setRestManager(mockedRestManager); - + Thread managerThread = new Thread(manager); managerThread.start(); - + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Error0"), anyMap(), anyString(), anyString())) .thenReturn(httpResponseErr); - + managerThread.join(100); } @Test public void testSdncExecutionBadResponse() throws InterruptedException { - PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow"); - PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy"); - PolicyEngine.manager.getEnvironment().put("sdnc.password", "BadResponse"); - - SdncManager manager = new SdncManager(mockedWorkingMemory, request); + SdncManager manager = new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "BadResponse"); manager.setRestManager(mockedRestManager); - + Thread managerThread = new Thread(manager); managerThread.start(); - + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString())) .thenReturn(httpResponseBadResponse); - + managerThread.join(100); } - + @Test public void testSdncExecutionOk() throws InterruptedException { - PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow"); - PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy"); - PolicyEngine.manager.getEnvironment().put("sdnc.password", "OK"); - - SdncManager manager = new SdncManager(mockedWorkingMemory, request); + SdncManager manager = new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "OOK"); manager.setRestManager(mockedRestManager); - + Thread managerThread = new Thread(manager); managerThread.start(); when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString())) .thenReturn(httpResponsePutOk); - + when(mockedRestManager.get(endsWith("1234"), eq("Dorothy"), eq("OK"), anyMap())) .thenReturn(httpResponseGetOk); - + managerThread.join(100); } + + @Override + public void onCallback(SdncResponse response) { + // + // Nothing really to do + // + } } diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseDescriptorTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseDescriptorTest.java index 09591639f..a397bdcab 100644 --- a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseDescriptorTest.java +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseDescriptorTest.java @@ -25,9 +25,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; -import java.util.ArrayList; -import java.util.List; - import org.junit.Test; public class SdncResponseDescriptorTest { diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseTest.java index 18c64aa0b..b36a72810 100644 --- a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseTest.java +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseTest.java @@ -25,7 +25,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; - import org.junit.Test; public class SdncResponseTest { @@ -35,15 +34,15 @@ public class SdncResponseTest { SdncResponse response = new SdncResponse(); assertNotNull(response); assertNotEquals(0, response.hashCode()); - + String requestId = "Get Home"; response.setRequestId(requestId); assertEquals(requestId, response.getRequestId()); - + SdncResponseOutput responseDescriptor = new SdncResponseOutput(); response.setResponseOutput(responseDescriptor); assertEquals(responseDescriptor, response.getResponseOutput()); - + assertNotEquals(0, response.hashCode()); } } diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/util/SerializationTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/util/SerializationTest.java index 5ac910a17..9dfb3742e 100644 --- a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/util/SerializationTest.java +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/util/SerializationTest.java @@ -21,8 +21,6 @@ package org.onap.policy.sdnc.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import org.junit.Test; diff --git a/models-interactions/model-impl/so/pom.xml b/models-interactions/model-impl/so/pom.xml index 030d34976..59bda9041 100644 --- a/models-interactions/model-impl/so/pom.xml +++ b/models-interactions/model-impl/so/pom.xml @@ -43,12 +43,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>org.drools</groupId> - <artifactId>drools-core</artifactId> - <version>6.5.0.Final</version> - <scope>provided</scope> - </dependency> - <dependency> <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> <artifactId>rest</artifactId> <version>${project.version}</version> @@ -60,12 +54,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>org.onap.policy.drools-pdp</groupId> - <artifactId>policy-management</artifactId> - <version>${policy.drools-pdp.version}</version> - <scope>provided</scope> - </dependency> - <dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-grizzly2-http</artifactId> <version>2.25.1</version> diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java index 4c9ba66bd..888afe2ae 100644 --- a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java @@ -30,11 +30,9 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import org.drools.core.WorkingMemory; 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.drools.system.PolicyEngine; import org.onap.policy.rest.RestManager; import org.onap.policy.rest.RestManager.Pair; import org.onap.policy.so.util.Serialization; @@ -66,10 +64,21 @@ public final class SoManager { private long restGetTimeout = GET_REQUEST_WAIT_INTERVAL; + private String url; + private String user; + private String password; + + public interface SoCallback { + public void onSoResponseWrapper(SoResponseWrapper wrapper); + } + /** * Default constructor. */ - public SoManager() { + public SoManager(String url, String user, String password) { + this.url = url; + this.user = user; + this.password = password; restManager = new RestManager(); } @@ -106,10 +115,10 @@ public final class SoManager { * except the vfModuleInstanceId is always null. * */ - public Future<SoResponse> asyncSoRestCall(final String requestId, final WorkingMemory wm, + public Future<SoResponse> asyncSoRestCall(final String requestId, final SoCallback callback, final String serviceInstanceId, final String vnfInstanceId, final SoRequest request) { - return asyncSoRestCall(requestId, wm, serviceInstanceId, vnfInstanceId, null, request); + return asyncSoRestCall(requestId, callback, serviceInstanceId, vnfInstanceId, null, request); } /** @@ -117,7 +126,7 @@ public final class SoManager { * Drools working memory. * * @param requestId the request id - * @param wm the Drools working memory + * @param callback callback method * @param serviceInstanceId service instance id to construct the request url * @param vnfInstanceId vnf instance id to construct the request url * @param vfModuleInstanceId vfModule instance id to construct the request url (required in case of delete vf @@ -126,12 +135,13 @@ public final class SoManager { * @return a concurrent Future for the thread that handles the request */ public Future<SoResponse> asyncSoRestCall(final String requestId, - final WorkingMemory wm, + final SoCallback callback, final String serviceInstanceId, final String vnfInstanceId, - final String vfModuleInstanceId, final SoRequest request) { - return executors.submit(new AsyncSoRestCallThread(requestId, wm, serviceInstanceId, vnfInstanceId, - vfModuleInstanceId, request)); + final String vfModuleInstanceId, + final SoRequest request) { + return executors.submit(new AsyncSoRestCallThread(requestId, callback, serviceInstanceId, vnfInstanceId, + vfModuleInstanceId, request, this.url, this.user, this.password)); } /** @@ -139,11 +149,14 @@ public final class SoManager { */ private class AsyncSoRestCallThread implements Callable<SoResponse> { final String requestId; - final WorkingMemory wm; + final SoCallback callback; final String serviceInstanceId; final String vnfInstanceId; final String vfModuleInstanceId; final SoRequest request; + final String baseUrl; + final String user; + final String password; /** * Constructor, sets the context of the request. @@ -156,15 +169,21 @@ public final class SoManager { * @param request the request itself */ private AsyncSoRestCallThread(final String requestId, - final WorkingMemory wm, final String serviceInstanceId, + final SoCallback callback, final String serviceInstanceId, final String vnfInstanceId, final String vfModuleInstanceId, - final SoRequest request) { + final SoRequest request, + final String url, + final String user, + final String password) { this.requestId = requestId; - this.wm = wm; + this.callback = callback; this.serviceInstanceId = serviceInstanceId; this.vnfInstanceId = vnfInstanceId; this.vfModuleInstanceId = vfModuleInstanceId; this.request = request; + this.baseUrl = url; + this.user = user; + this.password = password; } /** @@ -172,37 +191,39 @@ public final class SoManager { */ @Override public SoResponse call() { - String urlBase = PolicyEngine.manager.getEnvironmentProperty("so.url"); - String username = PolicyEngine.manager.getEnvironmentProperty("so.username"); - String password = PolicyEngine.manager.getEnvironmentProperty("so.password"); // Create a JSON representation of the request String soJson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create().toJson(request); - String url = null; + String initialUrl = null; Pair<Integer, String> httpResponse = null; if (request.getOperationType() != null && request.getOperationType() .equals(SoOperationType.SCALE_OUT)) { - url = urlBase + "/serviceInstantiation/v7/serviceInstances/" + serviceInstanceId + "/vnfs/" + initialUrl = this.baseUrl + "/serviceInstantiation/v7/serviceInstances/" + serviceInstanceId + "/vnfs/" + vnfInstanceId + "/vfModules/scaleOut"; - NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, url, soJson); - httpResponse = restManager.post(url, username, password, createSimpleHeaders(), MEDIA_TYPE, soJson); + NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, initialUrl, soJson); + httpResponse = restManager.post(initialUrl, this.user, this.password, createSimpleHeaders(), + MEDIA_TYPE, soJson); } else if (request.getOperationType() != null && request.getOperationType() .equals(SoOperationType.DELETE_VF_MODULE)) { - url = urlBase + "/serviceInstances/v7/" + serviceInstanceId + "/vnfs/" + vnfInstanceId + initialUrl = this.baseUrl + "/serviceInstances/v7/" + serviceInstanceId + "/vnfs/" + vnfInstanceId + "/vfModules/" + vfModuleInstanceId; - NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, url, soJson); - httpResponse = restManager.delete(url, username, password, createSimpleHeaders(), MEDIA_TYPE, soJson); + NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, initialUrl, soJson); + httpResponse = restManager.delete(initialUrl, this.user, this.password, createSimpleHeaders(), + MEDIA_TYPE, soJson); } else { return null; } // Process the response from SO - SoResponse response = waitForSoOperationCompletion(urlBase, username, password, url, httpResponse); + SoResponse response = waitForSoOperationCompletion(this.baseUrl, this.user, this.password, initialUrl, + httpResponse); // Return the response to Drools in its working memory SoResponseWrapper soWrapper = new SoResponseWrapper(response, requestId); - wm.insert(soWrapper); + if (this.callback != null) { + this.callback.onSoResponseWrapper(soWrapper); + } return response; } diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/DummyWorkingMemory.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/DummyWorkingMemory.java deleted file mode 100644 index caffef43d..000000000 --- a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/DummyWorkingMemory.java +++ /dev/null @@ -1,316 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * so - * ================================================================================ - * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.so; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; - -import org.drools.core.WorkingMemory; -import org.drools.core.WorkingMemoryEntryPoint; -import org.drools.core.common.InternalFactHandle; -import org.drools.core.impl.InternalKnowledgeBase; -import org.drools.core.spi.AsyncExceptionHandler; -import org.drools.core.spi.GlobalResolver; -import org.kie.api.event.kiebase.KieBaseEventListener; -import org.kie.api.event.rule.AgendaEventListener; -import org.kie.api.event.rule.RuleRuntimeEventListener; -import org.kie.api.runtime.Environment; -import org.kie.api.runtime.ObjectFilter; -import org.kie.api.runtime.process.ProcessInstance; -import org.kie.api.runtime.process.WorkItemManager; -import org.kie.api.runtime.rule.Agenda; -import org.kie.api.runtime.rule.AgendaFilter; -import org.kie.api.runtime.rule.FactHandle; -import org.kie.api.runtime.rule.FactHandle.State; -import org.kie.api.runtime.rule.QueryResults; -import org.kie.api.time.SessionClock; - -public class DummyWorkingMemory implements WorkingMemory { - - @Override - public void addEventListener(RuleRuntimeEventListener listener) { - } - - @Override - public void addEventListener(AgendaEventListener listener) { - } - - @Override - public void addEventListener(KieBaseEventListener listener) { - } - - @Override - public void removeEventListener(RuleRuntimeEventListener listener) { - } - - @Override - public void removeEventListener(AgendaEventListener listener) { - } - - @Override - public void removeEventListener(KieBaseEventListener listener) { - } - - @Override - public Collection<RuleRuntimeEventListener> getRuleRuntimeEventListeners() { - return null; - } - - @Override - public Collection<AgendaEventListener> getAgendaEventListeners() { - return null; - } - - @Override - public Collection<KieBaseEventListener> getKieBaseEventListeners() { - return null; - } - - @Override - public FactHandle insert(Object object, boolean dynamic) { - return null; - } - - @Override - public FactHandle insert(Object object) { - return null; - } - - @Override - public void dispose() { - } - - @Override - public String getEntryPointId() { - return null; - } - - @Override - public void retract(FactHandle handle) { - } - - @Override - public void delete(FactHandle handle) { - } - - @Override - public void delete(FactHandle handle, State fhState) { - - - } - - @Override - public void update(FactHandle handle, Object object) { - } - - @Override - public void update(FactHandle handle, Object object, String... modifiedProperties) { - } - - @Override - public Collection<? extends Object> getObjects() { - return null; - } - - @Override - public Collection<? extends Object> getObjects(ObjectFilter filter) { - return null; - } - - @Override - public <T extends FactHandle> Collection<T> getFactHandles() { - return null; - } - - @Override - public <T extends FactHandle> Collection<T> getFactHandles(ObjectFilter filter) { - return null; - } - - @Override - public long getFactCount() { - return 0; - } - - @Override - public Agenda getAgenda() { - return null; - } - - @Override - public void setGlobal(String identifier, Object value) { - } - - @Override - public Object getGlobal(String identifier) { - return null; - } - - @Override - public Environment getEnvironment() { - return null; - } - - @Override - public void setGlobalResolver(GlobalResolver globalResolver) { - } - - @Override - public GlobalResolver getGlobalResolver() { - return null; - } - - @Override - public InternalKnowledgeBase getKnowledgeBase() { - return null; - } - - @Override - public int fireAllRules() { - return 0; - } - - @Override - public int fireAllRules(AgendaFilter agendaFilter) { - return 0; - } - - @Override - public int fireAllRules(int fireLimit) { - return 0; - } - - @Override - public int fireAllRules(AgendaFilter agendaFilter, int fireLimit) { - return 0; - } - - @Override - public Object getObject(FactHandle handle) { - return null; - } - - @Override - public FactHandle getFactHandle(Object object) { - return null; - } - - @Override - public FactHandle getFactHandleByIdentity(Object object) { - return null; - } - - @Override - public Iterator<?> iterateObjects() { - return null; - } - - @Override - public Iterator<?> iterateObjects(ObjectFilter filter) { - return null; - } - - @Override - public Iterator<InternalFactHandle> iterateFactHandles() { - return null; - } - - @Override - public Iterator<InternalFactHandle> iterateFactHandles(ObjectFilter filter) { - return null; - } - - @Override - public void setFocus(String focus) { - } - - @Override - public QueryResults getQueryResults(String query, Object... arguments) { - return null; - } - - @Override - public void setAsyncExceptionHandler(AsyncExceptionHandler handler) { - } - - @Override - public void clearAgenda() { - } - - @Override - public void clearAgendaGroup(String group) { - } - - @Override - public void clearActivationGroup(String group) { - } - - @Override - public void clearRuleFlowGroup(String group) { - } - - @Override - public ProcessInstance startProcess(String processId) { - return null; - } - - @Override - public ProcessInstance startProcess(String processId, Map<String, Object> parameters) { - return null; - } - - @Override - public Collection<ProcessInstance> getProcessInstances() { - return null; - } - - @Override - public ProcessInstance getProcessInstance(long id) { - return null; - } - - @Override - public ProcessInstance getProcessInstance(long id, boolean readOnly) { - return null; - } - - @Override - public WorkItemManager getWorkItemManager() { - return null; - } - - @Override - public void halt() { - } - - @Override - public WorkingMemoryEntryPoint getWorkingMemoryEntryPoint(String id) { - return null; - } - - @Override - public SessionClock getSessionClock() { - return null; - } - -} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java index 4d7228ff7..03ac06dd5 100644 --- a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java @@ -40,16 +40,15 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; -import org.drools.core.WorkingMemory; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; import org.glassfish.jersey.server.ResourceConfig; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.so.SoManager.SoCallback; -public class SoManagerTest { +public class SoManagerTest implements SoCallback { private static final String BASE_URI = "http://localhost:46553/TestSOManager"; private static final String BASE_SO_URI = BASE_URI + "/SO"; private static HttpServer server; @@ -86,7 +85,7 @@ public class SoManagerTest { @Test public void testServiceInstantiation() throws IOException { - SoManager manager = new SoManager(); + SoManager manager = new SoManager(null, null, null); assertNotNull(manager); manager.setRestGetTimeout(100); @@ -161,19 +160,13 @@ public class SoManagerTest { @Test public void testVfModuleCreation() throws IOException { - SoManager manager = new SoManager(); + SoManager manager = new SoManager("http:/localhost:99999999", "sean", "citizen"); assertNotNull(manager); manager.setRestGetTimeout(100); - PolicyEngine.manager.setEnvironmentProperty("so.username", "sean"); - PolicyEngine.manager.setEnvironmentProperty("so.password", "citizen"); - - WorkingMemory wm = new DummyWorkingMemory(); - SoRequest soRequest = new SoRequest(); soRequest.setOperationType(SoOperationType.SCALE_OUT); - PolicyEngine.manager.setEnvironmentProperty("so.url", "http:/localhost:99999999"); - Future<SoResponse> asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, + Future<SoResponse> asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest); try { SoResponse response = asyncRestCallFuture.get(); @@ -182,8 +175,9 @@ public class SoManagerTest { fail("test should not throw an exception"); } - PolicyEngine.manager.setEnvironmentProperty("so.url", BASE_SO_URI); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + manager = new SoManager(BASE_SO_URI, "sean", "citizen"); + manager.setRestGetTimeout(100); + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest); try { SoResponse response = asyncRestCallFuture.get(); @@ -201,7 +195,7 @@ public class SoManagerTest { request.getRequestStatus().setRequestState("ONGOING"); request.setOperationType(SoOperationType.SCALE_OUT); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); try { SoResponse response = asyncRestCallFuture.get(); @@ -212,7 +206,7 @@ public class SoManagerTest { request.setRequestType("ReturnCompleted"); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); try { SoResponse response = asyncRestCallFuture.get(); @@ -222,7 +216,7 @@ public class SoManagerTest { } request.setRequestType("ReturnFailed"); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); try { SoResponse response = asyncRestCallFuture.get(); @@ -235,7 +229,7 @@ public class SoManagerTest { request.setRequestType("ReturnOnging200"); request.setRequestScope(new Integer(10).toString()); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); try { SoResponse response = asyncRestCallFuture.get(); @@ -247,7 +241,7 @@ public class SoManagerTest { request.setRequestType("ReturnOnging202"); request.setRequestScope(new Integer(20).toString()); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); try { SoResponse response = asyncRestCallFuture.get(); @@ -260,7 +254,7 @@ public class SoManagerTest { // Test timeout after 20 attempts for a response request.setRequestType("ReturnOnging202"); request.setRequestScope(new Integer(21).toString()); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); try { SoResponse response = asyncRestCallFuture.get(); @@ -272,7 +266,7 @@ public class SoManagerTest { // Test bad response after 3 attempts for a response request.setRequestType("ReturnBadAfterWait"); request.setRequestScope(new Integer(3).toString()); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); try { SoResponse response = asyncRestCallFuture.get(); @@ -284,19 +278,13 @@ public class SoManagerTest { @Test public void testVfModuleDeletion() { - SoManager manager = new SoManager(); + SoManager manager = new SoManager("http:/localhost:99999999", "sean", "citizen"); assertNotNull(manager); manager.setRestGetTimeout(100); - PolicyEngine.manager.setEnvironmentProperty("so.username", "sean"); - PolicyEngine.manager.setEnvironmentProperty("so.password", "citizen"); - - WorkingMemory wm = new DummyWorkingMemory(); - SoRequest soRequest = new SoRequest(); soRequest.setOperationType(SoOperationType.DELETE_VF_MODULE); - PolicyEngine.manager.setEnvironmentProperty("so.url", "http:/localhost:99999999"); - Future<SoResponse> asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, + Future<SoResponse> asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest); try { SoResponse response = asyncRestCallFuture.get(); @@ -305,8 +293,10 @@ public class SoManagerTest { fail("test should not throw an exception"); } - PolicyEngine.manager.setEnvironmentProperty("so.url", BASE_SO_URI); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + manager = new SoManager(BASE_SO_URI, "sean", "citizen"); + manager.setRestGetTimeout(100); + + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest); try { SoResponse response = asyncRestCallFuture.get(); @@ -324,7 +314,7 @@ public class SoManagerTest { request.getRequestStatus().setRequestState("ONGOING"); request.setOperationType(SoOperationType.DELETE_VF_MODULE); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); try { SoResponse response = asyncRestCallFuture.get(); @@ -335,7 +325,7 @@ public class SoManagerTest { request.setRequestType("ReturnCompleted"); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); try { SoResponse response = asyncRestCallFuture.get(); @@ -345,7 +335,7 @@ public class SoManagerTest { } request.setRequestType("ReturnFailed"); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); try { SoResponse response = asyncRestCallFuture.get(); @@ -358,7 +348,7 @@ public class SoManagerTest { request.setRequestType("ReturnOnging200"); request.setRequestScope(new Integer(10).toString()); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); try { SoResponse response = asyncRestCallFuture.get(); @@ -370,7 +360,7 @@ public class SoManagerTest { request.setRequestType("ReturnOnging202"); request.setRequestScope(new Integer(20).toString()); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); try { SoResponse response = asyncRestCallFuture.get(); @@ -383,7 +373,7 @@ public class SoManagerTest { // Test timeout after 20 attempts for a response request.setRequestType("ReturnOnging202"); request.setRequestScope(new Integer(21).toString()); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); try { SoResponse response = asyncRestCallFuture.get(); @@ -395,7 +385,7 @@ public class SoManagerTest { // Test bad response after 3 attempts for a response request.setRequestType("ReturnBadAfterWait"); request.setRequestScope(new Integer(3).toString()); - asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); try { SoResponse response = asyncRestCallFuture.get(); @@ -404,4 +394,11 @@ public class SoManagerTest { fail("test should not throw an exception"); } } + + @Override + public void onSoResponseWrapper(SoResponseWrapper wrapper) { + // + // Nothing really needed to do + // + } } diff --git a/models-interactions/model-impl/vfc/pom.xml b/models-interactions/model-impl/vfc/pom.xml index 9a36cd2e8..d0b473316 100644 --- a/models-interactions/model-impl/vfc/pom.xml +++ b/models-interactions/model-impl/vfc/pom.xml @@ -52,23 +52,11 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>org.drools</groupId> - <artifactId>drools-core</artifactId> - <version>6.5.0.Final</version> - <scope>provided</scope> - </dependency> - <dependency> <groupId>org.onap.policy.common</groupId> <artifactId>policy-endpoints</artifactId> <version>${policy.common.version}</version> <scope>provided</scope> </dependency> - <dependency> - <groupId>org.onap.policy.drools-pdp</groupId> - <artifactId>policy-management</artifactId> - <version>${policy.drools-pdp.version}</version> - <scope>provided</scope> - </dependency> </dependencies> <build> <plugins> diff --git a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java index 695b1b189..850f37552 100644 --- a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java +++ b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java @@ -26,11 +26,9 @@ import com.google.gson.JsonSyntaxException; import java.util.HashMap; import java.util.Map; -import org.drools.core.WorkingMemory; 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.drools.system.PolicyEngine; import org.onap.policy.rest.RestManager; import org.onap.policy.rest.RestManager.Pair; import org.onap.policy.vfc.util.Serialization; @@ -43,31 +41,41 @@ public final class VfcManager implements Runnable { private String username; private String password; private VfcRequest vfcRequest; - private WorkingMemory workingMem; + private VfcCallback callback; private static final Logger logger = LoggerFactory.getLogger(VfcManager.class); // The REST manager used for processing REST calls for this VFC manager private RestManager restManager; + public interface VfcCallback { + void onResponse(VfcResponse responseError); + } + /** * Constructor. * - * @param wm Drools working memory + * @param cb Callback method to call when response * @param request request + * @param url URL to VFC component + * @param user username + * @param pwd password */ - public VfcManager(WorkingMemory wm, VfcRequest request) { - if (wm == null || request == null) { + public VfcManager(VfcCallback cb, VfcRequest request, String url, String user, String pwd) { + if (cb == null || request == null) { throw new IllegalArgumentException( - "the parameters \"wm\" and \"request\" on the VfcManager constructor may not be null"); + "the parameters \"cb\" and \"request\" on the VfcManager constructor may not be null"); } - workingMem = wm; + if (url == null) { + throw new IllegalArgumentException( + "the \"url\" parameter on the VfcManager constructor may not be null"); + } + callback = cb; vfcRequest = request; + vfcUrlBase = url; + username = user; + password = pwd; 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")); } /** @@ -101,12 +109,12 @@ public final class VfcManager implements Runnable { httpDetails = restManager.post(vfcUrl, username, password, headers, "application/json", vfcRequestJson); } catch (Exception e) { logger.error(e.getMessage(), e); - workingMem.insert(responseError); + this.callback.onResponse(responseError); return; } if (httpDetails == null) { - workingMem.insert(responseError); + this.callback.onResponse(responseError); return; } @@ -142,7 +150,7 @@ public final class VfcManager implements Runnable { if (httpDetailsGet.first == 200 && ("finished".equalsIgnoreCase(responseStatus) || "error".equalsIgnoreCase(responseStatus))) { logger.debug("VFC Heal Status {}", responseGet.getResponseDescriptor().getStatus()); - workingMem.insert(responseGet); + this.callback.onResponse(responseGet); break; } Thread.sleep(20000); @@ -151,7 +159,7 @@ public final class VfcManager implements Runnable { && (responseGet.getResponseDescriptor().getStatus() != null) && (!responseGet.getResponseDescriptor().getStatus().isEmpty())) { logger.debug("VFC timeout. Status: ({})", responseGet.getResponseDescriptor().getStatus()); - workingMem.insert(responseGet); + this.callback.onResponse(responseGet); } } catch (JsonSyntaxException e) { logger.error("Failed to deserialize into VfcResponse {}", e.getLocalizedMessage(), e); @@ -171,21 +179,4 @@ public final class VfcManager implements Runnable { 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/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java index f8a5c5287..15534dbbb 100644 --- a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java +++ b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java @@ -24,7 +24,6 @@ package org.onap.policy.vfc; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; - import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.endsWith; @@ -37,18 +36,14 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import org.drools.core.WorkingMemory; -import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; -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.VfcManager.VfcCallback; import org.onap.policy.vfc.util.Serialization; -public class VfcManagerTest { - private static WorkingMemory mockedWorkingMemory; +public class VfcManagerTest implements VfcCallback { private RestManager mockedRestManager; @@ -60,11 +55,6 @@ public class VfcManagerTest { private VfcRequest request; private VfcResponse response; - @BeforeClass - public static void beforeTestVfcManager() { - mockedWorkingMemory = mock(WorkingMemory.class); - } - /** * Set up the mocked REST manager. */ @@ -118,64 +108,43 @@ public class VfcManagerTest { response.setResponseDescriptor(responseDescriptor); } - /** - * Remove the environnment. - */ - @After - public void tearDown() { - PolicyEngine.manager.getEnvironment().remove("vfc.password"); - PolicyEngine.manager.getEnvironment().remove("vfc.username"); - PolicyEngine.manager.getEnvironment().remove("vfc.url"); - } - @Test public void testVfcInitiation() { try { - new VfcManager(null, null); + new VfcManager(null, null, null, null, null); fail("test should throw an exception here"); } catch (IllegalArgumentException e) { - assertEquals("the parameters \"wm\" and \"request\" on the VfcManager constructor may not be null", + assertEquals("the parameters \"cb\" and \"request\" on the VfcManager constructor may not be null", e.getMessage()); } try { - new VfcManager(mockedWorkingMemory, null); + new VfcManager(this, null, null, null, null); fail("test should throw an exception here"); } catch (IllegalArgumentException e) { - assertEquals("the parameters \"wm\" and \"request\" on the VfcManager constructor may not be null", + assertEquals("the parameters \"cb\" and \"request\" on the VfcManager constructor may not be null", e.getMessage()); } try { - new VfcManager(mockedWorkingMemory, request); + new VfcManager(this, request, null, null, null); fail("test should throw an exception here"); } catch (IllegalArgumentException e) { - assertEquals("The value of policy engine manager environment property \"vfc.url\" may not be null", + assertEquals("the \"url\" parameter on the VfcManager constructor may not be null", e.getMessage()); } - // add url; username & password are not required - PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow"); - new VfcManager(mockedWorkingMemory, request); + new VfcManager(this, request, "http://somewhere.over.the.rainbow", null, null); - // url & username, but no password - PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy"); - - // url, username, and password - PolicyEngine.manager.getEnvironment().put("vfc.password", "Toto"); - new VfcManager(mockedWorkingMemory, request); + new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Toto"); } @Test public void testVfcExecutionException() throws InterruptedException { - PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow"); - PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy"); - PolicyEngine.manager.getEnvironment().put("vfc.password", "Exception"); - - VfcManager manager = new VfcManager(mockedWorkingMemory, request); + VfcManager manager = new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Exception"); manager.setRestManager(mockedRestManager); Thread managerThread = new Thread(manager); @@ -191,94 +160,62 @@ public class VfcManagerTest { .thenThrow(new RuntimeException("OzException")); managerThread.join(); - - PolicyEngine.manager.getEnvironment().remove("vfc.password"); - PolicyEngine.manager.getEnvironment().remove("vfc.username"); - PolicyEngine.manager.getEnvironment().remove("vfc.url"); } @Test public void testVfcExecutionNull() throws InterruptedException { - PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow"); - PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy"); - PolicyEngine.manager.getEnvironment().put("vfc.password", "Null"); - - VfcManager manager = new VfcManager(mockedWorkingMemory, request); + VfcManager manager = new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Null"); manager.setRestManager(mockedRestManager); Thread managerThread = new Thread(manager); managerThread.start(); - when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString())) .thenReturn(null); managerThread.join(); - - PolicyEngine.manager.getEnvironment().remove("vfc.password"); - PolicyEngine.manager.getEnvironment().remove("vfc.username"); - PolicyEngine.manager.getEnvironment().remove("vfc.url"); } @Test public void testVfcExecutionError0() throws InterruptedException { - PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow"); - PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy"); - PolicyEngine.manager.getEnvironment().put("vfc.password", "Error0"); - - VfcManager manager = new VfcManager(mockedWorkingMemory, request); + VfcManager manager = new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Error0"); manager.setRestManager(mockedRestManager); Thread managerThread = new Thread(manager); managerThread.start(); - when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Error0"), anyMap(), anyString(), anyString())) .thenReturn(httpResponseErr); managerThread.join(); - - PolicyEngine.manager.getEnvironment().remove("vfc.password"); - PolicyEngine.manager.getEnvironment().remove("vfc.username"); - PolicyEngine.manager.getEnvironment().remove("vfc.url"); } @Test public void testVfcExecutionBadResponse() throws InterruptedException { - PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow"); - PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy"); - PolicyEngine.manager.getEnvironment().put("vfc.password", "BadResponse"); - - VfcManager manager = new VfcManager(mockedWorkingMemory, request); + VfcManager manager = new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "BadResponse"); manager.setRestManager(mockedRestManager); Thread managerThread = new Thread(manager); managerThread.start(); - when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString())) .thenReturn(httpResponseBadResponse); managerThread.join(); - - PolicyEngine.manager.getEnvironment().remove("vfc.password"); - PolicyEngine.manager.getEnvironment().remove("vfc.username"); - PolicyEngine.manager.getEnvironment().remove("vfc.url"); } @Test public void testVfcExecutionOk() throws InterruptedException { - PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow"); - PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy"); - PolicyEngine.manager.getEnvironment().put("vfc.password", "OK"); - - VfcManager manager = new VfcManager(mockedWorkingMemory, request); + VfcManager manager = new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Ok"); manager.setRestManager(mockedRestManager); Thread managerThread = new Thread(manager); managerThread.start(); - when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString())) .thenReturn(httpResponsePutOk); @@ -286,9 +223,12 @@ public class VfcManagerTest { .thenReturn(httpResponseGetOk); managerThread.join(); + } - PolicyEngine.manager.getEnvironment().remove("vfc.password"); - PolicyEngine.manager.getEnvironment().remove("vfc.username"); - PolicyEngine.manager.getEnvironment().remove("vfc.url"); + @Override + public void onResponse(VfcResponse responseError) { + // + // Nothing needs to be done + // } } diff --git a/models-interactions/model-yaml/pom.xml b/models-interactions/model-yaml/pom.xml index 77f1d7035..233edc4dc 100644 --- a/models-interactions/model-yaml/pom.xml +++ b/models-interactions/model-yaml/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - drools-pdp-apps + ONAP ================================================================================ Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. Modifications Copyright (C) 2019 Nordix Foundation. @@ -40,8 +40,6 @@ <derby.version>10.13.1.1</derby.version> <javax.ws.rs-api.version>2.0.1</javax.ws.rs-api.version> <policy.common.version>1.4.0-SNAPSHOT</policy.common.version> - <policy.drools-applications.version>1.4.0-SNAPSHOT</policy.drools-applications.version> - <policy.drools-pdp.version>1.4.0-SNAPSHOT</policy.drools-pdp.version> <!-- sonar/jacoco overrides --> <!-- Overriding oparent default sonar/jacoco settings Combine all our reports into one file shared across sub-modules --> @@ -272,4 +270,4 @@ </plugins> </pluginManagement> </build> -</project>
\ No newline at end of file +</project> |