aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.so/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'models-interactions/model-actors/actor.so/src/main')
-rw-r--r--models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoConstants.java2
-rw-r--r--models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java87
-rw-r--r--models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java19
3 files changed, 74 insertions, 34 deletions
diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoConstants.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoConstants.java
index faafb43a6..b238671b4 100644
--- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoConstants.java
+++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoConstants.java
@@ -21,7 +21,7 @@
package org.onap.policy.controlloop.actor.so;
public class SoConstants {
- public static final String CONTEXT_KEY_VF_COUNT = "SO.VFCount";
+ public static final String VF_COUNT_PREFIX = "SO.VFCount";
private SoConstants() {
// do nothing
diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java
index 53fb973a5..41ecd07a0 100644
--- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java
+++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java
@@ -23,6 +23,7 @@ package org.onap.policy.controlloop.actor.so;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
@@ -32,6 +33,7 @@ import org.onap.aai.domain.yang.CloudRegion;
import org.onap.aai.domain.yang.GenericVnf;
import org.onap.aai.domain.yang.ServiceInstance;
import org.onap.aai.domain.yang.Tenant;
+import org.onap.policy.aai.AaiConstants;
import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
@@ -71,6 +73,13 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
private final SoConfig config;
+ // values extracted from the parameter Target
+ private final String modelCustomizationId;
+ private final String modelInvariantId;
+ private final String modelVersionId;
+
+ private final String vfCountKey;
+
/**
* Number of "get" requests issued so far, on the current operation attempt.
*/
@@ -87,6 +96,15 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
public SoOperation(ControlLoopOperationParams params, HttpConfig config) {
super(params, config, SoResponse.class);
this.config = (SoConfig) config;
+
+ verifyNotNull("Target information", params.getTarget());
+
+ this.modelCustomizationId = params.getTarget().getModelCustomizationId();
+ this.modelInvariantId = params.getTarget().getModelInvariantId();
+ this.modelVersionId = params.getTarget().getModelVersionId();
+
+ vfCountKey = SoConstants.VF_COUNT_PREFIX + "[" + modelCustomizationId + "][" + modelInvariantId + "]["
+ + modelVersionId + "]";
}
/**
@@ -101,10 +119,9 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
* the VF count from the custom query.
*/
protected void validateTarget() {
- verifyNotNull("Target information", params.getTarget());
- verifyNotNull("model-customization-id", params.getTarget().getModelCustomizationId());
- verifyNotNull("model-invariant-id", params.getTarget().getModelInvariantId());
- verifyNotNull("model-version-id", params.getTarget().getModelVersionId());
+ verifyNotNull("model-customization-id", modelCustomizationId);
+ verifyNotNull("model-invariant-id", modelInvariantId);
+ verifyNotNull("model-version-id", modelVersionId);
}
private void verifyNotNull(String type, Object value) {
@@ -122,21 +139,47 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
}
/**
- * Stores the VF count and then runs the guard.
+ * Gets the VF Count.
*
- * @return a future to cancel or await the guard response
+ * @return a future to cancel or await the VF Count
*/
- protected CompletableFuture<OperationOutcome> storeVfCountRunGuard() {
- String custId = params.getTarget().getModelCustomizationId();
- String invId = params.getTarget().getModelInvariantId();
- String verId = params.getTarget().getModelVersionId();
+ @SuppressWarnings("unchecked")
+ protected CompletableFuture<OperationOutcome> obtainVfCount() {
+ if (params.getContext().contains(vfCountKey)) {
+ // already have the VF count
+ return null;
+ }
- AaiCqResponse cq = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY);
- int vfcount = cq.getVfModuleCount(custId, invId, verId);
+ // need custom query from which to extract the VF count
+ ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
+ .operation(AaiCqResponse.OPERATION).payload(null).retry(null).timeoutSec(null).build();
- params.getContext().setProperty(SoConstants.CONTEXT_KEY_VF_COUNT, vfcount);
+ // run Custom Query and then extract the VF count
+ return sequence(() -> params.getContext().obtain(AaiCqResponse.CONTEXT_KEY, cqParams), this::storeVfCount);
+ }
- return startGuardAsync();
+ /**
+ * Stores the VF count.
+ *
+ * @return {@code null}
+ */
+ private CompletableFuture<OperationOutcome> storeVfCount() {
+ if (!params.getContext().contains(vfCountKey)) {
+ AaiCqResponse cq = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY);
+ int vfcount = cq.getVfModuleCount(modelCustomizationId, modelInvariantId, modelVersionId);
+
+ params.getContext().setProperty(vfCountKey, vfcount);
+ }
+
+ return null;
+ }
+
+ protected int getVfCount() {
+ return params.getContext().getProperty(vfCountKey);
+ }
+
+ protected void setVfCount(int vfCount) {
+ params.getContext().setProperty(vfCountKey, vfCount);
}
/**
@@ -289,18 +332,18 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
/**
* Builds the request parameters from the policy payload.
*/
- protected SoRequestParameters buildRequestParameters() {
+ protected Optional<SoRequestParameters> buildRequestParameters() {
if (params.getPayload() == null) {
- return null;
+ return Optional.empty();
}
Object data = params.getPayload().get(REQ_PARAM_NM);
if (data == null) {
- return null;
+ return Optional.empty();
}
try {
- return coder.decode(data.toString(), SoRequestParameters.class);
+ return Optional.of(coder.decode(data.toString(), SoRequestParameters.class));
} catch (CoderException e) {
throw new IllegalArgumentException("invalid payload value: " + REQ_PARAM_NM);
}
@@ -309,20 +352,20 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
/**
* Builds the configuration parameters from the policy payload.
*/
- protected List<Map<String, String>> buildConfigurationParameters() {
+ protected Optional<List<Map<String, String>>> buildConfigurationParameters() {
if (params.getPayload() == null) {
- return null;
+ return Optional.empty();
}
Object data = params.getPayload().get(CONFIG_PARAM_NM);
if (data == null) {
- return null;
+ return Optional.empty();
}
try {
@SuppressWarnings("unchecked")
List<Map<String, String>> result = coder.decode(data.toString(), ArrayList.class);
- return result;
+ return Optional.of(result);
} catch (CoderException | RuntimeException e) {
throw new IllegalArgumentException("invalid payload value: " + CONFIG_PARAM_NM);
}
diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java
index a0a1ec031..fb8fe6072 100644
--- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java
+++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java
@@ -77,27 +77,25 @@ public class VfModuleCreate extends SoOperation {
@Override
@SuppressWarnings("unchecked")
protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
- if (params.getContext().contains(SoConstants.CONTEXT_KEY_VF_COUNT)) {
- return startGuardAsync();
- }
// need the VF count
ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
.operation(AaiCqResponse.OPERATION).payload(null).retry(null).timeoutSec(null).build();
// run Custom Query, extract the VF count, and then run the Guard
+
+ // @formatter:off
return sequence(() -> params.getContext().obtain(AaiCqResponse.CONTEXT_KEY, cqParams),
- this::storeVfCountRunGuard);
+ this::obtainVfCount, this::startGuardAsync);
+ // @formatter:on
}
@Override
protected Map<String, Object> makeGuardPayload() {
Map<String, Object> payload = super.makeGuardPayload();
- int vfcount = params.getContext().getProperty(SoConstants.CONTEXT_KEY_VF_COUNT);
-
// run guard with the proposed vf count
- payload.put(PAYLOAD_KEY_VF_COUNT, vfcount + 1);
+ payload.put(PAYLOAD_KEY_VF_COUNT, getVfCount() + 1);
return payload;
}
@@ -127,8 +125,7 @@ public class VfModuleCreate extends SoOperation {
*/
@Override
protected void successfulCompletion() {
- int vfcount = params.getContext().getProperty(SoConstants.CONTEXT_KEY_VF_COUNT);
- params.getContext().setProperty(SoConstants.CONTEXT_KEY_VF_COUNT, vfcount + 1);
+ setVfCount(getVfCount() + 1);
}
/**
@@ -205,10 +202,10 @@ public class VfModuleCreate extends SoOperation {
request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement2);
// Request Parameters
- request.getRequestDetails().setRequestParameters(buildRequestParameters());
+ buildRequestParameters().ifPresent(request.getRequestDetails()::setRequestParameters);
// Configuration Parameters
- request.getRequestDetails().setConfigurationParameters(buildConfigurationParameters());
+ buildConfigurationParameters().ifPresent(request.getRequestDetails()::setConfigurationParameters);
// compute the path
String path = "/serviceInstantiation/v7/serviceInstances/" + vnfServiceItem.getServiceInstanceId() + "/vnfs/"