summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.cds/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-08-04 09:09:14 -0400
committerJim Hahn <jrh3@att.com>2020-08-04 09:34:39 -0400
commit364ef26929f06637bca03dd7bfb5e8ac69b611f8 (patch)
treed1f3ccd22bb56f2acce8ea05244a6197d32c5fdd /models-interactions/model-actors/actor.cds/src
parentacded8235dcbb0b06abaa98297fecef78b4eec41 (diff)
Skip preprocessor step in Actors
Modified Actors to skip the preprocessor step if the "preprocessed" flag is set to true in the parameters. Did not add any error checking code to ensure the data was actually available to the operation - will add that once the properties are being set by the application code. Extracted common code in GrpcOperationTest into the setup method. Issue-ID: POLICY-2746 Change-Id: Id70c31a2c96a7aaa9d73cc70cdf4f55f8a4e087f Signed-off-by: Jim Hahn <jrh3@att.com>
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.java4
-rw-r--r--models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperationTest.java69
2 files changed, 32 insertions, 41 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 241781254..ec8f2ac12 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
@@ -138,6 +138,10 @@ public class GrpcOperation extends OperationPartial {
@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);
}
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 cbc88a30e..06f239b63 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,6 +23,7 @@ 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.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
@@ -93,10 +94,15 @@ public class GrpcOperationTest {
@Mock
private CdsProcessorGrpcClient cdsClient;
+ @Mock
+ private ControlLoopEventContext context;
private CdsServerProperties cdsProps;
private VirtualControlLoopEvent onset;
private PseudoExecutor executor;
private Target target;
+ private ControlLoopOperationParams params;
+ private GrpcConfig config;
+ private CompletableFuture<OperationOutcome> cqFuture;
private GrpcOperation operation;
@BeforeClass
@@ -137,6 +143,14 @@ public class GrpcOperationTest {
target = new Target();
target.setType(TargetType.VM);
target.setResourceID(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).target(target).build();
}
/**
@@ -149,7 +163,7 @@ public class GrpcOperationTest {
Map<String, Object> payload = Map.of("artifact_name", "my_artifact", "artifact_version", "1.0");
- final ControlLoopOperationParams params = ControlLoopOperationParams.builder()
+ params = ControlLoopOperationParams.builder()
.actor(CdsActorConstants.CDS_ACTOR).operation("subscribe").context(context)
.actorService(new ActorService()).targetEntity(TARGET_ENTITY).target(target).retry(0)
.timeoutSec(5).executor(blockingExecutor).payload(payload).build();
@@ -175,13 +189,6 @@ public class GrpcOperationTest {
@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
@@ -212,24 +219,13 @@ public class GrpcOperationTest {
@Test
public void testStartPreprocessorAsync() 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();
- 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;
+ return cqFuture;
}
};
@@ -238,7 +234,7 @@ public class GrpcOperationTest {
assertTrue(guardStarted.get());
verify(context).obtain(eq(AaiCqResponse.CONTEXT_KEY), any());
- future2.complete(params.makeOutcome());
+ cqFuture.complete(params.makeOutcome());
assertTrue(executor.runAll(100));
assertEquals(PolicyResult.SUCCESS, future3.get(2, TimeUnit.SECONDS).getResult());
assertTrue(future3.isDone());
@@ -249,26 +245,15 @@ public class GrpcOperationTest {
*/
@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;
+ return cqFuture;
}
};
@@ -277,12 +262,21 @@ public class GrpcOperationTest {
assertTrue(guardStarted.get());
verify(context).obtain(eq(AaiGetPnfOperation.getKey(TARGET_ENTITY)), any());
- future2.complete(params.makeOutcome());
+ cqFuture.complete(params.makeOutcome());
assertTrue(executor.runAll(100));
assertEquals(PolicyResult.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 {
@@ -319,13 +313,6 @@ public class GrpcOperationTest {
@Test
public void testStartOperationAsyncError() throws Exception {
-
- ControlLoopEventContext context = new ControlLoopEventContext(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);
operation = new GrpcOperation(params, config);
assertThatIllegalArgumentException().isThrownBy(() -> operation.startOperationAsync(1, params.makeOutcome()));
}