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.Map.Entry;
37 import java.util.Optional;
38 import javax.annotation.PostConstruct;
39 import org.apache.commons.lang3.StringUtils;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
41 import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
42 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubInterfaceNetworkData;
43 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData;
44 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleTopology;
45 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfModuleAssignments;
46 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmNetworkData;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmTopologyData;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataFloatingIps;
51 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataInterfaceRoutePrefixes;
52 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkInformationItems;
53 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem;
54 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps;
55 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovParameters;
56 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters;
57 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNames;
58 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNetworks;
59 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmnamesVnfcNames;
60 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfNetworkData;
61 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfTopology;
62 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcNetworkData;
63 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcNetworkData;
64 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts;
65 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort;
66 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfResourceAssignments;
67 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones;
68 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks;
69 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyVnfTopology;
70 import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
71 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
72 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
73 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
74 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
75 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
76 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
77 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
78 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
79 import org.onap.so.entity.MsoRequest;
80 import org.onap.so.jsonpath.JsonPathUtil;
81 import org.onap.so.openstack.utils.MsoMulticloudUtils;
82 import org.onap.so.client.adapter.vnf.mapper.exceptions.MissingValueTagException;
83 import org.slf4j.Logger;
84 import org.slf4j.LoggerFactory;
85 import org.springframework.beans.factory.annotation.Autowired;
86 import org.springframework.stereotype.Component;
87 import com.fasterxml.jackson.core.JsonParseException;
88 import com.fasterxml.jackson.core.JsonProcessingException;
89 import com.fasterxml.jackson.databind.DeserializationFeature;
90 import com.fasterxml.jackson.databind.JsonMappingException;
91 import com.fasterxml.jackson.databind.ObjectMapper;
92 import com.google.common.base.Joiner;
96 public class VnfAdapterVfModuleObjectMapper {
98 protected VnfAdapterObjectMapperUtils vnfAdapterObjectMapperUtils;
99 private static final Logger logger = LoggerFactory.getLogger(VnfAdapterVfModuleObjectMapper.class);
100 private static List<String> sdncResponseParamsToSkip =
101 asList("vnf_id", "vf_module_id", "vnf_name", "vf_module_name");
103 private ObjectMapper mapper = new ObjectMapper();
104 private static final JsonPathUtil jsonPath = JsonPathUtil.getInstance();
105 private static final String SUB_INT = "subint";
106 private static final String SUBNET_ID = "_subnet_id";
107 private static final String V6_SUBNET_ID = "_v6_subnet_id";
108 private static final String PORT = "port";
109 private static final String SUB_INT_COUNT = "_subintcount";
110 private static final String VLAN_IDS = "_vlan_ids";
111 private static final String NET_NAMES = "_net_names";
112 private static final String NET_IDS = "_net_ids";
113 private static final String IP = "_ip";
114 private static final String V6_IP = "_v6_ip";
115 private static final String FLOATING_IP = "_floating_ip";
116 private static final String FLOATING_V6_IP = "_floating_v6_ip";
117 private static final String UNDERSCORE = "_";
121 mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
124 public CreateVfModuleRequest createVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion,
125 OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
126 VfModule vfModule, VolumeGroup volumeGroup, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse)
127 throws IOException, MissingValueTagException {
128 CreateVfModuleRequest createVfModuleRequest = new CreateVfModuleRequest();
130 createVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
131 createVfModuleRequest.setCloudOwner(cloudRegion.getCloudOwner());
132 createVfModuleRequest.setTenantId(cloudRegion.getTenantId());
133 createVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
134 createVfModuleRequest.setVfModuleName(vfModule.getVfModuleName());
135 createVfModuleRequest.setVnfId(genericVnf.getVnfId());
136 createVfModuleRequest.setVnfType(genericVnf.getVnfType());
137 createVfModuleRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
138 createVfModuleRequest.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
139 createVfModuleRequest.setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
140 if (volumeGroup != null) {
141 createVfModuleRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId());
142 createVfModuleRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId());
144 VfModule baseVfModule = getBaseVfModule(genericVnf);
145 if (baseVfModule != null) {
146 createVfModuleRequest.setBaseVfModuleId(baseVfModule.getVfModuleId());
147 createVfModuleRequest.setBaseVfModuleStackId(baseVfModule.getHeatStackId());
149 createVfModuleRequest.setVfModuleParams(buildVfModuleParamsMap(requestContext, serviceInstance, genericVnf,
150 vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse));
152 createVfModuleRequest.setSkipAAI(true);
153 createVfModuleRequest.setBackout(Boolean.TRUE.equals(orchestrationContext.getIsRollbackEnabled()));
154 createVfModuleRequest.setFailIfExists(true);
156 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
157 createVfModuleRequest.setMsoRequest(msoRequest);
159 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
160 createVfModuleRequest.setMessageId(messageId);
161 createVfModuleRequest
162 .setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
164 return createVfModuleRequest;
167 private MsoRequest buildMsoRequest(RequestContext requestContext, ServiceInstance serviceInstance) {
168 MsoRequest msoRequest = new MsoRequest();
169 msoRequest.setRequestId(requestContext.getMsoRequestId());
170 msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
174 private Map<String, Object> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance,
175 GenericVnf genericVnf, VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse)
176 throws IOException, MissingValueTagException {
179 GenericResourceApiVnfTopology vnfTop =
180 mapper.readValue(sdncVnfQueryResponse, GenericResourceApiVnfTopology.class);
181 GenericResourceApiVfModuleTopology vfModuleTop =
182 mapper.readValue(sdncVfModuleQueryResponse, GenericResourceApiVfModuleTopology.class);
183 GenericResourceApiVnftopologyVnfTopology vnfTopology = vnfTop.getVnfTopology();
184 GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = vfModuleTop.getVfModuleTopology();
185 Map<String, Object> paramsMap = new HashMap<>();
187 if (vfModuleTopology.getSdncGeneratedCloudResources()) {
188 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, true);
189 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, null, true);
191 Map<String, String> networkRoleMap = buildNetworkRoleMap(vfModuleTopology);
192 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, false);
193 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, networkRoleMap, false);
196 // build the sdnc_directives from paramsMap
197 buildDirectivesParamFromMap(paramsMap, MsoMulticloudUtils.SDNC_DIRECTIVES, paramsMap);
198 buildDirectivesParamFromMap(paramsMap, MsoMulticloudUtils.USER_DIRECTIVES, requestContext.getUserParams());
200 buildMandatoryParamsMap(paramsMap, serviceInstance, genericVnf, vfModule);
202 // Parameters received from the request should overwrite any parameters received from SDNC
203 paramsMap.putAll(requestContext.getUserParams());
205 if (vfModule.getCloudParams() != null) {
206 paramsMap.putAll(vfModule.getCloudParams());
211 protected void buildDirectivesParamFromMap(Map<String, Object> paramsMap, String directive,
212 Map<String, Object> srcMap) throws MissingValueTagException {
213 StringBuilder directives = new StringBuilder();
214 int noOfDirectivesSize = 0;
215 if (directive.equals(MsoMulticloudUtils.USER_DIRECTIVES)
216 && srcMap.containsKey(MsoMulticloudUtils.OOF_DIRECTIVES)) {
217 noOfDirectivesSize = 1;
219 if (srcMap.size() > noOfDirectivesSize) {
220 directives.append("{ \"attributes\": [ ");
222 for (Map.Entry<String, Object> attributeEntry : srcMap.entrySet()) {
223 String attributeName = attributeEntry.getKey();
224 Object attributeValue = attributeEntry.getValue();
225 if (!(MsoMulticloudUtils.USER_DIRECTIVES.equals(directive)
226 && attributeName.equals(MsoMulticloudUtils.OOF_DIRECTIVES))) {
227 if (attributeValue == null) {
228 logger.error("No value tag found for attribute: {}", attributeName);
229 throw new MissingValueTagException("No value tag found for " + attributeName);
231 directives.append(new AttributeNameValue(attributeName, attributeValue.toString()));
232 if (i < (srcMap.size() - 1 + noOfDirectivesSize))
233 directives.append(", ");
237 directives.append("] }");
239 directives.append("{}");
241 paramsMap.put(directive, directives.toString());
244 private void buildMandatoryParamsMap(Map<String, Object> paramsMap, ServiceInstance serviceInstance,
245 GenericVnf genericVnf, VfModule vfModule) {
246 paramsMap.put("vnf_id", genericVnf.getVnfId());
247 paramsMap.put("vnf_name", genericVnf.getVnfName());
248 paramsMap.put("vf_module_id", vfModule.getVfModuleId());
249 paramsMap.put("vf_module_name", vfModule.getVfModuleName());
250 paramsMap.put("environment_context", serviceInstance.getModelInfoServiceInstance().getEnvironmentContext());
251 paramsMap.putIfAbsent("environment_context", "");
252 paramsMap.put("workload_context", serviceInstance.getModelInfoServiceInstance().getWorkloadContext());
253 paramsMap.putIfAbsent("workload_context", "");
254 Integer vfModuleIndex = vfModule.getModuleIndex();
255 if (vfModuleIndex != null) {
256 paramsMap.put("vf_module_index", vfModuleIndex.toString());
260 private void buildParamsMapFromVnfSdncResponse(Map<String, Object> paramsMap,
261 GenericResourceApiVnftopologyVnfTopology vnfTopology, Map<String, String> networkRoleMap,
262 boolean skipVnfResourceAssignments) throws IOException {
263 // Get VNF parameters from SDNC response
264 GenericResourceApiParam vnfParametersData = vnfTopology.getVnfParametersData();
265 buildParamsMapFromSdncParams(paramsMap, vnfParametersData);
267 if (!skipVnfResourceAssignments) {
268 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments =
269 vnfTopology.getVnfResourceAssignments();
270 if (vnfResourceAssignments != null) {
271 // Availability Zones
272 buildAvailabilityZones(paramsMap, vnfResourceAssignments);
274 buildVnfNetworks(paramsMap, vnfResourceAssignments, networkRoleMap);
279 private void buildAvailabilityZones(Map<String, Object> paramsMap,
280 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments) {
281 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones availabilityZones =
282 vnfResourceAssignments.getAvailabilityZones();
283 if (availabilityZones != null) {
284 List<String> availabilityZonesList = availabilityZones.getAvailabilityZone();
285 if (availabilityZonesList != null) {
286 for (int i = 0; i < availabilityZonesList.size(); i++) {
287 paramsMap.put("availability_zone_" + i, availabilityZonesList.get(i));
293 private void buildVnfNetworks(Map<String, Object> paramsMap,
294 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments,
295 Map<String, String> networkRoleMap) {
296 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworks =
297 vnfResourceAssignments.getVnfNetworks();
298 if (vnfNetworks != null) {
299 List<GenericResourceApiVnfNetworkData> vnfNetworksList = vnfNetworks.getVnfNetwork();
300 if (vnfNetworksList != null) {
301 for (int i = 0; i < vnfNetworksList.size(); i++) {
302 GenericResourceApiVnfNetworkData vnfNetwork = vnfNetworksList.get(i);
303 String networkRole = vnfNetwork.getNetworkRole();
304 String vnfNetworkKey = networkRoleMap.get(networkRole);
305 if (vnfNetworkKey == null || vnfNetworkKey.isEmpty()) {
306 vnfNetworkKey = networkRole;
309 String vnfNetworkNeutronIdValue = vnfNetwork.getNeutronId();
310 paramsMap.put(vnfNetworkKey + "_net_id", vnfNetworkNeutronIdValue);
311 String vnfNetworkNetNameValue = vnfNetwork.getNetworkName();
312 paramsMap.put(vnfNetworkKey + "_net_name", vnfNetworkNetNameValue);
313 String vnfNetworkNetFqdnValue = vnfNetwork.getContrailNetworkFqdn();
314 paramsMap.put(vnfNetworkKey + "_net_fqdn", vnfNetworkNetFqdnValue);
316 buildVnfNetworkSubnets(paramsMap, vnfNetwork, vnfNetworkKey);
323 private void buildVnfNetworkSubnets(Map<String, Object> paramsMap, GenericResourceApiVnfNetworkData vnfNetwork,
324 String vnfNetworkKey) {
325 String vnfNetworkString = convertToString(vnfNetwork);
326 Optional<String> ipv4Ips = jsonPath.locateResult(vnfNetworkString,
327 "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv4' && @.dhcp-enabled == 'Y')].subnet-id");
328 if (ipv4Ips.isPresent())
329 addPairToMap(paramsMap, vnfNetworkKey, SUBNET_ID, ipv4Ips.get());
331 Optional<String> ipv6Ips = jsonPath.locateResult(vnfNetworkString,
332 "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv6' && @.dhcp-enabled == 'Y')].subnet-id");
333 if (ipv6Ips.isPresent())
334 addPairToMap(paramsMap, vnfNetworkKey, V6_SUBNET_ID, ipv6Ips.get());
337 private void buildParamsMapFromVfModuleSdncResponse(Map<String, Object> paramsMap,
338 GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology, boolean skipVfModuleAssignments)
340 // Get VF Module parameters from SDNC response
341 GenericResourceApiParam vfModuleParametersData = vfModuleTopology.getVfModuleParameters();
342 buildParamsMapFromSdncParams(paramsMap, vfModuleParametersData);
344 if (!skipVfModuleAssignments) {
345 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments =
346 vfModuleTopology.getVfModuleAssignments();
347 if (vfModuleAssignments != null) {
349 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
351 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
352 if (vmsList != null) {
353 for (GenericResourceApiVmTopologyData vm : vmsList) {
354 String key = vm.getVmType();
355 buildVfModuleVmNames(paramsMap, vm, key);
356 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
357 if (vmNetworks != null) {
358 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
359 if (vmNetworksList != null) {
360 for (int n = 0; n < vmNetworksList.size(); n++) {
361 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
362 network.getNetworkRoleTag();
363 String networkKey = network.getNetworkRole();
365 buildVfModuleFloatingIps(paramsMap, network, key, networkKey);
366 // Interface Route Prefixes
367 buildVfModuleInterfaceRoutePrefixes(paramsMap, network, key, networkKey);
369 buildVfModuleSriovParameters(paramsMap, network, networkKey);
370 // IPV4 and IPV6 Addresses
371 buildVfModuleNetworkInformation(paramsMap, network, key, networkKey);
373 buildVlanInformation(paramsMap, network, key, networkKey);
379 buildParamsMapFromVfModuleForHeatTemplate(paramsMap, vm);
387 protected void buildVlanInformation(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
388 String key, String networkKey) {
390 String networkString = convertToString(network);
391 String vlanFilterKey = key + UNDERSCORE + networkKey + UNDERSCORE + "vlan_filter";
392 String privateVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "private_vlans";
393 String publicVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "public_vlans";
394 String guestVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "guest_vlans";
396 if (network.getSegmentationId() != null) {
397 paramsMap.put(vlanFilterKey, network.getSegmentationId());
400 List<String> privateVlans = jsonPath.locateResultList(networkString,
401 "$.related-networks.related-network[?(@.vlan-tags.is-private == true)].vlan-tags.upper-tag-id");
402 List<String> publicVlans = jsonPath.locateResultList(networkString,
403 "$.related-networks.related-network[?(@.vlan-tags.is-private == false)].vlan-tags.upper-tag-id");
404 List<String> concat = new ArrayList<>(privateVlans);
405 concat.addAll(publicVlans);
406 Collection<String> guestVlans = new HashSet<>(concat);
408 if (!privateVlans.isEmpty()) {
409 paramsMap.put(privateVlansKey, Joiner.on(",").join(privateVlans));
411 if (!publicVlans.isEmpty()) {
412 paramsMap.put(publicVlansKey, Joiner.on(",").join(publicVlans));
414 if (!guestVlans.isEmpty()) {
415 paramsMap.put(guestVlansKey, Joiner.on(",").join(guestVlans));
419 private void buildVfModuleVmNames(Map<String, Object> paramsMap, GenericResourceApiVmTopologyData vm, String key) {
421 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
422 if (vmNames != null) {
423 List<String> valueList = vmNames.getVmName();
424 if (valueList != null) {
425 for (int i = 0; i < valueList.size(); i++) {
426 String value = valueList.get(i);
427 if (i != valueList.size() - 1) {
428 values += value + ",";
432 paramsMap.put(key + "_name_" + i, value);
434 paramsMap.put(key + "_names", values);
439 private void buildVfModuleFloatingIps(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
440 String key, String networkKey) {
441 GenericResourceApiVmnetworkdataFloatingIps floatingIps = network.getFloatingIps();
442 if (floatingIps != null) {
443 List<String> floatingIpV4List = floatingIps.getFloatingIpV4();
444 if (floatingIpV4List != null) {
445 // add only one ipv4 floating ip for now
446 String floatingIPKey = key + UNDERSCORE + networkKey + FLOATING_IP;
447 String floatingIPKeyValue = floatingIpV4List.get(0);
448 if (floatingIPKeyValue != null && !floatingIPKeyValue.isEmpty()) {
449 paramsMap.put(floatingIPKey, floatingIPKeyValue);
452 // add only one ipv6 floating ip for now
453 List<String> floatingIpV6List = floatingIps.getFloatingIpV6();
454 if (floatingIpV6List != null) {
455 String floatingIPV6Key = key + UNDERSCORE + networkKey + FLOATING_V6_IP;
456 String floatingIPV6KeyValue = floatingIpV6List.get(0);
457 if (floatingIPV6KeyValue != null && !floatingIPV6KeyValue.isEmpty()) {
458 paramsMap.put(floatingIPV6Key, floatingIPV6KeyValue);
464 private void buildVfModuleInterfaceRoutePrefixes(Map<String, Object> paramsMap,
465 GenericResourceApiVmNetworkData network, String key, String networkKey) {
466 GenericResourceApiVmnetworkdataInterfaceRoutePrefixes interfaceRoutePrefixes =
467 network.getInterfaceRoutePrefixes();
468 if (interfaceRoutePrefixes != null) {
469 List<String> interfaceRoutePrefixesList = interfaceRoutePrefixes.getInterfaceRoutePrefix();
470 StringBuilder sbInterfaceRoutePrefixes = new StringBuilder();
471 sbInterfaceRoutePrefixes.append("[");
472 if (interfaceRoutePrefixesList != null) {
473 for (int a = 0; a < interfaceRoutePrefixesList.size(); a++) {
474 String interfaceRoutePrefixValue = interfaceRoutePrefixesList.get(a);
475 if (a != interfaceRoutePrefixesList.size() - 1) {
476 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \""
477 + interfaceRoutePrefixValue + "\"}" + ",");
479 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \""
480 + interfaceRoutePrefixValue + "\"}");
483 sbInterfaceRoutePrefixes.append("]");
484 if (interfaceRoutePrefixesList.size() > 0) {
485 paramsMap.put(key + UNDERSCORE + networkKey + "_route_prefixes",
486 sbInterfaceRoutePrefixes.toString());
492 private void buildVfModuleSriovParameters(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
495 GenericResourceApiVmnetworkdataSriovParameters sriovParameters = network.getSriovParameters();
496 if (sriovParameters != null) {
497 GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters heatVlanFilters =
498 sriovParameters.getHeatVlanFilters();
499 if (heatVlanFilters != null) {
500 List<String> heatVlanFiltersList = heatVlanFilters.getHeatVlanFilter();
501 StringBuilder sriovFilterBuf = new StringBuilder();
502 if (heatVlanFiltersList != null) {
503 for (int a = 0; a < heatVlanFiltersList.size(); a++) {
504 String heatVlanFilterValue = heatVlanFiltersList.get(a);
505 if (a != heatVlanFiltersList.size() - 1) {
506 sriovFilterBuf.append(heatVlanFilterValue).append(",");
508 sriovFilterBuf.append(heatVlanFilterValue);
511 if (heatVlanFiltersList.size() > 0) {
512 paramsMap.put(networkKey + "_ATT_VF_VLAN_FILTER", sriovFilterBuf.toString());
519 private void buildVfModuleNetworkInformation(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
520 String key, String networkKey) {
522 GenericResourceApiVmnetworkdataNetworkInformationItems networkInformationItems =
523 network.getNetworkInformationItems();
524 StringBuilder sbIpv4Ips = new StringBuilder();
525 StringBuilder sbIpv6Ips = new StringBuilder();
527 if (networkInformationItems != null) {
528 List<GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem> networkInformationItemList =
529 networkInformationItems.getNetworkInformationItem();
530 if (networkInformationItemList != null) {
531 for (int a = 0; a < networkInformationItemList.size(); a++) {
532 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem ipAddress =
533 networkInformationItemList.get(a);
534 if (ipAddress != null) {
535 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps ips =
536 ipAddress.getNetworkIps();
538 List<String> ipsList = ips.getNetworkIp();
539 if (ipsList != null) {
540 String ipVersion = ipAddress.getIpVersion();
541 for (int b = 0; b < ipsList.size(); b++) {
542 String ipAddressValue = ipsList.get(b);
543 if (ipVersion.equals("ipv4")) {
544 if (b != ipsList.size() - 1) {
545 sbIpv4Ips.append(ipAddressValue + ",");
547 sbIpv4Ips.append(ipAddressValue);
549 paramsMap.put(key + UNDERSCORE + networkKey + IP + UNDERSCORE + b,
551 } else if (ipVersion.equals("ipv6")) {
552 if (b != ipsList.size() - 1) {
553 sbIpv6Ips.append(ipAddressValue + ",");
555 sbIpv6Ips.append(ipAddressValue);
557 paramsMap.put(key + UNDERSCORE + networkKey + V6_IP + UNDERSCORE + b,
561 paramsMap.put(key + UNDERSCORE + networkKey + "_ips", sbIpv4Ips.toString());
562 paramsMap.put(key + UNDERSCORE + networkKey + "_v6_ips", sbIpv6Ips.toString());
572 * Build Mapping from GenericResourceApi SDNC for Heat Template so that AIC - PO gets accurate requests for vf
573 * module assignments. Build Count of SubInterfaces, VLAN Tag, network_name, network_id, ip_address (V4 and V6) and
574 * Floating IPs Addresses (V4 and V6) for Heat Template
576 private void buildParamsMapFromVfModuleForHeatTemplate(Map<String, Object> paramsMap,
577 GenericResourceApiVmTopologyData vm) {
578 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
580 if (vmNames != null) {
582 List<GenericResourceApiVmtopologydataVmnamesVnfcNames> vnfcNamesList = vmNames.getVnfcNames();
583 if (vnfcNamesList != null) {
585 for (int i = 0; i < vnfcNamesList.size(); i++) {
587 GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames = vnfcNamesList.get(i);
588 parseVnfcNamesData(paramsMap, vnfcNames);
595 * Parse vnfcNames data to build Mapping from GenericResourceApi SDNC for Heat Template.
597 private void parseVnfcNamesData(Map<String, Object> paramsMap,
598 GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames) {
600 if (vnfcNames != null) {
601 GenericResourceApiVnfcNetworkData vnfcNetworks = vnfcNames.getVnfcNetworks();
602 if (vnfcNetworks != null) {
603 List<GenericResourceApiVnfcnetworkdataVnfcNetworkData> vnfcNetworkdataList =
604 vnfcNetworks.getVnfcNetworkData();
606 if (vnfcNetworkdataList != null) {
608 for (int networkDataIdx = 0; networkDataIdx < vnfcNetworkdataList.size(); networkDataIdx++) {
610 GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata =
611 vnfcNetworkdataList.get(networkDataIdx);
612 parseVnfcNetworkData(paramsMap, vnfcNetworkdata, networkDataIdx);
620 * Parse VnfcNetworkData to build Mapping from GenericResourceApi SDNC for Heat Template. Build Count of
621 * SubInterfaces, VLAN Tag, network_name, network_id, ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6)
624 private void parseVnfcNetworkData(Map<String, Object> paramsMap,
625 GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata, int networkDataIdx) {
627 String vmTypeKey = vnfcNetworkdata.getVnfcType();
628 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts vnfcPorts = vnfcNetworkdata.getVnfcPorts();
629 if (vnfcPorts != null) {
630 List<GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort> vnfcPortList =
631 vnfcPorts.getVnfcPort();
632 if (vnfcPortList != null) {
633 for (int portIdx = 0; portIdx < vnfcPortList.size(); portIdx++) {
635 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort vnfcPort =
636 vnfcPortList.get(portIdx);
637 GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces = vnfcPort.getVnicSubInterfaces();
639 String vnicSubInterfacesString = convertToString(vnicSubInterfaces);
640 String networkRoleKey = vnfcPort.getCommonSubInterfaceRole();
641 String subInterfaceKey =
642 createVnfcSubInterfaceKey(vmTypeKey, networkDataIdx, networkRoleKey, portIdx);
643 String globalSubInterfaceKey = createGlobalVnfcSubInterfaceKey(vmTypeKey, networkRoleKey, portIdx);
645 buildVfModuleSubInterfacesCount(paramsMap, globalSubInterfaceKey, vnicSubInterfaces);
647 buildVfModuleVlanTag(paramsMap, subInterfaceKey, vnicSubInterfacesString);
649 buildVfModuleNetworkName(paramsMap, subInterfaceKey, vnicSubInterfacesString);
651 buildVfModuleNetworkId(paramsMap, subInterfaceKey, vnicSubInterfacesString);
653 buildVfModuleIpV4AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
655 buildVfModuleIpV6AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
657 buildVfModuleFloatingIpV4HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
659 buildVfModuleFloatingIpV6HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
666 * Build "count" (calculating the total number of sub-interfaces) for Heat Template Building Criteria :
667 * {vm-type}_subint_{network-role}_port_{index}_subintcount vmTypeKey = vm-type, networkRoleKey =
668 * common-sub-interface-role Example: fw_subint_ctrl_port_0_subintcount
671 private void buildVfModuleSubInterfacesCount(Map<String, Object> paramsMap, String keyPrefix,
672 GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces) {
674 List<GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData> subInterfaceNetworkDataList =
675 vnicSubInterfaces.getSubInterfaceNetworkData();
677 if ((subInterfaceNetworkDataList != null) && !subInterfaceNetworkDataList.isEmpty()) {
678 addPairToMap(paramsMap, keyPrefix, SUB_INT_COUNT, String.valueOf(subInterfaceNetworkDataList.size()));
682 protected String createVnfcSubInterfaceKey(String vmTypeKey, int networkDataIdx, String networkRoleKey,
685 return Joiner.on(UNDERSCORE)
686 .join(Arrays.asList(vmTypeKey, networkDataIdx, SUB_INT, networkRoleKey, PORT, portIdx));
689 protected String createGlobalVnfcSubInterfaceKey(String vmTypeKey, String networkRoleKey, int portIdx) {
691 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, SUB_INT, networkRoleKey, PORT, portIdx));
695 * Build VLAN Tag for Heat Template Building Criteria :
696 * {vm-type}_{index}_subint_{network-role}_port_{index}_vlan_ids vmTypeKey = vm-type, networkRoleKey =
697 * common-sub-interface-role Example: fw_0_subint_ctrl_port_0_vlan_ids
700 protected void buildVfModuleVlanTag(Map<String, Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
702 List<String> vlanTagIds =
703 jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].vlan-tag-id");
705 addPairToMap(paramsMap, keyPrefix, VLAN_IDS, vlanTagIds);
709 * Build "network_name" for Heat Template Building Criteria :
710 * {vm-type}_{index}_subint_{network-role}_port_{index}_net_names vmTypeKey = vm-type, networkRoleKey =
711 * common-sub-interface-role Example: fw_0_subint_ctrl_port_0_net_names
714 protected void buildVfModuleNetworkName(Map<String, Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
716 List<String> neworkNames =
717 jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-name");
719 addPairToMap(paramsMap, keyPrefix, NET_NAMES, neworkNames);
723 * Build "network_id" for Heat Template Building Criteria :
724 * {vm-type}_{index}_subint_{network-role}_port_{index}_net_ids vmTypeKey = vm-type, networkRoleKey =
725 * common-sub-interface-role Example: fw_0_subint_ctrl_port_0_net_ids
728 protected void buildVfModuleNetworkId(Map<String, Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
730 List<String> neworkIds =
731 jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-id");
733 addPairToMap(paramsMap, keyPrefix, NET_IDS, neworkIds);
737 * Build ip_address for V4 for Heat Template Building Criteria :
738 * {vm-type}_{index}_subint_{network-role}_port_{index}_ip_{index} -- for ipV4 key = vm-type, networkRoleKey =
741 protected void buildVfModuleIpV4AddressHeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
742 String vnicSubInterfaces) {
744 List<String> ipv4Ips = jsonPath.locateResultList(vnicSubInterfaces,
745 "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv4')].network-ips.network-ip[*]");
747 addPairToMap(paramsMap, keyPrefix, IP, ipv4Ips);
749 for (int i = 0; i < ipv4Ips.size(); i++) {
750 addPairToMap(paramsMap, keyPrefix, IP + UNDERSCORE + i, ipv4Ips.get(i));
756 * Build ip_address for Heat Template Building Criteria :
757 * {vm-type}_{index}_subint_{network-role}_port_{index}_v6_ip_{index} -- for ipV6 key = vm-type, networkRoleKey =
760 protected void buildVfModuleIpV6AddressHeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
761 String vnicSubInterfaces) {
763 List<String> ipv6Ips = jsonPath.locateResultList(vnicSubInterfaces,
764 "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv6')].network-ips.network-ip[*]");
766 addPairToMap(paramsMap, keyPrefix, V6_IP, ipv6Ips);
768 for (int i = 0; i < ipv6Ips.size(); i++) {
769 addPairToMap(paramsMap, keyPrefix, V6_IP + UNDERSCORE + i, ipv6Ips.get(i));
774 * Build floatingip_address for Heat Template Building Criteria :
775 * {vm-type}_subint_{network-role}_port_{index}_floating_ip -- for ipV4
777 protected void buildVfModuleFloatingIpV4HeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
778 String vnicSubInterfaces) {
780 List<String> floatingV4 = jsonPath.locateResultList(vnicSubInterfaces,
781 "$.sub-interface-network-data[*].floating-ips.floating-ip-v4[*]");
783 if (!floatingV4.isEmpty()) {
784 floatingV4 = Collections.singletonList(floatingV4.get(0));
786 addPairToMap(paramsMap, keyPrefix, FLOATING_IP, floatingV4);
791 * Build floatingip_address for Heat Template Building Criteria :
792 * {vm-type}_subint_{network-role}_port_{index}_floating_v6_ip -- for ipV6
794 protected void buildVfModuleFloatingIpV6HeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
795 String vnicSubInterfaces) {
797 List<String> floatingV6 = jsonPath.locateResultList(vnicSubInterfaces,
798 "$.sub-interface-network-data[*].floating-ips.floating-ip-v6[*]");
800 if (!floatingV6.isEmpty()) {
801 floatingV6 = Collections.singletonList(floatingV6.get(0));
803 addPairToMap(paramsMap, keyPrefix, FLOATING_V6_IP, floatingV6);
806 protected void addPairToMap(Map<String, Object> paramsMap, String keyPrefix, String key, String value) {
808 addPairToMap(paramsMap, keyPrefix, key, Collections.singletonList(value));
811 protected void addPairToMap(Map<String, Object> paramsMap, String keyPrefix, String key, List<String> value) {
813 if (!value.isEmpty()) {
814 paramsMap.put(keyPrefix + key, Joiner.on(",").join(value));
818 private void buildParamsMapFromSdncParams(Map<String, Object> paramsMap, GenericResourceApiParam parametersData) {
819 if (parametersData != null) {
820 List<GenericResourceApiParamParam> paramsList = parametersData.getParam();
821 if (paramsList != null) {
822 for (int i = 0; i < paramsList.size(); i++) {
823 GenericResourceApiParamParam param = paramsList.get(i);
824 String parameterName = param.getName();
825 if (!sdncResponseParamsToSkip.contains(parameterName)) {
826 String parameterValue = param.getValue();
827 paramsMap.put(parameterName, parameterValue);
834 private Map<String, String> buildNetworkRoleMap(GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology)
835 throws JsonParseException, JsonMappingException, IOException {
836 Map<String, String> networkRoleMap = new HashMap<>();
837 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments =
838 vfModuleTopology.getVfModuleAssignments();
839 if (vfModuleAssignments != null) {
840 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
842 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
843 if (vmsList != null) {
844 for (GenericResourceApiVmTopologyData vm : vmsList) {
845 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
846 if (vmNetworks != null) {
847 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
848 if (vmNetworksList != null) {
849 for (int n = 0; n < vmNetworksList.size(); n++) {
850 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
851 String networkRole = network.getNetworkRole();
852 String networkRoleValue = network.getNetworkRoleTag();
853 if (networkRoleValue == null || networkRoleValue.isEmpty()) {
854 networkRoleValue = networkRole;
856 networkRoleMap.put(networkRole, networkRoleValue);
864 return networkRoleMap;
867 public DeleteVfModuleRequest deleteVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion,
868 ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule) throws IOException {
869 DeleteVfModuleRequest deleteVfModuleRequest = new DeleteVfModuleRequest();
870 deleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
871 deleteVfModuleRequest.setCloudOwner(cloudRegion.getCloudOwner());
872 deleteVfModuleRequest.setTenantId(cloudRegion.getTenantId());
873 deleteVfModuleRequest.setVnfId(genericVnf.getVnfId());
874 deleteVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
875 if (!StringUtils.isEmpty(vfModule.getHeatStackId())) {
876 deleteVfModuleRequest.setVfModuleStackId(vfModule.getHeatStackId());// DoDVfMod_heatStackId
878 deleteVfModuleRequest.setVfModuleStackId(vfModule.getVfModuleName());
881 deleteVfModuleRequest.setSkipAAI(true);
882 setIdAndUrl(deleteVfModuleRequest);
883 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
884 deleteVfModuleRequest.setMsoRequest(msoRequest);
885 return deleteVfModuleRequest;
888 protected void setIdAndUrl(DeleteVfModuleRequest deleteVfModuleRequest) throws UnsupportedEncodingException {
889 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
890 deleteVfModuleRequest.setMessageId(messageId);
891 deleteVfModuleRequest
892 .setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
895 private String convertToString(Object obj) {
898 json = mapper.writeValueAsString(obj);
899 } catch (JsonProcessingException 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);