Merge "Adjust audit to use device_id to find nova server"
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / adapter / vnf / mapper / VnfAdapterVfModuleObjectMapper.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.client.adapter.vnf.mapper;
22
23 import static java.util.Arrays.asList;
24
25 import java.io.IOException;
26 import java.io.UnsupportedEncodingException;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.Collection;
30 import java.util.Collections;
31 import java.util.HashMap;
32 import java.util.HashSet;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.Optional;
36
37 import javax.annotation.PostConstruct;
38
39 import org.apache.commons.lang3.StringUtils;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
41 import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
42 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubInterfaceNetworkData;
43 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData;
44 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleTopology;
45 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfModuleAssignments;
46 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmNetworkData;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmTopologyData;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataFloatingIps;
51 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataInterfaceRoutePrefixes;
52 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkInformationItems;
53 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem;
54 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps;
55 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovParameters;
56 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters;
57 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNames;
58 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNetworks;
59 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmnamesVnfcNames;
60 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfNetworkData;
61 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfTopology;
62 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcNetworkData;
63 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcNetworkData;
64 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts;
65 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort;
66 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfResourceAssignments;
67 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones;
68 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks;
69 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyVnfTopology;
70 import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
71 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
72 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
73 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
74 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
75 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
76 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
77 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
78 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
79 import org.onap.so.entity.MsoRequest;
80 import org.onap.so.jsonpath.JsonPathUtil;
81 import org.springframework.beans.factory.annotation.Autowired;
82 import org.springframework.stereotype.Component;
83
84 import com.fasterxml.jackson.core.JsonParseException;
85 import com.fasterxml.jackson.core.JsonProcessingException;
86 import com.fasterxml.jackson.databind.DeserializationFeature;
87 import com.fasterxml.jackson.databind.JsonMappingException;
88 import com.fasterxml.jackson.databind.ObjectMapper;
89 import com.google.common.base.Joiner;
90
91
92 @Component
93 public class VnfAdapterVfModuleObjectMapper {
94         @Autowired
95         protected VnfAdapterObjectMapperUtils vnfAdapterObjectMapperUtils;
96         private static List<String> sdncResponseParamsToSkip = asList("vnf_id", "vf_module_id", "vnf_name", "vf_module_name");
97         
98         private ObjectMapper mapper = new ObjectMapper();
99         private static final JsonPathUtil jsonPath = JsonPathUtil.getInstance();
100         private static final String SUB_INT = "subint";
101         private static final String SUBNET_ID = "_subnet_id";
102         private static final String V6_SUBNET_ID = "_v6_subnet_id";
103         private static final String PORT = "port";
104         private static final String SUB_INT_COUNT = "_subintcount";
105         private static final String VLAN_IDS = "_vlan_ids";
106         private static final String NET_NAMES = "_net_names";
107         private static final String NET_IDS = "_net_ids";
108         private static final String IP = "_ip";
109         private static final String V6_IP = "_v6_ip";
110         private static final String FLOATING_IP = "_floating_ip";
111         private static final String FLOATING_V6_IP = "_floating_v6_ip";
112         private static final String UNDERSCORE = "_";
113         
114         @PostConstruct
115         public void init () {
116                 mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
117         }
118         
119         public CreateVfModuleRequest createVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion, OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf, 
120                                 VfModule vfModule, VolumeGroup volumeGroup, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
121                 CreateVfModuleRequest createVfModuleRequest = new CreateVfModuleRequest();
122                 
123                 createVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
124                 createVfModuleRequest.setCloudOwner(cloudRegion.getCloudOwner());
125                 createVfModuleRequest.setTenantId(cloudRegion.getTenantId());
126                 createVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
127                 createVfModuleRequest.setVfModuleName(vfModule.getVfModuleName());
128                 createVfModuleRequest.setVnfId(genericVnf.getVnfId());
129                 createVfModuleRequest.setVnfType(genericVnf.getVnfType());              
130                 createVfModuleRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
131                 createVfModuleRequest.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
132                 createVfModuleRequest.setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
133                 if (volumeGroup != null) {
134                         createVfModuleRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId());
135                         createVfModuleRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId());
136                 }
137                 VfModule baseVfModule = getBaseVfModule(genericVnf);            
138                 if (baseVfModule != null) {
139                         createVfModuleRequest.setBaseVfModuleId(baseVfModule.getVfModuleId());
140                         createVfModuleRequest.setBaseVfModuleStackId(baseVfModule.getHeatStackId());
141                 }
142                 createVfModuleRequest.setVfModuleParams(buildVfModuleParamsMap(requestContext, serviceInstance, genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse));
143                 
144                 createVfModuleRequest.setSkipAAI(true);         
145                 createVfModuleRequest.setBackout(Boolean.TRUE.equals(orchestrationContext.getIsRollbackEnabled()));
146                 createVfModuleRequest.setFailIfExists(true);
147                 
148                 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);               
149                 createVfModuleRequest.setMsoRequest(msoRequest);
150                 
151                 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
152                 createVfModuleRequest.setMessageId(messageId);
153                 createVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
154                 
155                 return createVfModuleRequest;
156         }
157         
158         private MsoRequest buildMsoRequest(RequestContext requestContext,ServiceInstance serviceInstance) {
159                 MsoRequest msoRequest = new MsoRequest();
160                 msoRequest.setRequestId(requestContext.getMsoRequestId());
161                 msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
162                 return msoRequest;              
163         }
164         
165         private Map<String,Object> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance, GenericVnf genericVnf, 
166                                 VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
167                 
168                 
169                 GenericResourceApiVnfTopology vnfTop= mapper.readValue(sdncVnfQueryResponse, GenericResourceApiVnfTopology.class);
170                 GenericResourceApiVfModuleTopology vfModuleTop = mapper.readValue(sdncVfModuleQueryResponse, GenericResourceApiVfModuleTopology.class);
171                 GenericResourceApiVnftopologyVnfTopology vnfTopology = vnfTop.getVnfTopology();
172                 GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = vfModuleTop.getVfModuleTopology();
173                 Map<String,Object> paramsMap = new HashMap<>();
174
175                 if( vfModuleTopology.getSdncGeneratedCloudResources()) {
176                         buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, true);
177                         buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, null, true);
178                 }
179                 else {
180                         Map<String,String> networkRoleMap = buildNetworkRoleMap(vfModuleTopology);
181                         buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, false);
182                         buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, networkRoleMap, false);
183                 }
184                 
185                 buildMandatoryParamsMap(paramsMap, serviceInstance, genericVnf, vfModule);
186                 
187                 // Parameters received from the request should overwrite any parameters received from SDNC
188                 paramsMap.putAll(requestContext.getUserParams());
189                 
190                 if (vfModule.getCloudParams() != null) {
191                         paramsMap.putAll(vfModule.getCloudParams());
192                 }
193                 return paramsMap;
194         }
195         
196         private void  buildMandatoryParamsMap(Map<String,Object> paramsMap, ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule) {                
197                 paramsMap.put("vnf_id", genericVnf.getVnfId());
198                 paramsMap.put("vnf_name", genericVnf.getVnfName());
199                 paramsMap.put("vf_module_id", vfModule.getVfModuleId());
200                 paramsMap.put("vf_module_name", vfModule.getVfModuleName());
201                 paramsMap.put("environment_context",serviceInstance.getModelInfoServiceInstance().getEnvironmentContext());
202                 paramsMap.putIfAbsent("environment_context", "");
203                 paramsMap.put("workload_context", serviceInstance.getModelInfoServiceInstance().getWorkloadContext());
204                 paramsMap.putIfAbsent("workload_context", "");
205                 Integer vfModuleIndex = vfModule.getModuleIndex();
206                 if (vfModuleIndex != null) {
207                         paramsMap.put("vf_module_index", vfModuleIndex.toString());
208                 }               
209         }
210         
211         private void buildParamsMapFromVnfSdncResponse(Map<String,Object> paramsMap, GenericResourceApiVnftopologyVnfTopology vnfTopology, Map<String,String> networkRoleMap, boolean skipVnfResourceAssignments) throws JsonParseException, JsonMappingException, IOException {                                
212                 // Get VNF parameters from SDNC response
213                 GenericResourceApiParam vnfParametersData = vnfTopology.getVnfParametersData();
214                 buildParamsMapFromSdncParams(paramsMap, vnfParametersData);
215                 
216                 if(!skipVnfResourceAssignments) {
217                         GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments = vnfTopology.getVnfResourceAssignments();                
218                         if (vnfResourceAssignments != null) {
219                                 // Availability Zones
220                                 buildAvailabilityZones(paramsMap, vnfResourceAssignments);
221                                 // VNF Networks
222                                 buildVnfNetworks(paramsMap, vnfResourceAssignments, networkRoleMap);                    
223                         }
224                 }
225         }
226         
227         private void buildAvailabilityZones (Map<String,Object> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments) {             
228                 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones availabilityZones = vnfResourceAssignments.getAvailabilityZones();
229                 if (availabilityZones != null) {
230                         List<String> availabilityZonesList = availabilityZones.getAvailabilityZone();
231                         if (availabilityZonesList != null) {
232                                 for(int i = 0; i < availabilityZonesList.size(); i++) {
233                                         paramsMap.put("availability_zone_" + i, availabilityZonesList.get(i));
234                                 }
235                         }
236                 }
237         }
238         
239         private void buildVnfNetworks (Map<String,Object> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments, Map<String,String> networkRoleMap) {
240                 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworks = vnfResourceAssignments.getVnfNetworks();
241                 if (vnfNetworks != null) {
242                         List<GenericResourceApiVnfNetworkData> vnfNetworksList = vnfNetworks.getVnfNetwork();
243                         if (vnfNetworksList != null) {
244                                 for (int i = 0; i < vnfNetworksList.size(); i++) {
245                                         GenericResourceApiVnfNetworkData vnfNetwork = vnfNetworksList.get(i);
246                                         String networkRole = vnfNetwork.getNetworkRole();
247                                         String vnfNetworkKey = networkRoleMap.get(networkRole);
248                                         if (vnfNetworkKey == null || vnfNetworkKey.isEmpty()) {
249                                                 vnfNetworkKey = networkRole;
250                                         }               
251                                         
252                                         String vnfNetworkNeutronIdValue = vnfNetwork.getNeutronId();
253                                         paramsMap.put(vnfNetworkKey + "_net_id", vnfNetworkNeutronIdValue);
254                                         String vnfNetworkNetNameValue = vnfNetwork.getNetworkName();
255                                         paramsMap.put(vnfNetworkKey + "_net_name", vnfNetworkNetNameValue);
256                                         String vnfNetworkNetFqdnValue = vnfNetwork.getContrailNetworkFqdn();
257                                         paramsMap.put(vnfNetworkKey + "_net_fqdn", vnfNetworkNetFqdnValue);
258                                 
259                                         buildVnfNetworkSubnets(paramsMap, vnfNetwork, vnfNetworkKey);
260                                         
261                                 }
262                         }
263                 }
264         }
265         
266         private void buildVnfNetworkSubnets(Map<String,Object> paramsMap, GenericResourceApiVnfNetworkData vnfNetwork, String vnfNetworkKey) {
267                 String vnfNetworkString = convertToString(vnfNetwork);
268                 Optional<String> ipv4Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv4' && @.dhcp-enabled == 'Y')].subnet-id");
269                 if(ipv4Ips.isPresent())
270                         addPairToMap(paramsMap, vnfNetworkKey, SUBNET_ID, ipv4Ips.get());
271                 
272                 Optional<String> ipv6Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv6' && @.dhcp-enabled == 'Y')].subnet-id");
273                 if(ipv6Ips.isPresent())
274                         addPairToMap(paramsMap, vnfNetworkKey, V6_SUBNET_ID, ipv6Ips.get());
275         }       
276
277         private void buildParamsMapFromVfModuleSdncResponse(Map<String,Object> paramsMap, GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology, boolean skipVfModuleAssignments) throws JsonParseException, JsonMappingException, IOException {          
278                 // Get VF Module parameters from SDNC response
279                 GenericResourceApiParam vfModuleParametersData = vfModuleTopology.getVfModuleParameters();
280                 buildParamsMapFromSdncParams(paramsMap, vfModuleParametersData);
281                 
282                 if(!skipVfModuleAssignments) {          
283                         GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments = vfModuleTopology.getVfModuleAssignments();
284                         if (vfModuleAssignments != null) {                      
285                                 // VNF-VMS
286                                 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
287                                 if (vms != null) {
288                                 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
289                                         if (vmsList != null) {
290                                                 for (GenericResourceApiVmTopologyData vm : vmsList){
291                                                         String key = vm.getVmType();
292                                                         buildVfModuleVmNames(paramsMap, vm, key);                                                                               
293                                                         GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
294                                                         if (vmNetworks != null) {
295                                                                 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
296                                                                 if (vmNetworksList != null) {
297                                                                                 for(int n = 0; n < vmNetworksList.size(); n++){
298                                                                                 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
299                                                                                 network.getNetworkRoleTag();
300                                                                                 String networkKey = network.getNetworkRole();   
301                                                                                 // Floating IPs
302                                                                                 buildVfModuleFloatingIps(paramsMap, network, key, networkKey);                                                                  
303                                                                                 // Interface Route Prefixes
304                                                                                 buildVfModuleInterfaceRoutePrefixes(paramsMap, network, key, networkKey);                                                                       
305                                                                                 // SRIOV Parameters
306                                                                                 buildVfModuleSriovParameters(paramsMap, network, networkKey);                                                                   
307                                                                                 // IPV4 and IPV6 Addresses
308                                                                                 buildVfModuleNetworkInformation(paramsMap, network, key, networkKey);
309                                                                                 
310                                                                                 buildVlanInformation(paramsMap, network, key, networkKey);
311                                                                                 
312                                                                         }
313                                                                 }
314                                                         }
315                                                         
316                                                         buildParamsMapFromVfModuleForHeatTemplate(paramsMap, vm);
317                                                 }
318                                         }                               
319                                 }               
320                         }
321                 }
322         }
323         
324         protected void buildVlanInformation(Map<String, Object> paramsMap,
325                         GenericResourceApiVmNetworkData network, String key, String networkKey) {
326                 
327                 String networkString = convertToString(network);
328                 String vlanFilterKey = key + UNDERSCORE + networkKey + UNDERSCORE + "vlan_filter";
329                 String privateVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "private_vlans";
330                 String publicVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "public_vlans";
331                 String guestVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "guest_vlans";
332                 
333                 if (network.getSegmentationId() != null) {
334                         paramsMap.put(vlanFilterKey, network.getSegmentationId());
335                 }
336                 
337                 List<String> privateVlans = jsonPath.locateResultList(networkString, "$.related-networks.related-network[?(@.vlan-tags.is-private == true)].vlan-tags.upper-tag-id");
338                 List<String> publicVlans = jsonPath.locateResultList(networkString, "$.related-networks.related-network[?(@.vlan-tags.is-private == false)].vlan-tags.upper-tag-id");
339                 List<String> concat = new ArrayList<>(privateVlans);
340                 concat.addAll(publicVlans);
341                 Collection<String> guestVlans = new HashSet<>(concat);
342                 
343                 if (!privateVlans.isEmpty()) {
344                         paramsMap.put(privateVlansKey, Joiner.on(",").join(privateVlans));
345                 }
346                 if (!publicVlans.isEmpty()) {
347                         paramsMap.put(publicVlansKey, Joiner.on(",").join(publicVlans));
348                 }
349                 if (!guestVlans.isEmpty()) {
350                         paramsMap.put(guestVlansKey, Joiner.on(",").join(guestVlans));
351                 }
352         }
353
354         private void buildVfModuleVmNames(Map<String,Object> paramsMap, GenericResourceApiVmTopologyData vm, String key) {
355                 String values = "";
356                 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
357                 if (vmNames != null) {
358                         List<String> valueList = vmNames.getVmName();
359                         if (valueList != null) {
360                                 for(int i = 0; i < valueList.size(); i++){
361                                         String value = valueList.get(i);                                        
362                                         if (i != valueList.size() - 1) {
363                                                 values += value + ",";
364                                         }
365                                         else {
366                                                 values += value;
367                                         }
368                                         paramsMap.put(key + "_name_" + i, value);
369                                 }
370                                 paramsMap.put(key + "_names", values);
371                         }
372                 }
373         }
374         
375         private void buildVfModuleFloatingIps(Map<String,Object> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
376                 GenericResourceApiVmnetworkdataFloatingIps floatingIps = network.getFloatingIps();
377                 if (floatingIps != null) {
378                         List<String> floatingIpV4List = floatingIps.getFloatingIpV4();
379                         if (floatingIpV4List != null) {
380                                 // add only one ipv4 floating ip for now
381                                 String floatingIPKey = key + UNDERSCORE + networkKey + FLOATING_IP;
382                                 String floatingIPKeyValue = floatingIpV4List.get(0);
383                                 if (floatingIPKeyValue != null && !floatingIPKeyValue.isEmpty()) {
384                                         paramsMap.put(floatingIPKey, floatingIPKeyValue);
385                                 }
386                         }
387                         // add only one ipv6 floating ip for now
388                         List<String> floatingIpV6List = floatingIps.getFloatingIpV6();
389                         if (floatingIpV6List != null) {
390                                 String floatingIPV6Key = key + UNDERSCORE + networkKey + FLOATING_V6_IP;
391                                 String floatingIPV6KeyValue = floatingIpV6List.get(0);
392                                 if (floatingIPV6KeyValue != null && !floatingIPV6KeyValue.isEmpty()) {
393                                         paramsMap.put(floatingIPV6Key, floatingIPV6KeyValue);
394                                 }
395                         }
396                 }
397         }
398         
399         private void buildVfModuleInterfaceRoutePrefixes(Map<String,Object> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
400                 GenericResourceApiVmnetworkdataInterfaceRoutePrefixes interfaceRoutePrefixes = network.getInterfaceRoutePrefixes();
401                 if (interfaceRoutePrefixes != null) {
402                         List<String> interfaceRoutePrefixesList = interfaceRoutePrefixes.getInterfaceRoutePrefix();
403                         StringBuilder sbInterfaceRoutePrefixes = new StringBuilder();
404                         sbInterfaceRoutePrefixes.append("[");
405                         if (interfaceRoutePrefixesList != null) {
406                                 for(int a = 0; a < interfaceRoutePrefixesList.size(); a++){
407                                         String interfaceRoutePrefixValue = interfaceRoutePrefixesList.get(a);                                           
408                                         if (a != interfaceRoutePrefixesList.size() - 1) {
409                                                 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}" + ",");
410                                         }
411                                         else {
412                                                 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}");                                              
413                                         }
414                                 }                                                       
415                                 sbInterfaceRoutePrefixes.append("]");
416                                 if (interfaceRoutePrefixesList.size() > 0) {
417                                         paramsMap.put(key + UNDERSCORE + networkKey + "_route_prefixes", sbInterfaceRoutePrefixes.toString());
418                                 }
419                         }
420                 }
421         }
422         
423         private void buildVfModuleSriovParameters(Map<String,Object> paramsMap, GenericResourceApiVmNetworkData network, String networkKey) {
424                 // SRIOV Parameters
425                 GenericResourceApiVmnetworkdataSriovParameters sriovParameters = network.getSriovParameters();
426                 if (sriovParameters != null) {
427                         GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters heatVlanFilters = sriovParameters.getHeatVlanFilters();
428                         if (heatVlanFilters != null) {
429                                 List<String> heatVlanFiltersList = heatVlanFilters.getHeatVlanFilter();
430                                 StringBuilder sriovFilterBuf = new StringBuilder();
431                                 if (heatVlanFiltersList != null) {
432                                         for(int a = 0; a < heatVlanFiltersList.size(); a++){
433                                                 String heatVlanFilterValue = heatVlanFiltersList.get(a);                                                
434                                                 if (a != heatVlanFiltersList.size() - 1) {
435                                                         sriovFilterBuf.append(heatVlanFilterValue).append(",");
436                                                 }
437                                                 else {
438                                                         sriovFilterBuf.append(heatVlanFilterValue);                                             
439                                                 }
440                                         }                                                       
441                                         if (heatVlanFiltersList.size() > 0) {
442                                                 paramsMap.put(networkKey + "_ATT_VF_VLAN_FILTER", sriovFilterBuf.toString());
443                                         }
444                                 }
445                         }
446                 }
447         }
448         
449         private void buildVfModuleNetworkInformation(Map<String,Object> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
450                 
451                 GenericResourceApiVmnetworkdataNetworkInformationItems networkInformationItems = network.getNetworkInformationItems();
452                 StringBuilder sbIpv4Ips = new StringBuilder();
453                 StringBuilder sbIpv6Ips = new StringBuilder();
454                 
455                 if (networkInformationItems != null) {
456                         List<GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem> networkInformationItemList = networkInformationItems.getNetworkInformationItem();
457                         if (networkInformationItemList != null) {
458                                 for(int a = 0; a < networkInformationItemList.size(); a++){
459                                         GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem ipAddress = networkInformationItemList.get(a);
460                                         if (ipAddress != null) {
461                                                 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps ips = ipAddress.getNetworkIps();
462                                                 if (ips != null) {
463                                                         List<String> ipsList = ips.getNetworkIp();
464                                                         if (ipsList != null) {                                                  
465                                                                 String ipVersion = ipAddress.getIpVersion();
466                                                                 for (int b = 0; b < ipsList.size(); b++) {
467                                                                         String ipAddressValue = ipsList.get(b);
468                                                                         if (ipVersion.equals("ipv4")) {
469                                                                                 if (b != ipsList.size() - 1) {
470                                                                                         sbIpv4Ips.append(ipAddressValue + ",");
471                                                                                 }
472                                                                                 else {
473                                                                                         sbIpv4Ips.append(ipAddressValue);
474                                                                                 }
475                                                                                 paramsMap.put(key + UNDERSCORE + networkKey + IP + UNDERSCORE + b, ipAddressValue);                                             
476                                                                         }
477                                                                         else if (ipVersion.equals("ipv6")) {
478                                                                                 if (b != ipsList.size() - 1) {
479                                                                                         sbIpv6Ips.append(ipAddressValue + ",");
480                                                                                 }
481                                                                                 else {
482                                                                                         sbIpv6Ips.append(ipAddressValue);
483                                                                                 }
484                                                                                 paramsMap.put(key + UNDERSCORE + networkKey + V6_IP + UNDERSCORE + b, ipAddressValue);                                                          
485                                                                         }                                                       
486                                                                 }
487                                                                 paramsMap.put(key + UNDERSCORE + networkKey + "_ips", sbIpv4Ips.toString());
488                                                                 paramsMap.put(key + UNDERSCORE + networkKey + "_v6_ips", sbIpv6Ips.toString());                                                         
489                                                         }
490                                                 }
491                                         }
492                                 }
493                         }
494                 }
495         }
496         
497         /*
498          * Build Mapping from GenericResourceApi SDNC for Heat Template so that AIC - PO gets accurate requests for vf module assignments.
499          * Build Count of SubInterfaces, VLAN Tag, network_name, network_id,
500          * ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6) for Heat Template
501          */     
502         private void buildParamsMapFromVfModuleForHeatTemplate(Map<String,Object> paramsMap, GenericResourceApiVmTopologyData vm) {
503                 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
504         
505                 if (vmNames != null) {
506                 
507                         List<GenericResourceApiVmtopologydataVmnamesVnfcNames> vnfcNamesList = vmNames.getVnfcNames();
508                         if (vnfcNamesList != null) {
509                                 
510                                 for(int i = 0; i < vnfcNamesList.size(); i++){
511                                         
512                                         GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames = vnfcNamesList.get(i);
513                                         parseVnfcNamesData(paramsMap, vnfcNames);
514                                 }
515                         }
516                 }
517         }
518         
519         /*
520          * Parse vnfcNames data to build Mapping from GenericResourceApi SDNC for Heat Template.
521          */     
522         private void parseVnfcNamesData(Map<String,Object> paramsMap, GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames) {
523                 
524                 if (vnfcNames != null) {
525                         GenericResourceApiVnfcNetworkData vnfcNetworks = vnfcNames.getVnfcNetworks();
526                         if (vnfcNetworks != null) {
527                                 List<GenericResourceApiVnfcnetworkdataVnfcNetworkData> vnfcNetworkdataList = vnfcNetworks.getVnfcNetworkData();
528                                 
529                                 if (vnfcNetworkdataList != null) {
530                                         
531                                         for(int networkDataIdx = 0; networkDataIdx < vnfcNetworkdataList.size(); networkDataIdx++){
532                                         
533                                                 GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata = vnfcNetworkdataList.get(networkDataIdx);
534                                                 parseVnfcNetworkData(paramsMap, vnfcNetworkdata, networkDataIdx);
535                                         }
536                                 }
537                         }
538                 }
539         }
540         
541         /*
542          * Parse VnfcNetworkData to build Mapping from GenericResourceApi SDNC for Heat Template.
543          * Build Count of SubInterfaces, VLAN Tag, network_name, network_id,
544          * ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6) for Heat Template
545          */     
546         private void parseVnfcNetworkData(Map<String,Object> paramsMap, GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata, int networkDataIdx) {
547                 
548                 String vmTypeKey = vnfcNetworkdata.getVnfcType();
549                 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts vnfcPorts = vnfcNetworkdata.getVnfcPorts();
550                 if (vnfcPorts != null) {
551                         List<GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort> vnfcPortList = vnfcPorts.getVnfcPort();         
552                         if (vnfcPortList != null) {                                                                     
553                                 for(int portIdx = 0; portIdx < vnfcPortList.size(); portIdx++){
554                                 
555                                         GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort vnfcPort = vnfcPortList.get(portIdx);
556                                         GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces = vnfcPort.getVnicSubInterfaces();
557                                 
558                                         String vnicSubInterfacesString = convertToString(vnicSubInterfaces);
559                                         String  networkRoleKey = vnfcPort.getCommonSubInterfaceRole();  
560                                         String subInterfaceKey = createVnfcSubInterfaceKey(vmTypeKey, networkDataIdx, networkRoleKey, portIdx);
561                                         String globalSubInterfaceKey = createGlobalVnfcSubInterfaceKey(vmTypeKey, networkRoleKey, portIdx);
562                                         
563                                         buildVfModuleSubInterfacesCount(paramsMap, globalSubInterfaceKey, vnicSubInterfaces);
564                                 
565                                         buildVfModuleVlanTag(paramsMap, subInterfaceKey, vnicSubInterfacesString);
566                                 
567                                         buildVfModuleNetworkName(paramsMap, subInterfaceKey, vnicSubInterfacesString);
568                                 
569                                         buildVfModuleNetworkId(paramsMap, subInterfaceKey, vnicSubInterfacesString);
570         
571                                         buildVfModuleIpV4AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
572                                 
573                                         buildVfModuleIpV6AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
574                                 
575                                         buildVfModuleFloatingIpV4HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
576         
577                                         buildVfModuleFloatingIpV6HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
578                                 }
579                         }
580                 }
581         }
582         
583         /*
584          * Build "count" (calculating the total number of sub-interfaces) for Heat Template
585          * Building Criteria : {vm-type}_subint_{network-role}_port_{index}_subintcount
586          * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
587          * Example: fw_subint_ctrl_port_0_subintcount
588          * 
589          */
590         private void buildVfModuleSubInterfacesCount(Map<String,Object> paramsMap, String keyPrefix, GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces) {
591
592                 List<GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData> subInterfaceNetworkDataList = vnicSubInterfaces.getSubInterfaceNetworkData();
593                 
594                 if ( (subInterfaceNetworkDataList != null) && !subInterfaceNetworkDataList.isEmpty() ) {
595                         addPairToMap(paramsMap, keyPrefix, SUB_INT_COUNT, String.valueOf(subInterfaceNetworkDataList.size()));
596                 }
597     }
598         
599         protected String createVnfcSubInterfaceKey(String vmTypeKey, int networkDataIdx, String networkRoleKey, int portIdx) {
600                 
601                 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, networkDataIdx, SUB_INT, networkRoleKey, PORT, portIdx));
602         }
603         
604         protected String createGlobalVnfcSubInterfaceKey(String vmTypeKey,String networkRoleKey, int portIdx) {
605                 
606                 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, SUB_INT, networkRoleKey, PORT, portIdx));
607         }
608
609         /*
610          * Build VLAN Tag for Heat Template
611          * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_vlan_ids
612          * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
613          * Example: fw_0_subint_ctrl_port_0_vlan_ids
614          * 
615          */
616         protected void buildVfModuleVlanTag(Map<String,Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
617                 
618                 List<String> vlanTagIds = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].vlan-tag-id");
619
620                 addPairToMap(paramsMap, keyPrefix, VLAN_IDS, vlanTagIds);
621         }
622         /*
623          * Build "network_name" for Heat Template
624          * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_net_names
625          * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
626          * Example: fw_0_subint_ctrl_port_0_net_names
627          * 
628          */
629         protected void buildVfModuleNetworkName(Map<String,Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
630                 
631                 List<String> neworkNames = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-name");
632                 
633                 addPairToMap(paramsMap, keyPrefix, NET_NAMES, neworkNames);
634         }
635
636         /*
637          * Build "network_id" for Heat Template
638          * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_net_ids
639          * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
640          * Example: fw_0_subint_ctrl_port_0_net_ids
641          * 
642          */
643         protected void buildVfModuleNetworkId(Map<String,Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
644                 
645                 List<String> neworkIds = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-id");
646                 
647                 addPairToMap(paramsMap, keyPrefix, NET_IDS, neworkIds);
648         }
649         
650         /*
651          * Build ip_address for V4 for Heat Template
652          * Building Criteria : 
653          * {vm-type}_{index}_subint_{network-role}_port_{index}_ip_{index}  -- for ipV4
654          * key = vm-type, networkRoleKey = NetWork-Role
655          */
656         protected void buildVfModuleIpV4AddressHeatTemplate(Map<String,Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
657                 
658                 List<String> ipv4Ips = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv4')].network-ips.network-ip[*]");
659                 
660                 addPairToMap(paramsMap, keyPrefix, IP, ipv4Ips);
661
662                 for (int i = 0; i < ipv4Ips.size(); i++) {
663                         addPairToMap(paramsMap, keyPrefix, IP + UNDERSCORE + i, ipv4Ips.get(i));
664                 }
665
666         }
667         
668         /*
669          * Build ip_address for Heat Template
670          * Building Criteria : 
671          * {vm-type}_{index}_subint_{network-role}_port_{index}_v6_ip_{index} -- for ipV6
672          * key = vm-type, networkRoleKey = NetWork-Role
673          */
674         protected void buildVfModuleIpV6AddressHeatTemplate(Map<String,Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
675                 
676                 List<String> ipv6Ips = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv6')].network-ips.network-ip[*]");
677
678                 addPairToMap(paramsMap, keyPrefix, V6_IP, ipv6Ips);
679
680                 for (int i = 0; i < ipv6Ips.size(); i++) {
681                         addPairToMap(paramsMap, keyPrefix, V6_IP + UNDERSCORE + i, ipv6Ips.get(i));
682                 }
683     }
684         
685         /*
686          * Build floatingip_address for Heat Template
687          * Building Criteria : 
688          * {vm-type}_subint_{network-role}_port_{index}_floating_ip  -- for ipV4
689          */
690         protected void buildVfModuleFloatingIpV4HeatTemplate(Map<String,Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
691                 
692                 List<String> floatingV4 = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].floating-ips.floating-ip-v4[*]");
693
694                 if (!floatingV4.isEmpty()) {
695                         floatingV4 = Collections.singletonList(floatingV4.get(0));
696                 }
697                 addPairToMap(paramsMap, keyPrefix, FLOATING_IP, floatingV4);
698
699         }
700         
701         /*
702          * Build floatingip_address for Heat Template
703          * Building Criteria : 
704          * {vm-type}_subint_{network-role}_port_{index}_floating_v6_ip -- for ipV6
705          */
706         protected void buildVfModuleFloatingIpV6HeatTemplate(Map<String,Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
707                                 
708                 List<String> floatingV6 = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].floating-ips.floating-ip-v6[*]");
709                 
710                 if (!floatingV6.isEmpty()) {
711                         floatingV6 = Collections.singletonList(floatingV6.get(0));
712                 }
713                 addPairToMap(paramsMap, keyPrefix, FLOATING_V6_IP, floatingV6);
714         }
715         
716         protected void addPairToMap(Map<String, Object> paramsMap, String keyPrefix, String key, String value) {
717                 
718                 addPairToMap(paramsMap, keyPrefix, key, Collections.singletonList(value));
719         }
720
721         protected void addPairToMap(Map<String, Object> paramsMap, String keyPrefix, String key, List<String> value) {
722                 
723                 if (!value.isEmpty()) {
724                         paramsMap.put(keyPrefix + key, Joiner.on(",").join(value));
725                 }
726         }
727         
728         private void buildParamsMapFromSdncParams(Map<String,Object> paramsMap, GenericResourceApiParam parametersData) {               
729                 if (parametersData != null) {
730                         List<GenericResourceApiParamParam> paramsList = parametersData.getParam();
731                         if (paramsList != null) {
732                                 for (int i = 0; i < paramsList.size(); i++) {
733                                         GenericResourceApiParamParam param = paramsList.get(i);
734                                         String parameterName = param.getName();
735                                         if (!sdncResponseParamsToSkip.contains(parameterName)) {
736                                                 String parameterValue = param.getValue();
737                                                 paramsMap.put(parameterName, parameterValue);
738                                         }
739                                 }                               
740                         }
741                 }                                               
742         }
743         
744         private Map<String,String> buildNetworkRoleMap(GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology) throws JsonParseException, JsonMappingException, IOException {
745                 Map<String, String> networkRoleMap = new HashMap<>();           
746                 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments = vfModuleTopology.getVfModuleAssignments();
747                 if (vfModuleAssignments != null) {                      
748                         GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
749                         if (vms != null) {
750                         List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
751                         if (vmsList != null) {
752                                         for (GenericResourceApiVmTopologyData vm : vmsList){                                                    
753                                                 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
754                                                 if (vmNetworks != null) {
755                                                         List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
756                                                         if (vmNetworksList != null) {
757                                                                         for(int n = 0; n < vmNetworksList.size(); n++){
758                                                                                 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
759                                                                                 String networkRole = network.getNetworkRole();
760                                                                                 String networkRoleValue = network.getNetworkRoleTag();
761                                                                                 if (networkRoleValue ==  null || networkRoleValue.isEmpty()) {
762                                                                                         networkRoleValue = networkRole;
763                                                                                 }
764                                                                                 networkRoleMap.put(networkRole, networkRoleValue);
765                                                                         }
766                                                                 }
767                                                         }
768                                                 }
769                                         }
770                                 }
771                         }
772                         return networkRoleMap;
773                 }
774         
775         public DeleteVfModuleRequest deleteVfModuleRequestMapper(RequestContext requestContext,CloudRegion cloudRegion, 
776                         ServiceInstance serviceInstance, GenericVnf genericVnf,
777                         VfModule vfModule) throws IOException {
778                 DeleteVfModuleRequest deleteVfModuleRequest = new DeleteVfModuleRequest();
779                 deleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
780                 deleteVfModuleRequest.setCloudOwner(cloudRegion.getCloudOwner());
781                 deleteVfModuleRequest.setTenantId(cloudRegion.getTenantId());
782                 deleteVfModuleRequest.setVnfId(genericVnf.getVnfId());
783                 deleteVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
784                 if (!StringUtils.isEmpty(vfModule.getHeatStackId())){
785                         deleteVfModuleRequest.setVfModuleStackId(vfModule.getHeatStackId());//DoDVfMod_heatStackId
786                 } else
787                 {
788                         deleteVfModuleRequest.setVfModuleStackId(vfModule.getVfModuleName());
789                 }
790                 
791                 deleteVfModuleRequest.setSkipAAI(true);
792                 setIdAndUrl(deleteVfModuleRequest);
793                 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);       
794                 deleteVfModuleRequest.setMsoRequest(msoRequest);
795                 return deleteVfModuleRequest;
796         }
797         
798         protected void setIdAndUrl(DeleteVfModuleRequest deleteVfModuleRequest) throws UnsupportedEncodingException{
799                 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
800                 deleteVfModuleRequest.setMessageId(messageId);          
801                 deleteVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
802         }
803         
804         private String convertToString(Object obj) {
805                 String json;
806                 try {
807                         json = mapper.writeValueAsString(obj);
808                 } catch (JsonProcessingException e) {
809                         json = "{}";
810                 }
811                 
812                 return json;
813         }
814         
815         private VfModule getBaseVfModule(GenericVnf genericVnf) {
816                 List<VfModule> vfModules = genericVnf.getVfModules();
817                 VfModule baseVfModule = null;
818                 if (vfModules != null) {
819                         for(int i = 0; i < vfModules.size(); i++) {
820                                 if (vfModules.get(i).getModelInfoVfModule().getIsBaseBoolean()) {
821                                         baseVfModule = vfModules.get(i);
822                                         break;                                  
823                                 }
824                         }
825                 }
826                 return baseVfModule;
827         }
828 }