summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.aai
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-08-18 09:39:19 -0400
committerJim Hahn <jrh3@att.com>2020-08-18 17:11:52 -0400
commit8722cb8a654ddcdcb472546a58809e041fe84eba (patch)
treeeba3aee017377733f6a44840a58fc322f7e4f807 /models-interactions/model-actors/actor.aai
parentca3827f43ada2b160f6966d205ca97d4402a0935 (diff)
Make targetEntity a property
The target entity is not always known when an Operation is first constructed, thus it should be treated as an Operation property instead of being included within the ControlLoopParams. Started the process of moving it from the Params to the properties. Also fixed a bug in custom query - it was setting the outcome response to the String response instead of setting it to the AaiCqResponse object. Also added logging when an Operation's properties are set. Issue-ID: POLICY-2746 Change-Id: I56c0cd90985f6140363548b0b8d031471b586e88 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.aai')
-rw-r--r--models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java14
-rw-r--r--models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java9
-rw-r--r--models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperation.java2
-rw-r--r--models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperation.java2
-rw-r--r--models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java21
-rw-r--r--models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java10
-rw-r--r--models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperationTest.java11
7 files changed, 48 insertions, 21 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 388959ddf..54801358c 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
@@ -40,6 +40,7 @@ import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
+import org.onap.policy.controlloop.policy.PolicyResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -186,6 +187,19 @@ public class AaiCustomQueryOperation extends HttpOperation<String> {
return AaiUtil.makeHeaders(params);
}
+ @Override
+ public OperationOutcome setOutcome(OperationOutcome outcome, PolicyResult result, Response rawResponse,
+ String response) {
+
+ super.setOutcome(outcome, result, rawResponse, response);
+
+ if (response != null) {
+ outcome.setResponse(new AaiCqResponse(response));
+ }
+
+ return outcome;
+ }
+
/**
* Injects the response into the context.
*/
diff --git a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java
index c91e2a0d6..3fb978d88 100644
--- a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java
+++ b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java
@@ -20,7 +20,7 @@
package org.onap.policy.controlloop.actor.aai;
-import java.util.Collections;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
@@ -29,6 +29,7 @@ import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
@@ -45,6 +46,8 @@ public class AaiGetOperation extends HttpOperation<StandardCoderObject> {
public static final int DEFAULT_RETRY = 3;
+ private static final List<String> PROPERTY_NAMES = List.of(OperationProperties.AAI_TARGET_ENTITY);
+
/**
* Responses that are retrieved from A&AI are placed in the operation context under
@@ -59,7 +62,7 @@ public class AaiGetOperation extends HttpOperation<StandardCoderObject> {
* @param config configuration for this operation
*/
public AaiGetOperation(ControlLoopOperationParams params, HttpConfig config) {
- super(params, config, StandardCoderObject.class, Collections.emptyList());
+ super(params, config, StandardCoderObject.class, PROPERTY_NAMES);
this.propertyPrefix = getFullName() + ".";
}
@@ -110,9 +113,9 @@ public class AaiGetOperation extends HttpOperation<StandardCoderObject> {
@Override
protected CompletableFuture<OperationOutcome> postProcessResponse(OperationOutcome outcome, String url,
Response rawResponse, StandardCoderObject response) {
- String entity = params.getTargetEntity();
if (params.getContext() != null) {
+ String entity = getTargetEntity();
logger.info("{}: caching response of {} for {}", getFullName(), entity, params.getRequestId());
params.getContext().setProperty(propertyPrefix + entity, response);
}
diff --git a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperation.java b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperation.java
index fbf40967c..d89d8350a 100644
--- a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperation.java
+++ b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperation.java
@@ -74,7 +74,7 @@ public class AaiGetPnfOperation extends AaiGetOperation {
StringBuilder str = new StringBuilder(getClient().getBaseUrl());
- String path = getPath() + URI_SEP + URLEncoder.encode(params.getTargetEntity(), StandardCharsets.UTF_8);
+ String path = getPath() + URI_SEP + URLEncoder.encode(getTargetEntity(), StandardCharsets.UTF_8);
WebTarget web = getClient().getWebTarget().path(path);
str.append(path);
diff --git a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperation.java b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperation.java
index cbd179189..fe1179833 100644
--- a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperation.java
+++ b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperation.java
@@ -76,7 +76,7 @@ public class AaiGetTenantOperation extends AaiGetOperation {
str.append(path);
web = addQuery(web, str, "?", "search-node-type", "vserver");
- web = addQuery(web, str, "&", "filter", "vserver-name:EQUALS:" + params.getTargetEntity());
+ web = addQuery(web, str, "&", "filter", "vserver-name:EQUALS:" + getTargetEntity());
Builder webldr = web.request();
addHeaders(webldr, headers);
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 f1225373e..8e8b8f150 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
@@ -21,7 +21,6 @@
package org.onap.policy.controlloop.actor.aai;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
@@ -114,27 +113,22 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation {
HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/query").build();
config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
- params = params.toBuilder().targetEntity(SIM_VSERVER).retry(0).timeoutSec(5).executor(blockingExecutor)
- .preprocessed(true).build();
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).preprocessed(true).build();
oper = new AaiCustomQueryOperation(params, config);
+ oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, SIM_VSERVER);
oper.setProperty(OperationProperties.AAI_VSERVER_LINK, MY_LINK);
outcome = oper.start().get();
assertEquals(PolicyResult.SUCCESS, outcome.getResult());
- String resp = outcome.getResponse();
- assertThat(resp).isNotNull().contains("relationship-list");
+ assertNotNull(outcome.getResponse());
}
@Test
public void testConstructor() {
assertEquals(AaiConstants.ACTOR_NAME, oper.getActorName());
assertEquals(AaiCustomQueryOperation.NAME, oper.getName());
-
- // verify that it works with an empty target entity
- params = params.toBuilder().targetEntity("").build();
- assertThatCode(() -> new AaiCustomQueryOperation(params, config)).doesNotThrowAnyException();
}
@Test
@@ -263,6 +257,15 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation {
.withMessage("cannot perform custom query - no resource-link");
}
+ @Test
+ public void testSetOutcome() {
+ outcome = oper.setOutcome(params.makeOutcome(null), PolicyResult.SUCCESS, null, null);
+ assertNull(outcome.getResponse());
+
+ outcome = oper.setOutcome(params.makeOutcome(null), PolicyResult.SUCCESS, null, "{}");
+ assertTrue(outcome.getResponse() instanceof AaiCqResponse);
+ }
+
private String makeTenantReply() throws Exception {
Map<String, String> links = Map.of(AaiCustomQueryOperation.RESOURCE_LINK, MY_LINK);
List<Map<String, String>> data = Arrays.asList(links);
diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java
index b211db261..13b5b5926 100644
--- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java
+++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java
@@ -29,6 +29,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import javax.ws.rs.client.InvocationCallback;
@@ -41,6 +42,7 @@ import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
import org.onap.policy.controlloop.policy.PolicyResult;
@@ -82,7 +84,7 @@ public class AaiGetPnfOperationTest extends BasicAaiOperation {
@Test
public void testGetPropertyNames() {
- assertThat(oper.getPropertyNames()).isEmpty();
+ assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.AAI_TARGET_ENTITY));
}
/**
@@ -93,8 +95,9 @@ public class AaiGetPnfOperationTest extends BasicAaiOperation {
HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/network/pnfs/pnf").build();
config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
- params = params.toBuilder().targetEntity("OzVServer").retry(0).timeoutSec(5).executor(blockingExecutor).build();
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
oper = new AaiGetPnfOperation(params, config);
+ oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, "OzVServer");
outcome = oper.start().get();
assertEquals(PolicyResult.SUCCESS, outcome.getResult());
@@ -109,8 +112,9 @@ public class AaiGetPnfOperationTest extends BasicAaiOperation {
HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/network/pnfs/pnf").build();
config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
- params = params.toBuilder().targetEntity("getFail").retry(0).timeoutSec(5).executor(blockingExecutor).build();
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
oper = new AaiGetPnfOperation(params, config);
+ oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, "getFail");
outcome = oper.start().get();
assertEquals(PolicyResult.FAILURE, outcome.getResult());
diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperationTest.java
index fe0327c10..11604cdb9 100644
--- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperationTest.java
+++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperationTest.java
@@ -29,6 +29,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import javax.ws.rs.client.InvocationCallback;
@@ -41,6 +42,7 @@ import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
import org.onap.policy.controlloop.policy.PolicyResult;
@@ -82,7 +84,7 @@ public class AaiGetTenantOperationTest extends BasicAaiOperation {
@Test
public void testGetPropertyNames() {
- assertThat(oper.getPropertyNames()).isEmpty();
+ assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.AAI_TARGET_ENTITY));
}
/**
@@ -93,8 +95,9 @@ public class AaiGetTenantOperationTest extends BasicAaiOperation {
HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/search/nodes-query").build();
config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
- params = params.toBuilder().targetEntity("OzVServer").retry(0).timeoutSec(5).executor(blockingExecutor).build();
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
oper = new AaiGetTenantOperation(params, config);
+ oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, "OzVServer");
outcome = oper.start().get();
assertEquals(PolicyResult.SUCCESS, outcome.getResult());
@@ -109,9 +112,9 @@ public class AaiGetTenantOperationTest extends BasicAaiOperation {
HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/search/nodes-query").build();
config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
- params = params.toBuilder().targetEntity("failedVserver").retry(0).timeoutSec(5).executor(blockingExecutor)
- .build();
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
oper = new AaiGetTenantOperation(params, config);
+ oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, "failedVserver");
outcome = oper.start().get();
assertEquals(PolicyResult.FAILURE, outcome.getResult());