import static java.util.Arrays.asList;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Optional;
+import javax.annotation.PostConstruct;
+
+import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiSubInterfaceNetworkData;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleTopology;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfModuleAssignments;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVmNetworkData;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVmTopologyData;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataFloatingIps;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataInterfaceRoutePrefixes;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkInformationItems;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovParameters;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNames;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNetworks;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmnamesVnfcNames;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfNetworkData;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfTopology;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcNetworkData;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcNetworkData;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfResourceAssignments;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyVnfTopology;
import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
import org.onap.so.entity.MsoRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import org.onap.sdnc.apps.client.model.GenericResourceApiParam;
-import org.onap.sdnc.apps.client.model.GenericResourceApiParamParam;
-import org.onap.sdnc.apps.client.model.GenericResourceApiSubInterfaceNetworkData;
-import org.onap.sdnc.apps.client.model.GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVfmoduleassignmentsVfModuleAssignments;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVmNetworkData;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVmTopologyData;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVmnetworkdataFloatingIps;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVmnetworkdataInterfaceRoutePrefixes;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVmnetworkdataNetworkInformationItems;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVmtopologydataVmNames;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVmtopologydataVmNetworks;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVmtopologydataVmnamesVnfcNames;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVnfNetworkData;
-import org.onap.sdnc.apps.client.model.*;
-
-import org.onap.sdnc.apps.client.model.GenericResourceApiVnfresourceassignmentsVnfResourceAssignments;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks;
-import org.onap.sdnc.apps.client.model.GenericResourceApiVnftopologyVnfTopology;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
private static final String FLOATING_V6_IP = "_floating_v6_ip";
private static final String UNDERSCORE = "_";
+ @PostConstruct
+ public void init () {
+ mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
+ }
+
public CreateVfModuleRequest createVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion, OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
- VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
+ VfModule vfModule, VolumeGroup volumeGroup, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
CreateVfModuleRequest createVfModuleRequest = new CreateVfModuleRequest();
createVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
createVfModuleRequest.setTenantId(cloudRegion.getTenantId());
createVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
createVfModuleRequest.setVfModuleName(vfModule.getVfModuleName());
- createVfModuleRequest.setVnfType(genericVnf.getVnfType());
+ createVfModuleRequest.setVnfId(genericVnf.getVnfId());
+ createVfModuleRequest.setVnfType(genericVnf.getVnfType());
createVfModuleRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
createVfModuleRequest.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
createVfModuleRequest.setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
-
+ if (volumeGroup != null) {
+ createVfModuleRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId());
+ createVfModuleRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId());
+ }
+ VfModule baseVfModule = getBaseVfModule(genericVnf);
+ if (baseVfModule != null) {
+ createVfModuleRequest.setBaseVfModuleId(baseVfModule.getVfModuleId());
+ createVfModuleRequest.setBaseVfModuleStackId(baseVfModule.getHeatStackId());
+ }
createVfModuleRequest.setVfModuleParams(buildVfModuleParamsMap(requestContext, serviceInstance, genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse));
createVfModuleRequest.setSkipAAI(true);
private Map<String,String> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
- GenericResourceApiVnftopologyVnfTopology vnfTopology = mapper.readValue(sdncVnfQueryResponse, GenericResourceApiVnftopologyVnfTopology.class);
- GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = mapper.readValue(sdncVfModuleQueryResponse, GenericResourceApiVfmoduletopologyVfModuleTopology.class);
+
+
+ GenericResourceApiVnfTopology vnfTop= mapper.readValue(sdncVnfQueryResponse, GenericResourceApiVnfTopology.class);
+ GenericResourceApiVfModuleTopology vfModuleTop = mapper.readValue(sdncVfModuleQueryResponse, GenericResourceApiVfModuleTopology.class);
+ GenericResourceApiVnftopologyVnfTopology vnfTopology = vnfTop.getVnfTopology();
+ GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = vfModuleTop.getVfModuleTopology();
Map<String,String> paramsMap = new HashMap<>();
- if(vnfTopology.getSdncGeneratedCloudResources() && vfModuleTopology.getSdncGeneratedCloudResources()) {
+ if( vfModuleTopology.getSdncGeneratedCloudResources()) {
buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, true);
buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, null, true);
}
buildMandatoryParamsMap(paramsMap, serviceInstance, genericVnf, vfModule);
// Parameters received from the request should overwrite any parameters received from SDNC
- paramsMap.putAll(requestContext.getUserParams());
+
+ if (requestContext.getUserParams() != null) {
+ paramsMap.putAll(requestContext.getUserParams());
+ }
+ if (vfModule.getCloudParams() != null) {
+ paramsMap.putAll(vfModule.getCloudParams());
+ }
return paramsMap;
}
paramsMap.put("vf_module_id", vfModule.getVfModuleId());
paramsMap.put("vf_module_name", vfModule.getVfModuleName());
paramsMap.put("environment_context",serviceInstance.getModelInfoServiceInstance().getEnvironmentContext());
+ paramsMap.putIfAbsent("environment_context", "");
paramsMap.put("workload_context", serviceInstance.getModelInfoServiceInstance().getWorkloadContext());
+ paramsMap.putIfAbsent("workload_context", "");
Integer vfModuleIndex = vfModule.getModuleIndex();
if (vfModuleIndex != null) {
paramsMap.put("vf_module_index", vfModuleIndex.toString());
buildVfModuleSriovParameters(paramsMap, network, networkKey);
// IPV4 and IPV6 Addresses
buildVfModuleNetworkInformation(paramsMap, network, key, networkKey);
+
+ buildVlanInformation(paramsMap, network, key, networkKey);
+
}
}
}
}
}
+ protected void buildVlanInformation(Map<String, String> paramsMap,
+ GenericResourceApiVmNetworkData network, String key, String networkKey) {
+
+ String networkString = convertToString(network);
+ String vlanFilterKey = key + UNDERSCORE + networkKey + UNDERSCORE + "vlan_filter";
+ String privateVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "private_vlans";
+ String publicVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "public_vlans";
+ String guestVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "guest_vlans";
+
+ if (network.getSegmentationId() != null) {
+ paramsMap.put(vlanFilterKey, network.getSegmentationId());
+ }
+
+ List<String> privateVlans = jsonPath.locateResultList(networkString, "$.related-networks.related-network[?(@.vlan-tags.is-private == true)].vlan-tags.upper-tag-id");
+ List<String> publicVlans = jsonPath.locateResultList(networkString, "$.related-networks.related-network[?(@.vlan-tags.is-private == false)].vlan-tags.upper-tag-id");
+ List<String> concat = new ArrayList<>(privateVlans);
+ concat.addAll(publicVlans);
+ Collection<String> guestVlans = new HashSet<>(concat);
+
+ if (!privateVlans.isEmpty()) {
+ paramsMap.put(privateVlansKey, Joiner.on(",").join(privateVlans));
+ }
+ if (!publicVlans.isEmpty()) {
+ paramsMap.put(publicVlansKey, Joiner.on(",").join(publicVlans));
+ }
+ if (!guestVlans.isEmpty()) {
+ paramsMap.put(guestVlansKey, Joiner.on(",").join(guestVlans));
+ }
+ }
+
private void buildVfModuleVmNames(Map<String,String> paramsMap, GenericResourceApiVmTopologyData vm, String key) {
String values = "";
GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
}
private void buildVfModuleSriovParameters(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String networkKey) {
- /** SRIOV Parameters
+ // SRIOV Parameters
GenericResourceApiVmnetworkdataSriovParameters sriovParameters = network.getSriovParameters();
if (sriovParameters != null) {
GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters heatVlanFilters = sriovParameters.getHeatVlanFilters();
}
}
}
- **/
+
}
private void buildVfModuleNetworkInformation(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
String vmTypeKey = vnfcNetworkdata.getVnfcType();
GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts vnfcPorts = vnfcNetworkdata.getVnfcPorts();
- List<GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort> vnfcPortList = vnfcPorts.getVnfcPort();
- if (vnfcPortList != null) {
- for(int portIdx = 0; portIdx < vnfcPortList.size(); portIdx++){
-
- GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort vnfcPort = vnfcPortList.get(portIdx);
- GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces = vnfcPort.getVnicSubInterfaces();
-
- String vnicSubInterfacesString = convertToString(vnicSubInterfaces);
- String networkRoleKey = vnfcPort.getCommonSubInterfaceRole();
- String subInterfaceKey = createVnfcSubInterfaceKey(vmTypeKey, networkDataIdx, networkRoleKey, portIdx);
- String globalSubInterfaceKey = createGlobalVnfcSubInterfaceKey(vmTypeKey, networkRoleKey, portIdx);
+ if (vnfcPorts != null) {
+ List<GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort> vnfcPortList = vnfcPorts.getVnfcPort();
+ if (vnfcPortList != null) {
+ for(int portIdx = 0; portIdx < vnfcPortList.size(); portIdx++){
- buildVfModuleSubInterfacesCount(paramsMap, globalSubInterfaceKey, vnicSubInterfaces);
-
- buildVfModuleVlanTag(paramsMap, subInterfaceKey, vnicSubInterfacesString);
-
- buildVfModuleNetworkName(paramsMap, subInterfaceKey, vnicSubInterfacesString);
-
- buildVfModuleNetworkId(paramsMap, subInterfaceKey, vnicSubInterfacesString);
-
- buildVfModuleIpV4AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
-
- buildVfModuleIpV6AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
-
- buildVfModuleFloatingIpV4HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
-
- buildVfModuleFloatingIpV6HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
+ GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort vnfcPort = vnfcPortList.get(portIdx);
+ GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces = vnfcPort.getVnicSubInterfaces();
+
+ String vnicSubInterfacesString = convertToString(vnicSubInterfaces);
+ String networkRoleKey = vnfcPort.getCommonSubInterfaceRole();
+ String subInterfaceKey = createVnfcSubInterfaceKey(vmTypeKey, networkDataIdx, networkRoleKey, portIdx);
+ String globalSubInterfaceKey = createGlobalVnfcSubInterfaceKey(vmTypeKey, networkRoleKey, portIdx);
+
+ buildVfModuleSubInterfacesCount(paramsMap, globalSubInterfaceKey, vnicSubInterfaces);
+
+ buildVfModuleVlanTag(paramsMap, subInterfaceKey, vnicSubInterfacesString);
+
+ buildVfModuleNetworkName(paramsMap, subInterfaceKey, vnicSubInterfacesString);
+
+ buildVfModuleNetworkId(paramsMap, subInterfaceKey, vnicSubInterfacesString);
+
+ buildVfModuleIpV4AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
+
+ buildVfModuleIpV6AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
+
+ buildVfModuleFloatingIpV4HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
+
+ buildVfModuleFloatingIpV6HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
+ }
}
}
}
return json;
}
+
+ private VfModule getBaseVfModule(GenericVnf genericVnf) {
+ List<VfModule> vfModules = genericVnf.getVfModules();
+ VfModule baseVfModule = null;
+ if (vfModules != null) {
+ for(int i = 0; i < vfModules.size(); i++) {
+ if (vfModules.get(i).getModelInfoVfModule().getIsBaseBoolean()) {
+ baseVfModule = vfModules.get(i);
+ break;
+ }
+ }
+ }
+ return baseVfModule;
+ }
}