aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actorServiceProvider/src/main
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/actorServiceProvider/src/main
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/actorServiceProvider/src/main')
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/Operation.java17
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationProperties.java44
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java44
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java19
4 files changed, 80 insertions, 44 deletions
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/Operation.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/Operation.java
index dfa086595..2c63e98ee 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/Operation.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/Operation.java
@@ -51,6 +51,15 @@ public interface Operation {
List<String> getPropertyNames();
/**
+ * Determines if a property has been assigned for the operation.
+ *
+ * @param name property name
+ * @return {@code true} if the given property has been assigned for the operation,
+ * {@code false} otherwise
+ */
+ public boolean containsProperty(String name);
+
+ /**
* Sets a property.
*
* @param name property name
@@ -59,6 +68,14 @@ public interface Operation {
public void setProperty(String name, Object value);
/**
+ * Gets a property's value.
+ *
+ * @param name name of the property of interest
+ * @return the property's value, or {@code null} if it has no value
+ */
+ public <T> T getProperty(String name);
+
+ /**
* Called by enforcement PDP engine to start the operation. As part of the operation,
* it invokes the "start" and "complete" call-backs found within the parameters.
*
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationProperties.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationProperties.java
index c36b61e8b..718daedb1 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationProperties.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationProperties.java
@@ -23,6 +23,9 @@ package org.onap.policy.controlloop.actorserviceprovider;
/**
* Names of properties needed by the Actors defined within this repo. Note: this is not
* exhaustive, as additional property names may be returned by company-defined Actors.
+ * <p/>
+ * Note: any time a property is added, applications using the actors must be updated to
+ * provide the property's value when requested.
*/
public class OperationProperties {
@@ -43,6 +46,23 @@ public class OperationProperties {
public static final String AAI_DEFAULT_TENANT = "AAI/defaultTenant";
/**
+ * A&AI PNF. Obtained as follows:
+ * <ol>
+ * <li>using the target entity, invoke AaiGetPnfOperation</li>
+ * </ol>
+ */
+ public static final String AAI_PNF = "AAI/pnf";
+
+ /**
+ * A&AI VNF id for the target resource ID. Obtained as follows:
+ * <ol>
+ * <li>using the target resource ID, invoke the custom query
+ * getGenericVnfByModelInvariantId() method to get the generic VNF</li>
+ * </ol>
+ */
+ public static final String AAI_RESOURCE_VNF = "AAI/resourceId/vnf";
+
+ /**
* A&AI Service instance. Obtained as follows:
* <ol>
* <li>invoke the custom query getServiceInstance() method</li>
@@ -60,6 +80,13 @@ public class OperationProperties {
public static final String AAI_SERVICE_MODEL = "AAI/service/model";
/**
+ * A&AI Target Entity. This is a String that can typically be found in the enrichment
+ * data, depending on the Target type. Sometimes, however, it must be retrieved via an
+ * A&AI query.
+ */
+ public static final String AAI_TARGET_ENTITY = "AAI/targetEntity";
+
+ /**
* A&AI VNF. Obtained as follows:
* <ol>
* <li>using the target model invariant ID, invoke the custom query
@@ -83,23 +110,6 @@ public class OperationProperties {
public static final String AAI_VNF_MODEL = "AAI/vnf/model";
/**
- * A&AI VNF id for the target resource ID. Obtained as follows:
- * <ol>
- * <li>using the target resource ID, invoke the custom query
- * getGenericVnfByModelInvariantId() method to get the generic VNF</li>
- * </ol>
- */
- public static final String AAI_RESOURCE_VNF = "AAI/resourceId/vnf";
-
- /**
- * A&AI PNF. Obtained as follows:
- * <ol>
- * <li>using the target entity, invoke AaiGetPnfOperation</li>
- * </ol>
- */
- public static final String AAI_PNF = "AAI/pnf";
-
- /**
* A&AI link to the vserver. Obtained as follows:
* <ol>
* <li>using the vserver name from the enrichment data, perform an A&AI tenant
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java
index 0aa112234..b5cc15e19 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java
@@ -53,6 +53,7 @@ import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.actorserviceprovider.CallbackManager;
import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.OperatorConfig;
import org.onap.policy.controlloop.actorserviceprovider.pipeline.PipelineControllerFuture;
@@ -139,34 +140,19 @@ public abstract class OperationPartial implements Operation {
return params.getOperation();
}
- /**
- * Determines if a property has been assigned for the operation.
- *
- * @param name property name
- * @return {@code true} if the given property has been assigned for the operation,
- * {@code false} otherwise
- */
+ @Override
public boolean containsProperty(String name) {
return properties.containsKey(name);
}
- /**
- * Sets a property.
- *
- * @param name property name
- * @param value new value
- */
+ @Override
public void setProperty(String name, Object value) {
+ logger.info("{}: set property {}={}", getFullName(), name, value);
properties.put(name, value);
}
- /**
- * Gets a property's value.
- *
- * @param name name of the property of interest
- * @return the property's value, or {@code null} if it has no value
- */
@SuppressWarnings("unchecked")
+ @Override
public <T> T getProperty(String name) {
return (T) properties.get(name);
}
@@ -230,7 +216,7 @@ public abstract class OperationPartial implements Operation {
// propagate "stop" to the callbacks
controller.add(callbacks);
- final OperationOutcome outcome2 = params.makeOutcome();
+ final OperationOutcome outcome2 = params.makeOutcome(getTargetEntity());
// TODO need a FAILURE_MISSING_DATA (e.g., A&AI)
@@ -304,7 +290,7 @@ public abstract class OperationPartial implements Operation {
Map<String, Object> guard = new LinkedHashMap<>();
guard.put("actor", params.getActor());
guard.put("operation", params.getOperation());
- guard.put("target", params.getTargetEntity());
+ guard.put("target", getTargetEntity());
guard.put("requestId", params.getRequestId());
String clname = params.getContext().getEvent().getClosedLoopControlName();
@@ -358,7 +344,7 @@ public abstract class OperationPartial implements Operation {
logger.info("{}: start operation attempt {} for {}", getFullName(), attempt, params.getRequestId());
final Executor executor = params.getExecutor();
- final OperationOutcome outcome = params.makeOutcome();
+ final OperationOutcome outcome = params.makeOutcome(getTargetEntity());
final CallbackManager callbacks = new CallbackManager();
// this operation attempt gets its own controller
@@ -489,7 +475,7 @@ public abstract class OperationPartial implements Operation {
outcome = origOutcome;
} else {
logger.warn("{}: null outcome; treating as a failure for {}", getFullName(), params.getRequestId());
- outcome = this.setOutcome(params.makeOutcome(), PolicyResult.FAILURE);
+ outcome = this.setOutcome(params.makeOutcome(getTargetEntity()), PolicyResult.FAILURE);
}
// ensure correct actor/operation
@@ -588,7 +574,7 @@ public abstract class OperationPartial implements Operation {
private Function<Throwable, OperationOutcome> fromException(String type) {
return thrown -> {
- OperationOutcome outcome = params.makeOutcome();
+ OperationOutcome outcome = params.makeOutcome(getTargetEntity());
if (thrown instanceof CancellationException || thrown.getCause() instanceof CancellationException) {
// do not include exception in the message, as it just clutters the log
@@ -1107,6 +1093,16 @@ public abstract class OperationPartial implements Operation {
}
/**
+ * Gets the target entity, first trying the properties and then the parameters.
+ *
+ * @return the target entity
+ */
+ protected String getTargetEntity() {
+ String targetEntity = getProperty(OperationProperties.AAI_TARGET_ENTITY);
+ return (targetEntity != null ? targetEntity : params.getTargetEntity());
+ }
+
+ /**
* Gets the operation timeout.
*
* @param timeoutSec timeout, in seconds, extracted from the parameters, or
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java
index d0b7c26a8..66573f38a 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java
@@ -69,6 +69,7 @@ public class ControlLoopOperationParams {
/**
* Event for which the operation applies.
*/
+ // TODO to be removed
private ControlLoopEventContext context;
/**
@@ -106,15 +107,15 @@ public class ControlLoopOperationParams {
private Integer retry;
/**
- * The entity's target information. May be {@code null}, depending on the requirement
- * of the operation to be invoked.
+ * The Target information, extracted from the Policy. May be {@code null}, depending
+ * on the requirement of the operation to be invoked.
*/
private Target target;
/**
* Target entity.
*/
- @NotNull
+ // TODO to be removed
private String targetEntity;
/**
@@ -193,7 +194,19 @@ public class ControlLoopOperationParams {
*
* @return a new operation outcome
*/
+ // TODO to be removed
public OperationOutcome makeOutcome() {
+ return makeOutcome(getTargetEntity());
+ }
+
+ /**
+ * Makes an operation outcome, populating it from the parameters.
+ *
+ * @param targetEntity the target entity
+ *
+ * @return a new operation outcome
+ */
+ public OperationOutcome makeOutcome(String targetEntity) {
OperationOutcome outcome = new OperationOutcome();
outcome.setActor(getActor());
outcome.setOperation(getOperation());