aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.cds/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-04-17 15:09:21 -0400
committerJim Hahn <jrh3@att.com>2020-04-17 19:31:23 -0400
commite887a0c6c415a00888e17d1bbfe4acf548a2cfa5 (patch)
tree1cccd49d453eb1cf94b0f8f7fd7d14eae02404d9 /models-interactions/model-actors/actor.cds/src/test
parentbed21af59885a954e3facf7226c4678f4b69b153 (diff)
Add PNF support to new CDS actor
Made the following updates: - added new A&AI get-PNF Operation by refactoring AaiGetOperation, separating out Tenant and PNF operations - added PNF support to the CDS actor - added logging to the CDS Handler - added get-pnf to the A&AI simulator Issue-ID: POLICY-2505 Change-Id: Iff140e7c864f762790d8e2ecaba62c161c859e6e Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.cds/src/test')
-rw-r--r--models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperationTest.java103
-rw-r--r--models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperatorTest.java7
2 files changed, 105 insertions, 5 deletions
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 5dca2909f..9477a1585 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
@@ -42,30 +42,44 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.ServiceInstance;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.cds.client.CdsProcessorGrpcClient;
import org.onap.policy.cds.properties.CdsServerProperties;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.common.utils.time.PseudoExecutor;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
+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.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.policy.PolicyResult;
+import org.onap.policy.controlloop.policy.Target;
+import org.onap.policy.controlloop.policy.TargetType;
public class GrpcOperationTest {
-
+ private static final String TARGET_ENTITY = "entity";
+ private static final String MY_VNF = "my-vnf";
+ private static final String MY_SVC_ID = "my-service-instance-id";
+ private static final String RESOURCE_ID = "my-resource-id";
private static final String CDS_BLUEPRINT_NAME = "vfw-cds";
private static final String CDS_BLUEPRINT_VERSION = "1.0.0";
private static final UUID REQUEST_ID = UUID.randomUUID();
+ private static final Coder coder = new StandardCoder();
@Mock
private CdsProcessorGrpcClient cdsClient;
private CdsServerProperties cdsProps;
private VirtualControlLoopEvent onset;
private PseudoExecutor executor;
+ private Target target;
private GrpcOperation operation;
/**
@@ -92,6 +106,10 @@ public class GrpcOperationTest {
// Setup executor
executor = new PseudoExecutor();
+
+ target = new Target();
+ target.setType(TargetType.VM);
+ target.setResourceID(RESOURCE_ID);
}
@Test
@@ -106,7 +124,7 @@ public class GrpcOperationTest {
ControlLoopOperationParams params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR)
.operation(GrpcOperation.NAME).context(context).actorService(new ActorService())
- .targetEntity("entity").build();
+ .targetEntity(TARGET_ENTITY).target(target).build();
GrpcConfig config = new GrpcConfig(executor, cdsProps);
operation = new GrpcOperation(params, config) {
@@ -128,10 +146,65 @@ public class GrpcOperationTest {
assertTrue(future3.isDone());
}
+ /**
+ * Tests startPreprocessorAsync() when the target type is PNF.
+ */
+ @Test
+ public void testStartPreprocessorAsyncPnf() throws InterruptedException, ExecutionException, TimeoutException {
+
+ CompletableFuture<OperationOutcome> future2 = new CompletableFuture<>();
+ ControlLoopEventContext context = mock(ControlLoopEventContext.class);
+ when(context.obtain(eq(AaiCqResponse.CONTEXT_KEY), any())).thenReturn(future2);
+ when(context.getEvent()).thenReturn(onset);
+
+ AtomicBoolean guardStarted = new AtomicBoolean();
+
+ target.setType(TargetType.PNF);
+
+ 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);
+
+ operation = new GrpcOperation(params, config) {
+ @Override
+ protected CompletableFuture<OperationOutcome> startGuardAsync() {
+ guardStarted.set(true);
+ return future2;
+ }
+ };
+
+ CompletableFuture<OperationOutcome> future3 = operation.startPreprocessorAsync();
+ assertNotNull(future3);
+ assertTrue(guardStarted.get());
+ verify(context).obtain(eq(AaiGetPnfOperation.getKey(TARGET_ENTITY)), any());
+
+ future2.complete(params.makeOutcome());
+ assertTrue(executor.runAll(100));
+ assertEquals(PolicyResult.SUCCESS, future3.get(2, TimeUnit.SECONDS).getResult());
+ assertTrue(future3.isDone());
+ }
+
@Test
public void testStartOperationAsync() throws Exception {
ControlLoopEventContext context = new ControlLoopEventContext(onset);
+ loadCqData(context);
+
+ verifyOperation(context);
+ }
+
+ /**
+ * Tests startOperationAsync() when the target type is PNF.
+ */
+ @Test
+ public void testStartOperationAsyncPnf() throws Exception {
+
+ target.setType(TargetType.PNF);
+
+ ControlLoopEventContext context = new ControlLoopEventContext(onset);
+ loadPnfData(context);
+
verifyOperation(context);
}
@@ -142,6 +215,7 @@ public class GrpcOperationTest {
additionalParams.put("test", "additionalParams");
onset.setAdditionalEventParams(additionalParams);
ControlLoopEventContext context = new ControlLoopEventContext(onset);
+ loadCqData(context);
verifyOperation(context);
}
@@ -151,7 +225,7 @@ public class GrpcOperationTest {
ControlLoopEventContext context = new ControlLoopEventContext(onset);
ControlLoopOperationParams params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR)
.operation(GrpcOperation.NAME).context(context).actorService(new ActorService())
- .targetEntity("entity").build();
+ .targetEntity(TARGET_ENTITY).target(target).build();
GrpcConfig config = new GrpcConfig(executor, cdsProps);
operation = new GrpcOperation(params, config);
@@ -166,7 +240,7 @@ public class GrpcOperationTest {
ControlLoopOperationParams params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR)
.operation(GrpcOperation.NAME).context(context).actorService(new ActorService())
- .targetEntity("entity").payload(payloadMap).build();
+ .targetEntity(TARGET_ENTITY).target(target).payload(payloadMap).build();
GrpcConfig config = new GrpcConfig(executor, cdsProps);
operation = new GrpcOperation(params, config);
@@ -177,4 +251,25 @@ public class GrpcOperationTest {
CompletableFuture<OperationOutcome> future3 = operation.startOperationAsync(1, params.makeOutcome());
assertNotNull(future3);
}
+
+ private void loadPnfData(ControlLoopEventContext context) throws CoderException {
+ String json = "{'dataA': 'valueA', 'dataB': 'valueB'}".replace('\'', '"');
+ StandardCoderObject sco = coder.decode(json, StandardCoderObject.class);
+
+ context.setProperty(AaiGetPnfOperation.getKey(TARGET_ENTITY), sco);
+ }
+
+ private void loadCqData(ControlLoopEventContext context) {
+ GenericVnf genvnf = new GenericVnf();
+ genvnf.setVnfId(MY_VNF);
+
+ ServiceInstance serviceInstance = new ServiceInstance();
+ serviceInstance.setServiceInstanceId(MY_SVC_ID);
+
+ AaiCqResponse cq = mock(AaiCqResponse.class);
+ when(cq.getGenericVnfByModelInvariantId(any())).thenReturn(genvnf);
+ when(cq.getServiceInstance()).thenReturn(serviceInstance);
+
+ context.setProperty(AaiCqResponse.CONTEXT_KEY, cq);
+ }
}
diff --git a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperatorTest.java b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperatorTest.java
index 2fd54e40c..cfb20ab6c 100644
--- a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperatorTest.java
+++ b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperatorTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,6 +36,8 @@ import org.onap.policy.controlloop.actorserviceprovider.Util;
import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
+import org.onap.policy.controlloop.policy.Target;
+import org.onap.policy.controlloop.policy.TargetType;
public class GrpcOperatorTest {
@@ -85,8 +88,10 @@ public class GrpcOperatorTest {
public void testBuildOperation() {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
ControlLoopEventContext context = new ControlLoopEventContext(event);
+ Target target = new Target();
+ target.setType(TargetType.VM);
ControlLoopOperationParams params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR)
- .operation(GrpcOperation.NAME).context(context).build();
+ .operation(GrpcOperation.NAME).context(context).target(target).build();
// not configured yet
assertThatIllegalStateException().isThrownBy(() -> operation.buildOperation(params));