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>
13 files changed:
*/
@Override
protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
*/
@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();
ControlLoopOperationParams tenantParams =
params.toBuilder().actor(AaiConstants.ACTOR_NAME).operation(AaiGetTenantOperation.NAME)
.targetEntity(vserver).payload(null).retry(null).timeoutSec(null).build();
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
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.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
assertEquals("3", oper.getSubRequestId());
}
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 {
@Test
@SuppressWarnings("unchecked")
public void testStartOperationAsync_testStartPreprocessorAsync_testMakeRequest_testPostProcess() throws Exception {
@Override
@SuppressWarnings("unchecked")
protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
@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();
ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
.operation(AaiCqResponse.OPERATION).payload(null).retry(null).timeoutSec(null).build();
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
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;
import static org.junit.Assert.assertSame;
import java.util.Arrays;
assertNotNull(oper.startPreprocessorAsync());
}
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);
@Test
public void testMakeRequest() {
oper.generateSubRequestId(2);
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
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;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
assertEquals(PolicyResult.SUCCESS, future3.get().getResult());
}
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("{}");
@Test
public void testMakeRequest() throws CoderException {
AaiCqResponse cq = new AaiCqResponse("{}");
@Override
@SuppressWarnings("unchecked")
protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
@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);
}
// run A&AI Query and Guard, in parallel
return allOf(aaiRequestor, this::startGuardAsync);
}
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
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;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
@Mock
private CdsProcessorGrpcClient cdsClient;
@Mock
private CdsProcessorGrpcClient cdsClient;
+ @Mock
+ private ControlLoopEventContext context;
private CdsServerProperties cdsProps;
private VirtualControlLoopEvent onset;
private PseudoExecutor executor;
private Target target;
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
private GrpcOperation operation;
@BeforeClass
target = new Target();
target.setType(TargetType.VM);
target.setResourceID(RESOURCE_ID);
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();
Map<String, Object> payload = Map.of("artifact_name", "my_artifact", "artifact_version", "1.0");
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();
.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();
@Test
public void testGetPropertyNames() {
@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);
@Test
public void testStartPreprocessorAsync() throws InterruptedException, ExecutionException, TimeoutException {
@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();
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);
operation = new GrpcOperation(params, config) {
@Override
protected CompletableFuture<OperationOutcome> startGuardAsync() {
guardStarted.set(true);
assertTrue(guardStarted.get());
verify(context).obtain(eq(AaiCqResponse.CONTEXT_KEY), any());
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());
assertTrue(executor.runAll(100));
assertEquals(PolicyResult.SUCCESS, future3.get(2, TimeUnit.SECONDS).getResult());
assertTrue(future3.isDone());
*/
@Test
public void testStartPreprocessorAsyncPnf() throws InterruptedException, ExecutionException, TimeoutException {
*/
@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);
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);
operation = new GrpcOperation(params, config) {
@Override
protected CompletableFuture<OperationOutcome> startGuardAsync() {
guardStarted.set(true);
assertTrue(guardStarted.get());
verify(context).obtain(eq(AaiGetPnfOperation.getKey(TARGET_ENTITY)), any());
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());
}
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 {
@Test
public void testStartOperationAsync() throws Exception {
@Test
public void testStartOperationAsyncError() throws Exception {
@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()));
}
operation = new GrpcOperation(params, config);
assertThatIllegalArgumentException().isThrownBy(() -> operation.startOperationAsync(1, params.makeOutcome()));
}
@Override
@SuppressWarnings("unchecked")
protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
@Override
@SuppressWarnings("unchecked")
protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
+ if (params.isPreprocessed()) {
+ return null;
+ }
// need the VF count
ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
// need the VF count
ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
@Override
@SuppressWarnings("unchecked")
protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
@Override
@SuppressWarnings("unchecked")
protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
+ if (params.isPreprocessed()) {
+ return null;
+ }
// need the VF count
ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
// need the VF count
ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
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;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
assertTrue(guardStarted.get());
}
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
@Test
public void testStartGuardAsync() throws Exception {
// remove CQ data so it's forced to query
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
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;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
assertTrue(guardStarted.get());
}
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
@Test
public void testStartGuardAsync() throws Exception {
// remove CQ data so it's forced to query
* {@code null} if this operation has no guard
*/
protected CompletableFuture<OperationOutcome> startGuardAsync() {
* {@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();
// get the guard payload
Map<String, Object> payload = makeGuardPayload();
* @return a new guard payload
*/
protected Map<String, Object> makeGuardPayload() {
* @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());
Map<String, Object> guard = new LinkedHashMap<>();
guard.put("actor", params.getActor());
guard.put("operation", params.getOperation());
assertEquals(oper.makeGuardPayload(), payload);
}
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();
@Test
public void testMakeGuardPayload() {
Map<String, Object> payload = oper.makeGuardPayload();