diff options
author | Jim Hahn <jrh3@att.com> | 2020-08-04 16:27:18 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-08-06 19:19:46 -0400 |
commit | deed677c3dc8751209d50e7d35132c929fe6800d (patch) | |
tree | 01f3149d4a03206e134d889d50834ae8d141a0ce /models-interactions/model-actors/actor.sdnc | |
parent | 364ef26929f06637bca03dd7bfb5e8ac69b611f8 (diff) |
Modify Actors to use properties when provided
Modified the Actors to use properties when the application provides them
instead of going to the event context for the data. This sometimes entailed
moving code out of the Operation subclass constructor that used or validated
the context data.
Combined some property names and renamed others.
Changed VF Count from AtomicInteger to Integer.
Issue-ID: POLICY-2746
Change-Id: Ib8730538309bb77d2f4f6161e9a20a49362d8972
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.sdnc')
7 files changed, 128 insertions, 25 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 434b3b985..d2a153641 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 @@ -23,7 +23,6 @@ package org.onap.policy.controlloop.actor.sdnc; import java.util.List; import org.apache.commons.lang3.StringUtils; import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; -import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.sdnc.SdncHealRequest; @@ -38,15 +37,18 @@ import org.onap.policy.sdnc.SdncHealVnfInfo; import org.onap.policy.sdnc.SdncRequest; public class BandwidthOnDemandOperation extends SdncOperation { + public static final String NAME = "BandwidthOnDemand"; // fields in the enrichment data public static final String SERVICE_ID_KEY = "service-instance.service-instance-id"; + public static final String BANDWIDTH = "bandwidth"; + public static final String BANDWIDTH_CHANGE_TIME = "bandwidth-change-time"; public static final String VNF_ID = "vnfId"; // @formatter:off private static final List<String> PROPERTY_NAMES = List.of( - OperationProperties.ENRICHMENT_SERVICE_INSTANCE_ID, + OperationProperties.ENRICHMENT_SERVICE_ID, OperationProperties.ENRICHMENT_BANDWIDTH, OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, OperationProperties.ENRICHMENT_VNF_ID); @@ -64,20 +66,18 @@ public class BandwidthOnDemandOperation extends SdncOperation { @Override protected SdncRequest makeRequest(int attempt) { - ControlLoopEventContext context = params.getContext(); - - String serviceInstance = context.getEnrichment().get(SERVICE_ID_KEY); + String serviceInstance = getOptProperty(OperationProperties.ENRICHMENT_SERVICE_ID, SERVICE_ID_KEY); if (StringUtils.isBlank(serviceInstance)) { throw new IllegalArgumentException("missing enrichment data, " + SERVICE_ID_KEY); } SdncHealVfModuleParameter bandwidth = new SdncHealVfModuleParameter(); - bandwidth.setName("bandwidth"); - bandwidth.setValue(context.getEnrichment().get("bandwidth")); + bandwidth.setName(BANDWIDTH); + bandwidth.setValue(getOptProperty(OperationProperties.ENRICHMENT_BANDWIDTH, BANDWIDTH)); SdncHealVfModuleParameter timeStamp = new SdncHealVfModuleParameter(); - timeStamp.setName("bandwidth-change-time"); - timeStamp.setValue(context.getEnrichment().get("bandwidth-change-time")); + timeStamp.setName(BANDWIDTH_CHANGE_TIME); + timeStamp.setValue(getOptProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, 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(context.getEnrichment().get(VNF_ID)); + vnfInfo.setVnfId(getOptProperty(OperationProperties.ENRICHMENT_VNF_ID, 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 d26fad8c7..105a27601 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 @@ -23,7 +23,6 @@ package org.onap.policy.controlloop.actor.sdnc; import java.util.List; import org.apache.commons.lang3.StringUtils; import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; -import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.sdnc.SdncHealNetworkInfo; @@ -58,16 +57,14 @@ public class RerouteOperation extends SdncOperation { @Override protected SdncRequest makeRequest(int attempt) { - ControlLoopEventContext context = params.getContext(); - - String serviceInstance = context.getEnrichment().get(SERVICE_ID_KEY); + String serviceInstance = getOptProperty(OperationProperties.ENRICHMENT_SERVICE_ID, SERVICE_ID_KEY); if (StringUtils.isBlank(serviceInstance)) { throw new IllegalArgumentException("missing enrichment data, " + SERVICE_ID_KEY); } SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo(); serviceInfo.setServiceInstanceId(serviceInstance); - String networkId = context.getEnrichment().get(NETWORK_ID_KEY); + String networkId = getOptProperty(OperationProperties.ENRICHMENT_NETWORK_ID, NETWORK_ID_KEY); 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 4d8e35e71..defbcfbc9 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 @@ -96,4 +96,21 @@ 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 56b64e491..f80299f93 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 @@ -32,6 +32,7 @@ import org.junit.BeforeClass; 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.controlloop.ControlLoopEventContext; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.policy.PolicyResult; @@ -39,6 +40,10 @@ import org.onap.policy.sdnc.SdncRequest; import org.onap.policy.sdnc.SdncResponse; public class BandwidthOnDemandOperationTest extends BasicSdncOperation { + private static final String MY_SERVICE = "my-service"; + private static final String MY_VNF = "my-vnf"; + private static final String MY_BANDWIDTH = "my-bandwidth"; + private static final String MY_CHANGE_TIME = "my-change-time"; private BandwidthOnDemandOperation oper; @@ -76,7 +81,7 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation { // @formatter:off assertThat(oper.getPropertyNames()).isEqualTo( List.of( - OperationProperties.ENRICHMENT_SERVICE_INSTANCE_ID, + OperationProperties.ENRICHMENT_SERVICE_ID, OperationProperties.ENRICHMENT_BANDWIDTH, OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, OperationProperties.ENRICHMENT_VNF_ID)); @@ -93,9 +98,14 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation { .path("GENERIC-RESOURCE-API:vf-module-topology-operation").build(); config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); - params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).preprocessed(true).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); + oper.setProperty(OperationProperties.ENRICHMENT_VNF_ID, MY_VNF); + outcome = oper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); assertTrue(outcome.getResponse() instanceof SdncResponse); @@ -105,7 +115,7 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation { public void testMakeRequest() throws Exception { oper.generateSubRequestId(1); SdncRequest request = oper.makeRequest(1); - assertEquals("my-service", request.getNsInstanceId()); + assertEquals(MY_SERVICE, request.getNsInstanceId()); assertEquals(REQ_ID, request.getRequestId()); assertEquals("/my-path/", request.getUrl()); assertEquals(oper.getSubRequestId(), request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); @@ -119,9 +129,26 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation { 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); + oper.setProperty(OperationProperties.ENRICHMENT_VNF_ID, MY_VNF); + + verifyRequest("bod.json", verifyOperation(oper), IGNORE_FIELDS); + } + @Override protected Map<String, String> makeEnrichment() { - return Map.of(BandwidthOnDemandOperation.SERVICE_ID_KEY, "my-service", BandwidthOnDemandOperation.VNF_ID, - "my-vnf"); + 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/RerouteOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java index 9f06805f6..b71e567bf 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 @@ -32,6 +32,7 @@ import org.junit.BeforeClass; 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.controlloop.ControlLoopEventContext; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.policy.PolicyResult; @@ -39,6 +40,8 @@ import org.onap.policy.sdnc.SdncRequest; import org.onap.policy.sdnc.SdncResponse; public class RerouteOperationTest extends BasicSdncOperation { + private static final String MY_SERVICE = "my-service"; + private static final String MY_NETWORK = "my-network"; private RerouteOperation oper; @@ -74,9 +77,12 @@ public class RerouteOperationTest extends BasicSdncOperation { .path("GENERIC-RESOURCE-API:network-topology-operation").build(); config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); - params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).preprocessed(true).build(); oper = new RerouteOperation(params, config); + oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE); + oper.setProperty(OperationProperties.ENRICHMENT_NETWORK_ID, MY_NETWORK); + outcome = oper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); assertTrue(outcome.getResponse() instanceof SdncResponse); @@ -102,7 +108,7 @@ public class RerouteOperationTest extends BasicSdncOperation { public void testMakeRequest() throws Exception { oper.generateSubRequestId(1); SdncRequest request = oper.makeRequest(1); - assertEquals("my-service", request.getNsInstanceId()); + assertEquals(MY_SERVICE, request.getNsInstanceId()); assertEquals(REQ_ID, request.getRequestId()); assertEquals("/my-path/", request.getUrl()); assertEquals(oper.getSubRequestId(), request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); @@ -117,8 +123,22 @@ public class RerouteOperationTest extends BasicSdncOperation { 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"); + 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 fb9f71b05..4ba12c6ca 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 @@ -23,6 +23,7 @@ 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; @@ -30,6 +31,7 @@ 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; @@ -101,6 +103,44 @@ public class SdncOperationTest extends BasicSdncOperation { 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<>(); diff --git a/models-interactions/model-actors/actor.sdnc/src/test/resources/bod.json b/models-interactions/model-actors/actor.sdnc/src/test/resources/bod.json index 8c60bbdd8..8d3545e41 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/resources/bod.json +++ b/models-interactions/model-actors/actor.sdnc/src/test/resources/bod.json @@ -20,10 +20,12 @@ "vf-module-input-parameters": { "param": [ { - "name": "bandwidth" + "name": "bandwidth", + "value": "my-bandwidth" }, { - "name": "bandwidth-change-time" + "name": "bandwidth-change-time", + "value": "my-change-time" } ] } |