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;
25 import java.io.IOException;
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;
36 import javax.annotation.PostConstruct;
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.springframework.beans.factory.annotation.Autowired;
80 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 = asList("vnf_id", "vf_module_id", "vnf_name", "vf_module_name");
96 private ObjectMapper mapper = new ObjectMapper();
97 private static final JsonPathUtil jsonPath = JsonPathUtil.getInstance();
98 private static final String SUB_INT = "subint";
99 private static final String SUBNET_ID = "_subnet_id";
100 private static final String V6_SUBNET_ID = "_v6_subnet_id";
101 private static final String PORT = "port";
102 private static final String SUB_INT_COUNT = "_subintcount";
103 private static final String VLAN_IDS = "_vlan_ids";
104 private static final String NET_NAMES = "_net_names";
105 private static final String NET_IDS = "_net_ids";
106 private static final String IP = "_ip";
107 private static final String V6_IP = "_v6_ip";
108 private static final String FLOATING_IP = "_floating_ip";
109 private static final String FLOATING_V6_IP = "_floating_v6_ip";
110 private static final String UNDERSCORE = "_";
113 public void init () {
114 mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
117 public CreateVfModuleRequest createVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion, OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
118 VfModule vfModule, VolumeGroup volumeGroup, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
119 CreateVfModuleRequest createVfModuleRequest = new CreateVfModuleRequest();
121 createVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
122 createVfModuleRequest.setTenantId(cloudRegion.getTenantId());
123 createVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
124 createVfModuleRequest.setVfModuleName(vfModule.getVfModuleName());
125 createVfModuleRequest.setVnfId(genericVnf.getVnfId());
126 createVfModuleRequest.setVnfType(genericVnf.getVnfType());
127 createVfModuleRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
128 createVfModuleRequest.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
129 createVfModuleRequest.setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
130 if (volumeGroup != null) {
131 createVfModuleRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId());
132 createVfModuleRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId());
134 VfModule baseVfModule = getBaseVfModule(genericVnf);
135 if (baseVfModule != null) {
136 createVfModuleRequest.setBaseVfModuleId(baseVfModule.getVfModuleId());
137 createVfModuleRequest.setBaseVfModuleStackId(baseVfModule.getHeatStackId());
139 createVfModuleRequest.setVfModuleParams(buildVfModuleParamsMap(requestContext, serviceInstance, genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse));
141 createVfModuleRequest.setSkipAAI(true);
142 createVfModuleRequest.setBackout(Boolean.TRUE.equals(orchestrationContext.getIsRollbackEnabled()));
143 createVfModuleRequest.setFailIfExists(true);
145 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
146 createVfModuleRequest.setMsoRequest(msoRequest);
148 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
149 createVfModuleRequest.setMessageId(messageId);
150 createVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
152 return createVfModuleRequest;
155 private MsoRequest buildMsoRequest(RequestContext requestContext,ServiceInstance serviceInstance) {
156 MsoRequest msoRequest = new MsoRequest();
157 msoRequest.setRequestId(requestContext.getMsoRequestId());
158 msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
162 private Map<String,String> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
163 VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
166 GenericResourceApiVnfTopology vnfTop= mapper.readValue(sdncVnfQueryResponse, GenericResourceApiVnfTopology.class);
167 GenericResourceApiVfModuleTopology vfModuleTop = mapper.readValue(sdncVfModuleQueryResponse, GenericResourceApiVfModuleTopology.class);
168 GenericResourceApiVnftopologyVnfTopology vnfTopology = vnfTop.getVnfTopology();
169 GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = vfModuleTop.getVfModuleTopology();
170 Map<String,String> paramsMap = new HashMap<>();
172 if( vfModuleTopology.getSdncGeneratedCloudResources()) {
173 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, true);
174 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, null, true);
177 Map<String,String> networkRoleMap = buildNetworkRoleMap(vfModuleTopology);
178 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, false);
179 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, networkRoleMap, false);
182 buildMandatoryParamsMap(paramsMap, serviceInstance, genericVnf, vfModule);
184 // Parameters received from the request should overwrite any parameters received from SDNC
186 if (requestContext.getUserParams() != null) {
187 paramsMap.putAll(requestContext.getUserParams());
189 if (vfModule.getCloudParams() != null) {
190 paramsMap.putAll(vfModule.getCloudParams());
195 private void buildMandatoryParamsMap(Map<String,String> paramsMap, ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule) {
196 paramsMap.put("vnf_id", genericVnf.getVnfId());
197 paramsMap.put("vnf_name", genericVnf.getVnfName());
198 paramsMap.put("vf_module_id", vfModule.getVfModuleId());
199 paramsMap.put("vf_module_name", vfModule.getVfModuleName());
200 paramsMap.put("environment_context",serviceInstance.getModelInfoServiceInstance().getEnvironmentContext());
201 paramsMap.putIfAbsent("environment_context", "");
202 paramsMap.put("workload_context", serviceInstance.getModelInfoServiceInstance().getWorkloadContext());
203 paramsMap.putIfAbsent("workload_context", "");
204 Integer vfModuleIndex = vfModule.getModuleIndex();
205 if (vfModuleIndex != null) {
206 paramsMap.put("vf_module_index", vfModuleIndex.toString());
210 private void buildParamsMapFromVnfSdncResponse(Map<String,String> paramsMap, GenericResourceApiVnftopologyVnfTopology vnfTopology, Map<String,String> networkRoleMap, boolean skipVnfResourceAssignments) throws JsonParseException, JsonMappingException, IOException {
211 // Get VNF parameters from SDNC response
212 GenericResourceApiParam vnfParametersData = vnfTopology.getVnfParametersData();
213 buildParamsMapFromSdncParams(paramsMap, vnfParametersData);
215 if(!skipVnfResourceAssignments) {
216 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments = vnfTopology.getVnfResourceAssignments();
217 if (vnfResourceAssignments != null) {
218 // Availability Zones
219 buildAvailabilityZones(paramsMap, vnfResourceAssignments);
221 buildVnfNetworks(paramsMap, vnfResourceAssignments, networkRoleMap);
226 private void buildAvailabilityZones (Map<String,String> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments) {
227 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones availabilityZones = vnfResourceAssignments.getAvailabilityZones();
228 if (availabilityZones != null) {
229 List<String> availabilityZonesList = availabilityZones.getAvailabilityZone();
230 if (availabilityZonesList != null) {
231 for(int i = 0; i < availabilityZonesList.size(); i++) {
232 paramsMap.put("availability_zone_" + i, availabilityZonesList.get(i));
238 private void buildVnfNetworks (Map<String,String> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments, Map<String,String> networkRoleMap) {
239 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworks = vnfResourceAssignments.getVnfNetworks();
240 if (vnfNetworks != null) {
241 List<GenericResourceApiVnfNetworkData> vnfNetworksList = vnfNetworks.getVnfNetwork();
242 if (vnfNetworksList != null) {
243 for (int i = 0; i < vnfNetworksList.size(); i++) {
244 GenericResourceApiVnfNetworkData vnfNetwork = vnfNetworksList.get(i);
245 String networkRole = vnfNetwork.getNetworkRole();
246 String vnfNetworkKey = networkRoleMap.get(networkRole);
247 if (vnfNetworkKey == null || vnfNetworkKey.isEmpty()) {
248 vnfNetworkKey = networkRole;
251 String vnfNetworkNeutronIdValue = vnfNetwork.getNeutronId();
252 paramsMap.put(vnfNetworkKey + "_net_id", vnfNetworkNeutronIdValue);
253 String vnfNetworkNetNameValue = vnfNetwork.getNetworkName();
254 paramsMap.put(vnfNetworkKey + "_net_name", vnfNetworkNetNameValue);
255 String vnfNetworkNetFqdnValue = vnfNetwork.getContrailNetworkFqdn();
256 paramsMap.put(vnfNetworkKey + "_net_fqdn", vnfNetworkNetFqdnValue);
258 buildVnfNetworkSubnets(paramsMap, vnfNetwork, vnfNetworkKey);
265 private void buildVnfNetworkSubnets(Map<String,String> paramsMap, GenericResourceApiVnfNetworkData vnfNetwork, String vnfNetworkKey) {
266 String vnfNetworkString = convertToString(vnfNetwork);
267 Optional<String> ipv4Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv4' && @.dhcp-enabled == 'Y')].subnet-id");
268 if(ipv4Ips.isPresent())
269 addPairToMap(paramsMap, vnfNetworkKey, SUBNET_ID, ipv4Ips.get());
271 Optional<String> ipv6Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv6' && @.dhcp-enabled == 'Y')].subnet-id");
272 if(ipv6Ips.isPresent())
273 addPairToMap(paramsMap, vnfNetworkKey, V6_SUBNET_ID, ipv6Ips.get());
276 private void buildParamsMapFromVfModuleSdncResponse(Map<String,String> paramsMap, GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology, boolean skipVfModuleAssignments) throws JsonParseException, JsonMappingException, IOException {
277 // Get VF Module parameters from SDNC response
278 GenericResourceApiParam vfModuleParametersData = vfModuleTopology.getVfModuleParameters();
279 buildParamsMapFromSdncParams(paramsMap, vfModuleParametersData);
281 if(!skipVfModuleAssignments) {
282 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments = vfModuleTopology.getVfModuleAssignments();
283 if (vfModuleAssignments != null) {
285 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
287 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
288 if (vmsList != null) {
289 for (GenericResourceApiVmTopologyData vm : vmsList){
290 String key = vm.getVmType();
291 buildVfModuleVmNames(paramsMap, vm, key);
292 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
293 if (vmNetworks != null) {
294 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
295 if (vmNetworksList != null) {
296 for(int n = 0; n < vmNetworksList.size(); n++){
297 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
298 network.getNetworkRoleTag();
299 String networkKey = network.getNetworkRole();
301 buildVfModuleFloatingIps(paramsMap, network, key, networkKey);
302 // Interface Route Prefixes
303 buildVfModuleInterfaceRoutePrefixes(paramsMap, network, key, networkKey);
305 buildVfModuleSriovParameters(paramsMap, network, networkKey);
306 // IPV4 and IPV6 Addresses
307 buildVfModuleNetworkInformation(paramsMap, network, key, networkKey);
309 buildVlanInformation(paramsMap, network, key, networkKey);
315 buildParamsMapFromVfModuleForHeatTemplate(paramsMap, vm);
323 protected void buildVlanInformation(Map<String, String> paramsMap,
324 GenericResourceApiVmNetworkData network, String key, String networkKey) {
326 String networkString = convertToString(network);
327 String vlanFilterKey = key + UNDERSCORE + networkKey + UNDERSCORE + "vlan_filter";
328 String privateVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "private_vlans";
329 String publicVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "public_vlans";
330 String guestVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "guest_vlans";
332 if (network.getSegmentationId() != null) {
333 paramsMap.put(vlanFilterKey, network.getSegmentationId());
336 List<String> privateVlans = jsonPath.locateResultList(networkString, "$.related-networks.related-network[?(@.vlan-tags.is-private == true)].vlan-tags.upper-tag-id");
337 List<String> publicVlans = jsonPath.locateResultList(networkString, "$.related-networks.related-network[?(@.vlan-tags.is-private == false)].vlan-tags.upper-tag-id");
338 List<String> concat = new ArrayList<>(privateVlans);
339 concat.addAll(publicVlans);
340 Collection<String> guestVlans = new HashSet<>(concat);
342 if (!privateVlans.isEmpty()) {
343 paramsMap.put(privateVlansKey, Joiner.on(",").join(privateVlans));
345 if (!publicVlans.isEmpty()) {
346 paramsMap.put(publicVlansKey, Joiner.on(",").join(publicVlans));
348 if (!guestVlans.isEmpty()) {
349 paramsMap.put(guestVlansKey, Joiner.on(",").join(guestVlans));
353 private void buildVfModuleVmNames(Map<String,String> paramsMap, GenericResourceApiVmTopologyData vm, String key) {
355 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
356 if (vmNames != null) {
357 List<String> valueList = vmNames.getVmName();
358 if (valueList != null) {
359 for(int i = 0; i < valueList.size(); i++){
360 String value = valueList.get(i);
361 if (i != valueList.size() - 1) {
362 values += value + ",";
367 paramsMap.put(key + "_name_" + i, value);
369 paramsMap.put(key + "_names", values);
374 private void buildVfModuleFloatingIps(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
375 GenericResourceApiVmnetworkdataFloatingIps floatingIps = network.getFloatingIps();
376 if (floatingIps != null) {
377 List<String> floatingIpV4List = floatingIps.getFloatingIpV4();
378 if (floatingIpV4List != null) {
379 // add only one ipv4 floating ip for now
380 String floatingIPKey = key + UNDERSCORE + networkKey + FLOATING_IP;
381 String floatingIPKeyValue = floatingIpV4List.get(0);
382 if (floatingIPKeyValue != null && !floatingIPKeyValue.isEmpty()) {
383 paramsMap.put(floatingIPKey, floatingIPKeyValue);
386 // add only one ipv6 floating ip for now
387 List<String> floatingIpV6List = floatingIps.getFloatingIpV6();
388 if (floatingIpV6List != null) {
389 String floatingIPV6Key = key + UNDERSCORE + networkKey + FLOATING_V6_IP;
390 String floatingIPV6KeyValue = floatingIpV6List.get(0);
391 if (floatingIPV6KeyValue != null && !floatingIPV6KeyValue.isEmpty()) {
392 paramsMap.put(floatingIPV6Key, floatingIPV6KeyValue);
398 private void buildVfModuleInterfaceRoutePrefixes(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
399 GenericResourceApiVmnetworkdataInterfaceRoutePrefixes interfaceRoutePrefixes = network.getInterfaceRoutePrefixes();
400 if (interfaceRoutePrefixes != null) {
401 List<String> interfaceRoutePrefixesList = interfaceRoutePrefixes.getInterfaceRoutePrefix();
402 StringBuilder sbInterfaceRoutePrefixes = new StringBuilder();
403 sbInterfaceRoutePrefixes.append("[");
404 if (interfaceRoutePrefixesList != null) {
405 for(int a = 0; a < interfaceRoutePrefixesList.size(); a++){
406 String interfaceRoutePrefixValue = interfaceRoutePrefixesList.get(a);
407 if (a != interfaceRoutePrefixesList.size() - 1) {
408 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}" + ",");
411 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}");
414 sbInterfaceRoutePrefixes.append("]");
415 if (interfaceRoutePrefixesList.size() > 0) {
416 paramsMap.put(key + UNDERSCORE + networkKey + "_route_prefixes", sbInterfaceRoutePrefixes.toString());
422 private void buildVfModuleSriovParameters(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String networkKey) {
424 GenericResourceApiVmnetworkdataSriovParameters sriovParameters = network.getSriovParameters();
425 if (sriovParameters != null) {
426 GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters heatVlanFilters = sriovParameters.getHeatVlanFilters();
427 if (heatVlanFilters != null) {
428 List<String> heatVlanFiltersList = heatVlanFilters.getHeatVlanFilter();
429 StringBuilder sriovFilterBuf = new StringBuilder();
430 if (heatVlanFiltersList != null) {
431 for(int a = 0; a < heatVlanFiltersList.size(); a++){
432 String heatVlanFilterValue = heatVlanFiltersList.get(a);
433 if (a != heatVlanFiltersList.size() - 1) {
434 sriovFilterBuf.append(heatVlanFilterValue).append(",");
437 sriovFilterBuf.append(heatVlanFilterValue);
440 if (heatVlanFiltersList.size() > 0) {
441 paramsMap.put(networkKey + "_ATT_VF_VLAN_FILTER", sriovFilterBuf.toString());
449 private void buildVfModuleNetworkInformation(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
451 GenericResourceApiVmnetworkdataNetworkInformationItems networkInformationItems = network.getNetworkInformationItems();
452 StringBuilder sbIpv4Ips = new StringBuilder();
453 StringBuilder sbIpv6Ips = new StringBuilder();
455 if (networkInformationItems != null) {
456 List<GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem> networkInformationItemList = networkInformationItems.getNetworkInformationItem();
457 if (networkInformationItemList != null) {
458 for(int a = 0; a < networkInformationItemList.size(); a++){
459 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem ipAddress = networkInformationItemList.get(a);
460 if (ipAddress != null) {
461 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps ips = ipAddress.getNetworkIps();
463 List<String> ipsList = ips.getNetworkIp();
464 if (ipsList != null) {
465 String ipVersion = ipAddress.getIpVersion();
466 for (int b = 0; b < ipsList.size(); b++) {
467 String ipAddressValue = ipsList.get(b);
468 if (ipVersion.equals("ipv4")) {
469 if (b != ipsList.size() - 1) {
470 sbIpv4Ips.append(ipAddressValue + ",");
473 sbIpv4Ips.append(ipAddressValue);
475 paramsMap.put(key + UNDERSCORE + networkKey + IP + UNDERSCORE + b, ipAddressValue);
477 else if (ipVersion.equals("ipv6")) {
478 if (b != ipsList.size() - 1) {
479 sbIpv6Ips.append(ipAddressValue + ",");
482 sbIpv6Ips.append(ipAddressValue);
484 paramsMap.put(key + UNDERSCORE + networkKey + V6_IP + UNDERSCORE + b, ipAddressValue);
487 paramsMap.put(key + UNDERSCORE + networkKey + "_ips", sbIpv4Ips.toString());
488 paramsMap.put(key + UNDERSCORE + networkKey + "_v6_ips", sbIpv6Ips.toString());
498 * Build Mapping from GenericResourceApi SDNC for Heat Template so that AIC - PO gets accurate requests for vf module assignments.
499 * Build Count of SubInterfaces, VLAN Tag, network_name, network_id,
500 * ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6) for Heat Template
502 private void buildParamsMapFromVfModuleForHeatTemplate(Map<String,String> paramsMap, GenericResourceApiVmTopologyData vm) {
503 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
505 if (vmNames != null) {
507 List<GenericResourceApiVmtopologydataVmnamesVnfcNames> vnfcNamesList = vmNames.getVnfcNames();
508 if (vnfcNamesList != null) {
510 for(int i = 0; i < vnfcNamesList.size(); i++){
512 GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames = vnfcNamesList.get(i);
513 parseVnfcNamesData(paramsMap, vnfcNames);
520 * Parse vnfcNames data to build Mapping from GenericResourceApi SDNC for Heat Template.
522 private void parseVnfcNamesData(Map<String,String> paramsMap, GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames) {
524 if (vnfcNames != null) {
525 GenericResourceApiVnfcNetworkData vnfcNetworks = vnfcNames.getVnfcNetworks();
526 if (vnfcNetworks != null) {
527 List<GenericResourceApiVnfcnetworkdataVnfcNetworkData> vnfcNetworkdataList = vnfcNetworks.getVnfcNetworkData();
529 if (vnfcNetworkdataList != null) {
531 for(int networkDataIdx = 0; networkDataIdx < vnfcNetworkdataList.size(); networkDataIdx++){
533 GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata = vnfcNetworkdataList.get(networkDataIdx);
534 parseVnfcNetworkData(paramsMap, vnfcNetworkdata, networkDataIdx);
542 * Parse VnfcNetworkData to build Mapping from GenericResourceApi SDNC for Heat Template.
543 * Build Count of SubInterfaces, VLAN Tag, network_name, network_id,
544 * ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6) for Heat Template
546 private void parseVnfcNetworkData(Map<String,String> paramsMap, GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata, int networkDataIdx) {
548 String vmTypeKey = vnfcNetworkdata.getVnfcType();
549 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts vnfcPorts = vnfcNetworkdata.getVnfcPorts();
550 if (vnfcPorts != null) {
551 List<GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort> vnfcPortList = vnfcPorts.getVnfcPort();
552 if (vnfcPortList != null) {
553 for(int portIdx = 0; portIdx < vnfcPortList.size(); portIdx++){
555 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort vnfcPort = vnfcPortList.get(portIdx);
556 GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces = vnfcPort.getVnicSubInterfaces();
558 String vnicSubInterfacesString = convertToString(vnicSubInterfaces);
559 String networkRoleKey = vnfcPort.getCommonSubInterfaceRole();
560 String subInterfaceKey = createVnfcSubInterfaceKey(vmTypeKey, networkDataIdx, networkRoleKey, portIdx);
561 String globalSubInterfaceKey = createGlobalVnfcSubInterfaceKey(vmTypeKey, networkRoleKey, portIdx);
563 buildVfModuleSubInterfacesCount(paramsMap, globalSubInterfaceKey, vnicSubInterfaces);
565 buildVfModuleVlanTag(paramsMap, subInterfaceKey, vnicSubInterfacesString);
567 buildVfModuleNetworkName(paramsMap, subInterfaceKey, vnicSubInterfacesString);
569 buildVfModuleNetworkId(paramsMap, subInterfaceKey, vnicSubInterfacesString);
571 buildVfModuleIpV4AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
573 buildVfModuleIpV6AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
575 buildVfModuleFloatingIpV4HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
577 buildVfModuleFloatingIpV6HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
584 * Build "count" (calculating the total number of sub-interfaces) for Heat Template
585 * Building Criteria : {vm-type}_subint_{network-role}_port_{index}_subintcount
586 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
587 * Example: fw_subint_ctrl_port_0_subintcount
590 private void buildVfModuleSubInterfacesCount(Map<String,String> paramsMap, String keyPrefix, GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces) {
592 List<GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData> subInterfaceNetworkDataList = vnicSubInterfaces.getSubInterfaceNetworkData();
594 if ( (subInterfaceNetworkDataList != null) && !subInterfaceNetworkDataList.isEmpty() ) {
595 addPairToMap(paramsMap, keyPrefix, SUB_INT_COUNT, String.valueOf(subInterfaceNetworkDataList.size()));
599 protected String createVnfcSubInterfaceKey(String vmTypeKey, int networkDataIdx, String networkRoleKey, int portIdx) {
601 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, networkDataIdx, SUB_INT, networkRoleKey, PORT, portIdx));
604 protected String createGlobalVnfcSubInterfaceKey(String vmTypeKey,String networkRoleKey, int portIdx) {
606 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, SUB_INT, networkRoleKey, PORT, portIdx));
610 * Build VLAN Tag for Heat Template
611 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_vlan_ids
612 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
613 * Example: fw_0_subint_ctrl_port_0_vlan_ids
616 protected void buildVfModuleVlanTag(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
618 List<String> vlanTagIds = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].vlan-tag-id");
620 addPairToMap(paramsMap, keyPrefix, VLAN_IDS, vlanTagIds);
623 * Build "network_name" for Heat Template
624 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_net_names
625 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
626 * Example: fw_0_subint_ctrl_port_0_net_names
629 protected void buildVfModuleNetworkName(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
631 List<String> neworkNames = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-name");
633 addPairToMap(paramsMap, keyPrefix, NET_NAMES, neworkNames);
637 * Build "network_id" for Heat Template
638 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_net_ids
639 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
640 * Example: fw_0_subint_ctrl_port_0_net_ids
643 protected void buildVfModuleNetworkId(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
645 List<String> neworkIds = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-id");
647 addPairToMap(paramsMap, keyPrefix, NET_IDS, neworkIds);
651 * Build ip_address for V4 for Heat Template
652 * Building Criteria :
653 * {vm-type}_{index}_subint_{network-role}_port_{index}_ip_{index} -- for ipV4
654 * key = vm-type, networkRoleKey = NetWork-Role
656 protected void buildVfModuleIpV4AddressHeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
658 List<String> ipv4Ips = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv4')].network-ips.network-ip[*]");
660 addPairToMap(paramsMap, keyPrefix, IP, ipv4Ips);
662 for (int i = 0; i < ipv4Ips.size(); i++) {
663 addPairToMap(paramsMap, keyPrefix, IP + UNDERSCORE + i, ipv4Ips.get(i));
669 * Build ip_address for Heat Template
670 * Building Criteria :
671 * {vm-type}_{index}_subint_{network-role}_port_{index}_v6_ip_{index} -- for ipV6
672 * key = vm-type, networkRoleKey = NetWork-Role
674 protected void buildVfModuleIpV6AddressHeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
676 List<String> ipv6Ips = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv6')].network-ips.network-ip[*]");
678 addPairToMap(paramsMap, keyPrefix, V6_IP, ipv6Ips);
680 for (int i = 0; i < ipv6Ips.size(); i++) {
681 addPairToMap(paramsMap, keyPrefix, V6_IP + UNDERSCORE + i, ipv6Ips.get(i));
686 * Build floatingip_address for Heat Template
687 * Building Criteria :
688 * {vm-type}_subint_{network-role}_port_{index}_floating_ip -- for ipV4
690 protected void buildVfModuleFloatingIpV4HeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
692 List<String> floatingV4 = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].floating-ips.floating-ip-v4[*]");
694 if (!floatingV4.isEmpty()) {
695 floatingV4 = Collections.singletonList(floatingV4.get(0));
697 addPairToMap(paramsMap, keyPrefix, FLOATING_IP, floatingV4);
702 * Build floatingip_address for Heat Template
703 * Building Criteria :
704 * {vm-type}_subint_{network-role}_port_{index}_floating_v6_ip -- for ipV6
706 protected void buildVfModuleFloatingIpV6HeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
708 List<String> floatingV6 = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].floating-ips.floating-ip-v6[*]");
710 if (!floatingV6.isEmpty()) {
711 floatingV6 = Collections.singletonList(floatingV6.get(0));
713 addPairToMap(paramsMap, keyPrefix, FLOATING_V6_IP, floatingV6);
716 protected void addPairToMap(Map<String, String> paramsMap, String keyPrefix, String key, String value) {
718 addPairToMap(paramsMap, keyPrefix, key, Collections.singletonList(value));
721 protected void addPairToMap(Map<String, String> paramsMap, String keyPrefix, String key, List<String> value) {
723 if (!value.isEmpty()) {
724 paramsMap.put(keyPrefix + key, Joiner.on(",").join(value));
728 private void buildParamsMapFromSdncParams(Map<String,String> paramsMap, GenericResourceApiParam parametersData) {
729 if (parametersData != null) {
730 List<GenericResourceApiParamParam> paramsList = parametersData.getParam();
731 if (paramsList != null) {
732 for (int i = 0; i < paramsList.size(); i++) {
733 GenericResourceApiParamParam param = paramsList.get(i);
734 String parameterName = param.getName();
735 if (!sdncResponseParamsToSkip.contains(parameterName)) {
736 String parameterValue = param.getValue();
737 paramsMap.put(parameterName, parameterValue);
744 private Map<String,String> buildNetworkRoleMap(GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology) throws JsonParseException, JsonMappingException, IOException {
745 Map<String, String> networkRoleMap = new HashMap<>();
746 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments = vfModuleTopology.getVfModuleAssignments();
747 if (vfModuleAssignments != null) {
748 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
750 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
751 if (vmsList != null) {
752 for (GenericResourceApiVmTopologyData vm : vmsList){
753 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
754 if (vmNetworks != null) {
755 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
756 if (vmNetworksList != null) {
757 for(int n = 0; n < vmNetworksList.size(); n++){
758 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
759 String networkRole = network.getNetworkRole();
760 String networkRoleValue = network.getNetworkRoleTag();
761 if (networkRoleValue == null || networkRoleValue.isEmpty()) {
762 networkRoleValue = networkRole;
764 networkRoleMap.put(networkRole, networkRoleValue);
772 return networkRoleMap;
775 public DeleteVfModuleRequest deleteVfModuleRequestMapper(RequestContext requestContext,CloudRegion cloudRegion,
776 ServiceInstance serviceInstance, GenericVnf genericVnf,
777 VfModule vfModule) throws IOException {
778 DeleteVfModuleRequest deleteVfModuleRequest = new DeleteVfModuleRequest();
779 deleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
780 deleteVfModuleRequest.setTenantId(cloudRegion.getTenantId());
781 deleteVfModuleRequest.setVnfId(genericVnf.getVnfId());
782 deleteVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
783 deleteVfModuleRequest.setVfModuleStackId(vfModule.getHeatStackId());//DoDVfMod_heatStackId
784 deleteVfModuleRequest.setSkipAAI(true);
785 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
786 deleteVfModuleRequest.setMessageId(messageId);
787 deleteVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
788 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
789 deleteVfModuleRequest.setMsoRequest(msoRequest);
790 return deleteVfModuleRequest;
793 private String convertToString(Object obj) {
796 json = mapper.writeValueAsString(obj);
797 } catch (JsonProcessingException e) {
804 private VfModule getBaseVfModule(GenericVnf genericVnf) {
805 List<VfModule> vfModules = genericVnf.getVfModules();
806 VfModule baseVfModule = null;
807 if (vfModules != null) {
808 for(int i = 0; i < vfModules.size(); i++) {
809 if (vfModules.get(i).getModelInfoVfModule().getIsBaseBoolean()) {
810 baseVfModule = vfModules.get(i);