diff options
Diffstat (limited to 'models-interactions/model-actors/actor.so/src/main')
3 files changed, 95 insertions, 51 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 f269ea078..8f0dda3d2 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,10 +29,12 @@ 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; 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; @@ -43,6 +45,7 @@ import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; +import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig; @@ -170,10 +173,19 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { } protected int getVfCount() { + if (containsProperty(OperationProperties.DATA_VF_COUNT)) { + return getProperty(OperationProperties.DATA_VF_COUNT); + } + return params.getContext().getProperty(vfCountKey); } protected void setVfCount(int vfCount) { + if (containsProperty(OperationProperties.DATA_VF_COUNT)) { + setProperty(OperationProperties.DATA_VF_COUNT, vfCount); + return; + } + params.getContext().setProperty(vfCountKey, vfCount); } @@ -370,45 +382,77 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { return headers; } - /* - * These methods extract data from the Custom Query and throw an - * IllegalArgumentException if the desired data item is not found. + /** + * 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); + } - protected GenericVnf getVnfItem(AaiCqResponse aaiCqResponse, SoModelInfo soModelInfo) { - GenericVnf vnf = aaiCqResponse.getGenericVnfByVfModuleModelInvariantId(soModelInfo.getModelInvariantId()); - if (vnf == null) { - throw new IllegalArgumentException("missing generic VNF"); + final AaiCqResponse aaiCqResponse = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY); + T item = getter.apply(aaiCqResponse); + if (item == null) { + throw new IllegalArgumentException(errmsg); } - return vnf; + return item; } - protected ServiceInstance getServiceInstance(AaiCqResponse aaiCqResponse) { - ServiceInstance vnfService = aaiCqResponse.getServiceInstance(); - if (vnfService == null) { - throw new IllegalArgumentException("missing VNF Service Item"); - } + /* + * These methods extract data from the Custom Query and throw an + * IllegalArgumentException if the desired data item is not found. + */ - return vnfService; + protected GenericVnf getVnfItem(SoModelInfo soModelInfo) { + // @formatter:off + return getItem(OperationProperties.AAI_VNF, + cq -> cq.getGenericVnfByVfModuleModelInvariantId(soModelInfo.getModelInvariantId()), + "missing generic VNF"); + // @formatter:on } - protected Tenant getDefaultTenant(AaiCqResponse aaiCqResponse) { - Tenant tenant = aaiCqResponse.getDefaultTenant(); - if (tenant == null) { - throw new IllegalArgumentException("missing Tenant Item"); - } + protected ServiceInstance getServiceInstance() { + return getItem(OperationProperties.AAI_SERVICE, AaiCqResponse::getServiceInstance, "missing VNF Service Item"); + } - return tenant; + protected Tenant getDefaultTenant() { + // @formatter:off + return getItem(OperationProperties.AAI_DEFAULT_TENANT, + AaiCqResponse::getDefaultTenant, + "missing Default Tenant Item"); + // @formatter:on } - protected CloudRegion getDefaultCloudRegion(AaiCqResponse aaiCqResponse) { - CloudRegion cloudRegion = aaiCqResponse.getDefaultCloudRegion(); - if (cloudRegion == null) { - throw new IllegalArgumentException("missing Cloud Region"); - } + protected CloudRegion getDefaultCloudRegion() { + // @formatter:off + return getItem(OperationProperties.AAI_DEFAULT_CLOUD_REGION, + AaiCqResponse::getDefaultCloudRegion, + "missing Default Cloud Region"); + // @formatter:on + } + + protected ModelVer getVnfModel(GenericVnf vnfItem) { + // @formatter:off + return getItem(OperationProperties.AAI_VNF_MODEL, + cq -> cq.getModelVerByVersionId(vnfItem.getModelVersionId()), + "missing generic VNF Model"); + // @formatter:on + } - return cloudRegion; + protected ModelVer getServiceModel(ServiceInstance vnfServiceItem) { + // @formatter:off + return getItem(OperationProperties.AAI_SERVICE_MODEL, + cq -> cq.getModelVerByVersionId(vnfServiceItem.getModelVersionId()), + "missing Service Model"); + // @formatter:on } // 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 4bae1e84d..7e95bda03 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 @@ -29,6 +29,7 @@ import javax.ws.rs.core.Response; import org.apache.commons.lang3.tuple.Pair; import org.onap.aai.domain.yang.CloudRegion; 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; @@ -61,10 +62,12 @@ public class VfModuleCreate extends SoOperation { // @formatter:off private static final List<String> PROPERTY_NAMES = List.of( - OperationProperties.AAI_MODEL_SERVICE, - OperationProperties.AAI_MODEL_VNF, - OperationProperties.AAI_MODEL_CLOUD_REGION, - OperationProperties.AAI_MODEL_TENANT, + OperationProperties.AAI_SERVICE, + OperationProperties.AAI_SERVICE_MODEL, + OperationProperties.AAI_VNF, + OperationProperties.AAI_VNF_MODEL, + OperationProperties.AAI_DEFAULT_CLOUD_REGION, + OperationProperties.AAI_DEFAULT_TENANT, OperationProperties.DATA_VF_COUNT); // @formatter:off @@ -156,12 +159,13 @@ public class VfModuleCreate extends SoOperation { * @return a pair containing the request URL and the new request */ protected Pair<String, SoRequest> makeRequest() { - final AaiCqResponse aaiCqResponse = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY); final SoModelInfo soModelInfo = prepareSoModelInfo(); - final GenericVnf vnfItem = getVnfItem(aaiCqResponse, soModelInfo); - final ServiceInstance vnfServiceItem = getServiceInstance(aaiCqResponse); - final Tenant tenantItem = getDefaultTenant(aaiCqResponse); - final CloudRegion cloudRegionItem = getDefaultCloudRegion(aaiCqResponse); + final GenericVnf vnfItem = getVnfItem(soModelInfo); + final ServiceInstance vnfServiceItem = getServiceInstance(); + final Tenant tenantItem = getDefaultTenant(); + final CloudRegion cloudRegionItem = getDefaultCloudRegion(); + final ModelVer vnfModel = getVnfModel(vnfItem); + final ModelVer vnfServiceModel = getServiceModel(vnfServiceItem); SoRequest request = new SoRequest(); request.setOperationType(SoOperationType.SCALE_OUT); @@ -198,10 +202,8 @@ public class VfModuleCreate extends SoOperation { .setModelInvariantId(vnfServiceItem.getModelInvariantId()); relatedInstanceListElement1.getRelatedInstance().getModelInfo() .setModelVersionId(vnfServiceItem.getModelVersionId()); - relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelName( - aaiCqResponse.getModelVerByVersionId(vnfServiceItem.getModelVersionId()).getModelName()); - relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelVersion( - aaiCqResponse.getModelVerByVersionId(vnfServiceItem.getModelVersionId()).getModelVersion()); + relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelName(vnfModel.getModelName()); + relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelVersion(vnfModel.getModelVersion()); // VNF Item relatedInstanceListElement2.getRelatedInstance().setInstanceId(vnfItem.getVnfId()); @@ -211,10 +213,9 @@ public class VfModuleCreate extends SoOperation { .setModelInvariantId(vnfItem.getModelInvariantId()); relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelVersionId(vnfItem.getModelVersionId()); + relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelName(vnfServiceModel.getModelName()); relatedInstanceListElement2.getRelatedInstance().getModelInfo() - .setModelName(aaiCqResponse.getModelVerByVersionId(vnfItem.getModelVersionId()).getModelName()); - relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelVersion( - aaiCqResponse.getModelVerByVersionId(vnfItem.getModelVersionId()).getModelVersion()); + .setModelVersion(vnfServiceModel.getModelVersion()); relatedInstanceListElement2.getRelatedInstance().getModelInfo() .setModelCustomizationId(vnfItem.getModelCustomizationId()); 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 7db76d2d1..0ff833c59 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 @@ -70,10 +70,10 @@ public class VfModuleDelete extends SoOperation { // @formatter:off private static final List<String> PROPERTY_NAMES = List.of( - OperationProperties.AAI_MODEL_SERVICE, - OperationProperties.AAI_MODEL_VNF, - OperationProperties.AAI_MODEL_CLOUD_REGION, - OperationProperties.AAI_MODEL_TENANT, + OperationProperties.AAI_SERVICE, + OperationProperties.AAI_VNF, + OperationProperties.AAI_DEFAULT_CLOUD_REGION, + OperationProperties.AAI_DEFAULT_TENANT, OperationProperties.DATA_VF_COUNT); // @formatter:on @@ -239,12 +239,11 @@ public class VfModuleDelete extends SoOperation { * @return a pair containing the request URL and the new request */ protected Pair<String, SoRequest> makeRequest() { - final AaiCqResponse aaiCqResponse = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY); final SoModelInfo soModelInfo = prepareSoModelInfo(); - final GenericVnf vnfItem = getVnfItem(aaiCqResponse, soModelInfo); - final ServiceInstance vnfServiceItem = getServiceInstance(aaiCqResponse); - final Tenant tenantItem = getDefaultTenant(aaiCqResponse); - final CloudRegion cloudRegionItem = getDefaultCloudRegion(aaiCqResponse); + final GenericVnf vnfItem = getVnfItem(soModelInfo); + final ServiceInstance vnfServiceItem = getServiceInstance(); + final Tenant tenantItem = getDefaultTenant(); + final CloudRegion cloudRegionItem = getDefaultCloudRegion(); SoRequest request = new SoRequest(); request.setOperationType(SoOperationType.DELETE_VF_MODULE); |