aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.vfc/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.vfc/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.vfc/src/main')
-rw-r--r--models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java38
1 files changed, 28 insertions, 10 deletions
diff --git a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java
index 8bd4630d6..bb23fdcc5 100644
--- a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java
+++ b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java
@@ -26,7 +26,6 @@ import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
-import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
@@ -48,7 +47,7 @@ public abstract class VfcOperation extends HttpOperation<VfcResponse> {
// @formatter:off
private static final List<String> PROPERTY_NAMES = List.of(
- OperationProperties.ENRICHMENT_SERVICE_INSTANCE_ID,
+ OperationProperties.ENRICHMENT_SERVICE_ID,
OperationProperties.ENRICHMENT_VSERVER_ID,
OperationProperties.ENRICHMENT_VSERVER_NAME,
OperationProperties.ENRICHMENT_GENERIC_VNF_ID);
@@ -133,7 +132,7 @@ public abstract class VfcOperation extends HttpOperation<VfcResponse> {
*/
protected String getRequestState(VfcResponse response) {
if (response == null || response.getResponseDescriptor() == null
- || StringUtils.isBlank(response.getResponseDescriptor().getStatus())) {
+ || StringUtils.isBlank(response.getResponseDescriptor().getStatus())) {
return null;
}
return response.getResponseDescriptor().getStatus();
@@ -153,7 +152,7 @@ public abstract class VfcOperation extends HttpOperation<VfcResponse> {
*/
@Override
public OperationOutcome setOutcome(OperationOutcome outcome, PolicyResult result, Response rawResponse,
- VfcResponse response) {
+ VfcResponse response) {
// set default result and message
setOutcome(outcome, result);
@@ -171,14 +170,16 @@ public abstract class VfcOperation extends HttpOperation<VfcResponse> {
* @return request
*/
protected VfcRequest constructVfcRequest() {
- ControlLoopEventContext context = params.getContext();
- String serviceInstance = context.getEnrichment().get("service-instance.service-instance-id");
- String vmId = context.getEnrichment().get("vserver.vserver-id");
- String vmName = context.getEnrichment().get("vserver.vserver-name");
+ final String serviceInstance = getOptProperty(OperationProperties.ENRICHMENT_SERVICE_ID,
+ "service-instance.service-instance-id");
+ final String vmId = getOptProperty(OperationProperties.ENRICHMENT_VSERVER_ID, "vserver.vserver-id");
+ final String vmName = getOptProperty(OperationProperties.ENRICHMENT_VSERVER_NAME, "vserver.vserver-name");
+ final String vnfId = getOptProperty(OperationProperties.ENRICHMENT_GENERIC_VNF_ID, GENERIC_VNF_ID);
if (StringUtils.isBlank(serviceInstance) || StringUtils.isBlank(vmId) || StringUtils.isBlank(vmName)) {
+ // original code did not check the VNF id, so we won't check it either
throw new IllegalArgumentException(
- "Cannot extract enrichment data for service instance, server id, or server name.");
+ "Cannot extract enrichment data for service instance, server id, or server name.");
}
VfcHealActionVmInfo vmActionInfo = new VfcHealActionVmInfo();
@@ -190,7 +191,7 @@ public abstract class VfcOperation extends HttpOperation<VfcResponse> {
additionalParams.setActionInfo(vmActionInfo);
VfcHealRequest healRequest = new VfcHealRequest();
- healRequest.setVnfInstanceId(params.getContext().getEnrichment().get(GENERIC_VNF_ID));
+ healRequest.setVnfInstanceId(vnfId);
healRequest.setCause(getName());
healRequest.setAdditionalParams(additionalParams);
@@ -201,4 +202,21 @@ public abstract class VfcOperation extends HttpOperation<VfcResponse> {
return request;
}
+
+ /**
+ * 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);
+ }
}