8c13c9be977ce2d8b3a23f46a81eb35597b3f822
[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.client.adapter.vnf.mapper.exceptions.MissingValueTagException;
79 import org.onap.so.entity.MsoRequest;
80 import org.onap.so.jsonpath.JsonPathUtil;
81 import org.onap.so.openstack.utils.MsoMulticloudUtils;
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, MissingValueTagException {
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, MissingValueTagException {
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 noOfDirectivesSize = 0;
214         if (directive.equals(MsoMulticloudUtils.USER_DIRECTIVES)
215                 && srcMap.containsKey(MsoMulticloudUtils.OOF_DIRECTIVES)) {
216             noOfDirectivesSize = 1;
217         }
218         if (srcMap.size() > noOfDirectivesSize) {
219             directives.append("{ \"attributes\": [ ");
220             int i = 0;
221             for (Map.Entry<String, Object> attributeEntry : srcMap.entrySet()) {
222                 String attributeName = attributeEntry.getKey();
223                 Object attributeValue = attributeEntry.getValue();
224                 if (!(MsoMulticloudUtils.USER_DIRECTIVES.equals(directive)
225                         && attributeName.equals(MsoMulticloudUtils.OOF_DIRECTIVES))) {
226                     if (attributeValue == null) {
227                         logger.error("No value tag found for attribute: {}", attributeName);
228                         throw new MissingValueTagException("No value tag found for " + attributeName);
229                     }
230                     directives.append(new AttributeNameValue(attributeName, attributeValue.toString()));
231                     if (i < (srcMap.size() - 1 + noOfDirectivesSize))
232                         directives.append(", ");
233                     i++;
234                 }
235             }
236             directives.append("] }");
237         } else {
238             directives.append("{}");
239         }
240         paramsMap.put(directive, directives.toString());
241     }
242
243     private void buildMandatoryParamsMap(Map<String, Object> paramsMap, ServiceInstance serviceInstance,
244             GenericVnf genericVnf, VfModule vfModule) {
245         paramsMap.put("vnf_id", genericVnf.getVnfId());
246         paramsMap.put("vnf_name", genericVnf.getVnfName());
247         paramsMap.put("vf_module_id", vfModule.getVfModuleId());
248         paramsMap.put("vf_module_name", vfModule.getVfModuleName());
249         paramsMap.put("environment_context", serviceInstance.getModelInfoServiceInstance().getEnvironmentContext());
250         paramsMap.putIfAbsent("environment_context", "");
251         paramsMap.put("workload_context", serviceInstance.getModelInfoServiceInstance().getWorkloadContext());
252         paramsMap.putIfAbsent("workload_context", "");
253         Integer vfModuleIndex = vfModule.getModuleIndex();
254         if (vfModuleIndex != null) {
255             paramsMap.put("vf_module_index", vfModuleIndex.toString());
256         }
257     }
258
259     private void buildParamsMapFromVnfSdncResponse(Map<String, Object> paramsMap,
260             GenericResourceApiVnftopologyVnfTopology vnfTopology, Map<String, String> networkRoleMap,
261             boolean skipVnfResourceAssignments) throws IOException {
262         // Get VNF parameters from SDNC response
263         GenericResourceApiParam vnfParametersData = vnfTopology.getVnfParametersData();
264         buildParamsMapFromSdncParams(paramsMap, vnfParametersData);
265
266         if (!skipVnfResourceAssignments) {
267             GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments =
268                     vnfTopology.getVnfResourceAssignments();
269             if (vnfResourceAssignments != null) {
270                 // Availability Zones
271                 buildAvailabilityZones(paramsMap, vnfResourceAssignments);
272                 // VNF Networks
273                 buildVnfNetworks(paramsMap, vnfResourceAssignments, networkRoleMap);
274             }
275         }
276     }
277
278     private void buildAvailabilityZones(Map<String, Object> paramsMap,
279             GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments) {
280         GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones availabilityZones =
281                 vnfResourceAssignments.getAvailabilityZones();
282         if (availabilityZones != null) {
283             List<String> availabilityZonesList = availabilityZones.getAvailabilityZone();
284             if (availabilityZonesList != null) {
285                 for (int i = 0; i < availabilityZonesList.size(); i++) {
286                     paramsMap.put("availability_zone_" + i, availabilityZonesList.get(i));
287                 }
288             }
289         }
290     }
291
292     private void buildVnfNetworks(Map<String, Object> paramsMap,
293             GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments,
294             Map<String, String> networkRoleMap) {
295         GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworks =
296                 vnfResourceAssignments.getVnfNetworks();
297         if (vnfNetworks != null) {
298             List<GenericResourceApiVnfNetworkData> vnfNetworksList = vnfNetworks.getVnfNetwork();
299             if (vnfNetworksList != null) {
300                 for (int i = 0; i < vnfNetworksList.size(); i++) {
301                     GenericResourceApiVnfNetworkData vnfNetwork = vnfNetworksList.get(i);
302                     String networkRole = vnfNetwork.getNetworkRole();
303                     String vnfNetworkKey = networkRoleMap.get(networkRole);
304                     if (vnfNetworkKey == null || vnfNetworkKey.isEmpty()) {
305                         vnfNetworkKey = networkRole;
306                     }
307
308                     String vnfNetworkNeutronIdValue = vnfNetwork.getNeutronId();
309                     paramsMap.put(vnfNetworkKey + "_net_id", vnfNetworkNeutronIdValue);
310                     String vnfNetworkNetNameValue = vnfNetwork.getNetworkName();
311                     paramsMap.put(vnfNetworkKey + "_net_name", vnfNetworkNetNameValue);
312                     String vnfNetworkNetFqdnValue = vnfNetwork.getContrailNetworkFqdn();
313                     paramsMap.put(vnfNetworkKey + "_net_fqdn", vnfNetworkNetFqdnValue);
314
315                     buildVnfNetworkSubnets(paramsMap, vnfNetwork, vnfNetworkKey);
316
317                 }
318             }
319         }
320     }
321
322     private void buildVnfNetworkSubnets(Map<String, Object> paramsMap, GenericResourceApiVnfNetworkData vnfNetwork,
323             String vnfNetworkKey) {
324         String vnfNetworkString = convertToString(vnfNetwork);
325         Optional<String> ipv4Ips = jsonPath.locateResult(vnfNetworkString,
326                 "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv4' && @.dhcp-enabled == 'Y')].subnet-id");
327         if (ipv4Ips.isPresent())
328             addPairToMap(paramsMap, vnfNetworkKey, SUBNET_ID, ipv4Ips.get());
329
330         Optional<String> ipv6Ips = jsonPath.locateResult(vnfNetworkString,
331                 "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv6' && @.dhcp-enabled == 'Y')].subnet-id");
332         if (ipv6Ips.isPresent())
333             addPairToMap(paramsMap, vnfNetworkKey, V6_SUBNET_ID, ipv6Ips.get());
334     }
335
336     private void buildParamsMapFromVfModuleSdncResponse(Map<String, Object> paramsMap,
337             GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology, boolean skipVfModuleAssignments)
338             throws IOException {
339         // Get VF Module parameters from SDNC response
340         GenericResourceApiParam vfModuleParametersData = vfModuleTopology.getVfModuleParameters();
341         buildParamsMapFromSdncParams(paramsMap, vfModuleParametersData);
342
343         if (!skipVfModuleAssignments) {
344             GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments =
345                     vfModuleTopology.getVfModuleAssignments();
346             if (vfModuleAssignments != null) {
347                 // VNF-VMS
348                 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
349                 if (vms != null) {
350                     List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
351                     if (vmsList != null) {
352                         for (GenericResourceApiVmTopologyData vm : vmsList) {
353                             String key = vm.getVmType();
354                             buildVfModuleVmNames(paramsMap, vm, key);
355                             GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
356                             if (vmNetworks != null) {
357                                 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
358                                 if (vmNetworksList != null) {
359                                     for (int n = 0; n < vmNetworksList.size(); n++) {
360                                         GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
361                                         network.getNetworkRoleTag();
362                                         String networkKey = network.getNetworkRole();
363                                         // Floating IPs
364                                         buildVfModuleFloatingIps(paramsMap, network, key, networkKey);
365                                         // Interface Route Prefixes
366                                         buildVfModuleInterfaceRoutePrefixes(paramsMap, network, key, networkKey);
367                                         // SRIOV Parameters
368                                         buildVfModuleSriovParameters(paramsMap, network, networkKey);
369                                         // IPV4 and IPV6 Addresses
370                                         buildVfModuleNetworkInformation(paramsMap, network, key, networkKey);
371
372                                         buildVlanInformation(paramsMap, network, key, networkKey);
373
374                                     }
375                                 }
376                             }
377
378                             buildParamsMapFromVfModuleForHeatTemplate(paramsMap, vm);
379                         }
380                     }
381                 }
382             }
383         }
384     }
385
386     protected void buildVlanInformation(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
387             String key, String networkKey) {
388
389         String networkString = convertToString(network);
390         String vlanFilterKey = key + UNDERSCORE + networkKey + UNDERSCORE + "vlan_filter";
391         String privateVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "private_vlans";
392         String publicVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "public_vlans";
393         String guestVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "guest_vlans";
394
395         if (network.getSegmentationId() != null) {
396             paramsMap.put(vlanFilterKey, network.getSegmentationId());
397         }
398
399         List<String> privateVlans = jsonPath.locateResultList(networkString,
400                 "$.related-networks.related-network[?(@.vlan-tags.is-private == true)].vlan-tags.upper-tag-id");
401         List<String> publicVlans = jsonPath.locateResultList(networkString,
402                 "$.related-networks.related-network[?(@.vlan-tags.is-private == false)].vlan-tags.upper-tag-id");
403         List<String> concat = new ArrayList<>(privateVlans);
404         concat.addAll(publicVlans);
405         Collection<String> guestVlans = new HashSet<>(concat);
406
407         if (!privateVlans.isEmpty()) {
408             paramsMap.put(privateVlansKey, Joiner.on(",").join(privateVlans));
409         }
410         if (!publicVlans.isEmpty()) {
411             paramsMap.put(publicVlansKey, Joiner.on(",").join(publicVlans));
412         }
413         if (!guestVlans.isEmpty()) {
414             paramsMap.put(guestVlansKey, Joiner.on(",").join(guestVlans));
415         }
416     }
417
418     private void buildVfModuleVmNames(Map<String, Object> paramsMap, GenericResourceApiVmTopologyData vm, String key) {
419         String values = "";
420         GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
421         if (vmNames != null) {
422             List<String> valueList = vmNames.getVmName();
423             if (valueList != null) {
424                 for (int i = 0; i < valueList.size(); i++) {
425                     String value = valueList.get(i);
426                     if (i != valueList.size() - 1) {
427                         values += value + ",";
428                     } else {
429                         values += value;
430                     }
431                     paramsMap.put(key + "_name_" + i, value);
432                 }
433                 paramsMap.put(key + "_names", values);
434             }
435         }
436     }
437
438     private void buildVfModuleFloatingIps(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
439             String key, String networkKey) {
440         GenericResourceApiVmnetworkdataFloatingIps floatingIps = network.getFloatingIps();
441         if (floatingIps != null) {
442             List<String> floatingIpV4List = floatingIps.getFloatingIpV4();
443             if (floatingIpV4List != null) {
444                 // add only one ipv4 floating ip for now
445                 String floatingIPKey = key + UNDERSCORE + networkKey + FLOATING_IP;
446                 String floatingIPKeyValue = floatingIpV4List.get(0);
447                 if (floatingIPKeyValue != null && !floatingIPKeyValue.isEmpty()) {
448                     paramsMap.put(floatingIPKey, floatingIPKeyValue);
449                 }
450             }
451             // add only one ipv6 floating ip for now
452             List<String> floatingIpV6List = floatingIps.getFloatingIpV6();
453             if (floatingIpV6List != null) {
454                 String floatingIPV6Key = key + UNDERSCORE + networkKey + FLOATING_V6_IP;
455                 String floatingIPV6KeyValue = floatingIpV6List.get(0);
456                 if (floatingIPV6KeyValue != null && !floatingIPV6KeyValue.isEmpty()) {
457                     paramsMap.put(floatingIPV6Key, floatingIPV6KeyValue);
458                 }
459             }
460         }
461     }
462
463     private void buildVfModuleInterfaceRoutePrefixes(Map<String, Object> paramsMap,
464             GenericResourceApiVmNetworkData network, String key, String networkKey) {
465         GenericResourceApiVmnetworkdataInterfaceRoutePrefixes interfaceRoutePrefixes =
466                 network.getInterfaceRoutePrefixes();
467         if (interfaceRoutePrefixes != null) {
468             List<String> interfaceRoutePrefixesList = interfaceRoutePrefixes.getInterfaceRoutePrefix();
469             StringBuilder sbInterfaceRoutePrefixes = new StringBuilder();
470             sbInterfaceRoutePrefixes.append("[");
471             if (interfaceRoutePrefixesList != null) {
472                 for (int a = 0; a < interfaceRoutePrefixesList.size(); a++) {
473                     String interfaceRoutePrefixValue = interfaceRoutePrefixesList.get(a);
474                     if (a != interfaceRoutePrefixesList.size() - 1) {
475                         sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \""
476                                 + interfaceRoutePrefixValue + "\"}" + ",");
477                     } else {
478                         sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \""
479                                 + interfaceRoutePrefixValue + "\"}");
480                     }
481                 }
482                 sbInterfaceRoutePrefixes.append("]");
483                 if (!interfaceRoutePrefixesList.isEmpty()) {
484                     paramsMap.put(key + UNDERSCORE + networkKey + "_route_prefixes",
485                             sbInterfaceRoutePrefixes.toString());
486                 }
487             }
488         }
489     }
490
491     private void buildVfModuleSriovParameters(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
492             String networkKey) {
493         // SRIOV Parameters
494         GenericResourceApiVmnetworkdataSriovParameters sriovParameters = network.getSriovParameters();
495         if (sriovParameters != null) {
496             GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters heatVlanFilters =
497                     sriovParameters.getHeatVlanFilters();
498             if (heatVlanFilters != null) {
499                 List<String> heatVlanFiltersList = heatVlanFilters.getHeatVlanFilter();
500                 StringBuilder sriovFilterBuf = new StringBuilder();
501                 if (heatVlanFiltersList != null) {
502                     for (int a = 0; a < heatVlanFiltersList.size(); a++) {
503                         String heatVlanFilterValue = heatVlanFiltersList.get(a);
504                         if (a != heatVlanFiltersList.size() - 1) {
505                             sriovFilterBuf.append(heatVlanFilterValue).append(",");
506                         } else {
507                             sriovFilterBuf.append(heatVlanFilterValue);
508                         }
509                     }
510                     if (!heatVlanFiltersList.isEmpty()) {
511                         paramsMap.put(networkKey + "_ATT_VF_VLAN_FILTER", sriovFilterBuf.toString());
512                     }
513                 }
514             }
515         }
516     }
517
518     private void buildVfModuleNetworkInformation(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
519             String key, String networkKey) {
520
521         GenericResourceApiVmnetworkdataNetworkInformationItems networkInformationItems =
522                 network.getNetworkInformationItems();
523         StringBuilder sbIpv4Ips = new StringBuilder();
524         StringBuilder sbIpv6Ips = new StringBuilder();
525
526         if (networkInformationItems != null) {
527             List<GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem> networkInformationItemList =
528                     networkInformationItems.getNetworkInformationItem();
529             if (networkInformationItemList != null) {
530                 for (int a = 0; a < networkInformationItemList.size(); a++) {
531                     GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem ipAddress =
532                             networkInformationItemList.get(a);
533                     if (ipAddress != null) {
534                         GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps ips =
535                                 ipAddress.getNetworkIps();
536                         if (ips != null) {
537                             List<String> ipsList = ips.getNetworkIp();
538                             if (ipsList != null) {
539                                 String ipVersion = ipAddress.getIpVersion();
540                                 for (int b = 0; b < ipsList.size(); b++) {
541                                     String ipAddressValue = ipsList.get(b);
542                                     if ("ipv4".equals(ipVersion)) {
543                                         if (b != ipsList.size() - 1) {
544                                             sbIpv4Ips.append(ipAddressValue + ",");
545                                         } else {
546                                             sbIpv4Ips.append(ipAddressValue);
547                                         }
548                                         paramsMap.put(key + UNDERSCORE + networkKey + IP + UNDERSCORE + b,
549                                                 ipAddressValue);
550                                     } else if ("ipv6".equals(ipVersion)) {
551                                         if (b != ipsList.size() - 1) {
552                                             sbIpv6Ips.append(ipAddressValue + ",");
553                                         } else {
554                                             sbIpv6Ips.append(ipAddressValue);
555                                         }
556                                         paramsMap.put(key + UNDERSCORE + networkKey + V6_IP + UNDERSCORE + b,
557                                                 ipAddressValue);
558                                     }
559                                 }
560                                 paramsMap.put(key + UNDERSCORE + networkKey + "_ips", sbIpv4Ips.toString());
561                                 paramsMap.put(key + UNDERSCORE + networkKey + "_v6_ips", sbIpv6Ips.toString());
562                             }
563                         }
564                     }
565                 }
566             }
567         }
568     }
569
570     /*
571      * Build Mapping from GenericResourceApi SDNC for Heat Template so that AIC - PO gets accurate requests for vf
572      * module assignments. Build Count of SubInterfaces, VLAN Tag, network_name, network_id, ip_address (V4 and V6) and
573      * Floating IPs Addresses (V4 and V6) for Heat Template
574      */
575     private void buildParamsMapFromVfModuleForHeatTemplate(Map<String, Object> paramsMap,
576             GenericResourceApiVmTopologyData vm) {
577         GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
578
579         if (vmNames != null) {
580
581             List<GenericResourceApiVmtopologydataVmnamesVnfcNames> vnfcNamesList = vmNames.getVnfcNames();
582             if (vnfcNamesList != null) {
583
584                 for (int i = 0; i < vnfcNamesList.size(); i++) {
585
586                     GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames = vnfcNamesList.get(i);
587                     parseVnfcNamesData(paramsMap, vnfcNames);
588                 }
589             }
590         }
591     }
592
593     /*
594      * Parse vnfcNames data to build Mapping from GenericResourceApi SDNC for Heat Template.
595      */
596     private void parseVnfcNamesData(Map<String, Object> paramsMap,
597             GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames) {
598
599         if (vnfcNames != null) {
600             GenericResourceApiVnfcNetworkData vnfcNetworks = vnfcNames.getVnfcNetworks();
601             if (vnfcNetworks != null) {
602                 List<GenericResourceApiVnfcnetworkdataVnfcNetworkData> vnfcNetworkdataList =
603                         vnfcNetworks.getVnfcNetworkData();
604
605                 if (vnfcNetworkdataList != null) {
606
607                     for (int networkDataIdx = 0; networkDataIdx < vnfcNetworkdataList.size(); networkDataIdx++) {
608
609                         GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata =
610                                 vnfcNetworkdataList.get(networkDataIdx);
611                         parseVnfcNetworkData(paramsMap, vnfcNetworkdata, networkDataIdx);
612                     }
613                 }
614             }
615         }
616     }
617
618     /*
619      * Parse VnfcNetworkData to build Mapping from GenericResourceApi SDNC for Heat Template. Build Count of
620      * SubInterfaces, VLAN Tag, network_name, network_id, ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6)
621      * for Heat Template
622      */
623     private void parseVnfcNetworkData(Map<String, Object> paramsMap,
624             GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata, int networkDataIdx) {
625
626         String vmTypeKey = vnfcNetworkdata.getVnfcType();
627         GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts vnfcPorts = vnfcNetworkdata.getVnfcPorts();
628         if (vnfcPorts != null) {
629             List<GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort> vnfcPortList =
630                     vnfcPorts.getVnfcPort();
631             if (vnfcPortList != null) {
632                 for (int portIdx = 0; portIdx < vnfcPortList.size(); portIdx++) {
633
634                     GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort vnfcPort =
635                             vnfcPortList.get(portIdx);
636                     GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces = vnfcPort.getVnicSubInterfaces();
637
638                     String vnicSubInterfacesString = convertToString(vnicSubInterfaces);
639                     String networkRoleKey = vnfcPort.getCommonSubInterfaceRole();
640                     String subInterfaceKey =
641                             createVnfcSubInterfaceKey(vmTypeKey, networkDataIdx, networkRoleKey, portIdx);
642                     String globalSubInterfaceKey = createGlobalVnfcSubInterfaceKey(vmTypeKey, networkRoleKey, portIdx);
643
644                     buildVfModuleSubInterfacesCount(paramsMap, globalSubInterfaceKey, vnicSubInterfaces);
645
646                     buildVfModuleVlanTag(paramsMap, subInterfaceKey, vnicSubInterfacesString);
647
648                     buildVfModuleNetworkName(paramsMap, subInterfaceKey, vnicSubInterfacesString);
649
650                     buildVfModuleNetworkId(paramsMap, subInterfaceKey, vnicSubInterfacesString);
651
652                     buildVfModuleIpV4AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
653
654                     buildVfModuleIpV6AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
655
656                     buildVfModuleFloatingIpV4HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
657
658                     buildVfModuleFloatingIpV6HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
659                 }
660             }
661         }
662     }
663
664     /*
665      * Build "count" (calculating the total number of sub-interfaces) for Heat Template Building Criteria :
666      * {vm-type}_subint_{network-role}_port_{index}_subintcount vmTypeKey = vm-type, networkRoleKey =
667      * common-sub-interface-role Example: fw_subint_ctrl_port_0_subintcount
668      *
669      */
670     private void buildVfModuleSubInterfacesCount(Map<String, Object> paramsMap, String keyPrefix,
671             GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces) {
672
673         List<GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData> subInterfaceNetworkDataList =
674                 vnicSubInterfaces.getSubInterfaceNetworkData();
675
676         if ((subInterfaceNetworkDataList != null) && !subInterfaceNetworkDataList.isEmpty()) {
677             addPairToMap(paramsMap, keyPrefix, SUB_INT_COUNT, String.valueOf(subInterfaceNetworkDataList.size()));
678         }
679     }
680
681     protected String createVnfcSubInterfaceKey(String vmTypeKey, int networkDataIdx, String networkRoleKey,
682             int portIdx) {
683
684         return Joiner.on(UNDERSCORE)
685                 .join(Arrays.asList(vmTypeKey, networkDataIdx, SUB_INT, networkRoleKey, PORT, portIdx));
686     }
687
688     protected String createGlobalVnfcSubInterfaceKey(String vmTypeKey, String networkRoleKey, int portIdx) {
689
690         return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, SUB_INT, networkRoleKey, PORT, portIdx));
691     }
692
693     /*
694      * Build VLAN Tag for Heat Template Building Criteria :
695      * {vm-type}_{index}_subint_{network-role}_port_{index}_vlan_ids vmTypeKey = vm-type, networkRoleKey =
696      * common-sub-interface-role Example: fw_0_subint_ctrl_port_0_vlan_ids
697      *
698      */
699     protected void buildVfModuleVlanTag(Map<String, Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
700
701         List<String> vlanTagIds =
702                 jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].vlan-tag-id");
703
704         addPairToMap(paramsMap, keyPrefix, VLAN_IDS, vlanTagIds);
705     }
706
707     /*
708      * Build "network_name" for Heat Template Building Criteria :
709      * {vm-type}_{index}_subint_{network-role}_port_{index}_net_names vmTypeKey = vm-type, networkRoleKey =
710      * common-sub-interface-role Example: fw_0_subint_ctrl_port_0_net_names
711      *
712      */
713     protected void buildVfModuleNetworkName(Map<String, Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
714
715         List<String> neworkNames =
716                 jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-name");
717
718         addPairToMap(paramsMap, keyPrefix, NET_NAMES, neworkNames);
719     }
720
721     /*
722      * Build "network_id" for Heat Template Building Criteria :
723      * {vm-type}_{index}_subint_{network-role}_port_{index}_net_ids vmTypeKey = vm-type, networkRoleKey =
724      * common-sub-interface-role Example: fw_0_subint_ctrl_port_0_net_ids
725      *
726      */
727     protected void buildVfModuleNetworkId(Map<String, Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
728
729         List<String> neworkIds =
730                 jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-id");
731
732         addPairToMap(paramsMap, keyPrefix, NET_IDS, neworkIds);
733     }
734
735     /*
736      * Build ip_address for V4 for Heat Template Building Criteria :
737      * {vm-type}_{index}_subint_{network-role}_port_{index}_ip_{index} -- for ipV4 key = vm-type, networkRoleKey =
738      * NetWork-Role
739      */
740     protected void buildVfModuleIpV4AddressHeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
741             String vnicSubInterfaces) {
742
743         List<String> ipv4Ips = jsonPath.locateResultList(vnicSubInterfaces,
744                 "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv4')].network-ips.network-ip[*]");
745
746         addPairToMap(paramsMap, keyPrefix, IP, ipv4Ips);
747
748         for (int i = 0; i < ipv4Ips.size(); i++) {
749             addPairToMap(paramsMap, keyPrefix, IP + UNDERSCORE + i, ipv4Ips.get(i));
750         }
751
752     }
753
754     /*
755      * Build ip_address for Heat Template Building Criteria :
756      * {vm-type}_{index}_subint_{network-role}_port_{index}_v6_ip_{index} -- for ipV6 key = vm-type, networkRoleKey =
757      * NetWork-Role
758      */
759     protected void buildVfModuleIpV6AddressHeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
760             String vnicSubInterfaces) {
761
762         List<String> ipv6Ips = jsonPath.locateResultList(vnicSubInterfaces,
763                 "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv6')].network-ips.network-ip[*]");
764
765         addPairToMap(paramsMap, keyPrefix, V6_IP, ipv6Ips);
766
767         for (int i = 0; i < ipv6Ips.size(); i++) {
768             addPairToMap(paramsMap, keyPrefix, V6_IP + UNDERSCORE + i, ipv6Ips.get(i));
769         }
770     }
771
772     /*
773      * Build floatingip_address for Heat Template Building Criteria :
774      * {vm-type}_subint_{network-role}_port_{index}_floating_ip -- for ipV4
775      */
776     protected void buildVfModuleFloatingIpV4HeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
777             String vnicSubInterfaces) {
778
779         List<String> floatingV4 = jsonPath.locateResultList(vnicSubInterfaces,
780                 "$.sub-interface-network-data[*].floating-ips.floating-ip-v4[*]");
781
782         if (!floatingV4.isEmpty()) {
783             floatingV4 = Collections.singletonList(floatingV4.get(0));
784         }
785         addPairToMap(paramsMap, keyPrefix, FLOATING_IP, floatingV4);
786
787     }
788
789     /*
790      * Build floatingip_address for Heat Template Building Criteria :
791      * {vm-type}_subint_{network-role}_port_{index}_floating_v6_ip -- for ipV6
792      */
793     protected void buildVfModuleFloatingIpV6HeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
794             String vnicSubInterfaces) {
795
796         List<String> floatingV6 = jsonPath.locateResultList(vnicSubInterfaces,
797                 "$.sub-interface-network-data[*].floating-ips.floating-ip-v6[*]");
798
799         if (!floatingV6.isEmpty()) {
800             floatingV6 = Collections.singletonList(floatingV6.get(0));
801         }
802         addPairToMap(paramsMap, keyPrefix, FLOATING_V6_IP, floatingV6);
803     }
804
805     protected void addPairToMap(Map<String, Object> paramsMap, String keyPrefix, String key, String value) {
806
807         addPairToMap(paramsMap, keyPrefix, key, Collections.singletonList(value));
808     }
809
810     protected void addPairToMap(Map<String, Object> paramsMap, String keyPrefix, String key, List<String> value) {
811
812         if (!value.isEmpty()) {
813             paramsMap.put(keyPrefix + key, Joiner.on(",").join(value));
814         }
815     }
816
817     private void buildParamsMapFromSdncParams(Map<String, Object> paramsMap, GenericResourceApiParam parametersData) {
818         if (parametersData != null) {
819             List<GenericResourceApiParamParam> paramsList = parametersData.getParam();
820             if (paramsList != null) {
821                 for (int i = 0; i < paramsList.size(); i++) {
822                     GenericResourceApiParamParam param = paramsList.get(i);
823                     String parameterName = param.getName();
824                     if (!sdncResponseParamsToSkip.contains(parameterName)) {
825                         String parameterValue = param.getValue();
826                         paramsMap.put(parameterName, parameterValue);
827                     }
828                 }
829             }
830         }
831     }
832
833     private Map<String, String> buildNetworkRoleMap(GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology)
834             throws JsonParseException, JsonMappingException, IOException {
835         Map<String, String> networkRoleMap = new HashMap<>();
836         GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments =
837                 vfModuleTopology.getVfModuleAssignments();
838         if (vfModuleAssignments != null) {
839             GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
840             if (vms != null) {
841                 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
842                 if (vmsList != null) {
843                     for (GenericResourceApiVmTopologyData vm : vmsList) {
844                         GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
845                         if (vmNetworks != null) {
846                             List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
847                             if (vmNetworksList != null) {
848                                 for (int n = 0; n < vmNetworksList.size(); n++) {
849                                     GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
850                                     String networkRole = network.getNetworkRole();
851                                     String networkRoleValue = network.getNetworkRoleTag();
852                                     if (networkRoleValue == null || networkRoleValue.isEmpty()) {
853                                         networkRoleValue = networkRole;
854                                     }
855                                     networkRoleMap.put(networkRole, networkRoleValue);
856                                 }
857                             }
858                         }
859                     }
860                 }
861             }
862         }
863         return networkRoleMap;
864     }
865
866     public DeleteVfModuleRequest deleteVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion,
867             ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule) throws IOException {
868         DeleteVfModuleRequest deleteVfModuleRequest = new DeleteVfModuleRequest();
869         deleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
870         deleteVfModuleRequest.setCloudOwner(cloudRegion.getCloudOwner());
871         deleteVfModuleRequest.setTenantId(cloudRegion.getTenantId());
872         deleteVfModuleRequest.setVnfId(genericVnf.getVnfId());
873         deleteVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
874         if (!StringUtils.isEmpty(vfModule.getHeatStackId())) {
875             deleteVfModuleRequest.setVfModuleStackId(vfModule.getHeatStackId());// DoDVfMod_heatStackId
876         } else {
877             deleteVfModuleRequest.setVfModuleStackId(vfModule.getVfModuleName());
878         }
879
880         deleteVfModuleRequest.setSkipAAI(true);
881         setIdAndUrl(deleteVfModuleRequest);
882         MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
883         deleteVfModuleRequest.setMsoRequest(msoRequest);
884         return deleteVfModuleRequest;
885     }
886
887     protected void setIdAndUrl(DeleteVfModuleRequest deleteVfModuleRequest) throws UnsupportedEncodingException {
888         String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
889         deleteVfModuleRequest.setMessageId(messageId);
890         deleteVfModuleRequest
891                 .setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
892     }
893
894     private String convertToString(Object obj) {
895         String json;
896         try {
897             json = mapper.writeValueAsString(obj);
898         } catch (JsonProcessingException e) {
899             logger.error("JsonProcessingException in convertToString", e);
900             json = "{}";
901         }
902
903         return json;
904     }
905
906     private VfModule getBaseVfModule(GenericVnf genericVnf) {
907         List<VfModule> vfModules = genericVnf.getVfModules();
908         VfModule baseVfModule = null;
909         if (vfModules != null) {
910             for (int i = 0; i < vfModules.size(); i++) {
911                 if (vfModules.get(i).getModelInfoVfModule().getIsBaseBoolean()) {
912                     baseVfModule = vfModules.get(i);
913                     break;
914                 }
915             }
916         }
917         return baseVfModule;
918     }
919 }