summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.cds/src
diff options
context:
space:
mode:
authorRam Krishna Verma <ram_krishna.verma@bell.ca>2020-11-18 15:27:45 +0000
committerGerrit Code Review <gerrit@onap.org>2020-11-18 15:27:45 +0000
commitca468c57a4d09842f2608e32da74b30eba52d015 (patch)
tree2394aa1a842e9b9b560a1ec9baa2e0b6369bdf43 /models-interactions/model-actors/actor.cds/src
parent041f5dd96839596f985a349f4435787d7a068183 (diff)
parent19ef8b24a98c09a349e6ae7309f535a0135463f6 (diff)
Merge "Make Actors event-agnostic"
Diffstat (limited to 'models-interactions/model-actors/actor.cds/src')
-rw-r--r--models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java122
-rw-r--r--models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperationTest.java271
-rw-r--r--models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperatorTest.java8
3 files changed, 41 insertions, 360 deletions
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 c04453b7c..44d51813a 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
@@ -40,12 +40,8 @@ import org.onap.aai.domain.yang.ServiceInstance;
import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
-import org.onap.policy.aai.AaiConstants;
-import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.cds.client.CdsProcessorGrpcClient;
import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.controlloop.actor.aai.AaiCustomQueryOperation;
-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;
@@ -77,11 +73,6 @@ public class GrpcOperation extends OperationPartial {
private final GrpcConfig config;
/**
- * Function to request the A&AI data appropriate to the target type.
- */
- private final Supplier<CompletableFuture<OperationOutcome>> aaiRequestor;
-
- /**
* Function to convert the A&AI data associated with the target type.
*/
private final Supplier<Map<String, String>> aaiConverter;
@@ -112,11 +103,9 @@ public class GrpcOperation extends OperationPartial {
this.config = config;
if (TargetType.PNF.equals(params.getTargetType())) {
- aaiRequestor = this::getPnf;
aaiConverter = this::convertPnfToAaiProperties;
} else {
- aaiRequestor = this::getCq;
- aaiConverter = this::convertCqToAaiProperties;
+ aaiConverter = this::convertVnfToAaiProperties;
}
}
@@ -134,57 +123,20 @@ public class GrpcOperation extends OperationPartial {
}
/**
- * Ensures that A&AI query has been performed, and runs the guard.
- */
- @Override
- @SuppressWarnings("unchecked")
- protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
- if (params.isPreprocessed()) {
- return null;
- }
-
- // run A&AI Query and Guard, in parallel
- return allOf(aaiRequestor, this::startGuardAsync);
- }
-
- /**
- * Requests the A&AI PNF data.
- *
- * @return a future to get the PNF data
- */
- private CompletableFuture<OperationOutcome> getPnf() {
- ControlLoopOperationParams pnfParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
- .operation(AaiGetPnfOperation.NAME).payload(null).retry(null).timeoutSec(null).build();
-
- return params.getContext().obtain(AaiGetPnfOperation.getKey(params.getTargetEntity()), pnfParams);
- }
-
- /**
- * Requests the A&AI Custom Query data.
- *
- * @return a future to get the custom query data
- */
- private CompletableFuture<OperationOutcome> getCq() {
- ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
- .operation(AaiCustomQueryOperation.NAME).payload(null).retry(null).timeoutSec(null).build();
-
- return params.getContext().obtain(AaiCqResponse.CONTEXT_KEY, cqParams);
- }
-
- /**
* Converts the A&AI PNF data to a map suitable for passing via the "aaiProperties"
* field in the CDS request.
*
* @return a map of the PNF data
*/
private Map<String, String> convertPnfToAaiProperties() {
- Map<String, String> result = this.getProperty(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
+ Map<String, String> result = getProperty(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
if (result != null) {
return result;
}
// convert PNF data to a Map
- Map<String, Object> source = Util.translateToMap(getFullName(), getPnfData());
+ Object pnfData = getRequiredProperty(OperationProperties.AAI_PNF, "PNF");
+ Map<String, Object> source = Util.translateToMap(getFullName(), pnfData);
result = new LinkedHashMap<>();
@@ -196,33 +148,13 @@ public class GrpcOperation extends OperationPartial {
}
/**
- * Gets the PNF from the operation properties, if it exists, or from the context
- * properties otherwise.
- *
- * @return the PNF item
- */
- protected Object getPnfData() {
- Object pnf = getProperty(OperationProperties.AAI_PNF);
- if (pnf != null) {
- return pnf;
- }
-
- pnf = params.getContext().getProperty(AaiGetPnfOperation.getKey(params.getTargetEntity()));
- if (pnf == null) {
- throw new IllegalArgumentException("missing PNF data");
- }
-
- return pnf;
- }
-
- /**
- * Converts the A&AI Custom Query data to a map suitable for passing via the
+ * Converts the A&AI VNF data to a map suitable for passing via the
* "aaiProperties" field in the CDS request.
*
- * @return a map of the custom query data
+ * @return a map of the VNF data
*/
- private Map<String, String> convertCqToAaiProperties() {
- Map<String, String> result = this.getProperty(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
+ private Map<String, String> convertVnfToAaiProperties() {
+ Map<String, String> result = getProperty(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
if (result != null) {
return result;
}
@@ -236,35 +168,13 @@ public class GrpcOperation extends OperationPartial {
}
protected String getServiceInstanceId() {
- ServiceInstance serviceInstance = getProperty(OperationProperties.AAI_SERVICE);
- if (serviceInstance != null) {
- return serviceInstance.getServiceInstanceId();
- }
-
- AaiCqResponse aaicq = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY);
-
- serviceInstance = aaicq.getServiceInstance();
- if (serviceInstance == null) {
- throw new IllegalArgumentException("Target service instance could not be found");
- }
-
+ ServiceInstance serviceInstance =
+ getRequiredProperty(OperationProperties.AAI_SERVICE, "Target service instance");
return serviceInstance.getServiceInstanceId();
}
protected String getVnfId() {
- GenericVnf genericVnf = getProperty(OperationProperties.AAI_RESOURCE_VNF);
- if (genericVnf != null) {
- return genericVnf.getVnfId();
- }
-
- AaiCqResponse aaicq = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY);
-
- genericVnf = aaicq.getGenericVnfByModelInvariantId(params.getTargetEntityIds()
- .get(ControlLoopOperationParams.PARAMS_ENTITY_RESOURCEID));
- if (genericVnf == null) {
- throw new IllegalArgumentException("Target generic vnf could not be found");
- }
-
+ GenericVnf genericVnf = getRequiredProperty(OperationProperties.AAI_RESOURCE_VNF, "Target generic vnf");
return genericVnf.getVnfId();
}
@@ -345,7 +255,7 @@ public class GrpcOperation extends OperationPartial {
request.setAaiProperties(aaiConverter.get());
// Inject any additional event parameters that may be present in the onset event
- Map<String, String> additionalParams = getAdditionalEventParams();
+ Map<String, String> additionalParams = getProperty(OperationProperties.EVENT_ADDITIONAL_PARAMS);
if (additionalParams != null) {
request.setAdditionalEventParams(additionalParams);
}
@@ -375,14 +285,6 @@ public class GrpcOperation extends OperationPartial {
.setPayload(struct.build()).build();
}
- protected Map<String, String> getAdditionalEventParams() {
- if (containsProperty(OperationProperties.EVENT_ADDITIONAL_PARAMS)) {
- return getProperty(OperationProperties.EVENT_ADDITIONAL_PARAMS);
- }
-
- return params.getContext().getEvent().getAdditionalEventParams();
- }
-
private Map<String, String> convertPayloadMap(Map<String, Object> payload) {
Map<String, String> convertedPayload = new HashMap<>();
for (Entry<String, Object> entry : payload.entrySet()) {
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 709e179e6..da069d83e 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
@@ -23,13 +23,9 @@ 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;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Collections;
@@ -39,11 +35,7 @@ import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -51,11 +43,9 @@ 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.Pnf;
import org.onap.aai.domain.yang.ServiceInstance;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
-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;
@@ -63,15 +53,12 @@ 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.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.actorserviceprovider.TargetType;
-import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.simulators.CdsSimulator;
import org.onap.policy.simulators.Util;
@@ -96,16 +83,11 @@ public class GrpcOperationTest {
@Mock
private CdsProcessorGrpcClient cdsClient;
- @Mock
- private ControlLoopEventContext context;
private CdsServerProperties cdsProps;
- private VirtualControlLoopEvent onset;
private PseudoExecutor executor;
- private TargetType targetType;
private Map<String, String> targetEntityIds;
private ControlLoopOperationParams params;
private GrpcConfig config;
- private CompletableFuture<OperationOutcome> cqFuture;
private GrpcOperation operation;
@BeforeClass
@@ -136,25 +118,15 @@ public class GrpcOperationTest {
// Setup cdsClient
when(cdsClient.sendRequest(any(ExecutionServiceInput.class))).thenReturn(mock(CountDownLatch.class));
- // Setup onset event
- onset = new VirtualControlLoopEvent();
- onset.setRequestId(REQUEST_ID);
-
// Setup executor
executor = new PseudoExecutor();
- targetType = TargetType.VM;
targetEntityIds = new HashMap<>();
targetEntityIds.put(ControlLoopOperationParams.PARAMS_ENTITY_RESOURCEID, RESOURCE_ID);
- cqFuture = new CompletableFuture<>();
- when(context.obtain(eq(AaiCqResponse.CONTEXT_KEY), any())).thenReturn(cqFuture);
- when(context.getEvent()).thenReturn(onset);
-
- params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR)
- .operation(GrpcOperation.NAME).context(context).actorService(new ActorService())
- .targetEntity(TARGET_ENTITY).targetType(targetType).targetEntityIds(targetEntityIds)
- .build();
+ params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR).operation(GrpcOperation.NAME)
+ .requestId(REQUEST_ID).actorService(new ActorService()).targetEntity(TARGET_ENTITY)
+ .build();
}
/**
@@ -162,49 +134,12 @@ public class GrpcOperationTest {
*/
@Test
public void testSuccess() throws Exception {
- ControlLoopEventContext context = new ControlLoopEventContext(onset);
- loadCqData(context);
-
Map<String, Object> payload = Map.of("artifact_name", "my_artifact", "artifact_version", "1.0");
params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR).operation("subscribe")
- .context(context).actorService(new ActorService()).targetEntity(TARGET_ENTITY)
- .targetType(targetType).targetEntityIds(targetEntityIds)
- .retry(0).timeoutSec(5).executor(blockingExecutor).payload(payload).build();
-
- cdsProps.setHost("localhost");
- cdsProps.setPort(sim.getPort());
- cdsProps.setTimeout(3);
-
- GrpcConfig config = new GrpcConfig(blockingExecutor, cdsProps);
-
- operation = new GrpcOperation(params, config) {
- @Override
- protected CompletableFuture<OperationOutcome> startGuardAsync() {
- // indicate that guard completed successfully
- return CompletableFuture.completedFuture(params.makeOutcome(null));
- }
- };
-
- OperationOutcome outcome = operation.start().get();
- assertEquals(OperationResult.SUCCESS, outcome.getResult());
- assertTrue(outcome.getResponse() instanceof ExecutionServiceOutput);
- }
-
- /**
- * Tests "success" case with simulator using properties.
- */
- @Test
- public void testSuccessViaProperties() throws Exception {
- ControlLoopEventContext context = new ControlLoopEventContext(onset);
- loadCqData(context);
-
- Map<String, Object> payload = Map.of("artifact_name", "my_artifact", "artifact_version", "1.0");
-
- params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR).operation("subscribe")
- .context(context).actorService(new ActorService()).targetEntity(TARGET_ENTITY)
- .targetType(targetType).targetEntityIds(targetEntityIds)
- .retry(0).timeoutSec(5).executor(blockingExecutor).payload(payload).preprocessed(true).build();
+ .requestId(REQUEST_ID).actorService(new ActorService()).targetEntity(TARGET_ENTITY)
+ .retry(0).timeoutSec(5).executor(blockingExecutor).payload(payload)
+ .preprocessed(true).build();
cdsProps.setHost("localhost");
cdsProps.setPort(sim.getPort());
@@ -255,136 +190,22 @@ public class GrpcOperationTest {
}
@Test
- public void testGetPnf() {
- ControlLoopEventContext context = new ControlLoopEventContext(onset);
- params = params.toBuilder().context(context).build();
- operation = new GrpcOperation(params, config);
-
- // in neither property nor context
- assertThatIllegalArgumentException().isThrownBy(() -> operation.getPnfData()).withMessage("missing PNF data");
-
- // only in context
- Pnf pnf = new Pnf();
- params.getContext().setProperty(AaiGetPnfOperation.getKey(params.getTargetEntity()), pnf);
- assertSame(pnf, operation.getPnfData());
-
- // both - should choose the property
- Pnf pnf2 = new Pnf();
- operation.setProperty(OperationProperties.AAI_PNF, pnf2);
- assertSame(pnf2, operation.getPnfData());
- }
-
- @Test
public void testGetServiceInstanceId() {
- ControlLoopEventContext context = new ControlLoopEventContext(onset);
- params = params.toBuilder().context(context).build();
operation = new GrpcOperation(params, config);
-
- // in neither property nor custom query
- context.setProperty(AaiCqResponse.CONTEXT_KEY, mock(AaiCqResponse.class));
- assertThatIllegalArgumentException().isThrownBy(() -> operation.getServiceInstanceId())
- .withMessage("Target service instance could not be found");
-
- // only in custom query
- loadCqData(params.getContext());
+ loadVnfData();
assertEquals(MY_SVC_ID, operation.getServiceInstanceId());
-
- // both - should choose the property
- ServiceInstance serviceInstance = new ServiceInstance();
- serviceInstance.setServiceInstanceId("another-service-id");
- operation.setProperty(OperationProperties.AAI_SERVICE, serviceInstance);
- assertEquals("another-service-id", operation.getServiceInstanceId());
}
@Test
public void testGetVnfId() {
- ControlLoopEventContext context = new ControlLoopEventContext(onset);
- params = params.toBuilder().context(context).build();
operation = new GrpcOperation(params, config);
-
- // in neither property nor custom query
- context.setProperty(AaiCqResponse.CONTEXT_KEY, mock(AaiCqResponse.class));
- assertThatIllegalArgumentException().isThrownBy(() -> operation.getVnfId())
- .withMessage("Target generic vnf could not be found");
-
- // only in custom query
- loadCqData(params.getContext());
+ loadVnfData();
assertEquals(MY_VNF, operation.getVnfId());
-
- // both - should choose the property
- GenericVnf vnf = new GenericVnf();
- vnf.setVnfId("another-vnf-id");
- operation.setProperty(OperationProperties.AAI_RESOURCE_VNF, vnf);
- assertEquals("another-vnf-id", operation.getVnfId());
- }
-
- @Test
- public void testStartPreprocessorAsync() throws InterruptedException, ExecutionException, TimeoutException {
- AtomicBoolean guardStarted = new AtomicBoolean();
-
- operation = new GrpcOperation(params, config) {
- @Override
- protected CompletableFuture<OperationOutcome> startGuardAsync() {
- guardStarted.set(true);
- return cqFuture;
- }
- };
-
- CompletableFuture<OperationOutcome> future3 = operation.startPreprocessorAsync();
- assertNotNull(future3);
- assertTrue(guardStarted.get());
- verify(context).obtain(eq(AaiCqResponse.CONTEXT_KEY), any());
-
- cqFuture.complete(params.makeOutcome(null));
- assertTrue(executor.runAll(100));
- assertEquals(OperationResult.SUCCESS, future3.get(2, TimeUnit.SECONDS).getResult());
- assertTrue(future3.isDone());
- }
-
- /**
- * Tests startPreprocessorAsync() when the target type is PNF.
- */
- @Test
- public void testStartPreprocessorAsyncPnf() throws InterruptedException, ExecutionException, TimeoutException {
- AtomicBoolean guardStarted = new AtomicBoolean();
-
- params = params.toBuilder().targetType(TargetType.PNF).build();
-
- operation = new GrpcOperation(params, config) {
- @Override
- protected CompletableFuture<OperationOutcome> startGuardAsync() {
- guardStarted.set(true);
- return cqFuture;
- }
- };
-
- CompletableFuture<OperationOutcome> future3 = operation.startPreprocessorAsync();
- assertNotNull(future3);
- assertTrue(guardStarted.get());
- verify(context).obtain(eq(AaiGetPnfOperation.getKey(TARGET_ENTITY)), any());
-
- cqFuture.complete(params.makeOutcome(null));
- assertTrue(executor.runAll(100));
- assertEquals(OperationResult.SUCCESS, future3.get(2, TimeUnit.SECONDS).getResult());
- assertTrue(future3.isDone());
- }
-
- /**
- * Tests startPreprocessorAsync(), when preprocessing is disabled.
- */
- @Test
- public void testStartPreprocessorAsyncDisabled() {
- params = params.toBuilder().preprocessed(true).build();
- assertNull(new GrpcOperation(params, config).startPreprocessorAsync());
}
@Test
public void testStartOperationAsync() throws Exception {
-
- ControlLoopEventContext context = new ControlLoopEventContext(onset);
- loadCqData(context);
-
- verifyOperation(context);
+ verifyOperation(TargetType.VNF, this::loadVnfData);
}
/**
@@ -392,24 +213,7 @@ public class GrpcOperationTest {
*/
@Test
public void testStartOperationAsyncPnf() throws Exception {
-
- targetType = TargetType.PNF;
-
- ControlLoopEventContext context = new ControlLoopEventContext(onset);
- loadPnfData(context);
-
- verifyOperation(context);
- }
-
- @Test
- public void testStartOperationAsyncWithAdditionalParams() throws Exception {
-
- Map<String, String> additionalParams = new HashMap<>();
- additionalParams.put("test", "additionalParams");
- onset.setAdditionalEventParams(additionalParams);
- ControlLoopEventContext context = new ControlLoopEventContext(onset);
- loadCqData(context);
- verifyOperation(context);
+ verifyOperation(TargetType.PNF, this::loadPnfData);
}
@Test
@@ -419,39 +223,15 @@ public class GrpcOperationTest {
.isThrownBy(() -> operation.startOperationAsync(1, params.makeOutcome(null)));
}
- @Test
- public void testGetAdditionalEventParams() {
- operation = new GrpcOperation(params, config);
-
- // in neither property nor context
- assertNull(operation.getAdditionalEventParams());
-
- final Map<String, String> eventParams = Collections.emptyMap();
-
- // only in context
- onset.setAdditionalEventParams(eventParams);
- assertSame(eventParams, operation.getAdditionalEventParams());
-
- // both - should choose the property, even if it's null
- operation.setProperty(OperationProperties.EVENT_ADDITIONAL_PARAMS, null);
- assertNull(operation.getAdditionalEventParams());
-
- // both - should choose the property
- final Map<String, String> propParams = Collections.emptyMap();
- operation.setProperty(OperationProperties.EVENT_ADDITIONAL_PARAMS, propParams);
- assertSame(propParams, operation.getAdditionalEventParams());
- }
-
- private void verifyOperation(ControlLoopEventContext context) {
+ private void verifyOperation(TargetType targetType, Runnable loader) {
Map<String, Object> payloadMap = Map.of(CdsActorConstants.KEY_CBA_NAME, CDS_BLUEPRINT_NAME,
CdsActorConstants.KEY_CBA_VERSION, CDS_BLUEPRINT_VERSION, "data",
"{\"mapInfo\":{\"key\":\"val\"},\"arrayInfo\":[\"one\",\"two\"],\"paramInfo\":\"val\"}");
ControlLoopOperationParams params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR)
- .operation(GrpcOperation.NAME).context(context).actorService(new ActorService())
- .targetEntity(TARGET_ENTITY).targetType(targetType).targetEntityIds(targetEntityIds)
- .payload(payloadMap).build();
+ .operation(GrpcOperation.NAME).requestId(REQUEST_ID).actorService(new ActorService())
+ .targetType(targetType).targetEntity(TARGET_ENTITY).payload(payloadMap).build();
GrpcConfig config = new GrpcConfig(executor, cdsProps);
operation = new GrpcOperation(params, config);
@@ -459,28 +239,31 @@ public class GrpcOperationTest {
assertEquals(1000, operation.getTimeoutMs(0));
assertEquals(2000, operation.getTimeoutMs(2));
operation.generateSubRequestId(1);
+
+ loader.run();
CompletableFuture<OperationOutcome> future3 = operation.startOperationAsync(1, params.makeOutcome(null));
assertNotNull(future3);
}
- private void loadPnfData(ControlLoopEventContext context) throws CoderException {
- String json = "{'dataA': 'valueA', 'dataB': 'valueB'}".replace('\'', '"');
- StandardCoderObject sco = coder.decode(json, StandardCoderObject.class);
+ private void loadPnfData() {
+ try {
+ String json = "{'dataA': 'valueA', 'dataB': 'valueB'}".replace('\'', '"');
+ StandardCoderObject sco = coder.decode(json, StandardCoderObject.class);
+
+ operation.setProperty(OperationProperties.AAI_PNF, sco);
- context.setProperty(AaiGetPnfOperation.getKey(TARGET_ENTITY), sco);
+ } catch (CoderException e) {
+ throw new IllegalArgumentException("cannot decode PNF json", e);
+ }
}
- private void loadCqData(ControlLoopEventContext context) {
+ private void loadVnfData() {
GenericVnf genvnf = new GenericVnf();
genvnf.setVnfId(MY_VNF);
+ operation.setProperty(OperationProperties.AAI_RESOURCE_VNF, genvnf);
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);
+ operation.setProperty(OperationProperties.AAI_SERVICE, serviceInstance);
}
}
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 11121c0b3..3e3b1f573 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
@@ -25,16 +25,14 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import java.util.Map;
+import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.onap.policy.cds.properties.CdsServerProperties;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants;
import org.onap.policy.controlloop.actorserviceprovider.Operation;
-import org.onap.policy.controlloop.actorserviceprovider.TargetType;
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;
@@ -85,10 +83,8 @@ public class GrpcOperatorTest {
@Test
public void testBuildOperation() {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- ControlLoopEventContext context = new ControlLoopEventContext(event);
ControlLoopOperationParams params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR)
- .operation(GrpcOperation.NAME).context(context).targetType(TargetType.VM).build();
+ .operation(GrpcOperation.NAME).requestId(UUID.randomUUID()).build();
// not configured yet
assertThatIllegalStateException().isThrownBy(() -> operation.buildOperation(params));