Dynamic Cloud Owner Support
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / adapter / vnf / mapper / VnfAdapterVfModuleObjectMapper.java
index 515f04b..81c2107 100644 (file)
@@ -23,11 +23,15 @@ package org.onap.so.client.adapter.vnf.mapper;
 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;
@@ -36,6 +40,7 @@ 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;
@@ -52,6 +57,7 @@ import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmN
 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;
@@ -157,11 +163,14 @@ public class VnfAdapterVfModuleObjectMapper {
        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);
                }
@@ -297,6 +306,9 @@ public class VnfAdapterVfModuleObjectMapper {
                                                                                buildVfModuleSriovParameters(paramsMap, network, networkKey);                                                                   
                                                                                // IPV4 and IPV6 Addresses
                                                                                buildVfModuleNetworkInformation(paramsMap, network, key, networkKey);
+                                                                               
+                                                                               buildVlanInformation(paramsMap, network, key, networkKey);
+                                                                               
                                                                        }
                                                                }
                                                        }
@@ -309,6 +321,36 @@ public class VnfAdapterVfModuleObjectMapper {
                }
        }
        
+       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();
@@ -506,33 +548,35 @@ public class VnfAdapterVfModuleObjectMapper {
                
                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);
+                               }
                        }
                }
        }