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