aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-02-26 11:07:35 -0500
committerJim Hahn <jrh3@att.com>2020-02-26 11:17:18 -0500
commit72b4a13723049c5d4a066879aa67d08ec5e86180 (patch)
treeef98a84a5b0a4e0bda8ab88016271f380b5ab592 /models-interactions/model-actors
parentaa2e18733fbaa2a0910091eca9677c076c53f454 (diff)
Custom Query should always use vserver
Modified the Custom Query Operation to ignore the target entity passed via the "params" and always use the vserver name found in the enrichment data. Issue-ID: POLICY-2349 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: If2c45df2d0377ca08059bdbfa0bcc3d3f043c5b9
Diffstat (limited to 'models-interactions/model-actors')
-rw-r--r--models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java22
-rw-r--r--models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java21
2 files changed, 34 insertions, 9 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 d2e8be510..613b6689d 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
@@ -25,6 +25,8 @@ import java.util.concurrent.CompletableFuture;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import lombok.Getter;
+import org.apache.commons.lang3.StringUtils;
import org.onap.policy.aai.AaiConstants;
import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
@@ -40,18 +42,23 @@ import org.slf4j.LoggerFactory;
/**
* A&AI Custom Query. Stores the {@link AaiCqResponse} in the context. In addition, if the
* context does not contain the "tenant" data for the vserver, then it will request that,
- * as well.
+ * as well. Note: this ignores the "target entity" in the parameters as this query always
+ * applies to the vserver, thus the target entity may be set to an empty string.
*/
public class AaiCustomQueryOperation extends HttpOperation<String> {
private static final Logger logger = LoggerFactory.getLogger(AaiCustomQueryOperation.class);
public static final String NAME = AaiCqResponse.OPERATION;
+ public static final String VSERVER_VSERVER_NAME = "vserver.vserver-name";
public static final String RESOURCE_LINK = "resource-link";
public static final String RESULT_DATA = "result-data";
private static final String PREFIX = "/aai/v16";
+ @Getter
+ private final String vserver;
+
/**
* Constructs the object.
*
@@ -60,6 +67,11 @@ public class AaiCustomQueryOperation extends HttpOperation<String> {
*/
public AaiCustomQueryOperation(ControlLoopOperationParams params, HttpConfig config) {
super(params, config, String.class);
+
+ this.vserver = params.getContext().getEnrichment().get(VSERVER_VSERVER_NAME);
+ if (StringUtils.isBlank(this.vserver)) {
+ throw new IllegalArgumentException("missing " + VSERVER_VSERVER_NAME + " in enrichment data");
+ }
}
/**
@@ -67,10 +79,9 @@ public class AaiCustomQueryOperation extends HttpOperation<String> {
*/
@Override
protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
- String vserver = params.getTargetEntity();
-
- ControlLoopOperationParams tenantParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
- .operation(AaiGetOperation.TENANT).payload(null).retry(null).timeoutSec(null).build();
+ ControlLoopOperationParams tenantParams =
+ params.toBuilder().actor(AaiConstants.ACTOR_NAME).operation(AaiGetOperation.TENANT)
+ .targetEntity(vserver).payload(null).retry(null).timeoutSec(null).build();
return params.getContext().obtain(AaiGetOperation.getTenantKey(vserver), tenantParams);
}
@@ -99,7 +110,6 @@ public class AaiCustomQueryOperation extends HttpOperation<String> {
* Constructs the custom query using the previously retrieved tenant data.
*/
private Map<String, String> makeRequest() {
- String vserver = params.getTargetEntity();
StandardCoderObject tenant = params.getContext().getProperty(AaiGetOperation.getTenantKey(vserver));
String resourceLink = tenant.getString(RESULT_DATA, 0, RESOURCE_LINK);
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 1ec7bea4e..78ffc50e0 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
@@ -20,6 +20,8 @@
package org.onap.policy.controlloop.actor.aai;
+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.assertSame;
@@ -59,6 +61,7 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S
private static final StandardCoder coder = new StandardCoder();
private static final String MY_LINK = "my-link";
+ private static final String MY_VSERVER = "my-verserver-name";
@Captor
private ArgumentCaptor<Entity<Map<String, String>>> entityCaptor;
@@ -79,6 +82,8 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S
public void setUp() throws Exception {
super.setUpBasic();
+ params.getContext().getEnrichment().put(AaiCustomQueryOperation.VSERVER_VSERVER_NAME, MY_VSERVER);
+
MyTenantOperator tenantOperator = new MyTenantOperator();
when(service.getActor(AaiConstants.ACTOR_NAME)).thenReturn(tenantActor);
@@ -91,6 +96,16 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S
public void testAaiCustomQueryOperation() {
assertEquals(AaiConstants.ACTOR_NAME, oper.getActorName());
assertEquals(AaiCustomQueryOperation.NAME, oper.getName());
+ assertEquals(MY_VSERVER, oper.getVserver());
+
+ // verify that it works with an empty target entity
+ params = params.toBuilder().targetEntity("").build();
+ assertThatCode(() -> new AaiCustomQueryOperation(params, config)).doesNotThrowAnyException();
+
+ // try without enrichment data
+ params.getContext().getEnrichment().remove(AaiCustomQueryOperation.VSERVER_VSERVER_NAME);
+ assertThatIllegalArgumentException().isThrownBy(() -> new AaiCustomQueryOperation(params, config))
+ .withMessage("missing " + AaiCustomQueryOperation.VSERVER_VSERVER_NAME + " in enrichment data");
}
@Test
@@ -105,7 +120,7 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S
assertEquals(PolicyResult.SUCCESS, getResult(future2));
// tenant response should have been cached within the context
- assertNotNull(context.getProperty(AaiGetOperation.getTenantKey(TARGET_ENTITY)));
+ assertNotNull(context.getProperty(AaiGetOperation.getTenantKey(MY_VSERVER)));
// custom query response should have been cached within the context
AaiCqResponse cqData = context.getProperty(AaiCqResponse.CONTEXT_KEY);
@@ -129,7 +144,7 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S
assertEquals(PolicyResult.SUCCESS, getResult(future2));
// should not have replaced tenant response
- assertSame(data, context.getProperty(AaiGetOperation.getTenantKey(TARGET_ENTITY)));
+ assertSame(data, context.getProperty(AaiGetOperation.getTenantKey(MY_VSERVER)));
// custom query response should have been cached within the context
AaiCqResponse cqData = context.getProperty(AaiCqResponse.CONTEXT_KEY);
@@ -192,7 +207,7 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S
}
private void preloadTenantData(StandardCoderObject data) {
- context.setProperty(AaiGetOperation.getTenantKey(TARGET_ENTITY), data);
+ context.setProperty(AaiGetOperation.getTenantKey(MY_VSERVER), data);
}
private PolicyResult getResult(CompletableFuture<OperationOutcome> future2)