From acded8235dcbb0b06abaa98297fecef78b4eec41 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 29 Jul 2020 13:50:40 -0400 Subject: Add property lists to Actors Modified the Actor code to provide a list of properties needed by the actor to perform a given operation. Added a build() method to the parameter class so invokers can build an operation and set its properties prior to starting it. Added a "preprocessed" field to the parameter class so invokers can indicate that the Actor need not perform any preprocessing steps. Will modify the actors, in a subsequent review, to observe the flag. Added "properties" to Operation so invokers can set the properties. Will modify the actors, in a subsequent review, to use the property values instead of the event context. Tweaked a few Actors to get values using the "params" object instead of reaching inside to the event object that it contains. Addressed review comment(s): - add prefix to other property names Issue-ID: POLICY-2746 Change-Id: I65996aef5cec5afe25e8287c0b2f5f322c532ca5 Signed-off-by: Jim Hahn --- .../controlloop/actor/cds/GrpcOperation.java | 26 ++++++++++++-- .../controlloop/actor/cds/GrpcOperationTest.java | 40 ++++++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) (limited to 'models-interactions/model-actors/actor.cds/src') diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java index 0a882ce93..241781254 100644 --- a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java +++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java @@ -25,8 +25,10 @@ import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.Struct; import com.google.protobuf.Struct.Builder; import com.google.protobuf.util.JsonFormat; +import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.UUID; @@ -48,6 +50,7 @@ import org.onap.policy.controlloop.actor.aai.AaiGetPnfOperation; import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants; import org.onap.policy.controlloop.actor.cds.request.CdsActionRequest; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; +import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; import org.onap.policy.controlloop.actorserviceprovider.Util; import org.onap.policy.controlloop.actorserviceprovider.impl.OperationPartial; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; @@ -84,6 +87,19 @@ public class GrpcOperation extends OperationPartial { */ private final Supplier> aaiConverter; + + // @formatter:off + private static final List PNF_PROPERTY_NAMES = List.of( + OperationProperties.AAI_PNF, + OperationProperties.EVENT_ADDITIONAL_PARAMS); + + + private static final List VNF_PROPERTY_NAMES = List.of( + OperationProperties.AAI_MODEL_INVARIANT_GENERIC_VNF, + OperationProperties.AAI_RESOURCE_SERVICE_INSTANCE, + OperationProperties.EVENT_ADDITIONAL_PARAMS); + // @formatter:on + /** * Constructs the object. * @@ -91,7 +107,7 @@ public class GrpcOperation extends OperationPartial { * @param config configuration for this operation */ public GrpcOperation(ControlLoopOperationParams params, GrpcConfig config) { - super(params, config); + super(params, config, Collections.emptyList()); this.config = config; if (TargetType.PNF.equals(params.getTarget().getType())) { @@ -103,6 +119,11 @@ public class GrpcOperation extends OperationPartial { } } + @Override + public List getPropertyNames() { + return (TargetType.PNF.equals(params.getTarget().getType()) ? PNF_PROPERTY_NAMES : VNF_PROPERTY_NAMES); + } + /** * If no timeout is specified, then it returns the operator's configured timeout. */ @@ -287,8 +308,7 @@ public class GrpcOperation extends OperationPartial { // Build CDS gRPC request common-header CommonHeader commonHeader = CommonHeader.newBuilder().setOriginatorId(CdsActorConstants.ORIGINATOR_ID) - .setRequestId(params.getContext().getEvent().getRequestId().toString()) - .setSubRequestId(getSubRequestId()).build(); + .setRequestId(params.getRequestId().toString()).setSubRequestId(getSubRequestId()).build(); // Build CDS gRPC request action-identifier ActionIdentifiers actionIdentifiers = diff --git a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperationTest.java b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperationTest.java index fe8d42814..cbc88a30e 100644 --- a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperationTest.java +++ b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperationTest.java @@ -19,6 +19,7 @@ package org.onap.policy.controlloop.actor.cds; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -30,6 +31,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -62,6 +64,7 @@ import org.onap.policy.controlloop.actor.aai.AaiGetPnfOperation; import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants; import org.onap.policy.controlloop.actorserviceprovider.ActorService; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; +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.policy.PolicyResult; @@ -170,6 +173,43 @@ public class GrpcOperationTest { assertTrue(outcome.getResponse() instanceof ExecutionServiceOutput); } + @Test + public void testGetPropertyNames() { + ControlLoopEventContext context = mock(ControlLoopEventContext.class); + when(context.getEvent()).thenReturn(onset); + + ControlLoopOperationParams params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR) + .operation(GrpcOperation.NAME).context(context).actorService(new ActorService()) + .targetEntity(TARGET_ENTITY).target(target).build(); + GrpcConfig config = new GrpcConfig(executor, cdsProps); + + /* + * check VNF case + */ + operation = new GrpcOperation(params, config); + + // @formatter:off + assertThat(operation.getPropertyNames()).isEqualTo( + List.of( + OperationProperties.AAI_MODEL_INVARIANT_GENERIC_VNF, + OperationProperties.AAI_RESOURCE_SERVICE_INSTANCE, + OperationProperties.EVENT_ADDITIONAL_PARAMS)); + // @formatter:on + + /* + * check PNF case + */ + target.setType(TargetType.PNF); + operation = new GrpcOperation(params, config); + + // @formatter:off + assertThat(operation.getPropertyNames()).isEqualTo( + List.of( + OperationProperties.AAI_PNF, + OperationProperties.EVENT_ADDITIONAL_PARAMS)); + // @formatter:on + } + @Test public void testStartPreprocessorAsync() throws InterruptedException, ExecutionException, TimeoutException { -- cgit 1.2.3-korg