summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.cds/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-04-17 15:09:21 -0400
committerJim Hahn <jrh3@att.com>2020-04-17 19:31:23 -0400
commite887a0c6c415a00888e17d1bbfe4acf548a2cfa5 (patch)
tree1cccd49d453eb1cf94b0f8f7fd7d14eae02404d9 /models-interactions/model-actors/actor.cds/src/main
parentbed21af59885a954e3facf7226c4678f4b69b153 (diff)
Add PNF support to new CDS actor
Made the following updates: - added new A&AI get-PNF Operation by refactoring AaiGetOperation, separating out Tenant and PNF operations - added PNF support to the CDS actor - added logging to the CDS Handler - added get-pnf to the A&AI simulator Issue-ID: POLICY-2505 Change-Id: Iff140e7c864f762790d8e2ecaba62c161c859e6e 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.java109
1 files changed, 105 insertions, 4 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 702802d48..820f4de34 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
@@ -26,11 +26,15 @@ import com.google.protobuf.Struct;
import com.google.protobuf.Struct.Builder;
import com.google.protobuf.util.JsonFormat;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
+import java.util.function.Supplier;
import lombok.Getter;
+import org.onap.aai.domain.yang.GenericVnf;
+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;
@@ -38,12 +42,16 @@ 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.common.utils.coder.StandardCoderObject;
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;
+import org.onap.policy.controlloop.actorserviceprovider.Util;
import org.onap.policy.controlloop.actorserviceprovider.impl.OperationPartial;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.policy.TargetType;
/**
* Operation that uses gRPC to send request to CDS.
@@ -54,6 +62,10 @@ public class GrpcOperation extends OperationPartial {
public static final String NAME = "any";
+ private static final String AAI_PNF_PREFIX = "pnf.";
+ private static final String AAI_VNF_ID_KEY = "generic-vnf.vnf-id";
+ private static final String AAI_SERVICE_INSTANCE_ID_KEY = "service-instance.service-instance-id";
+
private CdsProcessorGrpcClient client;
/**
@@ -62,6 +74,16 @@ 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;
+
+ /**
* Constructs the object.
*
* @param params operation parameters
@@ -70,6 +92,14 @@ public class GrpcOperation extends OperationPartial {
public GrpcOperation(ControlLoopOperationParams params, GrpcConfig config) {
super(params, config);
this.config = config;
+
+ if (TargetType.PNF.equals(params.getTarget().getType())) {
+ aaiRequestor = this::getPnf;
+ aaiConverter = this::convertPnfToAaiProperties;
+ } else {
+ aaiRequestor = this::getCq;
+ aaiConverter = this::convertCqToAaiProperties;
+ }
}
/**
@@ -81,16 +111,84 @@ public class GrpcOperation extends OperationPartial {
}
/**
- * Ensures that A&AI customer query has been performed.
+ * Ensures that A&AI query has been performed, and runs the guard.
*/
@Override
@SuppressWarnings("unchecked")
protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
+ // 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();
- // run Custom Query and Guard, in parallel
- return allOf(() -> params.getContext().obtain(AaiCqResponse.CONTEXT_KEY, cqParams), this::startGuardAsync);
+ 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() {
+ // convert PNF data to a Map
+ StandardCoderObject pnf = params.getContext().getProperty(AaiGetPnfOperation.getKey(params.getTargetEntity()));
+ Map<String, Object> source = Util.translateToMap(getFullName(), pnf);
+
+ Map<String, String> result = new LinkedHashMap<>();
+
+ for (Entry<String, Object> ent : source.entrySet()) {
+ result.put(AAI_PNF_PREFIX + ent.getKey(), ent.getValue().toString());
+ }
+
+ return result;
+ }
+
+ /**
+ * Converts the A&AI Custom Query data to a map suitable for passing via the
+ * "aaiProperties" field in the CDS request.
+ *
+ * @return a map of the custom query data
+ */
+ private Map<String, String> convertCqToAaiProperties() {
+ AaiCqResponse aaicq = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY);
+
+ Map<String, String> result = new LinkedHashMap<>();
+
+ ServiceInstance serviceInstance = aaicq.getServiceInstance();
+ if (serviceInstance == null) {
+ throw new IllegalArgumentException("Target service instance could not be found");
+ }
+
+ GenericVnf genericVnf = aaicq.getGenericVnfByModelInvariantId(params.getTarget().getResourceID());
+ if (genericVnf == null) {
+ throw new IllegalArgumentException("Target generic vnf could not be found");
+ }
+
+ result.put(AAI_SERVICE_INSTANCE_ID_KEY, serviceInstance.getServiceInstanceId());
+ result.put(AAI_VNF_ID_KEY, genericVnf.getVnfId());
+
+ return result;
}
@Override
@@ -152,7 +250,10 @@ public class GrpcOperation extends OperationPartial {
// implementation to inject whatever AAI parameters are of interest to them.
// E.g. For vFW usecase El-Alto inject service-instance-id, generic-vnf-id as
// needed by CDS.
- request.setAaiProperties(params.getContext().getEnrichment());
+ //
+ // Note: that is a future enhancement. For now, the actor is hard-coded to
+ // use the A&AI query result specific to the target type
+ request.setAaiProperties(aaiConverter.get());
// Inject any additional event parameters that may be present in the onset event
if (params.getContext().getEvent().getAdditionalEventParams() != null) {