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