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