diff options
Diffstat (limited to 'models-interactions/model-actors')
13 files changed, 110 insertions, 41 deletions
diff --git a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java index caa8b9e1f..151f7a214 100644 --- a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java +++ b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java @@ -87,6 +87,10 @@ public class AaiCustomQueryOperation extends HttpOperation<String> { */ @Override protected CompletableFuture<OperationOutcome> startPreprocessorAsync() { + if (params.isPreprocessed()) { + return null; + } + ControlLoopOperationParams tenantParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME).operation(AaiGetTenantOperation.NAME) .targetEntity(vserver).payload(null).retry(null).timeoutSec(null).build(); diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java index 400096507..476e6432d 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java @@ -25,6 +25,7 @@ import static org.assertj.core.api.Assertions.assertThatCode; 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; @@ -151,6 +152,15 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation { assertEquals("3", oper.getSubRequestId()); } + /** + * Tests startPreprocessorAsync(), when preprocessing is disabled. + */ + @Test + public void testStartPreprocessorAsyncDisabled() { + params = params.toBuilder().preprocessed(true).build(); + assertNull(new AaiCustomQueryOperation(params, config).startPreprocessorAsync()); + } + @Test @SuppressWarnings("unchecked") public void testStartOperationAsync_testStartPreprocessorAsync_testMakeRequest_testPostProcess() throws Exception { diff --git a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java index d1f27b505..680bd9cc7 100644 --- a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java +++ b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java @@ -56,6 +56,10 @@ public class ModifyConfigOperation extends AppcOperation { @Override @SuppressWarnings("unchecked") protected CompletableFuture<OperationOutcome> startPreprocessorAsync() { + if (params.isPreprocessed()) { + return null; + } + ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME) .operation(AaiCqResponse.OPERATION).payload(null).retry(null).timeoutSec(null).build(); diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java index e544d46cb..4bbb057d7 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java @@ -23,6 +23,7 @@ package org.onap.policy.controlloop.actor.appc; 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 java.util.Arrays; @@ -85,6 +86,15 @@ public class AppcOperationTest extends BasicAppcOperation { assertNotNull(oper.startPreprocessorAsync()); } + /** + * Tests startPreprocessorAsync(), when preprocessing is disabled. + */ + @Test + public void testStartPreprocessorAsyncDisabled() { + params = params.toBuilder().preprocessed(true).build(); + assertNull(new MyOper(params, config).startPreprocessorAsync()); + } + @Test public void testMakeRequest() { oper.generateSubRequestId(2); diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java index d000038e3..9c602f52e 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java @@ -25,6 +25,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; 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; @@ -156,6 +157,15 @@ public class ModifyConfigOperationTest extends BasicAppcOperation { assertEquals(PolicyResult.SUCCESS, future3.get().getResult()); } + /** + * Tests startPreprocessorAsync(), when preprocessing is disabled. + */ + @Test + public void testStartPreprocessorAsyncDisabled() { + params = params.toBuilder().preprocessed(true).build(); + assertNull(new ModifyConfigOperation(params, config).startPreprocessorAsync()); + } + @Test public void testMakeRequest() throws CoderException { AaiCqResponse cq = new AaiCqResponse("{}"); 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())); } diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java index fcd48b1a5..4bae1e84d 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java @@ -87,6 +87,9 @@ public class VfModuleCreate extends SoOperation { @Override @SuppressWarnings("unchecked") protected CompletableFuture<OperationOutcome> startPreprocessorAsync() { + if (params.isPreprocessed()) { + return null; + } // need the VF count ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME) diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java index b7afb696c..7db76d2d1 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java @@ -96,6 +96,9 @@ public class VfModuleDelete extends SoOperation { @Override @SuppressWarnings("unchecked") protected CompletableFuture<OperationOutcome> startPreprocessorAsync() { + if (params.isPreprocessed()) { + return null; + } // need the VF count ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME) 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 0db209dad..012f8deff 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 @@ -25,6 +25,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; 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.Mockito.mock; @@ -151,6 +152,15 @@ public class VfModuleCreateTest extends BasicSoOperation { assertTrue(guardStarted.get()); } + /** + * Tests startPreprocessorAsync(), when preprocessing is disabled. + */ + @Test + public void testStartPreprocessorAsyncDisabled() { + params = params.toBuilder().preprocessed(true).build(); + assertNull(new VfModuleCreate(params, config).startPreprocessorAsync()); + } + @Test public void testStartGuardAsync() throws Exception { // remove CQ data so it's forced to query 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 7c37dc900..cc2aafa74 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 @@ -25,6 +25,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; 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; @@ -180,6 +181,15 @@ public class VfModuleDeleteTest extends BasicSoOperation { assertTrue(guardStarted.get()); } + /** + * Tests startPreprocessorAsync(), when preprocessing is disabled. + */ + @Test + public void testStartPreprocessorAsyncDisabled() { + params = params.toBuilder().preprocessed(true).build(); + assertNull(new MyOperation(params, config).startPreprocessorAsync()); + } + @Test public void testStartGuardAsync() throws Exception { // remove CQ data so it's forced to query diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java index 060f7a64b..9ce53aa7a 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java @@ -268,6 +268,10 @@ public abstract class OperationPartial implements Operation { * {@code null} if this operation has no guard */ protected CompletableFuture<OperationOutcome> startGuardAsync() { + if (params.isPreprocessed()) { + return null; + } + // get the guard payload Map<String, Object> payload = makeGuardPayload(); @@ -285,6 +289,7 @@ public abstract class OperationPartial implements Operation { * @return a new guard payload */ protected Map<String, Object> makeGuardPayload() { + // TODO delete this once preprocessing is done by the application Map<String, Object> guard = new LinkedHashMap<>(); guard.put("actor", params.getActor()); guard.put("operation", params.getOperation()); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java index 9bbc528ec..6d5435827 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java @@ -346,6 +346,15 @@ public class OperationPartialTest { assertEquals(oper.makeGuardPayload(), payload); } + /** + * Tests startGuardAsync() when preprocessing is disabled. + */ + @Test + public void testStartGuardAsyncDisabled() { + params = params.toBuilder().preprocessed(true).build(); + assertNull(new MyOper().startGuardAsync()); + } + @Test public void testMakeGuardPayload() { Map<String, Object> payload = oper.makeGuardPayload(); |