2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.client.adapter.vnf.mapper;
23 import static java.util.Arrays.asList;
24 import java.io.IOException;
25 import java.io.UnsupportedEncodingException;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.HashMap;
31 import java.util.HashSet;
32 import java.util.List;
34 import java.util.Optional;
35 import javax.annotation.PostConstruct;
36 import org.apache.commons.lang.builder.ToStringBuilder;
37 import org.apache.commons.lang3.StringUtils;
38 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
39 import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubInterfaceNetworkData;
41 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData;
42 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleTopology;
43 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfModuleAssignments;
44 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms;
45 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
46 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmNetworkData;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmTopologyData;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataFloatingIps;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataInterfaceRoutePrefixes;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkInformationItems;
51 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem;
52 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps;
53 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovParameters;
54 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters;
55 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNames;
56 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNetworks;
57 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmnamesVnfcNames;
58 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfNetworkData;
59 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfTopology;
60 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcNetworkData;
61 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcNetworkData;
62 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts;
63 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort;
64 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfResourceAssignments;
65 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones;
66 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks;
67 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyVnfTopology;
68 import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
69 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
70 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
71 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
72 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
73 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
74 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
75 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
76 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
77 import org.onap.so.entity.MsoRequest;
78 import org.onap.so.jsonpath.JsonPathUtil;
79 import org.onap.so.openstack.utils.MsoMulticloudUtils;
80 import org.springframework.beans.factory.annotation.Autowired;
81 import org.springframework.stereotype.Component;
82 import com.fasterxml.jackson.core.JsonParseException;
83 import com.fasterxml.jackson.core.JsonProcessingException;
84 import com.fasterxml.jackson.databind.DeserializationFeature;
85 import com.fasterxml.jackson.databind.JsonMappingException;
86 import com.fasterxml.jackson.databind.ObjectMapper;
87 import com.google.common.base.Joiner;
91 public class VnfAdapterVfModuleObjectMapper {
93 protected VnfAdapterObjectMapperUtils vnfAdapterObjectMapperUtils;
94 private static List<String> sdncResponseParamsToSkip =
95 asList("vnf_id", "vf_module_id", "vnf_name", "vf_module_name");
97 private ObjectMapper mapper = new ObjectMapper();
98 private static final JsonPathUtil jsonPath = JsonPathUtil.getInstance();
99 private static final String SUB_INT = "subint";
100 private static final String SUBNET_ID = "_subnet_id";
101 private static final String V6_SUBNET_ID = "_v6_subnet_id";
102 private static final String PORT = "port";
103 private static final String SUB_INT_COUNT = "_subintcount";
104 private static final String VLAN_IDS = "_vlan_ids";
105 private static final String NET_NAMES = "_net_names";
106 private static final String NET_IDS = "_net_ids";
107 private static final String IP = "_ip";
108 private static final String V6_IP = "_v6_ip";
109 private static final String FLOATING_IP = "_floating_ip";
110 private static final String FLOATING_V6_IP = "_floating_v6_ip";
111 private static final String UNDERSCORE = "_";
115 mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
118 public CreateVfModuleRequest createVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion,
119 OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
120 VfModule vfModule, VolumeGroup volumeGroup, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse)
121 throws JsonParseException, JsonMappingException, IOException {
122 CreateVfModuleRequest createVfModuleRequest = new CreateVfModuleRequest();
124 createVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
125 createVfModuleRequest.setCloudOwner(cloudRegion.getCloudOwner());
126 createVfModuleRequest.setTenantId(cloudRegion.getTenantId());
127 createVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
128 createVfModuleRequest.setVfModuleName(vfModule.getVfModuleName());
129 createVfModuleRequest.setVnfId(genericVnf.getVnfId());
130 createVfModuleRequest.setVnfType(genericVnf.getVnfType());
131 createVfModuleRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
132 createVfModuleRequest.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
133 createVfModuleRequest.setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
134 if (volumeGroup != null) {
135 createVfModuleRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId());
136 createVfModuleRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId());
138 VfModule baseVfModule = getBaseVfModule(genericVnf);
139 if (baseVfModule != null) {
140 createVfModuleRequest.setBaseVfModuleId(baseVfModule.getVfModuleId());
141 createVfModuleRequest.setBaseVfModuleStackId(baseVfModule.getHeatStackId());
143 createVfModuleRequest.setVfModuleParams(buildVfModuleParamsMap(requestContext, serviceInstance, genericVnf,
144 vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse));
146 createVfModuleRequest.setSkipAAI(true);
147 createVfModuleRequest.setBackout(Boolean.TRUE.equals(orchestrationContext.getIsRollbackEnabled()));
148 createVfModuleRequest.setFailIfExists(true);
150 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
151 createVfModuleRequest.setMsoRequest(msoRequest);
153 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
154 createVfModuleRequest.setMessageId(messageId);
155 createVfModuleRequest
156 .setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
158 return createVfModuleRequest;
161 private MsoRequest buildMsoRequest(RequestContext requestContext, ServiceInstance serviceInstance) {
162 MsoRequest msoRequest = new MsoRequest();
163 msoRequest.setRequestId(requestContext.getMsoRequestId());
164 msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
168 private Map<String, Object> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance,
169 GenericVnf genericVnf, VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse)
170 throws JsonParseException, JsonMappingException, IOException {
173 GenericResourceApiVnfTopology vnfTop =
174 mapper.readValue(sdncVnfQueryResponse, GenericResourceApiVnfTopology.class);
175 GenericResourceApiVfModuleTopology vfModuleTop =
176 mapper.readValue(sdncVfModuleQueryResponse, GenericResourceApiVfModuleTopology.class);
177 GenericResourceApiVnftopologyVnfTopology vnfTopology = vnfTop.getVnfTopology();
178 GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = vfModuleTop.getVfModuleTopology();
179 Map<String, Object> paramsMap = new HashMap<>();
181 if (vfModuleTopology.getSdncGeneratedCloudResources()) {
182 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, true);
183 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, null, true);
185 Map<String, String> networkRoleMap = buildNetworkRoleMap(vfModuleTopology);
186 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, false);
187 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, networkRoleMap, false);
190 // build the sdnc_directives from paramsMap
191 buildDirectivesParamFromMap(paramsMap, MsoMulticloudUtils.SDNC_DIRECTIVES, paramsMap);
192 buildDirectivesParamFromMap(paramsMap, MsoMulticloudUtils.USER_DIRECTIVES, requestContext.getUserParams());
194 buildMandatoryParamsMap(paramsMap, serviceInstance, genericVnf, vfModule);
196 // Parameters received from the request should overwrite any parameters received from SDNC
197 paramsMap.putAll(requestContext.getUserParams());
199 if (vfModule.getCloudParams() != null) {
200 paramsMap.putAll(vfModule.getCloudParams());
205 private void buildDirectivesParamFromMap(Map<String, Object> paramsMap, String directive,
206 Map<String, Object> srcMap) {
207 StringBuilder directives = new StringBuilder();
208 int no_directives_size = 0;
209 if (directives.equals(MsoMulticloudUtils.USER_DIRECTIVES)
210 && srcMap.containsKey(MsoMulticloudUtils.OOF_DIRECTIVES)) {
211 no_directives_size = 1;
213 if (srcMap.size() > no_directives_size) {
214 directives.append("{ \"attributes\": [ ");
216 for (String attributeName : srcMap.keySet()) {
217 if (!(MsoMulticloudUtils.USER_DIRECTIVES.equals(directives)
218 && attributeName.equals(MsoMulticloudUtils.OOF_DIRECTIVES))) {
219 directives.append(new AttributeNameValue(attributeName, srcMap.get(attributeName).toString()));
220 if (i < (srcMap.size() - 1 + no_directives_size))
221 directives.append(", ");
225 directives.append("] }");
227 directives.append("{}");
229 paramsMap.put(directive, directives.toString());
232 private void buildMandatoryParamsMap(Map<String, Object> paramsMap, ServiceInstance serviceInstance,
233 GenericVnf genericVnf, VfModule vfModule) {
234 paramsMap.put("vnf_id", genericVnf.getVnfId());
235 paramsMap.put("vnf_name", genericVnf.getVnfName());
236 paramsMap.put("vf_module_id", vfModule.getVfModuleId());
237 paramsMap.put("vf_module_name", vfModule.getVfModuleName());
238 paramsMap.put("environment_context", serviceInstance.getModelInfoServiceInstance().getEnvironmentContext());
239 paramsMap.putIfAbsent("environment_context", "");
240 paramsMap.put("workload_context", serviceInstance.getModelInfoServiceInstance().getWorkloadContext());
241 paramsMap.putIfAbsent("workload_context", "");
242 Integer vfModuleIndex = vfModule.getModuleIndex();
243 if (vfModuleIndex != null) {
244 paramsMap.put("vf_module_index", vfModuleIndex.toString());
248 private void buildParamsMapFromVnfSdncResponse(Map<String, Object> paramsMap,
249 GenericResourceApiVnftopologyVnfTopology vnfTopology, Map<String, String> networkRoleMap,
250 boolean skipVnfResourceAssignments) throws JsonParseException, JsonMappingException, IOException {
251 // Get VNF parameters from SDNC response
252 GenericResourceApiParam vnfParametersData = vnfTopology.getVnfParametersData();
253 buildParamsMapFromSdncParams(paramsMap, vnfParametersData);
255 if (!skipVnfResourceAssignments) {
256 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments =
257 vnfTopology.getVnfResourceAssignments();
258 if (vnfResourceAssignments != null) {
259 // Availability Zones
260 buildAvailabilityZones(paramsMap, vnfResourceAssignments);
262 buildVnfNetworks(paramsMap, vnfResourceAssignments, networkRoleMap);
267 private void buildAvailabilityZones(Map<String, Object> paramsMap,
268 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments) {
269 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones availabilityZones =
270 vnfResourceAssignments.getAvailabilityZones();
271 if (availabilityZones != null) {
272 List<String> availabilityZonesList = availabilityZones.getAvailabilityZone();
273 if (availabilityZonesList != null) {
274 for (int i = 0; i < availabilityZonesList.size(); i++) {
275 paramsMap.put("availability_zone_" + i, availabilityZonesList.get(i));
281 private void buildVnfNetworks(Map<String, Object> paramsMap,
282 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments,
283 Map<String, String> networkRoleMap) {
284 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworks =
285 vnfResourceAssignments.getVnfNetworks();
286 if (vnfNetworks != null) {
287 List<GenericResourceApiVnfNetworkData> vnfNetworksList = vnfNetworks.getVnfNetwork();
288 if (vnfNetworksList != null) {
289 for (int i = 0; i < vnfNetworksList.size(); i++) {
290 GenericResourceApiVnfNetworkData vnfNetwork = vnfNetworksList.get(i);
291 String networkRole = vnfNetwork.getNetworkRole();
292 String vnfNetworkKey = networkRoleMap.get(networkRole);
293 if (vnfNetworkKey == null || vnfNetworkKey.isEmpty()) {
294 vnfNetworkKey = networkRole;
297 String vnfNetworkNeutronIdValue = vnfNetwork.getNeutronId();
298 paramsMap.put(vnfNetworkKey + "_net_id", vnfNetworkNeutronIdValue);
299 String vnfNetworkNetNameValue = vnfNetwork.getNetworkName();
300 paramsMap.put(vnfNetworkKey + "_net_name", vnfNetworkNetNameValue);
301 String vnfNetworkNetFqdnValue = vnfNetwork.getContrailNetworkFqdn();
302 paramsMap.put(vnfNetworkKey + "_net_fqdn", vnfNetworkNetFqdnValue);
304 buildVnfNetworkSubnets(paramsMap, vnfNetwork, vnfNetworkKey);
311 private void buildVnfNetworkSubnets(Map<String, Object> paramsMap, GenericResourceApiVnfNetworkData vnfNetwork,
312 String vnfNetworkKey) {
313 String vnfNetworkString = convertToString(vnfNetwork);
314 Optional<String> ipv4Ips = jsonPath.locateResult(vnfNetworkString,
315 "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv4' && @.dhcp-enabled == 'Y')].subnet-id");
316 if (ipv4Ips.isPresent())
317 addPairToMap(paramsMap, vnfNetworkKey, SUBNET_ID, ipv4Ips.get());
319 Optional<String> ipv6Ips = jsonPath.locateResult(vnfNetworkString,
320 "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv6' && @.dhcp-enabled == 'Y')].subnet-id");
321 if (ipv6Ips.isPresent())
322 addPairToMap(paramsMap, vnfNetworkKey, V6_SUBNET_ID, ipv6Ips.get());
325 private void buildParamsMapFromVfModuleSdncResponse(Map<String, Object> paramsMap,
326 GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology, boolean skipVfModuleAssignments)
327 throws JsonParseException, JsonMappingException, IOException {
328 // Get VF Module parameters from SDNC response
329 GenericResourceApiParam vfModuleParametersData = vfModuleTopology.getVfModuleParameters();
330 buildParamsMapFromSdncParams(paramsMap, vfModuleParametersData);
332 if (!skipVfModuleAssignments) {
333 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments =
334 vfModuleTopology.getVfModuleAssignments();
335 if (vfModuleAssignments != null) {
337 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
339 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
340 if (vmsList != null) {
341 for (GenericResourceApiVmTopologyData vm : vmsList) {
342 String key = vm.getVmType();
343 buildVfModuleVmNames(paramsMap, vm, key);
344 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
345 if (vmNetworks != null) {
346 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
347 if (vmNetworksList != null) {
348 for (int n = 0; n < vmNetworksList.size(); n++) {
349 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
350 network.getNetworkRoleTag();
351 String networkKey = network.getNetworkRole();
353 buildVfModuleFloatingIps(paramsMap, network, key, networkKey);
354 // Interface Route Prefixes
355 buildVfModuleInterfaceRoutePrefixes(paramsMap, network, key, networkKey);
357 buildVfModuleSriovParameters(paramsMap, network, networkKey);
358 // IPV4 and IPV6 Addresses
359 buildVfModuleNetworkInformation(paramsMap, network, key, networkKey);
361 buildVlanInformation(paramsMap, network, key, networkKey);
367 buildParamsMapFromVfModuleForHeatTemplate(paramsMap, vm);
375 protected void buildVlanInformation(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
376 String key, String networkKey) {
378 String networkString = convertToString(network);
379 String vlanFilterKey = key + UNDERSCORE + networkKey + UNDERSCORE + "vlan_filter";
380 String privateVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "private_vlans";
381 String publicVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "public_vlans";
382 String guestVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "guest_vlans";
384 if (network.getSegmentationId() != null) {
385 paramsMap.put(vlanFilterKey, network.getSegmentationId());
388 List<String> privateVlans = jsonPath.locateResultList(networkString,
389 "$.related-networks.related-network[?(@.vlan-tags.is-private == true)].vlan-tags.upper-tag-id");
390 List<String> publicVlans = jsonPath.locateResultList(networkString,
391 "$.related-networks.related-network[?(@.vlan-tags.is-private == false)].vlan-tags.upper-tag-id");
392 List<String> concat = new ArrayList<>(privateVlans);
393 concat.addAll(publicVlans);
394 Collection<String> guestVlans = new HashSet<>(concat);
396 if (!privateVlans.isEmpty()) {
397 paramsMap.put(privateVlansKey, Joiner.on(",").join(privateVlans));
399 if (!publicVlans.isEmpty()) {
400 paramsMap.put(publicVlansKey, Joiner.on(",").join(publicVlans));
402 if (!guestVlans.isEmpty()) {
403 paramsMap.put(guestVlansKey, Joiner.on(",").join(guestVlans));
407 private void buildVfModuleVmNames(Map<String, Object> paramsMap, GenericResourceApiVmTopologyData vm, String key) {
409 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
410 if (vmNames != null) {
411 List<String> valueList = vmNames.getVmName();
412 if (valueList != null) {
413 for (int i = 0; i < valueList.size(); i++) {
414 String value = valueList.get(i);
415 if (i != valueList.size() - 1) {
416 values += value + ",";
420 paramsMap.put(key + "_name_" + i, value);
422 paramsMap.put(key + "_names", values);
427 private void buildVfModuleFloatingIps(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
428 String key, String networkKey) {
429 GenericResourceApiVmnetworkdataFloatingIps floatingIps = network.getFloatingIps();
430 if (floatingIps != null) {
431 List<String> floatingIpV4List = floatingIps.getFloatingIpV4();
432 if (floatingIpV4List != null) {
433 // add only one ipv4 floating ip for now
434 String floatingIPKey = key + UNDERSCORE + networkKey + FLOATING_IP;
435 String floatingIPKeyValue = floatingIpV4List.get(0);
436 if (floatingIPKeyValue != null && !floatingIPKeyValue.isEmpty()) {
437 paramsMap.put(floatingIPKey, floatingIPKeyValue);
440 // add only one ipv6 floating ip for now
441 List<String> floatingIpV6List = floatingIps.getFloatingIpV6();
442 if (floatingIpV6List != null) {
443 String floatingIPV6Key = key + UNDERSCORE + networkKey + FLOATING_V6_IP;
444 String floatingIPV6KeyValue = floatingIpV6List.get(0);
445 if (floatingIPV6KeyValue != null && !floatingIPV6KeyValue.isEmpty()) {
446 paramsMap.put(floatingIPV6Key, floatingIPV6KeyValue);
452 private void buildVfModuleInterfaceRoutePrefixes(Map<String, Object> paramsMap,
453 GenericResourceApiVmNetworkData network, String key, String networkKey) {
454 GenericResourceApiVmnetworkdataInterfaceRoutePrefixes interfaceRoutePrefixes =
455 network.getInterfaceRoutePrefixes();
456 if (interfaceRoutePrefixes != null) {
457 List<String> interfaceRoutePrefixesList = interfaceRoutePrefixes.getInterfaceRoutePrefix();
458 StringBuilder sbInterfaceRoutePrefixes = new StringBuilder();
459 sbInterfaceRoutePrefixes.append("[");
460 if (interfaceRoutePrefixesList != null) {
461 for (int a = 0; a < interfaceRoutePrefixesList.size(); a++) {
462 String interfaceRoutePrefixValue = interfaceRoutePrefixesList.get(a);
463 if (a != interfaceRoutePrefixesList.size() - 1) {
464 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \""
465 + interfaceRoutePrefixValue + "\"}" + ",");
467 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \""
468 + interfaceRoutePrefixValue + "\"}");
471 sbInterfaceRoutePrefixes.append("]");
472 if (interfaceRoutePrefixesList.size() > 0) {
473 paramsMap.put(key + UNDERSCORE + networkKey + "_route_prefixes",
474 sbInterfaceRoutePrefixes.toString());
480 private void buildVfModuleSriovParameters(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
483 GenericResourceApiVmnetworkdataSriovParameters sriovParameters = network.getSriovParameters();
484 if (sriovParameters != null) {
485 GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters heatVlanFilters =
486 sriovParameters.getHeatVlanFilters();
487 if (heatVlanFilters != null) {
488 List<String> heatVlanFiltersList = heatVlanFilters.getHeatVlanFilter();
489 StringBuilder sriovFilterBuf = new StringBuilder();
490 if (heatVlanFiltersList != null) {
491 for (int a = 0; a < heatVlanFiltersList.size(); a++) {
492 String heatVlanFilterValue = heatVlanFiltersList.get(a);
493 if (a != heatVlanFiltersList.size() - 1) {
494 sriovFilterBuf.append(heatVlanFilterValue).append(",");
496 sriovFilterBuf.append(heatVlanFilterValue);
499 if (heatVlanFiltersList.size() > 0) {
500 paramsMap.put(networkKey + "_ATT_VF_VLAN_FILTER", sriovFilterBuf.toString());
507 private void buildVfModuleNetworkInformation(Map<String, Object> paramsMap, GenericResourceApiVmNetworkData network,
508 String key, String networkKey) {
510 GenericResourceApiVmnetworkdataNetworkInformationItems networkInformationItems =
511 network.getNetworkInformationItems();
512 StringBuilder sbIpv4Ips = new StringBuilder();
513 StringBuilder sbIpv6Ips = new StringBuilder();
515 if (networkInformationItems != null) {
516 List<GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem> networkInformationItemList =
517 networkInformationItems.getNetworkInformationItem();
518 if (networkInformationItemList != null) {
519 for (int a = 0; a < networkInformationItemList.size(); a++) {
520 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem ipAddress =
521 networkInformationItemList.get(a);
522 if (ipAddress != null) {
523 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps ips =
524 ipAddress.getNetworkIps();
526 List<String> ipsList = ips.getNetworkIp();
527 if (ipsList != null) {
528 String ipVersion = ipAddress.getIpVersion();
529 for (int b = 0; b < ipsList.size(); b++) {
530 String ipAddressValue = ipsList.get(b);
531 if (ipVersion.equals("ipv4")) {
532 if (b != ipsList.size() - 1) {
533 sbIpv4Ips.append(ipAddressValue + ",");
535 sbIpv4Ips.append(ipAddressValue);
537 paramsMap.put(key + UNDERSCORE + networkKey + IP + UNDERSCORE + b,
539 } else if (ipVersion.equals("ipv6")) {
540 if (b != ipsList.size() - 1) {
541 sbIpv6Ips.append(ipAddressValue + ",");
543 sbIpv6Ips.append(ipAddressValue);
545 paramsMap.put(key + UNDERSCORE + networkKey + V6_IP + UNDERSCORE + b,
549 paramsMap.put(key + UNDERSCORE + networkKey + "_ips", sbIpv4Ips.toString());
550 paramsMap.put(key + UNDERSCORE + networkKey + "_v6_ips", sbIpv6Ips.toString());
560 * Build Mapping from GenericResourceApi SDNC for Heat Template so that AIC - PO gets accurate requests for vf
561 * module assignments. Build Count of SubInterfaces, VLAN Tag, network_name, network_id, ip_address (V4 and V6) and
562 * Floating IPs Addresses (V4 and V6) for Heat Template
564 private void buildParamsMapFromVfModuleForHeatTemplate(Map<String, Object> paramsMap,
565 GenericResourceApiVmTopologyData vm) {
566 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
568 if (vmNames != null) {
570 List<GenericResourceApiVmtopologydataVmnamesVnfcNames> vnfcNamesList = vmNames.getVnfcNames();
571 if (vnfcNamesList != null) {
573 for (int i = 0; i < vnfcNamesList.size(); i++) {
575 GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames = vnfcNamesList.get(i);
576 parseVnfcNamesData(paramsMap, vnfcNames);
583 * Parse vnfcNames data to build Mapping from GenericResourceApi SDNC for Heat Template.
585 private void parseVnfcNamesData(Map<String, Object> paramsMap,
586 GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames) {
588 if (vnfcNames != null) {
589 GenericResourceApiVnfcNetworkData vnfcNetworks = vnfcNames.getVnfcNetworks();
590 if (vnfcNetworks != null) {
591 List<GenericResourceApiVnfcnetworkdataVnfcNetworkData> vnfcNetworkdataList =
592 vnfcNetworks.getVnfcNetworkData();
594 if (vnfcNetworkdataList != null) {
596 for (int networkDataIdx = 0; networkDataIdx < vnfcNetworkdataList.size(); networkDataIdx++) {
598 GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata =
599 vnfcNetworkdataList.get(networkDataIdx);
600 parseVnfcNetworkData(paramsMap, vnfcNetworkdata, networkDataIdx);
608 * Parse VnfcNetworkData to build Mapping from GenericResourceApi SDNC for Heat Template. Build Count of
609 * SubInterfaces, VLAN Tag, network_name, network_id, ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6)
612 private void parseVnfcNetworkData(Map<String, Object> paramsMap,
613 GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata, int networkDataIdx) {
615 String vmTypeKey = vnfcNetworkdata.getVnfcType();
616 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts vnfcPorts = vnfcNetworkdata.getVnfcPorts();
617 if (vnfcPorts != null) {
618 List<GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort> vnfcPortList =
619 vnfcPorts.getVnfcPort();
620 if (vnfcPortList != null) {
621 for (int portIdx = 0; portIdx < vnfcPortList.size(); portIdx++) {
623 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort vnfcPort =
624 vnfcPortList.get(portIdx);
625 GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces = vnfcPort.getVnicSubInterfaces();
627 String vnicSubInterfacesString = convertToString(vnicSubInterfaces);
628 String networkRoleKey = vnfcPort.getCommonSubInterfaceRole();
629 String subInterfaceKey =
630 createVnfcSubInterfaceKey(vmTypeKey, networkDataIdx, networkRoleKey, portIdx);
631 String globalSubInterfaceKey = createGlobalVnfcSubInterfaceKey(vmTypeKey, networkRoleKey, portIdx);
633 buildVfModuleSubInterfacesCount(paramsMap, globalSubInterfaceKey, vnicSubInterfaces);
635 buildVfModuleVlanTag(paramsMap, subInterfaceKey, vnicSubInterfacesString);
637 buildVfModuleNetworkName(paramsMap, subInterfaceKey, vnicSubInterfacesString);
639 buildVfModuleNetworkId(paramsMap, subInterfaceKey, vnicSubInterfacesString);
641 buildVfModuleIpV4AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
643 buildVfModuleIpV6AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
645 buildVfModuleFloatingIpV4HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
647 buildVfModuleFloatingIpV6HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
654 * Build "count" (calculating the total number of sub-interfaces) for Heat Template Building Criteria :
655 * {vm-type}_subint_{network-role}_port_{index}_subintcount vmTypeKey = vm-type, networkRoleKey =
656 * common-sub-interface-role Example: fw_subint_ctrl_port_0_subintcount
659 private void buildVfModuleSubInterfacesCount(Map<String, Object> paramsMap, String keyPrefix,
660 GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces) {
662 List<GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData> subInterfaceNetworkDataList =
663 vnicSubInterfaces.getSubInterfaceNetworkData();
665 if ((subInterfaceNetworkDataList != null) && !subInterfaceNetworkDataList.isEmpty()) {
666 addPairToMap(paramsMap, keyPrefix, SUB_INT_COUNT, String.valueOf(subInterfaceNetworkDataList.size()));
670 protected String createVnfcSubInterfaceKey(String vmTypeKey, int networkDataIdx, String networkRoleKey,
673 return Joiner.on(UNDERSCORE)
674 .join(Arrays.asList(vmTypeKey, networkDataIdx, SUB_INT, networkRoleKey, PORT, portIdx));
677 protected String createGlobalVnfcSubInterfaceKey(String vmTypeKey, String networkRoleKey, int portIdx) {
679 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, SUB_INT, networkRoleKey, PORT, portIdx));
683 * Build VLAN Tag for Heat Template Building Criteria :
684 * {vm-type}_{index}_subint_{network-role}_port_{index}_vlan_ids vmTypeKey = vm-type, networkRoleKey =
685 * common-sub-interface-role Example: fw_0_subint_ctrl_port_0_vlan_ids
688 protected void buildVfModuleVlanTag(Map<String, Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
690 List<String> vlanTagIds =
691 jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].vlan-tag-id");
693 addPairToMap(paramsMap, keyPrefix, VLAN_IDS, vlanTagIds);
697 * Build "network_name" for Heat Template Building Criteria :
698 * {vm-type}_{index}_subint_{network-role}_port_{index}_net_names vmTypeKey = vm-type, networkRoleKey =
699 * common-sub-interface-role Example: fw_0_subint_ctrl_port_0_net_names
702 protected void buildVfModuleNetworkName(Map<String, Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
704 List<String> neworkNames =
705 jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-name");
707 addPairToMap(paramsMap, keyPrefix, NET_NAMES, neworkNames);
711 * Build "network_id" for Heat Template Building Criteria :
712 * {vm-type}_{index}_subint_{network-role}_port_{index}_net_ids vmTypeKey = vm-type, networkRoleKey =
713 * common-sub-interface-role Example: fw_0_subint_ctrl_port_0_net_ids
716 protected void buildVfModuleNetworkId(Map<String, Object> paramsMap, String keyPrefix, String vnicSubInterfaces) {
718 List<String> neworkIds =
719 jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-id");
721 addPairToMap(paramsMap, keyPrefix, NET_IDS, neworkIds);
725 * Build ip_address for V4 for Heat Template Building Criteria :
726 * {vm-type}_{index}_subint_{network-role}_port_{index}_ip_{index} -- for ipV4 key = vm-type, networkRoleKey =
729 protected void buildVfModuleIpV4AddressHeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
730 String vnicSubInterfaces) {
732 List<String> ipv4Ips = jsonPath.locateResultList(vnicSubInterfaces,
733 "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv4')].network-ips.network-ip[*]");
735 addPairToMap(paramsMap, keyPrefix, IP, ipv4Ips);
737 for (int i = 0; i < ipv4Ips.size(); i++) {
738 addPairToMap(paramsMap, keyPrefix, IP + UNDERSCORE + i, ipv4Ips.get(i));
744 * Build ip_address for Heat Template Building Criteria :
745 * {vm-type}_{index}_subint_{network-role}_port_{index}_v6_ip_{index} -- for ipV6 key = vm-type, networkRoleKey =
748 protected void buildVfModuleIpV6AddressHeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
749 String vnicSubInterfaces) {
751 List<String> ipv6Ips = jsonPath.locateResultList(vnicSubInterfaces,
752 "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv6')].network-ips.network-ip[*]");
754 addPairToMap(paramsMap, keyPrefix, V6_IP, ipv6Ips);
756 for (int i = 0; i < ipv6Ips.size(); i++) {
757 addPairToMap(paramsMap, keyPrefix, V6_IP + UNDERSCORE + i, ipv6Ips.get(i));
762 * Build floatingip_address for Heat Template Building Criteria :
763 * {vm-type}_subint_{network-role}_port_{index}_floating_ip -- for ipV4
765 protected void buildVfModuleFloatingIpV4HeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
766 String vnicSubInterfaces) {
768 List<String> floatingV4 = jsonPath.locateResultList(vnicSubInterfaces,
769 "$.sub-interface-network-data[*].floating-ips.floating-ip-v4[*]");
771 if (!floatingV4.isEmpty()) {
772 floatingV4 = Collections.singletonList(floatingV4.get(0));
774 addPairToMap(paramsMap, keyPrefix, FLOATING_IP, floatingV4);
779 * Build floatingip_address for Heat Template Building Criteria :
780 * {vm-type}_subint_{network-role}_port_{index}_floating_v6_ip -- for ipV6
782 protected void buildVfModuleFloatingIpV6HeatTemplate(Map<String, Object> paramsMap, String keyPrefix,
783 String vnicSubInterfaces) {
785 List<String> floatingV6 = jsonPath.locateResultList(vnicSubInterfaces,
786 "$.sub-interface-network-data[*].floating-ips.floating-ip-v6[*]");
788 if (!floatingV6.isEmpty()) {
789 floatingV6 = Collections.singletonList(floatingV6.get(0));
791 addPairToMap(paramsMap, keyPrefix, FLOATING_V6_IP, floatingV6);
794 protected void addPairToMap(Map<String, Object> paramsMap, String keyPrefix, String key, String value) {
796 addPairToMap(paramsMap, keyPrefix, key, Collections.singletonList(value));
799 protected void addPairToMap(Map<String, Object> paramsMap, String keyPrefix, String key, List<String> value) {
801 if (!value.isEmpty()) {
802 paramsMap.put(keyPrefix + key, Joiner.on(",").join(value));
806 private void buildParamsMapFromSdncParams(Map<String, Object> paramsMap, GenericResourceApiParam parametersData) {
807 if (parametersData != null) {
808 List<GenericResourceApiParamParam> paramsList = parametersData.getParam();
809 if (paramsList != null) {
810 for (int i = 0; i < paramsList.size(); i++) {
811 GenericResourceApiParamParam param = paramsList.get(i);
812 String parameterName = param.getName();
813 if (!sdncResponseParamsToSkip.contains(parameterName)) {
814 String parameterValue = param.getValue();
815 paramsMap.put(parameterName, parameterValue);
822 private Map<String, String> buildNetworkRoleMap(GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology)
823 throws JsonParseException, JsonMappingException, IOException {
824 Map<String, String> networkRoleMap = new HashMap<>();
825 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments =
826 vfModuleTopology.getVfModuleAssignments();
827 if (vfModuleAssignments != null) {
828 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
830 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
831 if (vmsList != null) {
832 for (GenericResourceApiVmTopologyData vm : vmsList) {
833 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
834 if (vmNetworks != null) {
835 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
836 if (vmNetworksList != null) {
837 for (int n = 0; n < vmNetworksList.size(); n++) {
838 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
839 String networkRole = network.getNetworkRole();
840 String networkRoleValue = network.getNetworkRoleTag();
841 if (networkRoleValue == null || networkRoleValue.isEmpty()) {
842 networkRoleValue = networkRole;
844 networkRoleMap.put(networkRole, networkRoleValue);
852 return networkRoleMap;
855 public DeleteVfModuleRequest deleteVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion,
856 ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule) throws IOException {
857 DeleteVfModuleRequest deleteVfModuleRequest = new DeleteVfModuleRequest();
858 deleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
859 deleteVfModuleRequest.setCloudOwner(cloudRegion.getCloudOwner());
860 deleteVfModuleRequest.setTenantId(cloudRegion.getTenantId());
861 deleteVfModuleRequest.setVnfId(genericVnf.getVnfId());
862 deleteVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
863 if (!StringUtils.isEmpty(vfModule.getHeatStackId())) {
864 deleteVfModuleRequest.setVfModuleStackId(vfModule.getHeatStackId());// DoDVfMod_heatStackId
866 deleteVfModuleRequest.setVfModuleStackId(vfModule.getVfModuleName());
869 deleteVfModuleRequest.setSkipAAI(true);
870 setIdAndUrl(deleteVfModuleRequest);
871 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
872 deleteVfModuleRequest.setMsoRequest(msoRequest);
873 return deleteVfModuleRequest;
876 protected void setIdAndUrl(DeleteVfModuleRequest deleteVfModuleRequest) throws UnsupportedEncodingException {
877 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
878 deleteVfModuleRequest.setMessageId(messageId);
879 deleteVfModuleRequest
880 .setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
883 private String convertToString(Object obj) {
886 json = mapper.writeValueAsString(obj);
887 } catch (JsonProcessingException e) {
894 private VfModule getBaseVfModule(GenericVnf genericVnf) {
895 List<VfModule> vfModules = genericVnf.getVfModules();
896 VfModule baseVfModule = null;
897 if (vfModules != null) {
898 for (int i = 0; i < vfModules.size(); i++) {
899 if (vfModules.get(i).getModelInfoVfModule().getIsBaseBoolean()) {
900 baseVfModule = vfModules.get(i);