diff options
author | Jim Hahn <jrh3@att.com> | 2020-08-21 13:43:08 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-10-27 14:55:15 -0400 |
commit | 19ef8b24a98c09a349e6ae7309f535a0135463f6 (patch) | |
tree | d988e5a58865ae6f3a38dcb31e4f195f18e59946 /models-interactions/model-actors/actor.cds/src/main | |
parent | 6b29d2c19e288148171db0c0e446e18dcd46effd (diff) |
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 <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.cds/src/main')
-rw-r--r-- | models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java | 122 |
1 files changed, 12 insertions, 110 deletions
diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java index c04453b7c..44d51813a 100644 --- a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java +++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java @@ -40,12 +40,8 @@ import org.onap.aai.domain.yang.ServiceInstance; import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers; import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader; import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput; -import org.onap.policy.aai.AaiConstants; -import org.onap.policy.aai.AaiCqResponse; import org.onap.policy.cds.client.CdsProcessorGrpcClient; import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.controlloop.actor.aai.AaiCustomQueryOperation; -import org.onap.policy.controlloop.actor.aai.AaiGetPnfOperation; import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants; import org.onap.policy.controlloop.actor.cds.request.CdsActionRequest; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; @@ -77,11 +73,6 @@ public class GrpcOperation extends OperationPartial { private final GrpcConfig config; /** - * Function to request the A&AI data appropriate to the target type. - */ - private final Supplier<CompletableFuture<OperationOutcome>> aaiRequestor; - - /** * Function to convert the A&AI data associated with the target type. */ private final Supplier<Map<String, String>> aaiConverter; @@ -112,11 +103,9 @@ public class GrpcOperation extends OperationPartial { this.config = config; if (TargetType.PNF.equals(params.getTargetType())) { - aaiRequestor = this::getPnf; aaiConverter = this::convertPnfToAaiProperties; } else { - aaiRequestor = this::getCq; - aaiConverter = this::convertCqToAaiProperties; + aaiConverter = this::convertVnfToAaiProperties; } } @@ -134,57 +123,20 @@ public class GrpcOperation extends OperationPartial { } /** - * Ensures that A&AI query has been performed, and runs the guard. - */ - @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); - } - - /** - * Requests the A&AI PNF data. - * - * @return a future to get the PNF data - */ - private CompletableFuture<OperationOutcome> getPnf() { - ControlLoopOperationParams pnfParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME) - .operation(AaiGetPnfOperation.NAME).payload(null).retry(null).timeoutSec(null).build(); - - return params.getContext().obtain(AaiGetPnfOperation.getKey(params.getTargetEntity()), pnfParams); - } - - /** - * Requests the A&AI Custom Query data. - * - * @return a future to get the custom query data - */ - private CompletableFuture<OperationOutcome> getCq() { - ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME) - .operation(AaiCustomQueryOperation.NAME).payload(null).retry(null).timeoutSec(null).build(); - - return params.getContext().obtain(AaiCqResponse.CONTEXT_KEY, cqParams); - } - - /** * Converts the A&AI PNF data to a map suitable for passing via the "aaiProperties" * field in the CDS request. * * @return a map of the PNF data */ private Map<String, String> convertPnfToAaiProperties() { - Map<String, String> result = this.getProperty(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES); + Map<String, String> result = getProperty(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES); if (result != null) { return result; } // convert PNF data to a Map - Map<String, Object> source = Util.translateToMap(getFullName(), getPnfData()); + Object pnfData = getRequiredProperty(OperationProperties.AAI_PNF, "PNF"); + Map<String, Object> source = Util.translateToMap(getFullName(), pnfData); result = new LinkedHashMap<>(); @@ -196,33 +148,13 @@ public class GrpcOperation extends OperationPartial { } /** - * Gets the PNF from the operation properties, if it exists, or from the context - * properties otherwise. - * - * @return the PNF item - */ - protected Object getPnfData() { - Object pnf = getProperty(OperationProperties.AAI_PNF); - if (pnf != null) { - return pnf; - } - - pnf = params.getContext().getProperty(AaiGetPnfOperation.getKey(params.getTargetEntity())); - if (pnf == null) { - throw new IllegalArgumentException("missing PNF data"); - } - - return pnf; - } - - /** - * Converts the A&AI Custom Query data to a map suitable for passing via the + * Converts the A&AI VNF data to a map suitable for passing via the * "aaiProperties" field in the CDS request. * - * @return a map of the custom query data + * @return a map of the VNF data */ - private Map<String, String> convertCqToAaiProperties() { - Map<String, String> result = this.getProperty(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES); + private Map<String, String> convertVnfToAaiProperties() { + Map<String, String> result = getProperty(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES); if (result != null) { return result; } @@ -236,35 +168,13 @@ public class GrpcOperation extends OperationPartial { } protected String getServiceInstanceId() { - ServiceInstance serviceInstance = getProperty(OperationProperties.AAI_SERVICE); - if (serviceInstance != null) { - return serviceInstance.getServiceInstanceId(); - } - - AaiCqResponse aaicq = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY); - - serviceInstance = aaicq.getServiceInstance(); - if (serviceInstance == null) { - throw new IllegalArgumentException("Target service instance could not be found"); - } - + ServiceInstance serviceInstance = + getRequiredProperty(OperationProperties.AAI_SERVICE, "Target service instance"); return serviceInstance.getServiceInstanceId(); } protected String getVnfId() { - GenericVnf genericVnf = getProperty(OperationProperties.AAI_RESOURCE_VNF); - if (genericVnf != null) { - return genericVnf.getVnfId(); - } - - AaiCqResponse aaicq = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY); - - genericVnf = aaicq.getGenericVnfByModelInvariantId(params.getTargetEntityIds() - .get(ControlLoopOperationParams.PARAMS_ENTITY_RESOURCEID)); - if (genericVnf == null) { - throw new IllegalArgumentException("Target generic vnf could not be found"); - } - + GenericVnf genericVnf = getRequiredProperty(OperationProperties.AAI_RESOURCE_VNF, "Target generic vnf"); return genericVnf.getVnfId(); } @@ -345,7 +255,7 @@ public class GrpcOperation extends OperationPartial { request.setAaiProperties(aaiConverter.get()); // Inject any additional event parameters that may be present in the onset event - Map<String, String> additionalParams = getAdditionalEventParams(); + Map<String, String> additionalParams = getProperty(OperationProperties.EVENT_ADDITIONAL_PARAMS); if (additionalParams != null) { request.setAdditionalEventParams(additionalParams); } @@ -375,14 +285,6 @@ public class GrpcOperation extends OperationPartial { .setPayload(struct.build()).build(); } - protected Map<String, String> getAdditionalEventParams() { - if (containsProperty(OperationProperties.EVENT_ADDITIONAL_PARAMS)) { - return getProperty(OperationProperties.EVENT_ADDITIONAL_PARAMS); - } - - return params.getContext().getEvent().getAdditionalEventParams(); - } - private Map<String, String> convertPayloadMap(Map<String, Object> payload) { Map<String, String> convertedPayload = new HashMap<>(); for (Entry<String, Object> entry : payload.entrySet()) { |