2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.client.adapter.vnf.mapper;
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;
36 import java.util.Optional;
37 import javax.annotation.PostConstruct;
38 import org.apache.commons.lang3.StringUtils;
39 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
41 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubInterfaceNetworkData;
42 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData;
43 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleTopology;
44 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfModuleAssignments;
45 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms;
46 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmNetworkData;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmTopologyData;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataFloatingIps;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataInterfaceRoutePrefixes;
51 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkInformationItems;
52 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem;
53 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps;
54 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovParameters;
55 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters;
56 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNames;
57 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNetworks;
58 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmnamesVnfcNames;
59 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfNetworkData;
60 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfTopology;
61 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcNetworkData;
62 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcNetworkData;
63 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts;
64 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort;
65 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfResourceAssignments;
66 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones;
67 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks;
68 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyVnfTopology;
69 import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
70 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
71 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
72 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
73 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
74 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
75 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
76 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
77 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
78 import org.onap.so.client.adapter.vnf.mapper.exceptions.MissingValueTagException;
79 import org.onap.so.entity.MsoRequest;
80 import org.onap.so.jsonpath.JsonPathUtil;
81 import org.onap.so.openstack.utils.MsoMulticloudUtils;
82 import org.slf4j.Logger;
83 import org.slf4j.LoggerFactory;
84 import org.springframework.beans.factory.annotation.Autowired;
85 import org.springframework.stereotype.Component;
86 import com.fasterxml.jackson.core.JsonParseException;
87 import com.fasterxml.jackson.core.JsonProcessingException;
88 import com.fasterxml.jackson.databind.DeserializationFeature;
89 import com.fasterxml.jackson.databind.JsonMappingException;
90 import com.fasterxml.jackson.databind.ObjectMapper;
91 import com.google.common.base.Joiner;
95 public class VnfAdapterVfModuleObjectMapper {
97 protected VnfAdapterObjectMapperUtils vnfAdapterObjectMapperUtils;
98 private static final Logger logger = LoggerFactory.getLogger(VnfAdapterVfModuleObjectMapper.class);
99 private static List<String> sdncResponseParamsToSkip =
100 asList("vnf_id", "vf_module_id", "vnf_name", "vf_module_name");
102 private ObjectMapper mapper = new ObjectMapper();
103 private static final JsonPathUtil jsonPath = JsonPathUtil.getInstance();
104 private static final String SUB_INT = "subint";
105 private static final String SUBNET_ID = "_subnet_id";
106 private static final String V6_SUBNET_ID = "_v6_subnet_id";
107 private static final String PORT = "port";
108 private static final String SUB_INT_COUNT = "_subintcount";
109 private static final String VLAN_IDS = "_vlan_ids";
110 private static final String NET_NAMES = "_net_names";
111 private static final String NET_IDS = "_net_ids";
112 private static final String IP = "_ip";
113 private static final String V6_IP = "_v6_ip";
114 private static final String FLOATING_IP = "_floating_ip";
115 private static final String FLOATING_V6_IP = "_floating_v6_ip";
116 private static final String UNDERSCORE = "_";
120 mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
123 public CreateVfModuleRequest createVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion,
124 OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
125 VfModule vfModule, VolumeGroup volumeGroup, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse)
126 throws IOException, MissingValueTagException {
127 CreateVfModuleRequest createVfModuleRequest = new CreateVfModuleRequest();
129 createVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
130 createVfModuleRequest.setCloudOwner(cloudRegion.getCloudOwner());
131 createVfModuleRequest.setTenantId(cloudRegion.getTenantId());
132 createVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
133 createVfModuleRequest.setVfModuleName(vfModule.getVfModuleName());
134 createVfModuleRequest.setVnfId(genericVnf.getVnfId());
135 createVfModuleRequest.setVnfType(genericVnf.getVnfType());
136 createVfModuleRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
137 createVfModuleRequest.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
138 createVfModuleRequest.setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
139 if (volumeGroup != null) {
140 createVfModuleRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId());
141 createVfModuleRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId());
143 VfModule baseVfModule = getBaseVfModule(genericVnf);
144 if (baseVfModule != null) {
145 createVfModuleRequest.setBaseVfModuleId(baseVfModule.getVfModuleId());
146 createVfModuleRequest.setBaseVfModuleStackId(baseVfModule.getHeatStackId());
148 createVfModuleRequest.setVfModuleParams(buildVfModuleParamsMap(requestContext, serviceInstance, genericVnf,
149 vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse));
151 createVfModuleRequest.setSkipAAI(true);
152 createVfModuleRequest.setBackout(Boolean.TRUE.equals(orchestrationContext.getIsRollbackEnabled()));
153 createVfModuleRequest.setFailIfExists(false);
155 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
156 createVfModuleRequest.setMsoRequest(msoRequest);
158 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
159 createVfModuleRequest.setMessageId(messageId);
160 createVfModuleRequest
161 .setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
163 return createVfModuleRequest;
166 private MsoRequest buildMsoRequest(RequestContext requestContext, ServiceInstance serviceInstance) {
167 MsoRequest msoRequest = new MsoRequest();
168 msoRequest.setRequestId(requestContext.getMsoRequestId());
169 msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
173 private Map<String, Object> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance,
174 GenericVnf genericVnf, VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse)
175 throws IOException, MissingValueTagException {
178 GenericResourceApiVnfTopology vnfTop =
179 mapper.readValue(sdncVnfQueryResponse, GenericResourceApiVnfTopology.class);
180 GenericResourceApiVfModuleTopology vfModuleTop =
181 mapper.readValue(sdncVfModuleQueryResponse, GenericResourceApiVfModuleTopology.class);
182 GenericResourceApiVnftopologyVnfTopology vnfTopology = vnfTop.getVnfTopology();
183 GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = vfModuleTop.getVfModuleTopology();
184 Map<String, Object> paramsMap = new HashMap<>();
186 if (vfModuleTopology.getSdncGeneratedCloudResources()) {
187 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, true);
188 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, null, true);
190 Map<String, String> networkRoleMap = buildNetworkRoleMap(vfModuleTopology);
191 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, false);
192 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, networkRoleMap, false);
195 // build the sdnc_directives from paramsMap
196 buildDirectivesParamFromMap(paramsMap, MsoMulticloudUtils.SDNC_DIRECTIVES, paramsMap);
197 buildDirectivesParamFromMap(paramsMap, MsoMulticloudUtils.USER_DIRECTIVES, requestContext.getUserParams());
199 buildMandatoryParamsMap(paramsMap, serviceInstance, genericVnf, vfModule);
201 // Parameters received from the request should overwrite any parameters received from SDNC
202 paramsMap.putAll(requestContext.getUserParams());
204 if (vfModule.getCloudParams() != null) {
205 paramsMap.putAll(vfModule.getCloudParams());
210 protected void buildDirectivesParamFromMap(Map<String, Object> paramsMap, String directive,
211 Map<String, Object> srcMap) throws MissingValueTagException {
212 StringBuilder directives = new StringBuilder();
213 int noOfDirectivesSize = 0;
214 if (directive.equals(MsoMulticloudUtils.USER_DIRECTIVES)
215 && srcMap.containsKey(MsoMulticloudUtils.OOF_DIRECTIVES)) {
216 noOfDirectivesSize = 1;
218 if (srcMap.size() > noOfDirectivesSize) {
219 directives.append("{ \"attributes\": [ ");
221 for (Map.Entry<String, Object> attributeEntry : srcMap.entrySet()) {
222 String attributeName = attributeEntry.getKey();
223 Object attributeValue = attributeEntry.getValue();
224 if (!(MsoMulticloudUtils.USER_DIRECTIVES.equals(directive)
225 && attributeName.equals(MsoMulticloudUtils.OOF_DIRECTIVES))) {
226 if (attributeValue == null) {
227 logger.error("No value tag found for attribute: {}", attributeName);
228 throw new MissingValueTagException("No value tag found for " + attributeName);
230 directives.append(new AttributeNameValue(attributeName, attributeValue.toString()));
231 if (i < (srcMap.size() - 1 + noOfDirectivesSize))
232 directives.append(", ");
236 directives.append("] }");
238 directives.append("{}");
240 paramsMap.put(directive, directives.toString());
243 private void buildMandatoryParamsMap(Map<String, Object> paramsMap, ServiceInstance serviceInstance,
244 GenericVnf genericVnf, VfModule vfModule) {
245 paramsMap.put("vnf_id", genericVnf.getVnfId());
246 paramsMap.put("vnf_name", genericVnf.getVnfName());
247 paramsMap.put("vf_module_id", vfModule.getVfModuleId());
248 paramsMap.put("vf_module_name", vfModule.getVfModuleName());
249 paramsMap.put("environment_context", serviceInstance.getModelInfoServiceInstance().getEnvironmentContext());
250 paramsMap.putIfAbsent("environment_context", "");
251 paramsMap.put("workload_context", serviceInstance.getModelInfoServiceInstance().getWorkloadContext());
252 paramsMap.putIfAbsent("workload_context", "");
253 Integer vfModuleIndex = vfModule.getModuleIndex();
254 if (vfModuleIndex != null) {
255 paramsMap.put("vf_module_index", vfModuleIndex.toString());
259 private void buildParamsMapFromVnfSdncResponse(Map<String, Object> paramsMap,
260 GenericResourceApiVnftopologyVnfTopology vnfTopology, Map<String, String> networkRoleMap,
261 boolean skipVnfResourceAssignments) throws IOException {
262 // Get VNF parameters from SDNC response
263 GenericResourceApiParam vnfParametersData = vnfTopology.getVnfParametersData();
264 buildParamsMapFromSdncParams(paramsMap, vnfParametersData);
266 if (!skipVnfResourceAssignments) {
267 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments =
268 vnfTopology.getVnfResourceAssignments();
269 if (vnfResourceAssignments != null) {
270 // Availability Zones
271 buildAvailabilityZones(paramsMap, vnfResourceAssignments);
273 buildVnfNetworks(paramsMap, vnfResourceAssignments, networkRoleMap);
278 private void buildAvailabilityZones(Map<String, Object> paramsMap,
279 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments) {
280 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones availabilityZones =
281 vnfResourceAssignments.getAvailabilityZones();
282 if (availabilityZones != null) {
283 List<String> availabilityZonesList = availabilityZones.getAvailabilityZone();
284 if (availabilityZonesList != null) {
285 for (int i = 0; i < availabilityZonesList.size(); i++) {
286 paramsMap.put("availability_zone_" + i, availabilityZonesList.get(i));
292 private void buildVnfNetworks(Map<String, Object> paramsMap,
293 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments,
294 Map<String, String> networkRoleMap) {
295 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworks =
296 vnfResourceAssignments.getVnfNetworks();
297 if (vnfNetworks != null) {
298 List<GenericResourceApiVnfNetworkData> vnfNetworksList = vnfNetworks.getVnfNetwork();
299 if (vnfNetworksList != null) {
300 for (int i = 0; i < vnfNetworksList.size(); i++) {
301 GenericResourceApiVnfNetworkData vnfNetwork = vnfNetworksList.get(i);
302 String networkRole = vnfNetwork.getNetworkRole();
303 String vnfNetworkKey = networkRoleMap.get(networkRole);
304 if (vnfNetworkKey == null || vnfNetworkKey.isEmpty()) {
305 vnfNetworkKey = networkRole;
308 String vnfNetworkNeutronIdValue = vnfNetwork.getNeutronId();
309 paramsMap.put(vnfNetworkKey + "_net_id", vnfNetworkNeutronIdValue);
310 String vnfNetworkNetNameValue = vnfNetwork.getNetworkName();
311 paramsMap.put(vnfNetworkKey + "_net_name", vnfNetworkNetNameValue);
312 String vnfNetworkNetFqdnValue = vnfNetwork.getContrailNetworkFqdn();
313 paramsMap.put(vnfNetworkKey + "_net_fqdn", vnfNetworkNetFqdnValue);
315 buildVnfNetworkSubnets(paramsMap, vnfNetwork, vnfNetworkKey);
322 private void buildVnfNetworkSubnets(Map<String, Object> paramsMap, GenericResourceApiVnfNetworkData vnfNetwork,
323 String vnfNetworkKey) {
324 String vnfNetworkString = convertToString(vnfNetwork);
325 Optional<String> ipv4Ips = jsonPath.locateResult(vnfNetworkString,
326 "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv4' && @.dhcp-enabled == 'Y')].subnet-id");
327 if (ipv4Ips.isPresent())
328 addPairToMap(paramsMap, vnfNetworkKey, SUBNET_ID, ipv4Ips.get());
330 Optional<String> ipv6Ips = jsonPath.locateResult(vnfNetworkString,
331 "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv6' && @.dhcp-enabled == 'Y')].subnet-id");
332 if (ipv6Ips.isPresent())
333 addPairToMap(paramsMap, vnfNetworkKey, V6_SUBNET_ID, ipv6Ips.get());
336 private void buildParamsMapFromVfModuleSdncResponse(Map<String, Object> paramsMap,
337 GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology, boolean skipVfModuleAssignments)
339 // Get VF Module parameters from SDNC response
340 GenericResourceApiParam vfModuleParametersData = vfModuleTopology.getVfModuleParameters();
341 buildParamsMapFromSdncParams(paramsMap, vfModuleParametersData);
343 if (!skipVfModuleAssignments) {
344 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments =
345 vfModuleTopology.getVfModuleAssignments();
346 if (vfModuleAssignments != null) {
348 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
350 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
351 if (vmsList != null) {
352 for (GenericResourceApiVmTopologyData vm : vmsList) {
353 String key = vm.getVmType();
354 buildVfModuleVmNames(paramsMap, vm, key);
355 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
356 if (vmNetworks != null) {
357 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
358 if (vmNetworksList != null) {
359 for (int n = 0; n < vmNetworksList.size(); n++) {
360 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
361 network.getNetworkRoleTag();
362 String networkKey = network.getNetworkRole();
364 buildVfModuleFloatingIps(paramsMap, network, key, networkKey);
365 // Interface Route Prefixes
366 buildVfModuleInterfaceRoutePrefixes(paramsMap, network, key, networkKey);
368 buildVfModuleSriovParameters(paramsMap, network, networkKey);
369 // IPV4 and IPV6 Addresses
370 buildVfModuleNetworkInformation(paramsMap, network, key, networkKey);
372 buildVlanInformation(paramsMap, network, key, networkKey);
378 buildParamsMapFromVfModuleForHeatTemplate(paramsMap, vm);
386 protected void buildVlanInformation(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
387 String key, String networkKey) {
389 String networkString = convertToString(network);
390 String vlanFilterKey = key + UNDERSCORE + networkKey + UNDERSCORE + "vlan_filter";
391 String privateVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "private_vlans";
392 String publicVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "public_vlans";
393 String guestVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "guest_vlans";
395 if (network.getSegmentationId() != null) {
396 paramsMap.put(vlanFilterKey, network.getSegmentationId());
399 List<String> privateVlans = jsonPath.locateResultList(networkString,
400 "$.related-networks.related-network[?(@.vlan-tags.is-private == true)].vlan-tags.upper-tag-id");
401 List<String> publicVlans = jsonPath.locateResultList(networkString,
402 "$.related-networks.related-network[?(@.vlan-tags.is-private == false)].vlan-tags.upper-tag-id");
403 List<String> concat = new ArrayList<>(privateVlans);
404 concat.addAll(publicVlans);
405 Collection<String> guestVlans = new HashSet<>(concat);
407 if (!privateVlans.isEmpty()) {
408 paramsMap.put(privateVlansKey, Joiner.on(",").join(privateVlans));
410 if (!publicVlans.isEmpty()) {
411 paramsMap.put(publicVlansKey, Joiner.on(",").join(publicVlans));
413 if (!guestVlans.isEmpty()) {
414 paramsMap.put(guestVlansKey, Joiner.on(",").join(guestVlans));
418 private void buildVfModuleVmNames(Map<String, Object> paramsMap, GenericResourceApiVmTopologyData vm, String key) {
420 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
421 if (vmNames != null) {
422 List<String> valueList = vmNames.getVmName();
423 if (valueList != null) {
424 for (int i = 0; i < valueList.size(); i++) {
425 String value = valueList.get(i);
426 if (i != valueList.size() - 1) {
427 values += value + ",";
431 paramsMap.put(key + "_name_" + i, value);
433 paramsMap.put(key + "_names", values);
438 private void buildVfModuleFloatingIps(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
439 String key, String networkKey) {
440 GenericResourceApiVmnetworkdataFloatingIps floatingIps = network.getFloatingIps();
441 if (floatingIps != null) {
442 List<String> floatingIpV4List = floatingIps.getFloatingIpV4();
443 if (floatingIpV4List != null) {
444 // add only one ipv4 floating ip for now
445 String floatingIPKey = key + UNDERSCORE + networkKey + FLOATING_IP;
446 String floatingIPKeyValue = floatingIpV4List.get(0);
447 if (floatingIPKeyValue != null && !floatingIPKeyValue.isEmpty()) {
448 paramsMap.put(floatingIPKey, floatingIPKeyValue);
451 // add only one ipv6 floating ip for now
452 List<String> floatingIpV6List = floatingIps.getFloatingIpV6();
453 if (floatingIpV6List != null) {
454 String floatingIPV6Key = key + UNDERSCORE + networkKey + FLOATING_V6_IP;
455 String floatingIPV6KeyValue = floatingIpV6List.get(0);
456 if (floatingIPV6KeyValue != null && !floatingIPV6KeyValue.isEmpty()) {
457 paramsMap.put(floatingIPV6Key, floatingIPV6KeyValue);
463 private void buildVfModuleInterfaceRoutePrefixes(Map<String, Object> paramsMap,
464 GenericResourceApiVmNetworkData network, String key, String networkKey) {
465 GenericResourceApiVmnetworkdataInterfaceRoutePrefixes interfaceRoutePrefixes =
466 network.getInterfaceRoutePrefixes();
467 if (interfaceRoutePrefixes != null) {
468 List<String> interfaceRoutePrefixesList = interfaceRoutePrefixes.getInterfaceRoutePrefix();
469 StringBuilder sbInterfaceRoutePrefixes = new StringBuilder();
470 sbInterfaceRoutePrefixes.append("[");
471 if (interfaceRoutePrefixesList != null) {
472 for (int a = 0; a < interfaceRoutePrefixesList.size(); a++) {
473 String interfaceRoutePrefixValue = interfaceRoutePrefixesList.get(a);
474 if (a != interfaceRoutePrefixesList.size() - 1) {
475 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \""
476 + interfaceRoutePrefixValue + "\"}" + ",");
478 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \""
479 + interfaceRoutePrefixValue + "\"}");
482 sbInterfaceRoutePrefixes.append("]");
483 if (!interfaceRoutePrefixesList.isEmpty()) {
484 paramsMap.put(key + UNDERSCORE + networkKey + "_route_prefixes",
485 sbInterfaceRoutePrefixes.toString());
491 private void buildVfModuleSriovParameters(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
494 GenericResourceApiVmnetworkdataSriovParameters sriovParameters = network.getSriovParameters();
495 if (sriovParameters != null) {
496 GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters heatVlanFilters =
497 sriovParameters.getHeatVlanFilters();
498 if (heatVlanFilters != null) {
499 List<String> heatVlanFiltersList = heatVlanFilters.getHeatVlanFilter();
500 StringBuilder sriovFilterBuf = new StringBuilder();
501 if (heatVlanFiltersList != null) {
502 for (int a = 0; a < heatVlanFiltersList.size(); a++) {
503 String heatVlanFilterValue = heatVlanFiltersList.get(a);
504 if (a != heatVlanFiltersList.size() - 1) {
505 sriovFilterBuf.append(heatVlanFilterValue).append(",");
507 sriovFilterBuf.append(heatVlanFilterValue);
510 if (!heatVlanFiltersList.isEmpty()) {
511 paramsMap.put(networkKey + "_ATT_VF_VLAN_FILTER", sriovFilterBuf.toString());
518 private void buildVfModuleNetworkInformation(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
519 String key, String networkKey) {
521 GenericResourceApiVmnetworkdataNetworkInformationItems networkInformationItems =
522 network.getNetworkInformationItems();
523 StringBuilder sbIpv4Ips = new StringBuilder();
524 StringBuilder sbIpv6Ips = new StringBuilder();
526 if (networkInformationItems != null) {
527 List<GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem> networkInformationItemList =
528 networkInformationItems.getNetworkInformationItem();
529 if (networkInformationItemList != null) {
530 for (int a = 0; a < networkInformationItemList.size(); a++) {
531 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem ipAddress =
532 networkInformationItemList.get(a);
533 if (ipAddress != null) {
534 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps ips =
535 ipAddress.getNetworkIps();
537 List<String> ipsList = ips.getNetworkIp();
538 if (ipsList != null) {
539 String ipVersion = ipAddress.getIpVersion();
540 for (int b = 0; b < ipsList.size(); b++) {
541 String ipAddressValue = ipsList.get(b);
542 if ("ipv4".equals(ipVersion)) {
543 if (b != ipsList.size() - 1) {
544 sbIpv4Ips.append(ipAddressValue + ",");
546 sbIpv4Ips.append(ipAddressValue);
548 paramsMap.put(key + UNDERSCORE + networkKey + IP + UNDERSCORE + b,
550 } else if ("ipv6".equals(ipVersion)) {
551 if (b != ipsList.size() - 1) {
552 sbIpv6Ips.append(ipAddressValue + ",");
554 sbIpv6Ips.append(ipAddressValue);
556 paramsMap.put(key + UNDERSCORE + networkKey + V6_IP + UNDERSCORE + b,
560 paramsMap.put(key + UNDERSCORE + networkKey + "_ips", sbIpv4Ips.toString());
561 paramsMap.put(key + UNDERSCORE + networkKey + "_v6_ips", sbIpv6Ips.toString());
571 * Build Mapping from GenericResourceApi SDNC for Heat Template so that AIC - PO gets accurate requests for vf
572 * module assignments. Build Count of SubInterfaces, VLAN Tag, network_name, network_id, ip_address (V4 and V6) and
573 * Floating IPs Addresses (V4 and V6) for Heat Template
575 private void buildParamsMapFromVfModuleForHeatTemplate(Map<String, Object> paramsMap,
576 GenericResourceApiVmTopologyData vm) {
577 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
579 if (vmNames != null) {
581 List<GenericResourceApiVmtopologydataVmnamesVnfcNames> vnfcNamesList = vmNames.getVnfcNames();
582 if (vnfcNamesList != null) {
584 for (int i = 0; i < vnfcNamesList.size(); i++) {
586 GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames = vnfcNamesList.get(i);
587 parseVnfcNamesData(paramsMap, vnfcNames);
594 * Parse vnfcNames data to build Mapping from GenericResourceApi SDNC for Heat Template.
596 private void parseVnfcNamesData(Map<String, Object> paramsMap,
597 GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames) {
599 if (vnfcNames != null) {
600 GenericResourceApiVnfcNetworkData vnfcNetworks = vnfcNames.getVnfcNetworks();
601 if (vnfcNetworks != null) {
602 List<GenericResourceApiVnfcnetworkdataVnfcNetworkData> vnfcNetworkdataList =
603 vnfcNetworks.getVnfcNetworkData();
605 if (vnfcNetworkdataList != null) {
607 for (int networkDataIdx = 0; networkDataIdx < vnfcNetworkdataList.size(); networkDataIdx++) {
609 GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata =
610 vnfcNetworkdataList.get(networkDataIdx);
611 parseVnfcNetworkData(paramsMap, vnfcNetworkdata, networkDataIdx);
619 * Parse VnfcNetworkData to build Mapping from GenericResourceApi SDNC for Heat Template. Build Count of
620 * SubInterfaces, VLAN Tag, network_name, network_id, ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6)
623 private void parseVnfcNetworkData(Map<String, Object> paramsMap,
624 GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata, int networkDataIdx) {
626 String vmTypeKey = vnfcNetworkdata.getVnfcType();
627 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts vnfcPorts = vnfcNetworkdata.getVnfcPorts();
628 if (vnfcPorts != null) {
629 List<GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort> vnfcPortList =
630 vnfcPorts.getVnfcPort();
631 if (vnfcPortList != null) {
632 for (int portIdx = 0; portIdx < vnfcPortList.size(); portIdx++) {
634 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort vnfcPort =
635 vnfcPortList.get(portIdx);
636 GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces = vnfcPort.getVnicSubInterfaces();
638 String vnicSubInterfacesString = convertToString(vnicSubInterfaces);
639 String networkRoleKey = vnfcPort.getCommonSubInterfaceRole();
640 String subInterfaceKey =
641 createVnfcSubInterfaceKey(vmTypeKey, networkDataIdx, networkRoleKey, portIdx);
642 String globalSubInterfaceKey = createGlobalVnfcSubInterfaceKey(vmTypeKey, networkRoleKey, portIdx);
644 buildVfModuleSubInterfacesCount(paramsMap, globalSubInterfaceKey, vnicSubInterfaces);
646 buildVfModuleVlanTag(paramsMap, subInterfaceKey, vnicSubInterfacesString);
648 buildVfModuleNetworkName(paramsMap, subInterfaceKey, vnicSubInterfacesString);
650 buildVfModuleNetworkId(paramsMap, subInterfaceKey, vnicSubInterfacesString);
652 buildVfModuleIpV4AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
654 buildVfModuleIpV6AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
656 buildVfModuleFloatingIpV4HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
658 buildVfModuleFloatingIpV6HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
665 * Build "count" (calculating the total number of sub-interfaces) for Heat Template Building Criteria :
666 * {vm-type}_subint_{network-role}_port_{index}_subintcount vmTypeKey = vm-type, networkRoleKey =
667 * common-sub-interface-role Example: fw_subint_ctrl_port_0_subintcount
670 private void buildVfModuleSubInterfacesCount(Map<String, Object> paramsMap, String keyPrefix,
671 GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces) {
673 List<GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData> subInterfaceNetworkDataList =
674 vnicSubInterfaces.getSubInterfaceNetworkData();
676 if ((subInterfaceNetworkDataList != null) && !subInterfaceNetworkDataList.isEmpty()) {
677 addPairToMap(paramsMap, keyPrefix, SUB_INT_COUNT, String.valueOf(subInterfaceNetworkDataList.size()));
681 protected String createVnfcSubInterfaceKey(String vmTypeKey, int networkDataIdx, String networkRoleKey,
684 return Joiner.on(UNDERSCORE)
685 .join(Arrays.asList(vmTypeKey, networkDataIdx, SUB_INT, networkRoleKey, PORT, portIdx));
688 protected String createGlobalVnfcSubInterfaceKey(String vmTypeKey, String networkRoleKey, int portIdx) {
690 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, SUB_INT, networkRoleKey, PORT, portIdx));
694 * Build VLAN Tag for Heat Template Building Criteria :
695 * {vm-type}_{index}_subint_{network-role}_port_{index}_vlan_ids vmTypeKey = vm-type, networkRoleKey =
696 * common-sub-interface-role Example: fw_0_subint_ctrl_port_0_vlan_ids
699 protected void buildVfModuleVlanTag(Map<String, Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
701 List<String> vlanTagIds =
702 jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].vlan-tag-id");
704 addPairToMap(paramsMap, keyPrefix, VLAN_IDS, vlanTagIds);
708 * Build "network_name" for Heat Template Building Criteria :
709 * {vm-type}_{index}_subint_{network-role}_port_{index}_net_names vmTypeKey = vm-type, networkRoleKey =
710 * common-sub-interface-role Example: fw_0_subint_ctrl_port_0_net_names
713 protected void buildVfModuleNetworkName(Map<String, Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
715 List<String> neworkNames =
716 jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-name");
718 addPairToMap(paramsMap, keyPrefix, NET_NAMES, neworkNames);
722 * Build "network_id" for Heat Template Building Criteria :
723 * {vm-type}_{index}_subint_{network-role}_port_{index}_net_ids vmTypeKey = vm-type, networkRoleKey =
724 * common-sub-interface-role Example: fw_0_subint_ctrl_port_0_net_ids
727 protected void buildVfModuleNetworkId(Map<String, Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
729 List<String> neworkIds =
730 jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-id");
732 addPairToMap(paramsMap, keyPrefix, NET_IDS, neworkIds);
736 * Build ip_address for V4 for Heat Template Building Criteria :
737 * {vm-type}_{index}_subint_{network-role}_port_{index}_ip_{index} -- for ipV4 key = vm-type, networkRoleKey =
740 protected void buildVfModuleIpV4AddressHeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
741 String vnicSubInterfaces) {
743 List<String> ipv4Ips = jsonPath.locateResultList(vnicSubInterfaces,
744 "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv4')].network-ips.network-ip[*]");
746 addPairToMap(paramsMap, keyPrefix, IP, ipv4Ips);
748 for (int i = 0; i < ipv4Ips.size(); i++) {
749 addPairToMap(paramsMap, keyPrefix, IP + UNDERSCORE + i, ipv4Ips.get(i));
755 * Build ip_address for Heat Template Building Criteria :
756 * {vm-type}_{index}_subint_{network-role}_port_{index}_v6_ip_{index} -- for ipV6 key = vm-type, networkRoleKey =
759 protected void buildVfModuleIpV6AddressHeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
760 String vnicSubInterfaces) {
762 List<String> ipv6Ips = jsonPath.locateResultList(vnicSubInterfaces,
763 "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv6')].network-ips.network-ip[*]");
765 addPairToMap(paramsMap, keyPrefix, V6_IP, ipv6Ips);
767 for (int i = 0; i < ipv6Ips.size(); i++) {
768 addPairToMap(paramsMap, keyPrefix, V6_IP + UNDERSCORE + i, ipv6Ips.get(i));
773 * Build floatingip_address for Heat Template Building Criteria :
774 * {vm-type}_subint_{network-role}_port_{index}_floating_ip -- for ipV4
776 protected void buildVfModuleFloatingIpV4HeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
777 String vnicSubInterfaces) {
779 List<String> floatingV4 = jsonPath.locateResultList(vnicSubInterfaces,
780 "$.sub-interface-network-data[*].floating-ips.floating-ip-v4[*]");
782 if (!floatingV4.isEmpty()) {
783 floatingV4 = Collections.singletonList(floatingV4.get(0));
785 addPairToMap(paramsMap, keyPrefix, FLOATING_IP, floatingV4);
790 * Build floatingip_address for Heat Template Building Criteria :
791 * {vm-type}_subint_{network-role}_port_{index}_floating_v6_ip -- for ipV6
793 protected void buildVfModuleFloatingIpV6HeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
794 String vnicSubInterfaces) {
796 List<String> floatingV6 = jsonPath.locateResultList(vnicSubInterfaces,
797 "$.sub-interface-network-data[*].floating-ips.floating-ip-v6[*]");
799 if (!floatingV6.isEmpty()) {
800 floatingV6 = Collections.singletonList(floatingV6.get(0));
802 addPairToMap(paramsMap, keyPrefix, FLOATING_V6_IP, floatingV6);
805 protected void addPairToMap(Map<String, Object> paramsMap, String keyPrefix, String key, String value) {
807 addPairToMap(paramsMap, keyPrefix, key, Collections.singletonList(value));
810 protected void addPairToMap(Map<String, Object> paramsMap, String keyPrefix, String key, List<String> value) {
812 if (!value.isEmpty()) {
813 paramsMap.put(keyPrefix + key, Joiner.on(",").join(value));
817 private void buildParamsMapFromSdncParams(Map<String, Object> paramsMap, GenericResourceApiParam parametersData) {
818 if (parametersData != null) {
819 List<GenericResourceApiParamParam> paramsList = parametersData.getParam();
820 if (paramsList != null) {
821 for (int i = 0; i < paramsList.size(); i++) {
822 GenericResourceApiParamParam param = paramsList.get(i);
823 String parameterName = param.getName();
824 if (!sdncResponseParamsToSkip.contains(parameterName)) {
825 String parameterValue = param.getValue();
826 paramsMap.put(parameterName, parameterValue);
833 private Map<String, String> buildNetworkRoleMap(GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology)
834 throws JsonParseException, JsonMappingException, IOException {
835 Map<String, String> networkRoleMap = new HashMap<>();
836 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments =
837 vfModuleTopology.getVfModuleAssignments();
838 if (vfModuleAssignments != null) {
839 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
841 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
842 if (vmsList != null) {
843 for (GenericResourceApiVmTopologyData vm : vmsList) {
844 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
845 if (vmNetworks != null) {
846 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
847 if (vmNetworksList != null) {
848 for (int n = 0; n < vmNetworksList.size(); n++) {
849 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
850 String networkRole = network.getNetworkRole();
851 String networkRoleValue = network.getNetworkRoleTag();
852 if (networkRoleValue == null || networkRoleValue.isEmpty()) {
853 networkRoleValue = networkRole;
855 networkRoleMap.put(networkRole, networkRoleValue);
863 return networkRoleMap;
866 public DeleteVfModuleRequest deleteVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion,
867 ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule) throws IOException {
868 DeleteVfModuleRequest deleteVfModuleRequest = new DeleteVfModuleRequest();
869 deleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
870 deleteVfModuleRequest.setCloudOwner(cloudRegion.getCloudOwner());
871 deleteVfModuleRequest.setTenantId(cloudRegion.getTenantId());
872 deleteVfModuleRequest.setVnfId(genericVnf.getVnfId());
873 deleteVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
874 if (!StringUtils.isEmpty(vfModule.getHeatStackId())) {
875 deleteVfModuleRequest.setVfModuleStackId(vfModule.getHeatStackId());// DoDVfMod_heatStackId
877 deleteVfModuleRequest.setVfModuleStackId(vfModule.getVfModuleName());
880 deleteVfModuleRequest.setSkipAAI(true);
881 setIdAndUrl(deleteVfModuleRequest);
882 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
883 deleteVfModuleRequest.setMsoRequest(msoRequest);
884 return deleteVfModuleRequest;
887 protected void setIdAndUrl(DeleteVfModuleRequest deleteVfModuleRequest) throws UnsupportedEncodingException {
888 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
889 deleteVfModuleRequest.setMessageId(messageId);
890 deleteVfModuleRequest
891 .setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
894 private String convertToString(Object obj) {
897 json = mapper.writeValueAsString(obj);
898 } catch (JsonProcessingException e) {
899 logger.error("JsonProcessingException in convertToString", e);
906 private VfModule getBaseVfModule(GenericVnf genericVnf) {
907 List<VfModule> vfModules = genericVnf.getVfModules();
908 VfModule baseVfModule = null;
909 if (vfModules != null) {
910 for (int i = 0; i < vfModules.size(); i++) {
911 if (vfModules.get(i).getModelInfoVfModule().getIsBaseBoolean()) {
912 baseVfModule = vfModules.get(i);