From 19ef8b24a98c09a349e6ae7309f535a0135463f6 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 21 Aug 2020 13:43:08 -0400 Subject: Make Actors event-agnostic Removed event and event-context code from the Actor code. Also removed the preprocessing steps from the Actor code, giving the application complete control over any preprocessing. Also fixed a bug wherein the APPC actor was treating the AAI_RESOURCE_VNF property as a String instead of as a GenericVnf. Issue-ID: POLICY-2746-actor Change-Id: Ibc05fe39ffedc0bc461abf10e6a960861ac70119 Signed-off-by: Jim Hahn --- .../actor/aai/AaiCustomQueryOperation.java | 75 +--------------------- .../controlloop/actor/aai/AaiGetOperation.java | 31 --------- 2 files changed, 1 insertion(+), 105 deletions(-) (limited to 'models-interactions/model-actors/actor.aai/src/main') 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 612fba98d..27dd56c60 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,20 +29,15 @@ 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 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; import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; -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.OperationResult; 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.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * A&AI Custom Query. Stores the {@link AaiCqResponse} in the context. In addition, if the @@ -51,8 +46,6 @@ import org.slf4j.LoggerFactory; * applies to the vserver, thus the target entity may be set to an empty string. */ public class AaiCustomQueryOperation extends HttpOperation { - 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"; @@ -61,9 +54,6 @@ public class AaiCustomQueryOperation extends HttpOperation { private static final List PROPERTY_NAMES = List.of(OperationProperties.AAI_VSERVER_LINK); - // TODO make this configurable - private static final String PREFIX = "/aai/v16"; - /** * Constructs the object. * @@ -74,37 +64,6 @@ public class AaiCustomQueryOperation extends HttpOperation { super(params, config, String.class, PROPERTY_NAMES); } - /** - * 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; - } - - /** - * Queries the vserver, if necessary. - */ - @Override - protected CompletableFuture startPreprocessorAsync() { - if (params.isPreprocessed()) { - 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(); - - return params.getContext().obtain(AaiGetTenantOperation.getKey(vserver), tenantParams); - } - @Override public void generateSubRequestId(int attempt) { setSubRequestId(String.valueOf(attempt)); @@ -162,24 +121,7 @@ public class AaiCustomQueryOperation extends HttpOperation { * @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"); - } - - 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 resourceLink; + return getRequiredProperty(OperationProperties.AAI_VSERVER_LINK, "vserver link"); } @Override @@ -199,19 +141,4 @@ public class AaiCustomQueryOperation extends HttpOperation { return outcome; } - - /** - * Injects the response into the context. - */ - @Override - protected CompletableFuture postProcessResponse(OperationOutcome outcome, String url, - Response rawResponse, String response) { - - if (params.getContext() != null) { - logger.info("{}: caching response for {}", getFullName(), params.getRequestId()); - params.getContext().setProperty(AaiCqResponse.CONTEXT_KEY, new AaiCqResponse(response)); - } - - return super.postProcessResponse(outcome, url, rawResponse, response); - } } 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 3fb978d88..a07722383 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 @@ -23,18 +23,13 @@ package org.onap.policy.controlloop.actor.aai; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.concurrent.CompletableFuture; import javax.ws.rs.client.Invocation.Builder; 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; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Superclass of A&AI operators that use "get" to perform their request and store their @@ -42,19 +37,10 @@ import org.slf4j.LoggerFactory; * which they are stored is ${actor}.${operation}.${targetEntity}. */ public class AaiGetOperation extends HttpOperation { - private static final Logger logger = LoggerFactory.getLogger(AaiGetOperation.class); - public static final int DEFAULT_RETRY = 3; private static final List PROPERTY_NAMES = List.of(OperationProperties.AAI_TARGET_ENTITY); - - /** - * Responses that are retrieved from A&AI are placed in the operation context under - * the name "${propertyPrefix}.${targetEntity}". - */ - private final String propertyPrefix; - /** * Constructs the object. * @@ -63,7 +49,6 @@ public class AaiGetOperation extends HttpOperation { */ public AaiGetOperation(ControlLoopOperationParams params, HttpConfig config) { super(params, config, StandardCoderObject.class, PROPERTY_NAMES); - this.propertyPrefix = getFullName() + "."; } @Override @@ -107,22 +92,6 @@ public class AaiGetOperation extends HttpOperation { return AaiUtil.makeHeaders(params); } - /** - * Injects the response into the context. - */ - @Override - protected CompletableFuture postProcessResponse(OperationOutcome outcome, String url, - Response rawResponse, StandardCoderObject response) { - - if (params.getContext() != null) { - String entity = getTargetEntity(); - logger.info("{}: caching response of {} for {}", getFullName(), entity, params.getRequestId()); - params.getContext().setProperty(propertyPrefix + entity, response); - } - - return super.postProcessResponse(outcome, url, rawResponse, response); - } - /** * Provides a default retry value, if none specified. */ -- cgit 1.2.3-korg