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