diff options
author | Jim Hahn <jrh3@att.com> | 2020-08-21 13:43:08 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-10-27 14:55:15 -0400 |
commit | 19ef8b24a98c09a349e6ae7309f535a0135463f6 (patch) | |
tree | d988e5a58865ae6f3a38dcb31e4f195f18e59946 /models-interactions/model-actors/actor.so/src/main | |
parent | 6b29d2c19e288148171db0c0e446e18dcd46effd (diff) |
Make Actors event-agnostic
Removed event and event-context code from the Actor code. Also removed
the preprocessing steps from the Actor code, giving the application
complete control over any preprocessing.
Also fixed a bug wherein the APPC actor was treating the
AAI_RESOURCE_VNF property as a String instead of as a GenericVnf.
Issue-ID: POLICY-2746-actor
Change-Id: Ibc05fe39ffedc0bc461abf10e6a960861ac70119
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.so/src/main')
3 files changed, 23 insertions, 204 deletions
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 ac25c841e..9020c0b35 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 @@ -29,8 +29,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Function; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.onap.aai.domain.yang.CloudRegion; @@ -38,8 +36,6 @@ import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.ModelVer; 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.gson.GsonMessageBodyHandler; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; @@ -67,7 +63,6 @@ import org.onap.policy.so.util.SoLocalDateTimeTypeAdapter; public abstract class SoOperation extends HttpOperation<SoResponse> { private static final Coder coder = new SoCoder(); - public static final String PAYLOAD_KEY_VF_COUNT = "vfCount"; public static final String FAILED = "FAILED"; public static final String COMPLETE = "COMPLETE"; public static final int SO_RESPONSE_CODE = 999; @@ -86,8 +81,6 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { private final String modelVersion; - private final String vfCountKey; - /** * Constructs the object. @@ -104,7 +97,6 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { this.modelVersionId = null; this.modelVersion = null; this.modelName = null; - this.vfCountKey = null; verifyNotNull("Target information", params.getTargetType()); } @@ -134,9 +126,6 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { this.modelName = targetEntityIds .get(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_NAME); - this.vfCountKey = SoConstants.VF_COUNT_PREFIX + "[" + modelCustomizationId + "][" + modelInvariantId + "][" - + modelVersionId + "]"; - verifyNotNull("Target information", params.getTargetType()); } @@ -147,8 +136,8 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { } /** - * Validates that the parameters contain the required target information to extract - * the VF count from the custom query. + * Validates that the parameters contain the required target information to construct + * the request. */ protected void validateTarget() { verifyNotNull(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_CUSTOMIZATION_ID, modelCustomizationId); @@ -158,69 +147,16 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { private void verifyNotNull(String type, Object value) { if (value == null) { - throw new IllegalArgumentException("missing " + type + " for guard payload"); + throw new IllegalArgumentException("missing Target." + type); } } - /** - * Starts the GUARD. - */ - @Override - protected CompletableFuture<OperationOutcome> startPreprocessorAsync() { - return startGuardAsync(); - } - - /** - * Gets the VF Count. - * - * @return a future to cancel or await the VF Count - */ - @SuppressWarnings("unchecked") - protected CompletableFuture<OperationOutcome> obtainVfCount() { - if (params.getContext().contains(vfCountKey)) { - // already have the VF count - return null; - } - - // 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(); - - // run Custom Query and then extract the VF count - return sequence(() -> params.getContext().obtain(AaiCqResponse.CONTEXT_KEY, cqParams), this::storeVfCount); - } - - /** - * 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() { - if (containsProperty(OperationProperties.DATA_VF_COUNT)) { - return getProperty(OperationProperties.DATA_VF_COUNT); - } - - return params.getContext().getProperty(vfCountKey); + return getRequiredProperty(OperationProperties.DATA_VF_COUNT, "VF Count"); } protected void setVfCount(int vfCount) { - if (containsProperty(OperationProperties.DATA_VF_COUNT)) { - setProperty(OperationProperties.DATA_VF_COUNT, vfCount); - return; - } - - params.getContext().setProperty(vfCountKey, vfCount); + setProperty(OperationProperties.DATA_VF_COUNT, vfCount); } @Override @@ -381,13 +317,12 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { } /** - * Construct cloudConfiguration for the SO requestDetails. Overridden for custom - * query. + * Construct cloudConfiguration for the SO requestDetails. * * @param tenantItem tenant item from A&AI named-query response * @return SO cloud configuration */ - protected SoCloudConfiguration constructCloudConfigurationCq(Tenant tenantItem, CloudRegion cloudRegionItem) { + protected SoCloudConfiguration constructCloudConfiguration(Tenant tenantItem, CloudRegion cloudRegionItem) { SoCloudConfiguration cloudConfiguration = new SoCloudConfiguration(); cloudConfiguration.setTenantId(tenantItem.getTenantId()); cloudConfiguration.setLcpCloudRegionId(cloudRegionItem.getCloudRegionId()); @@ -405,77 +340,33 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { return headers; } - /** - * Gets an item from a property. If the property is not found, then it invokes the - * given function to retrieve it from the custom query data. If that fails as well, - * then an exception is thrown. - * - * @param propName property name - * @param getter method to extract the value from the custom query data - * @param errmsg error message to include in any exception - * @return the retrieved item - */ - protected <T> T getItem(String propName, Function<AaiCqResponse, T> getter, String errmsg) { - if (containsProperty(propName)) { - return getProperty(propName); - } - - final AaiCqResponse aaiCqResponse = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY); - T item = getter.apply(aaiCqResponse); - if (item == null) { - throw new IllegalArgumentException(errmsg); - } - - return item; - } - /* * These methods extract data from the Custom Query and throw an * IllegalArgumentException if the desired data item is not found. */ protected GenericVnf getVnfItem(SoModelInfo soModelInfo) { - // @formatter:off - return getItem(OperationProperties.AAI_VNF, - cq -> cq.getGenericVnfByVfModuleModelInvariantId(soModelInfo.getModelInvariantId()), - "missing generic VNF"); - // @formatter:on + return getRequiredProperty(OperationProperties.AAI_VNF, "generic VNF"); } protected ServiceInstance getServiceInstance() { - return getItem(OperationProperties.AAI_SERVICE, AaiCqResponse::getServiceInstance, "missing VNF Service Item"); + return getRequiredProperty(OperationProperties.AAI_SERVICE, "VNF Service Item"); } protected Tenant getDefaultTenant() { - // @formatter:off - return getItem(OperationProperties.AAI_DEFAULT_TENANT, - AaiCqResponse::getDefaultTenant, - "missing Default Tenant Item"); - // @formatter:on + return getRequiredProperty(OperationProperties.AAI_DEFAULT_TENANT, "Default Tenant Item"); } protected CloudRegion getDefaultCloudRegion() { - // @formatter:off - return getItem(OperationProperties.AAI_DEFAULT_CLOUD_REGION, - AaiCqResponse::getDefaultCloudRegion, - "missing Default Cloud Region"); - // @formatter:on + return getRequiredProperty(OperationProperties.AAI_DEFAULT_CLOUD_REGION, "Default Cloud Region"); } - protected ModelVer getVnfModel(GenericVnf vnfItem) { - // @formatter:off - return getItem(OperationProperties.AAI_VNF_MODEL, - cq -> cq.getModelVerByVersionId(vnfItem.getModelVersionId()), - "missing generic VNF Model"); - // @formatter:on + protected ModelVer getVnfModel() { + return getRequiredProperty(OperationProperties.AAI_VNF_MODEL, "generic VNF Model"); } - protected ModelVer getServiceModel(ServiceInstance vnfServiceItem) { - // @formatter:off - return getItem(OperationProperties.AAI_SERVICE_MODEL, - cq -> cq.getModelVerByVersionId(vnfServiceItem.getModelVersionId()), - "missing Service Model"); - // @formatter:on + protected ModelVer getServiceModel() { + return getRequiredProperty(OperationProperties.AAI_SERVICE_MODEL, "Service Model"); } // these may be overridden by junit tests 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 af06c9184..f5c860e11 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 @@ -33,8 +33,6 @@ import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.ModelVer; 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; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; @@ -51,10 +49,8 @@ import org.onap.policy.so.SoRequestParameters; import org.onap.policy.so.SoResponse; /** - * Operation to create a VF Module. This gets the VF count from the A&AI Custom Query - * response and stores it in the context. It also passes the count+1 to the guard. Once - * the "create" completes successfully, it bumps the VF count that's stored in the - * context. + * Operation to create a VF Module. When this completes successfully, it increments its VF + * Count property. */ public class VfModuleCreate extends SoOperation { public static final String NAME = "VF Module Create"; @@ -86,38 +82,6 @@ public class VfModuleCreate extends SoOperation { validateTarget(); } - /** - * Ensures that A&AI custom query has been performed, and then runs the guard. - */ - @Override - @SuppressWarnings("unchecked") - protected CompletableFuture<OperationOutcome> startPreprocessorAsync() { - if (params.isPreprocessed()) { - return null; - } - - // 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::obtainVfCount, this::startGuardAsync); - // @formatter:on - } - - @Override - protected Map<String, Object> makeGuardPayload() { - Map<String, Object> payload = super.makeGuardPayload(); - - // run guard with the proposed vf count - payload.put(PAYLOAD_KEY_VF_COUNT, getVfCount() + 1); - - return payload; - } - @Override protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) { @@ -166,8 +130,8 @@ public class VfModuleCreate extends SoOperation { final ServiceInstance vnfServiceItem = getServiceInstance(); final Tenant tenantItem = getDefaultTenant(); final CloudRegion cloudRegionItem = getDefaultCloudRegion(); - final ModelVer vnfModel = getVnfModel(vnfItem); - final ModelVer vnfServiceModel = getServiceModel(vnfServiceItem); + final ModelVer vnfModel = getVnfModel(); + final ModelVer vnfServiceModel = getServiceModel(); SoRequest request = new SoRequest(); request.setOperationType(SoOperationType.SCALE_OUT); @@ -181,7 +145,7 @@ public class VfModuleCreate extends SoOperation { request.getRequestDetails().getRequestParameters().setUserParams(null); // cloudConfiguration - request.getRequestDetails().setCloudConfiguration(constructCloudConfigurationCq(tenantItem, cloudRegionItem)); + request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem, cloudRegionItem)); // modelInfo request.getRequestDetails().setModelInfo(soModelInfo); diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java index f35cdb4e1..9adb62c83 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java @@ -42,8 +42,6 @@ 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.http.client.HttpClient; import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; @@ -59,10 +57,8 @@ import org.onap.policy.so.SoRequestDetails; import org.onap.policy.so.SoResponse; /** - * Operation to delete a VF Module. This gets the VF count from the A&AI Custom Query - * response and stores it in the context. It also passes the count-1 to the guard. Once - * the "delete" completes successfully, it decrements the VF count that's stored in the - * context. + * Operation to delete a VF Module. When this completes successfully, it decrements its VF + * Count property. */ public class VfModuleDelete extends SoOperation { public static final String NAME = "VF Module Delete"; @@ -93,38 +89,6 @@ public class VfModuleDelete extends SoOperation { validateTarget(); } - /** - * Ensures that A&AI custom query has been performed, and then runs the guard. - */ - @Override - @SuppressWarnings("unchecked") - protected CompletableFuture<OperationOutcome> startPreprocessorAsync() { - if (params.isPreprocessed()) { - return null; - } - - // 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::obtainVfCount, this::startGuardAsync); - // @formatter:on - } - - @Override - protected Map<String, Object> makeGuardPayload() { - Map<String, Object> payload = super.makeGuardPayload(); - - // run guard with the proposed vf count - payload.put(PAYLOAD_KEY_VF_COUNT, getVfCount() - 1); - - return payload; - } - @Override protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) { @@ -261,7 +225,7 @@ public class VfModuleDelete extends SoOperation { details.setConfigurationParameters(null); // cloudConfiguration - details.setCloudConfiguration(constructCloudConfigurationCq(tenantItem, cloudRegionItem)); + details.setCloudConfiguration(constructCloudConfiguration(tenantItem, cloudRegionItem)); // modelInfo details.setModelInfo(soModelInfo); |