diff options
Diffstat (limited to 'bpmn/MSOCommonBPMN/src')
25 files changed, 645 insertions, 131 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/flowmanipulator/FlowManipulatorListenerRunner.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/flowmanipulator/FlowManipulatorListenerRunner.java index 054cc378ef..c6d92cc9ab 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/flowmanipulator/FlowManipulatorListenerRunner.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/flowmanipulator/FlowManipulatorListenerRunner.java @@ -60,6 +60,9 @@ public class FlowManipulatorListenerRunner extends ListenerRunner { int sequenceBeforeFlowManipulator; do { sequenceBeforeFlowManipulator = execution.getVariable(BBConstants.G_CURRENT_SEQUENCE); + if (sequenceBeforeFlowManipulator >= flowsToExecute.size()) { + break; + } ExecuteBuildingBlock currentBB = flowsToExecute.get(execution.getCurrentSequence()); List<PreFlowManipulator> filtered = filterListeners(flowManipulators, (item -> item.shouldRunFor(currentBB.getBuildingBlock().getBpmnFlowName(), diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ResourceKey.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ResourceKey.java index 30a6e1fe35..641cd35027 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ResourceKey.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ResourceKey.java @@ -34,5 +34,7 @@ public enum ResourceKey { VPN_ID, VPN_BONDING_LINK_ID, INSTANCE_GROUP_ID, - PNF + PNF, + VNF_INSTANCE_NAME, + VF_MODULE_INSTANCE_NAME } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/WorkflowResourceIds.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/WorkflowResourceIds.java index 508709e12c..5df7c60f74 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/WorkflowResourceIds.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/WorkflowResourceIds.java @@ -40,6 +40,8 @@ public class WorkflowResourceIds implements Serializable { private String networkCollectionId; private String configurationId; private String instanceGroupId; + private String vnfInstanceName; + private String vfModuleInstanceName; public WorkflowResourceIds() { @@ -139,4 +141,20 @@ public class WorkflowResourceIds implements Serializable { public void setInstanceGroupId(String instanceGroupId) { this.instanceGroupId = instanceGroupId; } + + public String getVnfInstanceName() { + return vnfInstanceName; + } + + public void setVnfInstanceName(String vnfInstanceName) { + this.vnfInstanceName = vnfInstanceName; + } + + public String getVfModuleInstanceName() { + return vfModuleInstanceName; + } + + public void setVfModuleInstanceName(String vfModuleInstanceName) { + this.vfModuleInstanceName = vfModuleInstanceName; + } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/modelinfo/ModelInfoServiceInstance.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/modelinfo/ModelInfoServiceInstance.java index b554d7a9ba..4ad7fbdbd3 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/modelinfo/ModelInfoServiceInstance.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/modelinfo/ModelInfoServiceInstance.java @@ -45,6 +45,14 @@ public class ModelInfoServiceInstance extends ModelInfoMetadata implements Seria private String namingPolicy; @JsonProperty("onap-generated-naming") private Boolean onapGeneratedNaming; + @JsonProperty("cds-blueprint-name") + private String blueprintName; + @JsonProperty("cds-blueprint-version") + private String blueprintVersion; + @JsonProperty("controller-actor") + private String controllerActor; + @JsonProperty("skip-post-instantiation-configuration") + private Boolean skipPostInstConf = Boolean.TRUE; public String getDescription() { @@ -119,4 +127,36 @@ public class ModelInfoServiceInstance extends ModelInfoMetadata implements Seria public void setOnapGeneratedNaming(Boolean onapGeneratedNaming) { this.onapGeneratedNaming = onapGeneratedNaming; } + + public String getBlueprintName() { + return blueprintName; + } + + public void setBlueprintName(String blueprintName) { + this.blueprintName = blueprintName; + } + + public String getBlueprintVersion() { + return blueprintVersion; + } + + public void setBlueprintVersion(String blueprintVersion) { + this.blueprintVersion = blueprintVersion; + } + + public String getControllerActor() { + return controllerActor; + } + + public void setControllerActor(String controllerActor) { + this.controllerActor = controllerActor; + } + + public Boolean getSkipPostInstConf() { + return skipPostInstConf; + } + + public void setSkipPostInstConf(Boolean skipPostInstConf) { + this.skipPostInstConf = skipPostInstConf; + } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java index 83d1f5249f..d39da5ee37 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.UUID; +import org.apache.commons.lang3.StringUtils; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; import org.javatuples.Pair; @@ -74,6 +75,7 @@ import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException; +import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.ResourceNotFoundException; import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.ServiceModelNotFoundException; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization; @@ -258,6 +260,8 @@ public class BBInputSetup implements JavaDelegate { lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, workflowResourceIds.getVolumeGroupId()); lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, workflowResourceIds.getConfigurationId()); lookupKeyMap.put(ResourceKey.INSTANCE_GROUP_ID, workflowResourceIds.getInstanceGroupId()); + lookupKeyMap.put(ResourceKey.VNF_INSTANCE_NAME, workflowResourceIds.getVnfInstanceName()); + lookupKeyMap.put(ResourceKey.VF_MODULE_INSTANCE_NAME, workflowResourceIds.getVfModuleInstanceName()); } protected GeneralBuildingBlock getGBBALaCarteNonService(ExecuteBuildingBlock executeBB, @@ -1245,7 +1249,8 @@ public class BBInputSetup implements JavaDelegate { || requestAction.equalsIgnoreCase("activateInstance") || requestAction.equalsIgnoreCase("activateFabricConfiguration") || requestAction.equalsIgnoreCase("recreateInstance") - || requestAction.equalsIgnoreCase("replaceInstance")) { + || requestAction.equalsIgnoreCase("replaceInstance") + || requestAction.equalsIgnoreCase("upgradeInstance")) { return getGBBMacroExistingService(executeBB, lookupKeyMap, bbName, requestAction, requestDetails.getCloudConfiguration()); } @@ -1425,7 +1430,13 @@ public class BBInputSetup implements JavaDelegate { if (serviceInstanceId != null) { aaiServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId); if (aaiServiceInstance != null) { - service = bbInputSetupUtils.getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId()); + String modelVersionId = aaiServiceInstance.getModelVersionId(); + if ("upgradeInstance".equalsIgnoreCase(requestAction)) { + modelVersionId = requestDetails.getModelInfo().getModelVersionId(); + } + + service = bbInputSetupUtils.getCatalogServiceByModelUUID(modelVersionId); + if (service == null) { String message = String.format( "Related service instance model not found in MSO CatalogDB: model-version-id=%s", @@ -1581,7 +1592,13 @@ public class BBInputSetup implements JavaDelegate { .setBbName(bbName).setServiceInstance(serviceInstance).setLookupKeyMap(lookupKeyMap).build(); if (bbName.contains(VNF) || (bbName.contains(CONTROLLER) && (VNF).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope()))) { - vnfs = findVnfsByKey(key, resources, vnfs); + String vnfInstanceName = lookupKeyMap.get(ResourceKey.VNF_INSTANCE_NAME); + if (StringUtils.isNotBlank(vnfInstanceName)) { + vnfs = findVnfsByInstanceName(vnfInstanceName, resources); + } else { + vnfs = findVnfsByKey(key, resources); + } + String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID); // This stores the vnf id in request db to be retrieved later when // working on a vf module or volume group @@ -1611,15 +1628,15 @@ public class BBInputSetup implements JavaDelegate { .ifPresent(pnfs -> BBInputSetupPnf.populatePnfToServiceInstance(pnfs, pnfId, serviceInstance)); } else if (bbName.contains(VF_MODULE) || bbName.contains(VOLUME_GROUP) || (bbName.contains(CONTROLLER) && (VF_MODULE).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope()))) { - Pair<Vnfs, VfModules> vnfsAndVfModules = getVfModulesAndItsVnfsByKey(key, resources); - if (vnfsAndVfModules != null) { - vfModules = vnfsAndVfModules.getValue1(); - vnfs = vnfsAndVfModules.getValue0(); + String vfModuleInstanceName = lookupKeyMap.get(ResourceKey.VF_MODULE_INSTANCE_NAME); + if (StringUtils.isNotBlank(vfModuleInstanceName)) { + vfModules = getVfModulesByInstanceName(vfModuleInstanceName, resources); + } else { + vfModules = getVfModulesByKey(key, resources); } + lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, getVnfId(executeBB, lookupKeyMap)); - if (vnfs == null) { - throw new Exception("Could not find Vnf to orchestrate VfModule"); - } + parameter.setModelInfo(vfModules.getModelInfo()); if (bbName.contains(VOLUME_GROUP)) { parameter.setResourceId(lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID)); @@ -1682,25 +1699,45 @@ public class BBInputSetup implements JavaDelegate { return null; } - protected Pair<Vnfs, VfModules> getVfModulesAndItsVnfsByKey(String key, Resources resources) { + protected VfModules getVfModulesByInstanceName(String vfModuleInstanceName, Resources resources) { + for (Vnfs vnfs : resources.getVnfs()) { + for (VfModules vfModules : vnfs.getVfModules()) { + if (vfModules.getInstanceName().equals(vfModuleInstanceName)) { + return vfModules; + } + } + } + throw new ResourceNotFoundException( + "Could not find vf-module with instanceName: " + vfModuleInstanceName + " in userparams"); + } + + protected VfModules getVfModulesByKey(String key, Resources resources) { for (Vnfs vnfs : resources.getVnfs()) { for (VfModules vfModules : vnfs.getVfModules()) { if (vfModules.getModelInfo().getModelCustomizationId().equalsIgnoreCase(key)) { - return new Pair<Vnfs, VfModules>(vnfs, vfModules); + return vfModules; } } } - return null; + throw new ResourceNotFoundException("Could not find vf-module with key: " + key + " in userparams"); } - protected Vnfs findVnfsByKey(String key, Resources resources, Vnfs vnfs) { + protected Vnfs findVnfsByInstanceName(String instanceName, Resources resources) { + for (Vnfs tempVnfs : resources.getVnfs()) { + if (tempVnfs.getInstanceName().equals(instanceName)) { + return tempVnfs; + } + } + throw new ResourceNotFoundException("Could not find vnf with instanceName: " + instanceName + " in userparams"); + } + + protected Vnfs findVnfsByKey(String key, Resources resources) { for (Vnfs tempVnfs : resources.getVnfs()) { if (tempVnfs.getModelInfo().getModelCustomizationId().equalsIgnoreCase(key)) { - vnfs = tempVnfs; - break; + return tempVnfs; } } - return vnfs; + throw new ResourceNotFoundException("Could not find vnf with key: " + key + " in userparams"); } protected CloudRegion getCloudRegionFromMacroRequest(CloudConfiguration cloudConfiguration, Resources resources) { diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/exceptions/ResourceNotFoundException.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/exceptions/ResourceNotFoundException.java new file mode 100644 index 0000000000..d8eed9610a --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/exceptions/ResourceNotFoundException.java @@ -0,0 +1,14 @@ +package org.onap.so.bpmn.servicedecomposition.tasks.exceptions; + +public class ResourceNotFoundException extends RuntimeException { + + static final long serialVersionUID = -2741357347054072719L; + + public ResourceNotFoundException() { + super(); + } + + public ResourceNotFoundException(String message) { + super(message); + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForPnf.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForPnf.java index 0d79dbb375..f393d2a49d 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForPnf.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForPnf.java @@ -20,6 +20,7 @@ package org.onap.so.client.cds; +import static org.onap.so.client.cds.ConfigureInstanceParamsUtil.applyParamsToObject; import com.google.gson.JsonObject; import org.onap.so.client.exception.PayloadGenerationException; import org.onap.so.serviceinstancebeans.Service; @@ -51,13 +52,17 @@ public class ConfigureInstanceParamsForPnf { public void populateInstanceParams(JsonObject jsonObject, List<Map<String, Object>> userParamsFromRequest, String modelCustomizationUuid) throws PayloadGenerationException { try { - Service service = extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest); - List<Map<String, String>> instanceParamsList = getInstanceParamForPnf(service, modelCustomizationUuid); + Optional<Service> service = + extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest); - instanceParamsList.stream().flatMap(instanceParamsMap -> instanceParamsMap.entrySet().stream()) - .forEachOrdered(entry -> jsonObject.addProperty(entry.getKey(), entry.getValue())); + if (service.isPresent()) { + List<Map<String, String>> instanceParamsList = + getInstanceParamForPnf(service.get(), modelCustomizationUuid); + + applyParamsToObject(instanceParamsList, jsonObject); + } } catch (Exception exception) { - throw new PayloadGenerationException("Couldn't able to resolve instance parameters", exception); + throw new PayloadGenerationException("Failed to resolve instance parameters", exception); } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForService.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForService.java new file mode 100644 index 0000000000..e8c88e00d7 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForService.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2021 Bell Canada + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.cds; + +import static org.onap.so.client.cds.ConfigureInstanceParamsUtil.applyParamsToObject; +import com.google.gson.JsonObject; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import org.onap.so.client.exception.PayloadGenerationException; +import org.onap.so.serviceinstancebeans.Service; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class ConfigureInstanceParamsForService { + + @Autowired + private ExtractServiceFromUserParameters extractServiceFromUserParameters; + + /** + * Read instance parameters for Service and put into JsonObject. + * + * @param jsonObject - JsonObject which will hold the payload to send to CDS. + * @param userParamsFromRequest - User parameters. + * @throws PayloadGenerationException if it doesn't able to populate instance parameters from SO payload. + */ + public void populateInstanceParams(JsonObject jsonObject, List<Map<String, Object>> userParamsFromRequest) + throws PayloadGenerationException { + try { + Optional<Service> service = + extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest); + + service.map(Service::getInstanceParams).ifPresent(p -> applyParamsToObject(p, jsonObject)); + } catch (Exception e) { + throw new PayloadGenerationException("Failed to resolve instance parameters", e); + } + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java index 6f850fa898..b1e632a701 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java @@ -20,8 +20,10 @@ package org.onap.so.client.cds; +import static org.onap.so.client.cds.ConfigureInstanceParamsUtil.applyParamsToObject; import com.google.gson.JsonObject; -import org.onap.so.client.cds.ExtractServiceFromUserParameters; +import java.util.Optional; +import org.apache.commons.lang3.StringUtils; import org.onap.so.client.exception.PayloadGenerationException; import org.onap.so.serviceinstancebeans.Service; import org.onap.so.serviceinstancebeans.VfModules; @@ -47,20 +49,36 @@ public class ConfigureInstanceParamsForVfModule { * @throws PayloadGenerationException- If it doesn't able to populate instance parameters from SO payload. */ public void populateInstanceParams(JsonObject jsonObject, List<Map<String, Object>> userParamsFromRequest, - String vnfCustomizationUuid, String vfModuleCustomizationUuid) throws PayloadGenerationException { + String vnfCustomizationUuid, String vfModuleCustomizationUuid, String vfModuleInstanceName) + throws PayloadGenerationException { try { - Service service = extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest); + Optional<Service> service = + extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest); - List<Map<String, String>> instanceParamsList = - getInstanceParams(service, vnfCustomizationUuid, vfModuleCustomizationUuid); + if (service.isPresent()) { + List<Map<String, String>> instanceParamsList; + if (StringUtils.isNotBlank(vfModuleInstanceName)) { + instanceParamsList = getInstanceParamsByInstanceNames(service.get(), vfModuleInstanceName); + } else { + instanceParamsList = + getInstanceParams(service.get(), vnfCustomizationUuid, vfModuleCustomizationUuid); + } - instanceParamsList.stream().flatMap(instanceParamsMap -> instanceParamsMap.entrySet().stream()) - .forEachOrdered(entry -> jsonObject.addProperty(entry.getKey(), entry.getValue())); + applyParamsToObject(instanceParamsList, jsonObject); + } } catch (Exception e) { - throw new PayloadGenerationException("Couldn't able to resolve instance parameters", e); + throw new PayloadGenerationException("Failed to resolve instance parameters", e); } } + private List<Map<String, String>> getInstanceParamsByInstanceNames(Service service, String vfModuleInstanceName) + throws PayloadGenerationException { + return service.getResources().getVnfs().stream().map(Vnfs::getVfModules).flatMap(List::stream) + .filter(vfm -> vfModuleInstanceName.equals(vfm.getInstanceName())).findFirst() + .map(VfModules::getInstanceParams).orElseThrow(() -> new PayloadGenerationException( + "Could not find vfModule with instanceName: " + vfModuleInstanceName)); + } + private List<Map<String, String>> getInstanceParams(Service service, String vnfCustomizationUuid, String vfModuleCustomizationUuid) throws PayloadGenerationException { diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java index 22c9a7bee4..5d8388b6e0 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java @@ -20,6 +20,8 @@ package org.onap.so.client.cds; +import static org.onap.so.client.cds.ConfigureInstanceParamsUtil.applyParamsToObject; +import org.apache.commons.lang3.StringUtils; import com.google.gson.JsonObject; import org.onap.so.client.exception.PayloadGenerationException; import org.onap.so.serviceinstancebeans.Service; @@ -45,18 +47,32 @@ public class ConfigureInstanceParamsForVnf { * @throws PayloadGenerationException if it doesn't able to populate instance parameters from SO payload. */ public void populateInstanceParams(JsonObject jsonObject, List<Map<String, Object>> userParamsFromRequest, - String modelCustomizationUuid) throws PayloadGenerationException { + String modelCustomizationUuid, String vnfInstanceName) throws PayloadGenerationException { try { - Service service = extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest); - List<Map<String, String>> instanceParamsList = getInstanceParamForVnf(service, modelCustomizationUuid); + Optional<Service> service = + extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest); - instanceParamsList.stream().flatMap(instanceParamsMap -> instanceParamsMap.entrySet().stream()) - .forEachOrdered(entry -> jsonObject.addProperty(entry.getKey(), entry.getValue())); + if (service.isPresent()) { + List<Map<String, String>> instanceParamsList; + if (StringUtils.isNotBlank(vnfInstanceName)) { + instanceParamsList = getInstanceParamByVnfInstanceName(service.get(), vnfInstanceName); + } else { + instanceParamsList = getInstanceParamForVnf(service.get(), modelCustomizationUuid); + } + applyParamsToObject(instanceParamsList, jsonObject); + } } catch (Exception e) { - throw new PayloadGenerationException("Couldn't able to resolve instance parameters", e); + throw new PayloadGenerationException("Failed to resolve instance parameters", e); } } + private List<Map<String, String>> getInstanceParamByVnfInstanceName(Service service, String instanceName) + throws PayloadGenerationException { + return service.getResources().getVnfs().stream().filter(vnf -> instanceName.equals(vnf.getInstanceName())) + .findFirst().map(Vnfs::getInstanceParams).orElseThrow( + () -> new PayloadGenerationException("Could not find vnf with instanceName: " + instanceName)); + } + private List<Map<String, String>> getInstanceParamForVnf(Service service, String genericVnfModelCustomizationUuid) throws PayloadGenerationException { Optional<Vnfs> foundedVnf = service.getResources().getVnfs().stream() diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsUtil.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsUtil.java new file mode 100644 index 0000000000..117fd74498 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsUtil.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2021 Bell Canada + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.cds; + +import com.google.gson.JsonObject; +import java.util.List; +import java.util.Map; + +public final class ConfigureInstanceParamsUtil { + + public static void applyParamsToObject(List<Map<String, String>> instanceParamsList, JsonObject jsonObject) { + instanceParamsList.stream().flatMap(instanceParamsMap -> instanceParamsMap.entrySet().stream()) + .forEachOrdered(entry -> jsonObject.addProperty(entry.getKey(), entry.getValue())); + } + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ExtractServiceFromUserParameters.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ExtractServiceFromUserParameters.java index 43fabd3253..53e1da410e 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ExtractServiceFromUserParameters.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ExtractServiceFromUserParameters.java @@ -20,6 +20,7 @@ package org.onap.so.client.cds; import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.Optional; import org.onap.so.client.exception.PayloadGenerationException; import org.onap.so.serviceinstancebeans.Service; import org.springframework.beans.factory.annotation.Autowired; @@ -35,10 +36,13 @@ public class ExtractServiceFromUserParameters { @Autowired private ObjectMapper objectMapper; - public Service getServiceFromRequestUserParams(List<Map<String, Object>> userParams) throws Exception { - Map<String, Object> serviceMap = userParams.stream().filter(key -> key.containsKey(SERVICE_KEY)).findFirst() - .orElseThrow(() -> new Exception("Can not find service in userParams section in generalBuildingBlock")); - return getServiceObjectFromServiceMap(serviceMap); + public Optional<Service> getServiceFromRequestUserParams(List<Map<String, Object>> userParams) throws Exception { + Optional<Map<String, Object>> serviceMap = + userParams.stream().filter(key -> key.containsKey(SERVICE_KEY)).findFirst(); + if (serviceMap.isPresent()) { + return Optional.of(getServiceObjectFromServiceMap(serviceMap.get())); + } + return Optional.empty(); } private Service getServiceObjectFromServiceMap(Map<String, Object> serviceMap) throws PayloadGenerationException { diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ServiceCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ServiceCDSRequestProvider.java index 12c841a2c6..ce784dd5d6 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ServiceCDSRequestProvider.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ServiceCDSRequestProvider.java @@ -21,8 +21,11 @@ package org.onap.so.client.cds; import com.google.gson.JsonObject; +import java.util.List; +import java.util.Map; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.exception.PayloadGenerationException; @@ -38,21 +41,22 @@ import static org.onap.so.client.cds.PayloadConstants.SEPARATOR; @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class ServiceCDSRequestProvider implements CDSRequestProvider { - private static final String EMPTY_STRING = ""; private String resolutionKey; private BuildingBlockExecution execution; + private String bluePrintName; + private String bluePrintVersion; @Autowired - private ExtractPojosForBB extractPojosForBB; + private ConfigureInstanceParamsForService configureInstanceParamsForService; @Override public String getBlueprintName() { - return EMPTY_STRING; + return bluePrintName; } @Override public String getBlueprintVersion() { - return EMPTY_STRING; + return bluePrintVersion; } @Override @@ -65,17 +69,21 @@ public class ServiceCDSRequestProvider implements CDSRequestProvider { JsonObject cdsPropertyObject = new JsonObject(); JsonObject serviceObject = new JsonObject(); try { - ServiceInstance serviceInstance = - extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); - + ServiceInstance serviceInstance = execution.getGeneralBuildingBlock().getServiceInstance(); + bluePrintName = serviceInstance.getModelInfoServiceInstance().getBlueprintName(); + bluePrintVersion = serviceInstance.getModelInfoServiceInstance().getBlueprintVersion(); resolutionKey = serviceInstance.getServiceInstanceName(); - // TODO Need to figure out how to populate blueprint name and version for service. - serviceObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId()); serviceObject.addProperty("service-model-uuid", serviceInstance.getModelInfoServiceInstance().getModelUuid()); + final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock(); + List<Map<String, Object>> userParamsFromRequest = + buildingBlock.getRequestContext().getRequestParameters().getUserParams(); + if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) { + configureInstanceParamsForService.populateInstanceParams(serviceObject, userParamsFromRequest); + } } catch (Exception e) { throw new PayloadGenerationException("Failed to buildPropertyObjectForService", e); } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java index 478b65c349..06ab84a114 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java @@ -104,9 +104,11 @@ public class VfModuleCDSRequestProvider implements CDSRequestProvider { final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock(); List<Map<String, Object>> userParamsFromRequest = buildingBlock.getRequestContext().getRequestParameters().getUserParams(); + String vfModuleInstanceName = + execution.getLookupMap().getOrDefault(ResourceKey.VF_MODULE_INSTANCE_NAME, ""); if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) { configureInstanceParamsForVfModule.populateInstanceParams(vfModuleObject, userParamsFromRequest, - modelCustomizationUuidForVnf, modelCustomizationUuidForVfModule); + modelCustomizationUuidForVnf, modelCustomizationUuidForVfModule, vfModuleInstanceName); } } catch (Exception e) { throw new PayloadGenerationException("Failed to buildPropertyObject for VF-Module", e); diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java index 6251eb6fad..5f63732458 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java @@ -23,6 +23,7 @@ package org.onap.so.client.cds; import com.google.gson.JsonObject; +import org.apache.commons.lang3.StringUtils; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; @@ -93,9 +94,10 @@ public class VnfCDSRequestProvider implements CDSRequestProvider { final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock(); List<Map<String, Object>> userParamsFromRequest = buildingBlock.getRequestContext().getRequestParameters().getUserParams(); + String vnfInstanceName = execution.getLookupMap().getOrDefault(ResourceKey.VNF_INSTANCE_NAME, ""); if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) { configureInstanceParamsForVnf.populateInstanceParams(vnfObject, userParamsFromRequest, - modelCustomizationUuid); + modelCustomizationUuid, vnfInstanceName); } } catch (Exception e) { throw new PayloadGenerationException("Failed to buildPropertyObjectForVnf", e); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java index 127253a72e..b561055468 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java @@ -46,6 +46,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.UUID; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.junit.Assert; import org.junit.Rule; @@ -131,6 +132,8 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.so.serviceinstancebeans.VfModules; +import org.onap.so.serviceinstancebeans.Vnfs; @RunWith(MockitoJUnitRunner.class) public class BBInputSetupTest { @@ -2116,6 +2119,8 @@ public class BBInputSetupTest { String volumeGroupId = "volumeGroupId"; String configurationId = "configurationId"; String instanceGroupId = "instancegroupId"; + String vnfInstanceName = "vnfInstanceName"; + String vfModuleInstanceName = "vfModuleInstanceName"; expected.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstanceId); expected.put(ResourceKey.NETWORK_ID, networkId); @@ -2125,6 +2130,8 @@ public class BBInputSetupTest { expected.put(ResourceKey.VOLUME_GROUP_ID, volumeGroupId); expected.put(ResourceKey.CONFIGURATION_ID, configurationId); expected.put(ResourceKey.INSTANCE_GROUP_ID, instanceGroupId); + expected.put(ResourceKey.VNF_INSTANCE_NAME, vnfInstanceName); + expected.put(ResourceKey.VF_MODULE_INSTANCE_NAME, vfModuleInstanceName); WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); workflowResourceIds.setServiceInstanceId(serviceInstanceId); @@ -2135,6 +2142,8 @@ public class BBInputSetupTest { workflowResourceIds.setVolumeGroupId(volumeGroupId); workflowResourceIds.setConfigurationId(configurationId); workflowResourceIds.setInstanceGroupId(instanceGroupId); + workflowResourceIds.setVnfInstanceName(vnfInstanceName); + workflowResourceIds.setVfModuleInstanceName(vfModuleInstanceName); SPY_bbInputSetup.populateLookupKeyMapWithIds(workflowResourceIds, actual); @@ -2142,6 +2151,44 @@ public class BBInputSetupTest { } @Test + public void testGetVfModulesByInstanceName() throws IOException { + org.onap.so.serviceinstancebeans.Service serviceMacro = mapper.readValue( + new File(RESOURCE_PATH + "ServiceMacroVfModules.json"), org.onap.so.serviceinstancebeans.Service.class); + Resources resources = serviceMacro.getResources(); + VfModules expectedVfModule = resources.getVnfs().get(0).getVfModules().get(2); + assertEquals(expectedVfModule, + SPY_bbInputSetup.getVfModulesByInstanceName("vmxnjr001_AVPN_base_vRE_BV_expansion_002", resources)); + } + + @Test + public void testGetVfModulesByKey() throws IOException { + org.onap.so.serviceinstancebeans.Service serviceMacro = mapper.readValue( + new File(RESOURCE_PATH + "ServiceMacroVfModules.json"), org.onap.so.serviceinstancebeans.Service.class); + Resources resources = serviceMacro.getResources(); + VfModules expectedVfModule = resources.getVnfs().get(0).getVfModules().get(0); + assertEquals(expectedVfModule, + SPY_bbInputSetup.getVfModulesByKey("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f", resources)); + } + + @Test + public void testFindVnfsByInstanceName() throws IOException { + org.onap.so.serviceinstancebeans.Service serviceMacro = mapper.readValue( + new File(RESOURCE_PATH + "ServiceMacroVfModules.json"), org.onap.so.serviceinstancebeans.Service.class); + Resources resources = serviceMacro.getResources(); + Vnfs expectedVnf = resources.getVnfs().get(0); + assertEquals(expectedVnf, SPY_bbInputSetup.findVnfsByInstanceName("vmxnjr001", resources)); + } + + @Test + public void testVnfsByKey() throws IOException { + org.onap.so.serviceinstancebeans.Service serviceMacro = mapper.readValue( + new File(RESOURCE_PATH + "ServiceMacroVfModules.json"), org.onap.so.serviceinstancebeans.Service.class); + Resources resources = serviceMacro.getResources(); + Vnfs expectedVnf = resources.getVnfs().get(0); + assertEquals(expectedVnf, SPY_bbInputSetup.findVnfsByKey("ab153b6e-c364-44c0-bef6-1f2982117f04", resources)); + } + + @Test public void testGBBMacroNoUserParamsVrfConfiguration() throws Exception { String resourceId = "123"; String vnfType = "vnfType"; @@ -2938,6 +2985,31 @@ public class BBInputSetupTest { } @Test + public void testGetGBBMacroExistingServiceUpgrade() throws Exception { + String requestAction = "upgradeInstance"; + GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), + GeneralBuildingBlock.class); + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + RequestDetails requestDetails = mapper + .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceUpgrade.json"), RequestDetails.class); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + executeBB.setRequestDetails(requestDetails); + + doReturn(new Service()).when(SPY_bbInputSetupUtils) + .getCatalogServiceByModelUUID(requestDetails.getModelInfo().getModelVersionId()); + doReturn(new org.onap.aai.domain.yang.ServiceInstance()).when(SPY_bbInputSetupUtils) + .getAAIServiceInstanceById(lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); + doReturn(gBB).when(SPY_bbInputSetup).populateGBBWithSIAndAdditionalInfo(any(BBInputSetupParameter.class)); + + SPY_bbInputSetup.getGBBMacroExistingService(executeBB, lookupKeyMap, + executeBB.getBuildingBlock().getBpmnFlowName(), requestAction, null); + + verify(SPY_bbInputSetupUtils, times(1)) + .getCatalogServiceByModelUUID(requestDetails.getModelInfo().getModelVersionId()); + } + + @Test public void testGetGBBMacroExistingServiceServiceinstancenotFoundInAai() throws Exception { ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), ExecuteBuildingBlock.class); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java index 06defaa84c..42b29ea669 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java @@ -20,6 +20,7 @@ package org.onap.so.client.cds; import com.google.gson.JsonParser; +import java.util.Optional; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; import org.junit.Before; @@ -82,6 +83,7 @@ public abstract class AbstractVnfCDSRequestProviderTest { @Before public void setUp() { buildingBlockExecution = createBuildingBlockExecution(); + buildingBlockExecution.setVariable("lookupKeyMap", new HashMap<>()); executeBuildingBlock = new ExecuteBuildingBlock(); } @@ -142,12 +144,12 @@ public abstract class AbstractVnfCDSRequestProviderTest { return userParams; } - protected Service getUserParams() { + protected Optional<Service> getUserParams() { Service service = new Service(); Resources resources = new Resources(); resources.setVnfs(createVnfList()); service.setResources(resources); - return service; + return Optional.of(service); } protected List<Vnfs> createVnfList() { diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java index 9baf5dc5bf..be100652c0 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java @@ -20,27 +20,28 @@ package org.onap.so.client.cds; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; import com.google.gson.JsonObject; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.Resources; import org.onap.so.serviceinstancebeans.Service; import org.onap.so.serviceinstancebeans.VfModules; import org.onap.so.serviceinstancebeans.Vnfs; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.Mockito.doReturn; -@RunWith(MockitoJUnitRunner.Silent.class) +@RunWith(MockitoJUnitRunner.class) public class ConfigureInstanceParamsForVfModuleTest { @InjectMocks @@ -49,79 +50,77 @@ public class ConfigureInstanceParamsForVfModuleTest { @Mock private ExtractServiceFromUserParameters extractServiceFromUserParameters; - private static final String TEST_VNF_MODEL_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4"; - private static final String TEST_VF_MODULE_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce2"; - private static final String TEST_INSTANCE_PARAM_VALUE_1 = "vf-module-1-value"; - private static final String TEST_INSTANCE_PARAM_VALUE_2 = "vf-module-2-value"; - private static final String TEST_INSTANCE_PARAM_KEY_1 = "instance-param-1"; - private static final String TEST_INSTANCE_PARAM_KEY_2 = "instance-param-2"; + private static final String VNF_CUSTOMIZATION_ID = UUID.randomUUID().toString(); + private static final String VFMODULE_1_CUSTOMIZATION_ID = UUID.randomUUID().toString(); + private static final String VFMODULE_2_CUSTOMIZATION_ID = UUID.randomUUID().toString(); + private static final String VFMODULE_1_INSTANCE_NAME = "vfmodule-instance-1"; + private static final String VFMODULE_2_INSTANCE_NAME = "vfmodule-instance-2"; + private static final List<Map<String, String>> VFMODULE_1_INSTANCE_PARAMS = + Arrays.asList(Map.of("param-1", "xyz", "param-2", "123"), Map.of("param-3", "CCC")); + private static final List<Map<String, String>> VFMODULE_2_INSTANCE_PARAMS = + Arrays.asList(Map.of("param-1", "abc", "param-2", "999"), Map.of("param-3", "AAA")); + @Test - public void testInstanceParamsForVfModule() throws Exception { - // given - List<Map<String, Object>> userParamsFromRequest = createRequestParameters(); - JsonObject jsonObject = new JsonObject(); - doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList()); + public void testPopulateInstanceParamsByInstanceName() throws Exception { + Service service = new Service(); + Resources resources = new Resources(); + resources.setVnfs(createVnfs()); + service.setResources(resources); - // when - configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, userParamsFromRequest, - TEST_VNF_MODEL_CUSTOMIZATION_UUID, TEST_VF_MODULE_CUSTOMIZATION_UUID); + when(extractServiceFromUserParameters.getServiceFromRequestUserParams(any())).thenReturn(Optional.of(service)); + JsonObject jsonObject = new JsonObject(); - // verify - assertEquals(TEST_INSTANCE_PARAM_VALUE_1, jsonObject.get(TEST_INSTANCE_PARAM_KEY_1).getAsString()); - assertEquals(TEST_INSTANCE_PARAM_VALUE_2, jsonObject.get(TEST_INSTANCE_PARAM_KEY_2).getAsString()); - } + configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, new ArrayList<>(), VNF_CUSTOMIZATION_ID, + VFMODULE_2_CUSTOMIZATION_ID, VFMODULE_2_INSTANCE_NAME); - private List<Map<String, Object>> createRequestParameters() { - List<Map<String, Object>> userParams = new ArrayList<>(); - Map<String, Object> userParamMap = new HashMap<>(); - userParamMap.put("service", getUserParams()); - userParams.add(userParamMap); - return userParams; + assertEquals("abc", jsonObject.get("param-1").getAsString()); + assertEquals("999", jsonObject.get("param-2").getAsString()); + assertEquals("AAA", jsonObject.get("param-3").getAsString()); } - private Service getUserParams() { + @Test + public void testPopulateInstanceParamsByCustomizationId() throws Exception { Service service = new Service(); Resources resources = new Resources(); resources.setVnfs(createVnfs()); service.setResources(resources); - return service; - } - - private List<Vnfs> createVnfs() { - Vnfs searchedVnf = createVnf(); - List<Vnfs> vnfList = new ArrayList<>(); - vnfList.add(searchedVnf); - return vnfList; - } - - private Vnfs createVnf() { - Vnfs vnf = new Vnfs(); - ModelInfo modelInfoForVnf = new ModelInfo(); - modelInfoForVnf.setModelCustomizationId(TEST_VNF_MODEL_CUSTOMIZATION_UUID); - vnf.setModelInfo(modelInfoForVnf); - - VfModules vfModule = new VfModules(); - ModelInfo modelInfoForVfModule = new ModelInfo(); - modelInfoForVfModule.setModelCustomizationId(TEST_VF_MODULE_CUSTOMIZATION_UUID); - - vfModule.setModelInfo(modelInfoForVfModule); - - // Set instance parameters. - List<Map<String, String>> instanceParamsListSearchedVfModule = new ArrayList<>(); - Map<String, String> instanceParams = new HashMap<>(); - instanceParams.put("instance-param-1", TEST_INSTANCE_PARAM_VALUE_1); - instanceParams.put("instance-param-2", TEST_INSTANCE_PARAM_VALUE_2); - - instanceParamsListSearchedVfModule.add(instanceParams); - vfModule.setInstanceParams(instanceParamsListSearchedVfModule); + when(extractServiceFromUserParameters.getServiceFromRequestUserParams(any())).thenReturn(Optional.of(service)); + JsonObject jsonObject = new JsonObject(); - List<VfModules> vfModules = new ArrayList<>(); - vfModules.add(vfModule); + // No instance name is passed + configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, new ArrayList<>(), VNF_CUSTOMIZATION_ID, + VFMODULE_1_CUSTOMIZATION_ID, null); - vnf.setVfModules(vfModules); + assertEquals("xyz", jsonObject.get("param-1").getAsString()); + assertEquals("123", jsonObject.get("param-2").getAsString()); + assertEquals("CCC", jsonObject.get("param-3").getAsString()); + } - return vnf; + private List<Vnfs> createVnfs() { + Vnfs vnf1 = new Vnfs(); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationId(VNF_CUSTOMIZATION_ID); + vnf1.setModelInfo(modelInfo); + + VfModules vfModule1 = new VfModules(); + modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationId(VFMODULE_1_CUSTOMIZATION_ID); + vfModule1.setModelInfo(modelInfo); + vfModule1.setInstanceName(VFMODULE_1_INSTANCE_NAME); + vfModule1.setInstanceParams(VFMODULE_1_INSTANCE_PARAMS); + + VfModules vfModule2 = new VfModules(); + modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationId(VFMODULE_2_CUSTOMIZATION_ID); + vfModule2.setModelInfo(modelInfo); + vfModule2.setInstanceName(VFMODULE_2_INSTANCE_NAME); + vfModule2.setInstanceParams(VFMODULE_2_INSTANCE_PARAMS); + + vnf1.setVfModules(Arrays.asList(vfModule1, vfModule2)); + + return Arrays.asList(vnf1); } + } diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnfTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnfTest.java new file mode 100644 index 0000000000..6466da59d0 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnfTest.java @@ -0,0 +1,115 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2021 Bell Canada + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.cds; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import com.google.gson.JsonObject; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.Resources; +import org.onap.so.serviceinstancebeans.Service; +import org.onap.so.serviceinstancebeans.Vnfs; + +@RunWith(MockitoJUnitRunner.class) +public class ConfigureInstanceParamsForVnfTest { + + @InjectMocks + private ConfigureInstanceParamsForVnf configureInstanceParamsForVnf; + + @Mock + private ExtractServiceFromUserParameters extractServiceFromUserParameters; + + private static final String VNF_1_CUSTOMIZATION_ID = UUID.randomUUID().toString(); + private static final String VNF_2_CUSTOMIZATION_ID = UUID.randomUUID().toString(); + private static final String VNF_1_INSTANCE_NAME = "vnf-instance-1"; + private static final String VNF_2_INSTANCE_NAME = "vnf-instance-2"; + private static final List<Map<String, String>> VNF_1_INSTANCE_PARAMS = + Arrays.asList(Map.of("param-1", "xyz", "param-2", "123"), Map.of("param-3", "CCC")); + private static final List<Map<String, String>> VNF_2_INSTANCE_PARAMS = + Arrays.asList(Map.of("param-1", "abc", "param-2", "999"), Map.of("param-3", "AAA")); + + + @Test + public void testPopulateInstanceParamsByInstanceName() throws Exception { + Service service = new Service(); + Resources resources = new Resources(); + resources.setVnfs(createVnfs()); + service.setResources(resources); + when(extractServiceFromUserParameters.getServiceFromRequestUserParams(any())).thenReturn(Optional.of(service)); + JsonObject jsonObject = new JsonObject(); + + configureInstanceParamsForVnf.populateInstanceParams(jsonObject, new ArrayList<>(), VNF_2_CUSTOMIZATION_ID, + VNF_2_INSTANCE_NAME); + + assertEquals("abc", jsonObject.get("param-1").getAsString()); + assertEquals("999", jsonObject.get("param-2").getAsString()); + assertEquals("AAA", jsonObject.get("param-3").getAsString()); + } + + @Test + public void testPopulateInstanceParamsByCustomizationId() throws Exception { + Service service = new Service(); + Resources resources = new Resources(); + resources.setVnfs(createVnfs()); + service.setResources(resources); + when(extractServiceFromUserParameters.getServiceFromRequestUserParams(any())).thenReturn(Optional.of(service)); + JsonObject jsonObject = new JsonObject(); + + // No instance name is passed + configureInstanceParamsForVnf.populateInstanceParams(jsonObject, new ArrayList<>(), VNF_1_CUSTOMIZATION_ID, + null); + + assertEquals("xyz", jsonObject.get("param-1").getAsString()); + assertEquals("123", jsonObject.get("param-2").getAsString()); + assertEquals("CCC", jsonObject.get("param-3").getAsString()); + } + + private List<Vnfs> createVnfs() { + Vnfs vnf1 = new Vnfs(); + vnf1.setInstanceName(VNF_1_INSTANCE_NAME); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationId(VNF_1_CUSTOMIZATION_ID); + vnf1.setModelInfo(modelInfo); + vnf1.setInstanceParams(VNF_1_INSTANCE_PARAMS); + + Vnfs vnf2 = new Vnfs(); + modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationId(VNF_2_CUSTOMIZATION_ID); + vnf2.setModelInfo(modelInfo); + vnf2.setInstanceName(VNF_2_INSTANCE_NAME); + vnf2.setInstanceParams(VNF_2_INSTANCE_PARAMS); + + return Arrays.asList(vnf1, vnf2); + } + +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsUtilTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsUtilTest.java new file mode 100644 index 0000000000..f7c3e8a192 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsUtilTest.java @@ -0,0 +1,24 @@ +package org.onap.so.client.cds; + +import static org.junit.Assert.assertEquals; +import com.google.gson.JsonObject; +import java.util.List; +import java.util.Map; +import org.junit.Test; + +public class ConfigureInstanceParamsUtilTest { + + @Test + public void testApplyParamsToObject() { + List<Map<String, String>> instanceParamsList = + List.of(Map.of("test-param-1", "value1", "test-param-2", "value2"), Map.of("test-param-3", "value3")); + JsonObject jsonObject = new JsonObject(); + + ConfigureInstanceParamsUtil.applyParamsToObject(instanceParamsList, jsonObject); + + assertEquals("value1", jsonObject.get("test-param-1").getAsString()); + assertEquals("value2", jsonObject.get("test-param-2").getAsString()); + assertEquals("value3", jsonObject.get("test-param-3").getAsString()); + } + +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ServiceCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ServiceCDSRequestProviderTest.java index 70ce3a1eed..c860d0fc5e 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ServiceCDSRequestProviderTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ServiceCDSRequestProviderTest.java @@ -23,6 +23,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.Test; import org.mockito.InjectMocks; +import org.mockito.Mock; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import static org.assertj.core.api.Assertions.assertThat; @@ -35,13 +36,15 @@ public class ServiceCDSRequestProviderTest extends AbstractVnfCDSRequestProvider @InjectMocks private ServiceCDSRequestProvider serviceCDSRequestProvider; + @Mock + private ConfigureInstanceParamsForService configureInstanceParamsForService; + @Test public void testRequestPayloadForCreateService() throws Exception { // given setScopeAndAction(SERVICE_SCOPE, SERVICE_ACTION); ServiceInstance instance = createServiceInstance(); - doReturn(instance).when(extractPojosForBB).extractByKey(buildingBlockExecution, - ResourceKey.SERVICE_INSTANCE_ID); + buildingBlockExecution.getGeneralBuildingBlock().setServiceInstance(instance); // when serviceCDSRequestProvider.setExecutionObject(buildingBlockExecution); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java index f224ebf21e..f5045b1ea0 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java @@ -22,18 +22,28 @@ package org.onap.so.client.cds; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.JsonObject; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.UUID; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; -import org.onap.so.client.exception.PayloadGenerationException; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.Resources; import org.onap.so.serviceinstancebeans.Service; +import org.onap.so.serviceinstancebeans.VfModules; +import org.onap.so.serviceinstancebeans.Vnfs; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.*; @@ -68,7 +78,7 @@ public class VfModuleCDSRequestProviderTest extends AbstractVnfCDSRequestProvide ResourceKey.VF_MODULE_ID); doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList()); doCallRealMethod().when(configureInstanceParamsForVfModule).populateInstanceParams(any(), any(), anyString(), - anyString()); + anyString(), any()); // when vfModuleCDSRequestProvider.setExecutionObject(buildingBlockExecution); @@ -105,7 +115,7 @@ public class VfModuleCDSRequestProviderTest extends AbstractVnfCDSRequestProvide ResourceKey.VF_MODULE_ID); doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList()); doCallRealMethod().when(configureInstanceParamsForVfModule).populateInstanceParams(any(), any(), anyString(), - anyString()); + anyString(), any()); vfModuleCDSRequestProvider.setExecutionObject(buildingBlockExecution); String payload = vfModuleCDSRequestProvider.buildRequestPayload(DEPLOY_ACTION).get(); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VnfCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VnfCDSRequestProviderTest.java index 7aafd900d4..e801c2afab 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VnfCDSRequestProviderTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VnfCDSRequestProviderTest.java @@ -50,8 +50,6 @@ public class VnfCDSRequestProviderTest extends AbstractVnfCDSRequestProviderTest ResourceKey.SERVICE_INSTANCE_ID); doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution, ResourceKey.GENERIC_VNF_ID); - doNothing().when(configureInstanceParamsForVnf).populateInstanceParams(any(), any(), anyString()); - // when vnfCDSRequestProvider.setExecutionObject(buildingBlockExecution); String payload = vnfCDSRequestProvider.buildRequestPayload(ASSIGN_ACTION).get(); @@ -81,7 +79,6 @@ public class VnfCDSRequestProviderTest extends AbstractVnfCDSRequestProviderTest ResourceKey.SERVICE_INSTANCE_ID); doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution, ResourceKey.GENERIC_VNF_ID); - doNothing().when(configureInstanceParamsForVnf).populateInstanceParams(any(), any(), any()); // when vnfCDSRequestProvider.setExecutionObject(buildingBlockExecution); diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/ModelInfoServiceInstance.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/ModelInfoServiceInstance.json index 42ae25a7b1..af3b3ffba8 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/ModelInfoServiceInstance.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/ModelInfoServiceInstance.json @@ -8,5 +8,6 @@ "service-type": "serviceType", "service-role": "serviceRole", "environment-context": "environmentContext", - "workload-context": "workloadContext" + "workload-context": "workloadContext", + "skip-post-instantiation-configuration": true }
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestDetailsInput_serviceUpgrade.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestDetailsInput_serviceUpgrade.json new file mode 100644 index 0000000000..2a721ddd96 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestDetailsInput_serviceUpgrade.json @@ -0,0 +1,31 @@ +{ + "modelInfo": { + "modelType": "service", + "modelInvariantId": "5d48acb5-097d-4982-aeb2-f4a3bd87d31b", + "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", + "modelName": "Sample Service Upgrade", + "modelVersion": "10.0" + }, + "owningEntity": { + "owningEntityId": "038d99af-0427-42c2-9d15-971b99b9b489", + "owningEntityName": "TEST" + }, + "project": { + "projectName": "projectName" + }, + "subscriberInfo": { + "globalSubscriberId": "subscriberId" + }, + "requestInfo": { + "instanceName": "test_Service", + "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", + "source": "VID", + "suppressRollback": false, + "requestorId": "xxxxxx" + }, + "requestParameters": { + "subscriptionServiceType": "test", + "aLaCarte": false, + "userParams": [] + } +} |