diff options
author | Jim Hahn <jrh3@att.com> | 2020-08-21 13:43:08 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-10-27 14:55:15 -0400 |
commit | 19ef8b24a98c09a349e6ae7309f535a0135463f6 (patch) | |
tree | d988e5a58865ae6f3a38dcb31e4f195f18e59946 /models-interactions/model-actors/actor.sdnc/src | |
parent | 6b29d2c19e288148171db0c0e446e18dcd46effd (diff) |
Make Actors event-agnostic
Removed event and event-context code from the Actor code. Also removed
the preprocessing steps from the Actor code, giving the application
complete control over any preprocessing.
Also fixed a bug wherein the APPC actor was treating the
AAI_RESOURCE_VNF property as a String instead of as a GenericVnf.
Issue-ID: POLICY-2746-actor
Change-Id: Ibc05fe39ffedc0bc461abf10e6a960861ac70119
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.sdnc/src')
7 files changed, 6 insertions, 178 deletions
diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java index d2a153641..2946a2055 100644 --- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java +++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java @@ -66,18 +66,18 @@ public class BandwidthOnDemandOperation extends SdncOperation { @Override protected SdncRequest makeRequest(int attempt) { - String serviceInstance = getOptProperty(OperationProperties.ENRICHMENT_SERVICE_ID, SERVICE_ID_KEY); + String serviceInstance = getProperty(OperationProperties.ENRICHMENT_SERVICE_ID); if (StringUtils.isBlank(serviceInstance)) { throw new IllegalArgumentException("missing enrichment data, " + SERVICE_ID_KEY); } SdncHealVfModuleParameter bandwidth = new SdncHealVfModuleParameter(); bandwidth.setName(BANDWIDTH); - bandwidth.setValue(getOptProperty(OperationProperties.ENRICHMENT_BANDWIDTH, BANDWIDTH)); + bandwidth.setValue(getProperty(OperationProperties.ENRICHMENT_BANDWIDTH)); SdncHealVfModuleParameter timeStamp = new SdncHealVfModuleParameter(); timeStamp.setName(BANDWIDTH_CHANGE_TIME); - timeStamp.setValue(getOptProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, BANDWIDTH_CHANGE_TIME)); + timeStamp.setValue(getProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME)); SdncHealVfModuleParametersInfo vfParametersInfo = new SdncHealVfModuleParametersInfo(); vfParametersInfo.addParameters(bandwidth); @@ -102,7 +102,7 @@ public class BandwidthOnDemandOperation extends SdncOperation { request.setUrl("/" + getPath()); SdncHealVnfInfo vnfInfo = new SdncHealVnfInfo(); - vnfInfo.setVnfId(getOptProperty(OperationProperties.ENRICHMENT_VNF_ID, VNF_ID)); + vnfInfo.setVnfId(getProperty(OperationProperties.ENRICHMENT_VNF_ID)); SdncHealVfModuleInfo vfModuleInfo = new SdncHealVfModuleInfo(); vfModuleInfo.setVfModuleId(""); diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java index 105a27601..02209bbd2 100644 --- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java +++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java @@ -57,14 +57,14 @@ public class RerouteOperation extends SdncOperation { @Override protected SdncRequest makeRequest(int attempt) { - String serviceInstance = getOptProperty(OperationProperties.ENRICHMENT_SERVICE_ID, SERVICE_ID_KEY); + String serviceInstance = getProperty(OperationProperties.ENRICHMENT_SERVICE_ID); if (StringUtils.isBlank(serviceInstance)) { throw new IllegalArgumentException("missing enrichment data, " + SERVICE_ID_KEY); } SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo(); serviceInfo.setServiceInstanceId(serviceInstance); - String networkId = getOptProperty(OperationProperties.ENRICHMENT_NETWORK_ID, NETWORK_ID_KEY); + String networkId = getProperty(OperationProperties.ENRICHMENT_NETWORK_ID); if (StringUtils.isBlank(networkId)) { throw new IllegalArgumentException("missing enrichment data, " + NETWORK_ID_KEY); } diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java index defbcfbc9..d235fb2c8 100644 --- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java +++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java @@ -51,14 +51,6 @@ public abstract class SdncOperation extends HttpOperation<SdncResponse> { super(params, config, SdncResponse.class, propertyNames); } - /** - * Starts the GUARD. - */ - @Override - protected CompletableFuture<OperationOutcome> startPreprocessorAsync() { - return startGuardAsync(); - } - @Override protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) { @@ -96,21 +88,4 @@ public abstract class SdncOperation extends HttpOperation<SdncResponse> { protected boolean isSuccess(Response rawResponse, SdncResponse response) { return response.getResponseOutput() != null && "200".equals(response.getResponseOutput().getResponseCode()); } - - /** - * Gets an optional property, first checking the properties, then checking the - * enrichment data. - * - * @param propName property name - * @param enrichmentName property name within the enrichment data - * @return the property's value, or {@code null} if it is not found - */ - protected String getOptProperty(String propName, String enrichmentName) { - if (containsProperty(propName)) { - // return the value, even if it's null - return getProperty(propName); - } - - return params.getContext().getEnrichment().get(enrichmentName); - } } diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java index 5e71a6cd5..ba68534c4 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java @@ -25,7 +25,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.List; -import java.util.Map; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -33,10 +32,8 @@ import org.junit.Test; import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; import org.onap.policy.controlloop.actorserviceprovider.OperationResult; -import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; -import org.onap.policy.sdnc.SdncRequest; import org.onap.policy.sdnc.SdncResponse; public class BandwidthOnDemandOperationTest extends BasicSdncOperation { @@ -114,30 +111,6 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation { @Test public void testMakeRequest() throws Exception { - oper.generateSubRequestId(1); - SdncRequest request = oper.makeRequest(1); - assertEquals(MY_SERVICE, request.getNsInstanceId()); - assertEquals(REQ_ID, request.getRequestId()); - assertEquals("/my-path/", request.getUrl()); - assertEquals(oper.getSubRequestId(), request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); - - verifyRequest("bod.json", request, IGNORE_FIELDS); - - verifyMissing(BandwidthOnDemandOperation.SERVICE_ID_KEY, "service", BandwidthOnDemandOperation::new); - - // perform the operation - makeContext(); - verifyRequest("bod.json", verifyOperation(oper), IGNORE_FIELDS); - } - - @Test - public void testMakeRequestViaProperties() throws Exception { - // clear the enrichment data and remake the operation - event.setAai(null); - context = new ControlLoopEventContext(event); - params = params.toBuilder().context(context).build(); - oper = new BandwidthOnDemandOperation(params, config); - oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE); oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH); oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME); @@ -145,11 +118,4 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation { verifyRequest("bod.json", verifyOperation(oper), IGNORE_FIELDS); } - - @Override - protected Map<String, String> makeEnrichment() { - return Map.of(BandwidthOnDemandOperation.SERVICE_ID_KEY, MY_SERVICE, BandwidthOnDemandOperation.BANDWIDTH, - MY_BANDWIDTH, BandwidthOnDemandOperation.BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME, - BandwidthOnDemandOperation.VNF_ID, MY_VNF); - } } diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java index a118ab124..f4b6141f8 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java @@ -20,7 +20,6 @@ package org.onap.policy.controlloop.actor.sdnc; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -29,7 +28,6 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; @@ -41,13 +39,10 @@ import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.controlloop.actor.test.BasicHttpOperation; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.OperationResult; -import org.onap.policy.controlloop.actorserviceprovider.impl.OperationMaker; -import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.sdnc.SdncRequest; import org.onap.policy.sdnc.SdncResponse; import org.onap.policy.sdnc.SdncResponseOutput; import org.onap.policy.simulators.Util; -import org.powermock.reflect.Whitebox; /** * Superclass for various operator tests. @@ -137,26 +132,4 @@ public abstract class BasicSdncOperation extends BasicHttpOperation { return coder.decode(reqText, SdncRequest.class); } - - /** - * Verifies that an exception is thrown if a field is missing from the enrichment - * data. - * - * @param fieldName name of the field to be removed from the enrichment data - * @param expectedText text expected in the exception message - */ - protected void verifyMissing(String fieldName, String expectedText, - OperationMaker<HttpConfig, SdncOperation> maker) { - - makeContext(); - enrichment.remove(fieldName); - - SdncOperation oper = maker.apply(params, config); - - assertThatIllegalArgumentException().isThrownBy(() -> Whitebox.invokeMethod(oper, "makeRequest", 1)) - .withMessageContaining("missing").withMessageContaining(expectedText); - } - - @Override - protected abstract Map<String, String> makeEnrichment(); } diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java index e41ef3fec..3f087844b 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java @@ -25,7 +25,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.List; -import java.util.Map; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -33,10 +32,8 @@ import org.junit.Test; import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; import org.onap.policy.controlloop.actorserviceprovider.OperationResult; -import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; -import org.onap.policy.sdnc.SdncRequest; import org.onap.policy.sdnc.SdncResponse; public class RerouteOperationTest extends BasicSdncOperation { @@ -107,39 +104,9 @@ public class RerouteOperationTest extends BasicSdncOperation { @Test public void testMakeRequest() throws Exception { - oper.generateSubRequestId(1); - SdncRequest request = oper.makeRequest(1); - assertEquals(MY_SERVICE, request.getNsInstanceId()); - assertEquals(REQ_ID, request.getRequestId()); - assertEquals("/my-path/", request.getUrl()); - assertEquals(oper.getSubRequestId(), request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); - - verifyRequest("reroute.json", request, IGNORE_FIELDS); - - verifyMissing(RerouteOperation.SERVICE_ID_KEY, "service", RerouteOperation::new); - verifyMissing(RerouteOperation.NETWORK_ID_KEY, "network", RerouteOperation::new); - - // perform the operation - makeContext(); - verifyRequest("reroute.json", verifyOperation(oper), IGNORE_FIELDS); - } - - @Test - public void testMakeRequestViaProperties() throws Exception { - // clear the enrichment data and remake the operation - event.setAai(null); - context = new ControlLoopEventContext(event); - params = params.toBuilder().context(context).build(); - oper = new RerouteOperation(params, config); - oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE); oper.setProperty(OperationProperties.ENRICHMENT_NETWORK_ID, MY_NETWORK); verifyRequest("reroute.json", verifyOperation(oper), IGNORE_FIELDS); } - - @Override - protected Map<String, String> makeEnrichment() { - return Map.of(RerouteOperation.SERVICE_ID_KEY, MY_SERVICE, RerouteOperation.NETWORK_ID_KEY, MY_NETWORK); - } } diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java index 4ba12c6ca..9055715b4 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java @@ -22,16 +22,11 @@ package org.onap.policy.controlloop.actor.sdnc; import static org.junit.Assert.assertEquals; 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.util.Collections; -import java.util.Map; -import java.util.TreeMap; import org.junit.Before; import org.junit.Test; -import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; import org.onap.policy.sdnc.SdncHealRequest; import org.onap.policy.sdnc.SdncHealRequestHeaderInfo; import org.onap.policy.sdnc.SdncRequest; @@ -75,11 +70,6 @@ public class SdncOperationTest extends BasicSdncOperation { } @Test - public void testStartPreprocessorAsync() { - assertNotNull(oper.startPreprocessorAsync()); - } - - @Test public void testStartOperationAsync_testStartRequestAsync() throws Exception { verifyOperation(oper); } @@ -102,47 +92,4 @@ public class SdncOperationTest extends BasicSdncOperation { response.setResponseOutput(null); assertFalse(oper.isSuccess(null, response)); } - - @Test - public void testGetOptProperty() { - // in neither property nor enrichment - assertNull(oper.getOptProperty("propA", "propA2")); - - // both - should choose the property - remakeOper(Map.of("propB2", "valueB2")); - oper.setProperty("propB", "valueB"); - assertEquals("valueB", oper.getOptProperty("propB", "propB2")); - - // both - should choose the property, even if it's null - remakeOper(Map.of("propC2", "valueC2")); - oper.setProperty("propC", null); - assertNull(oper.getOptProperty("propC", "propC2")); - - // only in enrichment data - remakeOper(Map.of("propD2", "valueD2")); - assertEquals("valueD2", oper.getOptProperty("propD", "propD2")); - } - - /** - * Remakes the operation, with the specified A&AI enrichment data. - * - * @param aai A&AI enrichment data - */ - private void remakeOper(Map<String, String> aai) { - event.setAai(aai); - context = new ControlLoopEventContext(event); - params = params.toBuilder().context(context).build(); - - oper = new SdncOperation(params, config, Collections.emptyList()) { - @Override - protected SdncRequest makeRequest(int attempt) { - return request; - } - }; - } - - @Override - protected Map<String, String> makeEnrichment() { - return new TreeMap<>(); - } } |