summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.aai/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-08-04 16:27:18 -0400
committerJim Hahn <jrh3@att.com>2020-08-06 19:19:46 -0400
commitdeed677c3dc8751209d50e7d35132c929fe6800d (patch)
tree01f3149d4a03206e134d889d50834ae8d141a0ce /models-interactions/model-actors/actor.aai/src/main
parent364ef26929f06637bca03dd7bfb5e8ac69b611f8 (diff)
Modify Actors to use properties when provided
Modified the Actors to use properties when the application provides them instead of going to the event context for the data. This sometimes entailed moving code out of the Operation subclass constructor that used or validated the context data. Combined some property names and renamed others. Changed VF Count from AtomicInteger to Integer. Issue-ID: POLICY-2746 Change-Id: Ib8730538309bb77d2f4f6161e9a20a49362d8972 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.aai/src/main')
-rw-r--r--models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java41
1 files changed, 32 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 151f7a214..c8e087036 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
@@ -29,7 +29,6 @@ import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
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;
@@ -64,9 +63,6 @@ public class AaiCustomQueryOperation extends HttpOperation<String> {
// TODO make this configurable
private static final String PREFIX = "/aai/v16";
- @Getter
- private final String vserver;
-
/**
* Constructs the object.
*
@@ -75,11 +71,20 @@ public class AaiCustomQueryOperation extends HttpOperation<String> {
*/
public AaiCustomQueryOperation(ControlLoopOperationParams params, HttpConfig config) {
super(params, config, String.class, PROPERTY_NAMES);
+ }
- this.vserver = params.getContext().getEnrichment().get(VSERVER_VSERVER_NAME);
- if (StringUtils.isBlank(this.vserver)) {
+ /**
+ * Gets the vserver name from the enrichment data.
+ *
+ * @return the vserver name
+ */
+ protected String getVserver() {
+ String vserver = this.params.getContext().getEnrichment().get(VSERVER_VSERVER_NAME);
+ if (StringUtils.isBlank(vserver)) {
throw new IllegalArgumentException("missing " + VSERVER_VSERVER_NAME + " in enrichment data");
}
+
+ return vserver;
}
/**
@@ -91,6 +96,7 @@ public class AaiCustomQueryOperation extends HttpOperation<String> {
return null;
}
+ String vserver = getVserver();
ControlLoopOperationParams tenantParams =
params.toBuilder().actor(AaiConstants.ACTOR_NAME).operation(AaiGetTenantOperation.NAME)
.targetEntity(vserver).payload(null).retry(null).timeoutSec(null).build();
@@ -146,16 +152,33 @@ public class AaiCustomQueryOperation extends HttpOperation<String> {
* Constructs the custom query using the previously retrieved tenant data.
*/
private Map<String, String> makeRequest() {
+ return Map.of("start", getVserverLink(), "query", "query/closed-loop");
+ }
+
+ /**
+ * Gets the vserver link, first checking the properties, and then the tenant data.
+ *
+ * @return the vserver link
+ */
+ protected String getVserverLink() {
+ String resourceLink = getProperty(OperationProperties.AAI_VSERVER_LINK);
+ if (resourceLink != null) {
+ return resourceLink;
+ }
+
+ String vserver = getVserver();
StandardCoderObject tenant = params.getContext().getProperty(AaiGetTenantOperation.getKey(vserver));
+ if (tenant == null) {
+ throw new IllegalStateException("cannot perform custom query - cannot determine resource-link");
+ }
- String resourceLink = tenant.getString(RESULT_DATA, 0, RESOURCE_LINK);
+ resourceLink = tenant.getString(RESULT_DATA, 0, RESOURCE_LINK);
if (resourceLink == null) {
throw new IllegalArgumentException("cannot perform custom query - no resource-link");
}
resourceLink = resourceLink.replace(PREFIX, "");
-
- return Map.of("start", resourceLink, "query", "query/closed-loop");
+ return resourceLink;
}
@Override