summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.sdnc/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.sdnc/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.sdnc/src/main')
-rw-r--r--models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java20
-rw-r--r--models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java7
-rw-r--r--models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java17
3 files changed, 29 insertions, 15 deletions
diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java
index 434b3b985..d2a153641 100644
--- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java
+++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java
@@ -23,7 +23,6 @@ package org.onap.policy.controlloop.actor.sdnc;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
-import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
import org.onap.policy.sdnc.SdncHealRequest;
@@ -38,15 +37,18 @@ import org.onap.policy.sdnc.SdncHealVnfInfo;
import org.onap.policy.sdnc.SdncRequest;
public class BandwidthOnDemandOperation extends SdncOperation {
+
public static final String NAME = "BandwidthOnDemand";
// fields in the enrichment data
public static final String SERVICE_ID_KEY = "service-instance.service-instance-id";
+ public static final String BANDWIDTH = "bandwidth";
+ public static final String BANDWIDTH_CHANGE_TIME = "bandwidth-change-time";
public static final String VNF_ID = "vnfId";
// @formatter:off
private static final List<String> PROPERTY_NAMES = List.of(
- OperationProperties.ENRICHMENT_SERVICE_INSTANCE_ID,
+ OperationProperties.ENRICHMENT_SERVICE_ID,
OperationProperties.ENRICHMENT_BANDWIDTH,
OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME,
OperationProperties.ENRICHMENT_VNF_ID);
@@ -64,20 +66,18 @@ public class BandwidthOnDemandOperation extends SdncOperation {
@Override
protected SdncRequest makeRequest(int attempt) {
- ControlLoopEventContext context = params.getContext();
-
- String serviceInstance = context.getEnrichment().get(SERVICE_ID_KEY);
+ String serviceInstance = getOptProperty(OperationProperties.ENRICHMENT_SERVICE_ID, SERVICE_ID_KEY);
if (StringUtils.isBlank(serviceInstance)) {
throw new IllegalArgumentException("missing enrichment data, " + SERVICE_ID_KEY);
}
SdncHealVfModuleParameter bandwidth = new SdncHealVfModuleParameter();
- bandwidth.setName("bandwidth");
- bandwidth.setValue(context.getEnrichment().get("bandwidth"));
+ bandwidth.setName(BANDWIDTH);
+ bandwidth.setValue(getOptProperty(OperationProperties.ENRICHMENT_BANDWIDTH, BANDWIDTH));
SdncHealVfModuleParameter timeStamp = new SdncHealVfModuleParameter();
- timeStamp.setName("bandwidth-change-time");
- timeStamp.setValue(context.getEnrichment().get("bandwidth-change-time"));
+ timeStamp.setName(BANDWIDTH_CHANGE_TIME);
+ timeStamp.setValue(getOptProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, BANDWIDTH_CHANGE_TIME));
SdncHealVfModuleParametersInfo vfParametersInfo = new SdncHealVfModuleParametersInfo();
vfParametersInfo.addParameters(bandwidth);
@@ -102,7 +102,7 @@ public class BandwidthOnDemandOperation extends SdncOperation {
request.setUrl("/" + getPath());
SdncHealVnfInfo vnfInfo = new SdncHealVnfInfo();
- vnfInfo.setVnfId(context.getEnrichment().get(VNF_ID));
+ vnfInfo.setVnfId(getOptProperty(OperationProperties.ENRICHMENT_VNF_ID, VNF_ID));
SdncHealVfModuleInfo vfModuleInfo = new SdncHealVfModuleInfo();
vfModuleInfo.setVfModuleId("");
diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java
index d26fad8c7..105a27601 100644
--- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java
+++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java
@@ -23,7 +23,6 @@ package org.onap.policy.controlloop.actor.sdnc;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
-import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
import org.onap.policy.sdnc.SdncHealNetworkInfo;
@@ -58,16 +57,14 @@ public class RerouteOperation extends SdncOperation {
@Override
protected SdncRequest makeRequest(int attempt) {
- ControlLoopEventContext context = params.getContext();
-
- String serviceInstance = context.getEnrichment().get(SERVICE_ID_KEY);
+ String serviceInstance = getOptProperty(OperationProperties.ENRICHMENT_SERVICE_ID, SERVICE_ID_KEY);
if (StringUtils.isBlank(serviceInstance)) {
throw new IllegalArgumentException("missing enrichment data, " + SERVICE_ID_KEY);
}
SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo();
serviceInfo.setServiceInstanceId(serviceInstance);
- String networkId = context.getEnrichment().get(NETWORK_ID_KEY);
+ String networkId = getOptProperty(OperationProperties.ENRICHMENT_NETWORK_ID, NETWORK_ID_KEY);
if (StringUtils.isBlank(networkId)) {
throw new IllegalArgumentException("missing enrichment data, " + NETWORK_ID_KEY);
}
diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java
index 4d8e35e71..defbcfbc9 100644
--- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java
+++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java
@@ -96,4 +96,21 @@ public abstract class SdncOperation extends HttpOperation<SdncResponse> {
protected boolean isSuccess(Response rawResponse, SdncResponse response) {
return response.getResponseOutput() != null && "200".equals(response.getResponseOutput().getResponseCode());
}
+
+ /**
+ * Gets an optional property, first checking the properties, then checking the
+ * enrichment data.
+ *
+ * @param propName property name
+ * @param enrichmentName property name within the enrichment data
+ * @return the property's value, or {@code null} if it is not found
+ */
+ protected String getOptProperty(String propName, String enrichmentName) {
+ if (containsProperty(propName)) {
+ // return the value, even if it's null
+ return getProperty(propName);
+ }
+
+ return params.getContext().getEnrichment().get(enrichmentName);
+ }
}