diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2020-08-27 08:44:12 -0400 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2020-08-27 14:29:09 -0400 |
commit | f456cc5c8e1efd15edb6da718e1428d8fd7c66c5 (patch) | |
tree | b7b4ba3fc6255b056e00f6e203d7ec8fd6a7c194 /models-interactions/model-actors/actor.so | |
parent | 68a60a45f27287a4a523c82ef466cbeec655f641 (diff) |
Remove Target and TargetType
The dependency should have been removed in the last review to
remove SDC and policy-yaml legacy code.
It was revealed that usage of TargetType and Type were spread out over the
actor code. Those fields are represented differently in the new
TOSCA Operational Policy Type, so fields were created to capture
those values to be used by actor code.
Issue-ID: POLICY-2428
Change-Id: Ib783526a518ca7942ae9e38019bd343639f4dd98
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.so')
5 files changed, 73 insertions, 82 deletions
diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java index 8f0dda3d2..8a0cb703b 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java @@ -46,11 +46,10 @@ import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; +import org.onap.policy.controlloop.actorserviceprovider.OperationResult; import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig; -import org.onap.policy.controlloop.policy.PolicyResult; -import org.onap.policy.controlloop.policy.Target; import org.onap.policy.so.SoCloudConfiguration; import org.onap.policy.so.SoModelInfo; import org.onap.policy.so.SoRequest; @@ -80,6 +79,8 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { private final String modelCustomizationId; private final String modelInvariantId; private final String modelVersionId; + private final String modelName; + private final String modelVersion; private final String vfCountKey; @@ -96,11 +97,20 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { setUsePolling(); - verifyNotNull("Target information", params.getTarget()); + verifyNotNull("Target information", params.getTargetType()); - this.modelCustomizationId = params.getTarget().getModelCustomizationId(); - this.modelInvariantId = params.getTarget().getModelInvariantId(); - this.modelVersionId = params.getTarget().getModelVersionId(); + verifyNotNull("Target entity Ids information", params.getTargetEntityIds()); + + this.modelCustomizationId = params.getTargetEntityIds() + .get(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_CUSTOMIZATION_ID); + this.modelInvariantId = params.getTargetEntityIds() + .get(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_INVARIANT_ID); + this.modelVersionId = params.getTargetEntityIds() + .get(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_VERSION_ID); + this.modelVersion = params.getTargetEntityIds() + .get(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_VERSION); + this.modelName = params.getTargetEntityIds() + .get(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_NAME); vfCountKey = SoConstants.VF_COUNT_PREFIX + "[" + modelCustomizationId + "][" + modelInvariantId + "][" + modelVersionId + "]"; @@ -117,9 +127,9 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { * the VF count from the custom query. */ protected void validateTarget() { - verifyNotNull("modelCustomizationId", modelCustomizationId); - verifyNotNull("modelInvariantId", modelInvariantId); - verifyNotNull("modelVersionId", modelVersionId); + verifyNotNull(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_CUSTOMIZATION_ID, modelCustomizationId); + verifyNotNull(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_INVARIANT_ID, modelInvariantId); + verifyNotNull(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_VERSION_ID, modelVersionId); } private void verifyNotNull(String type, Object value) { @@ -267,13 +277,13 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { * Prepends the message with the http status code. */ @Override - public OperationOutcome setOutcome(OperationOutcome outcome, PolicyResult result, Response rawResponse, + public OperationOutcome setOutcome(OperationOutcome outcome, OperationResult result, Response rawResponse, SoResponse response) { // set default result and message setOutcome(outcome, result); - int code = (result == PolicyResult.FAILURE_TIMEOUT ? SO_RESPONSE_CODE : rawResponse.getStatus()); + int code = (result == OperationResult.FAILURE_TIMEOUT ? SO_RESPONSE_CODE : rawResponse.getStatus()); outcome.setResponse(response); outcome.setMessage(code + " " + outcome.getMessage()); @@ -281,23 +291,12 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { } protected SoModelInfo prepareSoModelInfo() { - Target target = params.getTarget(); - if (target == null) { - throw new IllegalArgumentException("missing Target"); - } - - if (target.getModelCustomizationId() == null || target.getModelInvariantId() == null - || target.getModelName() == null || target.getModelVersion() == null - || target.getModelVersionId() == null) { - throw new IllegalArgumentException("missing VF Module model"); - } - SoModelInfo soModelInfo = new SoModelInfo(); - soModelInfo.setModelCustomizationId(target.getModelCustomizationId()); - soModelInfo.setModelInvariantId(target.getModelInvariantId()); - soModelInfo.setModelName(target.getModelName()); - soModelInfo.setModelVersion(target.getModelVersion()); - soModelInfo.setModelVersionId(target.getModelVersionId()); + soModelInfo.setModelCustomizationId(modelCustomizationId); + soModelInfo.setModelInvariantId(modelInvariantId); + soModelInfo.setModelName(modelName); + soModelInfo.setModelVersion(modelVersion); + soModelInfo.setModelVersionId(modelVersionId); soModelInfo.setModelType("vfModule"); return soModelInfo; } diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java index 3541333c0..d2e2872d5 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java @@ -34,9 +34,10 @@ import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.controlloop.actor.test.BasicHttpOperation; +import org.onap.policy.controlloop.actorserviceprovider.TargetType; import org.onap.policy.controlloop.actorserviceprovider.Util; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig; -import org.onap.policy.controlloop.policy.Target; import org.onap.policy.simulators.SoSimulatorJaxRs; import org.onap.policy.so.SoRequest; import org.onap.policy.so.SoRequestParameters; @@ -65,7 +66,8 @@ public abstract class BasicSoOperation extends BasicHttpOperation { @Mock protected HttpPollingConfig config; - protected Target target; + protected TargetType targetType; + protected Map<String, String> targetEntities = new HashMap<>(); protected SoResponse response; /** @@ -144,14 +146,16 @@ public abstract class BasicSoOperation extends BasicHttpOperation { protected void makeContext() { super.makeContext(); - target = new Target(); - target.setModelCustomizationId(MODEL_CUSTOM_ID); - target.setModelInvariantId(MODEL_INVAR_ID); - target.setModelName(MODEL_NAME); - target.setModelVersion(MODEL_VERSION); - target.setModelVersionId(MODEL_VERS_ID); + targetType = TargetType.VNF; - params = params.toBuilder().target(target).build(); + targetEntities = new HashMap<>(); + targetEntities.put(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_CUSTOMIZATION_ID, MODEL_CUSTOM_ID); + targetEntities.put(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_INVARIANT_ID, MODEL_INVAR_ID); + targetEntities.put(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_NAME, MODEL_NAME); + targetEntities.put(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_VERSION, MODEL_VERSION); + targetEntities.put(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_VERSION_ID, MODEL_VERS_ID); + + params = params.toBuilder().targetType(targetType).targetEntityIds(targetEntities).build(); } @Override diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java index e364246e4..464e5d162 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java @@ -35,9 +35,9 @@ import java.time.LocalDateTime; import java.time.Month; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.function.BiConsumer; -import java.util.function.Consumer; import java.util.function.Supplier; import org.junit.Before; import org.junit.Test; @@ -52,7 +52,8 @@ import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; -import org.onap.policy.controlloop.policy.PolicyResult; +import org.onap.policy.controlloop.actorserviceprovider.OperationResult; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.so.SoModelInfo; import org.onap.policy.so.SoRequest; import org.onap.policy.so.SoRequestInfo; @@ -73,6 +74,7 @@ public class SoOperationTest extends BasicSoOperation { /** * Sets up. */ + @Override @Before public void setUp() throws Exception { super.setUp(); @@ -90,7 +92,7 @@ public class SoOperationTest extends BasicSoOperation { assertTrue(oper.isUsePolling()); // check when Target is null - params = params.toBuilder().target(null).build(); + params = params.toBuilder().targetType(null).build(); assertThatIllegalArgumentException().isThrownBy(() -> new SoOperation(params, config, PROP_NAMES) {}) .withMessageContaining("Target information"); } @@ -98,23 +100,23 @@ public class SoOperationTest extends BasicSoOperation { @Test public void testValidateTarget() { // check when various fields are null - verifyNotNull("modelCustomizationId", target::getModelCustomizationId, target::setModelCustomizationId); - verifyNotNull("modelInvariantId", target::getModelInvariantId, target::setModelInvariantId); - verifyNotNull("modelVersionId", target::getModelVersionId, target::setModelVersionId); + verifyNotNull(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_CUSTOMIZATION_ID, targetEntities); + verifyNotNull(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_INVARIANT_ID, targetEntities); + verifyNotNull(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_VERSION_ID, targetEntities); // verify it's still valid assertThatCode(() -> new VfModuleCreate(params, config)).doesNotThrowAnyException(); } - private void verifyNotNull(String expectedText, Supplier<String> getter, Consumer<String> setter) { - String originalValue = getter.get(); + private void verifyNotNull(String expectedText, Map<String, String> targetEntities) { + String originalValue = targetEntities.get(expectedText); // try with null - setter.accept(null); + targetEntities.put(expectedText, null); assertThatIllegalArgumentException().isThrownBy(() -> new VfModuleCreate(params, config)) .withMessageContaining(expectedText); - setter.accept(originalValue); + targetEntities.put(expectedText, originalValue); } @Test @@ -178,7 +180,7 @@ public class SoOperationTest extends BasicSoOperation { assertTrue(executor.runAll(100)); assertTrue(future2.isDone()); - assertEquals(PolicyResult.SUCCESS, future2.get().getResult()); + assertEquals(OperationResult.SUCCESS, future2.get().getResult()); // verify that the count was stored Integer vfcount = context.getProperty(VF_COUNT_KEY); @@ -219,49 +221,33 @@ public class SoOperationTest extends BasicSoOperation { public void testSetOutcome() { // success case when(rawResponse.getStatus()).thenReturn(200); - assertSame(outcome, oper.setOutcome(outcome, PolicyResult.SUCCESS, rawResponse, response)); + assertSame(outcome, oper.setOutcome(outcome, OperationResult.SUCCESS, rawResponse, response)); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertEquals("200 " + ControlLoopOperation.SUCCESS_MSG, outcome.getMessage()); assertSame(response, outcome.getResponse()); // failure case when(rawResponse.getStatus()).thenReturn(500); - assertSame(outcome, oper.setOutcome(outcome, PolicyResult.FAILURE, rawResponse, response)); + assertSame(outcome, oper.setOutcome(outcome, OperationResult.FAILURE, rawResponse, response)); - assertEquals(PolicyResult.FAILURE, outcome.getResult()); + assertEquals(OperationResult.FAILURE, outcome.getResult()); assertEquals("500 " + ControlLoopOperation.FAILED_MSG, outcome.getMessage()); assertSame(response, outcome.getResponse()); } @Test public void testPrepareSoModelInfo() throws CoderException { - verifyMissingModelInfo(target::getModelCustomizationId, target::setModelCustomizationId); - verifyMissingModelInfo(target::getModelInvariantId, target::setModelInvariantId); - verifyMissingModelInfo(target::getModelName, target::setModelName); - verifyMissingModelInfo(target::getModelVersion, target::setModelVersion); - verifyMissingModelInfo(target::getModelVersionId, target::setModelVersionId); - // valid data SoModelInfo info = oper.prepareSoModelInfo(); verifyRequest("model.json", info); // try with null target - params = params.toBuilder().target(null).build(); + params = params.toBuilder().targetType(null).build(); assertThatIllegalArgumentException().isThrownBy(() -> new SoOperation(params, config, PROP_NAMES) {}) .withMessageContaining("missing Target"); } - private void verifyMissingModelInfo(Supplier<String> getter, Consumer<String> setter) { - String original = getter.get(); - - setter.accept(null); - assertThatIllegalArgumentException().isThrownBy(() -> oper.prepareSoModelInfo()) - .withMessage("missing VF Module model"); - - setter.accept(original); - } - @Test public void testConstructRequestInfo() throws CoderException { SoRequestInfo info = oper.constructRequestInfo(); diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java index 9d80343e6..f1741d677 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java @@ -54,10 +54,10 @@ import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; +import org.onap.policy.controlloop.actorserviceprovider.OperationResult; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams; -import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.so.SoRequest; import org.onap.policy.so.SoResponse; @@ -83,6 +83,7 @@ public class VfModuleCreateTest extends BasicSoOperation { destroyAfterClass(); } + @Override @Before public void setUp() throws Exception { super.setUp(); @@ -104,7 +105,7 @@ public class VfModuleCreateTest extends BasicSoOperation { oper = new VfModuleCreate(params, config); outcome = oper.start().get(); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertTrue(outcome.getResponse() instanceof SoResponse); } @@ -146,7 +147,7 @@ public class VfModuleCreateTest extends BasicSoOperation { // run the operation outcome = oper.start().get(); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertTrue(outcome.getResponse() instanceof SoResponse); int count = oper.getProperty(OperationProperties.DATA_VF_COUNT); @@ -159,7 +160,7 @@ public class VfModuleCreateTest extends BasicSoOperation { assertEquals(VfModuleCreate.NAME, oper.getName()); // verify that target validation is done - params = params.toBuilder().target(null).build(); + params = params.toBuilder().targetType(null).build(); assertThatIllegalArgumentException().isThrownBy(() -> new VfModuleCreate(params, config)) .withMessageContaining("Target information"); } @@ -220,7 +221,7 @@ public class VfModuleCreateTest extends BasicSoOperation { provideCqResponse(makeCqResponse()); assertTrue(executor.runAll(100)); assertTrue(future2.isDone()); - assertEquals(PolicyResult.SUCCESS, future2.get().getResult()); + assertEquals(OperationResult.SUCCESS, future2.get().getResult()); } @Test @@ -264,7 +265,7 @@ public class VfModuleCreateTest extends BasicSoOperation { CompletableFuture<OperationOutcome> future2 = oper.start(); outcome = future2.get(5, TimeUnit.SECONDS); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); SoResponse resp = outcome.getResponse(); assertNotNull(resp); @@ -296,7 +297,7 @@ public class VfModuleCreateTest extends BasicSoOperation { CompletableFuture<OperationOutcome> future2 = oper.start(); outcome = future2.get(5, TimeUnit.SECONDS); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); } @Test diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java index 9335f0141..2ab1dbe83 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java @@ -67,10 +67,10 @@ import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; +import org.onap.policy.controlloop.actorserviceprovider.OperationResult; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams; -import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.so.SoRequest; import org.onap.policy.so.SoResponse; @@ -108,6 +108,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { /** * Sets up. */ + @Override @Before public void setUp() throws Exception { super.setUp(); @@ -133,7 +134,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { oper = new VfModuleDelete(params, config); outcome = oper.start().get(); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertTrue(outcome.getResponse() instanceof SoResponse); } @@ -167,7 +168,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { // run the operation outcome = oper.start().get(); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertTrue(outcome.getResponse() instanceof SoResponse); int count = oper.getProperty(OperationProperties.DATA_VF_COUNT); @@ -180,7 +181,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { assertEquals(VfModuleDelete.NAME, oper.getName()); // verify that target validation is done - params = params.toBuilder().target(null).build(); + params = params.toBuilder().targetType(null).build(); assertThatIllegalArgumentException().isThrownBy(() -> new MyOperation(params, config)) .withMessageContaining("Target information"); } @@ -239,7 +240,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { provideCqResponse(makeCqResponse()); assertTrue(executor.runAll(100)); assertTrue(future2.isDone()); - assertEquals(PolicyResult.SUCCESS, future2.get().getResult()); + assertEquals(OperationResult.SUCCESS, future2.get().getResult()); } @Test @@ -281,7 +282,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { CompletableFuture<OperationOutcome> future2 = oper.start(); outcome = future2.get(5, TimeUnit.SECONDS); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); SoResponse resp = outcome.getResponse(); assertNotNull(resp); @@ -315,7 +316,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { CompletableFuture<OperationOutcome> future2 = oper.start(); outcome = future2.get(5, TimeUnit.SECONDS); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); } @Test |