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