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.Arrays;
27 import java.util.Collections;
28 import java.util.HashMap;
29 import java.util.List;
31 import java.util.Optional;
33 import javax.annotation.PostConstruct;
35 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
36 import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
37 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubInterfaceNetworkData;
38 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData;
39 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfModuleAssignments;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms;
41 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
42 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmNetworkData;
43 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmTopologyData;
44 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataFloatingIps;
45 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataInterfaceRoutePrefixes;
46 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkInformationItems;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovParameters;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters;
51 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNames;
52 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNetworks;
53 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmnamesVnfcNames;
54 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfNetworkData;
55 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcNetworkData;
56 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcNetworkData;
57 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts;
58 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort;
59 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfResourceAssignments;
60 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones;
61 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks;
62 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyVnfTopology;
63 import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
64 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
65 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
66 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
67 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
68 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
69 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
70 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
71 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
72 import org.onap.so.entity.MsoRequest;
73 import org.onap.so.jsonpath.JsonPathUtil;
74 import org.springframework.beans.factory.annotation.Autowired;
75 import org.springframework.stereotype.Component;
77 import com.fasterxml.jackson.core.JsonParseException;
78 import com.fasterxml.jackson.core.JsonProcessingException;
79 import com.fasterxml.jackson.databind.DeserializationFeature;
80 import com.fasterxml.jackson.databind.JsonMappingException;
81 import com.fasterxml.jackson.databind.ObjectMapper;
83 import jersey.repackaged.com.google.common.base.Joiner;
86 public class VnfAdapterVfModuleObjectMapper {
88 protected VnfAdapterObjectMapperUtils vnfAdapterObjectMapperUtils;
89 private static List<String> sdncResponseParamsToSkip = asList("vnf_id", "vf_module_id", "vnf_name", "vf_module_name");
91 private ObjectMapper mapper = new ObjectMapper();
92 private static final JsonPathUtil jsonPath = JsonPathUtil.getInstance();
93 private static final String SUB_INT = "subint";
94 private static final String SUBNET_ID = "_subnet_id";
95 private static final String V6_SUBNET_ID = "_v6_subnet_id";
96 private static final String PORT = "port";
97 private static final String SUB_INT_COUNT = "_subintcount";
98 private static final String VLAN_IDS = "_vlan_ids";
99 private static final String NET_NAMES = "_net_names";
100 private static final String NET_IDS = "_net_ids";
101 private static final String IP = "_ip";
102 private static final String V6_IP = "_v6_ip";
103 private static final String FLOATING_IP = "_floating_ip";
104 private static final String FLOATING_V6_IP = "_floating_v6_ip";
105 private static final String UNDERSCORE = "_";
108 public void init () {
109 mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
112 public CreateVfModuleRequest createVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion, OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
113 VfModule vfModule, VolumeGroup volumeGroup, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
114 CreateVfModuleRequest createVfModuleRequest = new CreateVfModuleRequest();
116 createVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
117 createVfModuleRequest.setTenantId(cloudRegion.getTenantId());
118 createVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
119 createVfModuleRequest.setVfModuleName(vfModule.getVfModuleName());
120 createVfModuleRequest.setVnfId(genericVnf.getVnfId());
121 createVfModuleRequest.setVnfType(genericVnf.getVnfType());
122 createVfModuleRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
123 createVfModuleRequest.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
124 createVfModuleRequest.setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
125 if (volumeGroup != null) {
126 createVfModuleRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId());
127 createVfModuleRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId());
129 VfModule baseVfModule = getBaseVfModule(genericVnf);
130 if (baseVfModule != null) {
131 createVfModuleRequest.setBaseVfModuleId(baseVfModule.getVfModuleId());
132 createVfModuleRequest.setBaseVfModuleStackId(baseVfModule.getHeatStackId());
134 createVfModuleRequest.setVfModuleParams(buildVfModuleParamsMap(requestContext, serviceInstance, genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse));
136 createVfModuleRequest.setSkipAAI(true);
137 createVfModuleRequest.setBackout(orchestrationContext.getIsRollbackEnabled());
138 createVfModuleRequest.setFailIfExists(true);
140 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
141 createVfModuleRequest.setMsoRequest(msoRequest);
143 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
144 createVfModuleRequest.setMessageId(messageId);
145 createVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
147 return createVfModuleRequest;
150 private MsoRequest buildMsoRequest(RequestContext requestContext,ServiceInstance serviceInstance) {
151 MsoRequest msoRequest = new MsoRequest();
152 msoRequest.setRequestId(requestContext.getMsoRequestId());
153 msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
157 private Map<String,String> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
158 VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
160 GenericResourceApiVnftopologyVnfTopology vnfTopology = mapper.readValue(sdncVnfQueryResponse, GenericResourceApiVnftopologyVnfTopology.class);
161 GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = mapper.readValue(sdncVfModuleQueryResponse, GenericResourceApiVfmoduletopologyVfModuleTopology.class);
162 Map<String,String> paramsMap = new HashMap<>();
164 if(vnfTopology.getSdncGeneratedCloudResources() && vfModuleTopology.getSdncGeneratedCloudResources()) {
165 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, true);
166 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, null, true);
169 Map<String,String> networkRoleMap = buildNetworkRoleMap(vfModuleTopology);
170 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, false);
171 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, networkRoleMap, false);
174 buildMandatoryParamsMap(paramsMap, serviceInstance, genericVnf, vfModule);
176 // Parameters received from the request should overwrite any parameters received from SDNC
178 if (requestContext.getUserParams() != null) {
179 paramsMap.putAll(requestContext.getUserParams());
184 private void buildMandatoryParamsMap(Map<String,String> paramsMap, ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule) {
185 paramsMap.put("vnf_id", genericVnf.getVnfId());
186 paramsMap.put("vnf_name", genericVnf.getVnfName());
187 paramsMap.put("vf_module_id", vfModule.getVfModuleId());
188 paramsMap.put("vf_module_name", vfModule.getVfModuleName());
189 paramsMap.put("environment_context",serviceInstance.getModelInfoServiceInstance().getEnvironmentContext());
190 paramsMap.putIfAbsent("environment_context", "");
191 paramsMap.put("workload_context", serviceInstance.getModelInfoServiceInstance().getWorkloadContext());
192 paramsMap.putIfAbsent("workload_context", "");
193 Integer vfModuleIndex = vfModule.getModuleIndex();
194 if (vfModuleIndex != null) {
195 paramsMap.put("vf_module_index", vfModuleIndex.toString());
199 private void buildParamsMapFromVnfSdncResponse(Map<String,String> paramsMap, GenericResourceApiVnftopologyVnfTopology vnfTopology, Map<String,String> networkRoleMap, boolean skipVnfResourceAssignments) throws JsonParseException, JsonMappingException, IOException {
200 // Get VNF parameters from SDNC response
201 GenericResourceApiParam vnfParametersData = vnfTopology.getVnfParametersData();
202 buildParamsMapFromSdncParams(paramsMap, vnfParametersData);
204 if(!skipVnfResourceAssignments) {
205 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments = vnfTopology.getVnfResourceAssignments();
206 if (vnfResourceAssignments != null) {
207 // Availability Zones
208 buildAvailabilityZones(paramsMap, vnfResourceAssignments);
210 buildVnfNetworks(paramsMap, vnfResourceAssignments, networkRoleMap);
215 private void buildAvailabilityZones (Map<String,String> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments) {
216 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones availabilityZones = vnfResourceAssignments.getAvailabilityZones();
217 if (availabilityZones != null) {
218 List<String> availabilityZonesList = availabilityZones.getAvailabilityZone();
219 if (availabilityZonesList != null) {
220 for(int i = 0; i < availabilityZonesList.size(); i++) {
221 paramsMap.put("availability_zone_" + i, availabilityZonesList.get(i));
227 private void buildVnfNetworks (Map<String,String> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments, Map<String,String> networkRoleMap) {
228 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworks = vnfResourceAssignments.getVnfNetworks();
229 if (vnfNetworks != null) {
230 List<GenericResourceApiVnfNetworkData> vnfNetworksList = vnfNetworks.getVnfNetwork();
231 if (vnfNetworksList != null) {
232 for (int i = 0; i < vnfNetworksList.size(); i++) {
233 GenericResourceApiVnfNetworkData vnfNetwork = vnfNetworksList.get(i);
234 String networkRole = vnfNetwork.getNetworkRole();
235 String vnfNetworkKey = networkRoleMap.get(networkRole);
236 if (vnfNetworkKey == null || vnfNetworkKey.isEmpty()) {
237 vnfNetworkKey = networkRole;
240 String vnfNetworkNeutronIdValue = vnfNetwork.getNeutronId();
241 paramsMap.put(vnfNetworkKey + "_net_id", vnfNetworkNeutronIdValue);
242 String vnfNetworkNetNameValue = vnfNetwork.getNetworkName();
243 paramsMap.put(vnfNetworkKey + "_net_name", vnfNetworkNetNameValue);
244 String vnfNetworkNetFqdnValue = vnfNetwork.getContrailNetworkFqdn();
245 paramsMap.put(vnfNetworkKey + "_net_fqdn", vnfNetworkNetFqdnValue);
247 buildVnfNetworkSubnets(paramsMap, vnfNetwork, vnfNetworkKey);
254 private void buildVnfNetworkSubnets(Map<String,String> paramsMap, GenericResourceApiVnfNetworkData vnfNetwork, String vnfNetworkKey) {
255 String vnfNetworkString = convertToString(vnfNetwork);
256 Optional<String> ipv4Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv4' && @.dhcp-enabled == 'Y')].subnet-id");
257 if(ipv4Ips.isPresent())
258 addPairToMap(paramsMap, vnfNetworkKey, SUBNET_ID, ipv4Ips.get());
260 Optional<String> ipv6Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv6' && @.dhcp-enabled == 'Y')].subnet-id");
261 if(ipv6Ips.isPresent())
262 addPairToMap(paramsMap, vnfNetworkKey, V6_SUBNET_ID, ipv6Ips.get());
265 private void buildParamsMapFromVfModuleSdncResponse(Map<String,String> paramsMap, GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology, boolean skipVfModuleAssignments) throws JsonParseException, JsonMappingException, IOException {
266 // Get VF Module parameters from SDNC response
267 GenericResourceApiParam vfModuleParametersData = vfModuleTopology.getVfModuleParameters();
268 buildParamsMapFromSdncParams(paramsMap, vfModuleParametersData);
270 if(!skipVfModuleAssignments) {
271 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments = vfModuleTopology.getVfModuleAssignments();
272 if (vfModuleAssignments != null) {
274 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
276 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
277 if (vmsList != null) {
278 for (GenericResourceApiVmTopologyData vm : vmsList){
279 String key = vm.getVmType();
280 buildVfModuleVmNames(paramsMap, vm, key);
281 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
282 if (vmNetworks != null) {
283 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
284 if (vmNetworksList != null) {
285 for(int n = 0; n < vmNetworksList.size(); n++){
286 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
287 network.getNetworkRoleTag();
288 String networkKey = network.getNetworkRole();
290 buildVfModuleFloatingIps(paramsMap, network, key, networkKey);
291 // Interface Route Prefixes
292 buildVfModuleInterfaceRoutePrefixes(paramsMap, network, key, networkKey);
294 buildVfModuleSriovParameters(paramsMap, network, networkKey);
295 // IPV4 and IPV6 Addresses
296 buildVfModuleNetworkInformation(paramsMap, network, key, networkKey);
301 buildParamsMapFromVfModuleForHeatTemplate(paramsMap, vm);
309 private void buildVfModuleVmNames(Map<String,String> paramsMap, GenericResourceApiVmTopologyData vm, String key) {
311 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
312 if (vmNames != null) {
313 List<String> valueList = vmNames.getVmName();
314 if (valueList != null) {
315 for(int i = 0; i < valueList.size(); i++){
316 String value = valueList.get(i);
317 if (i != valueList.size() - 1) {
318 values += value + ",";
323 paramsMap.put(key + "_name_" + i, value);
325 paramsMap.put(key + "_names", values);
330 private void buildVfModuleFloatingIps(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
331 GenericResourceApiVmnetworkdataFloatingIps floatingIps = network.getFloatingIps();
332 if (floatingIps != null) {
333 List<String> floatingIpV4List = floatingIps.getFloatingIpV4();
334 if (floatingIpV4List != null) {
335 // add only one ipv4 floating ip for now
336 String floatingIPKey = key + UNDERSCORE + networkKey + FLOATING_IP;
337 String floatingIPKeyValue = floatingIpV4List.get(0);
338 if (floatingIPKeyValue != null && !floatingIPKeyValue.isEmpty()) {
339 paramsMap.put(floatingIPKey, floatingIPKeyValue);
342 // add only one ipv6 floating ip for now
343 List<String> floatingIpV6List = floatingIps.getFloatingIpV6();
344 if (floatingIpV6List != null) {
345 String floatingIPV6Key = key + UNDERSCORE + networkKey + FLOATING_V6_IP;
346 String floatingIPV6KeyValue = floatingIpV6List.get(0);
347 if (floatingIPV6KeyValue != null && !floatingIPV6KeyValue.isEmpty()) {
348 paramsMap.put(floatingIPV6Key, floatingIPV6KeyValue);
354 private void buildVfModuleInterfaceRoutePrefixes(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
355 GenericResourceApiVmnetworkdataInterfaceRoutePrefixes interfaceRoutePrefixes = network.getInterfaceRoutePrefixes();
356 if (interfaceRoutePrefixes != null) {
357 List<String> interfaceRoutePrefixesList = interfaceRoutePrefixes.getInterfaceRoutePrefix();
358 StringBuilder sbInterfaceRoutePrefixes = new StringBuilder();
359 sbInterfaceRoutePrefixes.append("[");
360 if (interfaceRoutePrefixesList != null) {
361 for(int a = 0; a < interfaceRoutePrefixesList.size(); a++){
362 String interfaceRoutePrefixValue = interfaceRoutePrefixesList.get(a);
363 if (a != interfaceRoutePrefixesList.size() - 1) {
364 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}" + ",");
367 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}");
370 sbInterfaceRoutePrefixes.append("]");
371 if (interfaceRoutePrefixesList.size() > 0) {
372 paramsMap.put(key + UNDERSCORE + networkKey + "_route_prefixes", sbInterfaceRoutePrefixes.toString());
378 private void buildVfModuleSriovParameters(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String networkKey) {
380 GenericResourceApiVmnetworkdataSriovParameters sriovParameters = network.getSriovParameters();
381 if (sriovParameters != null) {
382 GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters heatVlanFilters = sriovParameters.getHeatVlanFilters();
383 if (heatVlanFilters != null) {
384 List<String> heatVlanFiltersList = heatVlanFilters.getHeatVlanFilter();
385 StringBuilder sriovFilterBuf = new StringBuilder();
386 if (heatVlanFiltersList != null) {
387 for(int a = 0; a < heatVlanFiltersList.size(); a++){
388 String heatVlanFilterValue = heatVlanFiltersList.get(a);
389 if (a != heatVlanFiltersList.size() - 1) {
390 sriovFilterBuf.append(heatVlanFilterValue).append(",");
393 sriovFilterBuf.append(heatVlanFilterValue);
396 if (heatVlanFiltersList.size() > 0) {
397 paramsMap.put(networkKey + "_ATT_VF_VLAN_FILTER", sriovFilterBuf.toString());
405 private void buildVfModuleNetworkInformation(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
407 GenericResourceApiVmnetworkdataNetworkInformationItems networkInformationItems = network.getNetworkInformationItems();
408 StringBuilder sbIpv4Ips = new StringBuilder();
409 StringBuilder sbIpv6Ips = new StringBuilder();
411 if (networkInformationItems != null) {
412 List<GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem> networkInformationItemList = networkInformationItems.getNetworkInformationItem();
413 if (networkInformationItemList != null) {
414 for(int a = 0; a < networkInformationItemList.size(); a++){
415 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem ipAddress = networkInformationItemList.get(a);
416 if (ipAddress != null) {
417 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps ips = ipAddress.getNetworkIps();
419 List<String> ipsList = ips.getNetworkIp();
420 if (ipsList != null) {
421 String ipVersion = ipAddress.getIpVersion();
422 for (int b = 0; b < ipsList.size(); b++) {
423 String ipAddressValue = ipsList.get(b);
424 if (ipVersion.equals("ipv4")) {
425 if (b != ipsList.size() - 1) {
426 sbIpv4Ips.append(ipAddressValue + ",");
429 sbIpv4Ips.append(ipAddressValue);
431 paramsMap.put(key + UNDERSCORE + networkKey + IP + UNDERSCORE + b, ipAddressValue);
433 else if (ipVersion.equals("ipv6")) {
434 if (b != ipsList.size() - 1) {
435 sbIpv6Ips.append(ipAddressValue + ",");
438 sbIpv6Ips.append(ipAddressValue);
440 paramsMap.put(key + UNDERSCORE + networkKey + V6_IP + UNDERSCORE + b, ipAddressValue);
443 paramsMap.put(key + UNDERSCORE + networkKey + "_ips", sbIpv4Ips.toString());
444 paramsMap.put(key + UNDERSCORE + networkKey + "_v6_ips", sbIpv6Ips.toString());
454 * Build Mapping from GenericResourceApi SDNC for Heat Template so that AIC - PO gets accurate requests for vf module assignments.
455 * Build Count of SubInterfaces, VLAN Tag, network_name, network_id,
456 * ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6) for Heat Template
458 private void buildParamsMapFromVfModuleForHeatTemplate(Map<String,String> paramsMap, GenericResourceApiVmTopologyData vm) {
459 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
461 if (vmNames != null) {
463 List<GenericResourceApiVmtopologydataVmnamesVnfcNames> vnfcNamesList = vmNames.getVnfcNames();
464 if (vnfcNamesList != null) {
466 for(int i = 0; i < vnfcNamesList.size(); i++){
468 GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames = vnfcNamesList.get(i);
469 parseVnfcNamesData(paramsMap, vnfcNames);
476 * Parse vnfcNames data to build Mapping from GenericResourceApi SDNC for Heat Template.
478 private void parseVnfcNamesData(Map<String,String> paramsMap, GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames) {
480 if (vnfcNames != null) {
481 GenericResourceApiVnfcNetworkData vnfcNetworks = vnfcNames.getVnfcNetworks();
482 if (vnfcNetworks != null) {
483 List<GenericResourceApiVnfcnetworkdataVnfcNetworkData> vnfcNetworkdataList = vnfcNetworks.getVnfcNetworkData();
485 if (vnfcNetworkdataList != null) {
487 for(int networkDataIdx = 0; networkDataIdx < vnfcNetworkdataList.size(); networkDataIdx++){
489 GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata = vnfcNetworkdataList.get(networkDataIdx);
490 parseVnfcNetworkData(paramsMap, vnfcNetworkdata, networkDataIdx);
498 * Parse VnfcNetworkData to build Mapping from GenericResourceApi SDNC for Heat Template.
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 parseVnfcNetworkData(Map<String,String> paramsMap, GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata, int networkDataIdx) {
504 String vmTypeKey = vnfcNetworkdata.getVnfcType();
505 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts vnfcPorts = vnfcNetworkdata.getVnfcPorts();
506 List<GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort> vnfcPortList = vnfcPorts.getVnfcPort();
507 if (vnfcPortList != null) {
508 for(int portIdx = 0; portIdx < vnfcPortList.size(); portIdx++){
510 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort vnfcPort = vnfcPortList.get(portIdx);
511 GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces = vnfcPort.getVnicSubInterfaces();
513 String vnicSubInterfacesString = convertToString(vnicSubInterfaces);
514 String networkRoleKey = vnfcPort.getCommonSubInterfaceRole();
515 String subInterfaceKey = createVnfcSubInterfaceKey(vmTypeKey, networkDataIdx, networkRoleKey, portIdx);
516 String globalSubInterfaceKey = createGlobalVnfcSubInterfaceKey(vmTypeKey, networkRoleKey, portIdx);
518 buildVfModuleSubInterfacesCount(paramsMap, globalSubInterfaceKey, vnicSubInterfaces);
520 buildVfModuleVlanTag(paramsMap, subInterfaceKey, vnicSubInterfacesString);
522 buildVfModuleNetworkName(paramsMap, subInterfaceKey, vnicSubInterfacesString);
524 buildVfModuleNetworkId(paramsMap, subInterfaceKey, vnicSubInterfacesString);
526 buildVfModuleIpV4AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
528 buildVfModuleIpV6AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
530 buildVfModuleFloatingIpV4HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
532 buildVfModuleFloatingIpV6HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
538 * Build "count" (calculating the total number of sub-interfaces) for Heat Template
539 * Building Criteria : {vm-type}_subint_{network-role}_port_{index}_subintcount
540 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
541 * Example: fw_subint_ctrl_port_0_subintcount
544 private void buildVfModuleSubInterfacesCount(Map<String,String> paramsMap, String keyPrefix, GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces) {
546 List<GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData> subInterfaceNetworkDataList = vnicSubInterfaces.getSubInterfaceNetworkData();
548 if ( (subInterfaceNetworkDataList != null) && !subInterfaceNetworkDataList.isEmpty() ) {
549 addPairToMap(paramsMap, keyPrefix, SUB_INT_COUNT, String.valueOf(subInterfaceNetworkDataList.size()));
553 protected String createVnfcSubInterfaceKey(String vmTypeKey, int networkDataIdx, String networkRoleKey, int portIdx) {
555 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, networkDataIdx, SUB_INT, networkRoleKey, PORT, portIdx));
558 protected String createGlobalVnfcSubInterfaceKey(String vmTypeKey,String networkRoleKey, int portIdx) {
560 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, SUB_INT, networkRoleKey, PORT, portIdx));
564 * Build VLAN Tag for Heat Template
565 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_vlan_ids
566 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
567 * Example: fw_0_subint_ctrl_port_0_vlan_ids
570 protected void buildVfModuleVlanTag(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
572 List<String> vlanTagIds = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].vlan-tag-id");
574 addPairToMap(paramsMap, keyPrefix, VLAN_IDS, vlanTagIds);
577 * Build "network_name" for Heat Template
578 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_net_names
579 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
580 * Example: fw_0_subint_ctrl_port_0_net_names
583 protected void buildVfModuleNetworkName(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
585 List<String> neworkNames = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-name");
587 addPairToMap(paramsMap, keyPrefix, NET_NAMES, neworkNames);
591 * Build "network_id" for Heat Template
592 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_net_ids
593 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
594 * Example: fw_0_subint_ctrl_port_0_net_ids
597 protected void buildVfModuleNetworkId(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
599 List<String> neworkIds = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-id");
601 addPairToMap(paramsMap, keyPrefix, NET_IDS, neworkIds);
605 * Build ip_address for V4 for Heat Template
606 * Building Criteria :
607 * {vm-type}_{index}_subint_{network-role}_port_{index}_ip_{index} -- for ipV4
608 * key = vm-type, networkRoleKey = NetWork-Role
610 protected void buildVfModuleIpV4AddressHeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
612 List<String> ipv4Ips = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv4')].network-ips.network-ip[*]");
614 addPairToMap(paramsMap, keyPrefix, IP, ipv4Ips);
616 for (int i = 0; i < ipv4Ips.size(); i++) {
617 addPairToMap(paramsMap, keyPrefix, IP + UNDERSCORE + i, ipv4Ips.get(i));
623 * Build ip_address for Heat Template
624 * Building Criteria :
625 * {vm-type}_{index}_subint_{network-role}_port_{index}_v6_ip_{index} -- for ipV6
626 * key = vm-type, networkRoleKey = NetWork-Role
628 protected void buildVfModuleIpV6AddressHeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
630 List<String> ipv6Ips = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv6')].network-ips.network-ip[*]");
632 addPairToMap(paramsMap, keyPrefix, V6_IP, ipv6Ips);
634 for (int i = 0; i < ipv6Ips.size(); i++) {
635 addPairToMap(paramsMap, keyPrefix, V6_IP + UNDERSCORE + i, ipv6Ips.get(i));
640 * Build floatingip_address for Heat Template
641 * Building Criteria :
642 * {vm-type}_subint_{network-role}_port_{index}_floating_ip -- for ipV4
644 protected void buildVfModuleFloatingIpV4HeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
646 List<String> floatingV4 = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].floating-ips.floating-ip-v4[*]");
648 if (!floatingV4.isEmpty()) {
649 floatingV4 = Collections.singletonList(floatingV4.get(0));
651 addPairToMap(paramsMap, keyPrefix, FLOATING_IP, floatingV4);
656 * Build floatingip_address for Heat Template
657 * Building Criteria :
658 * {vm-type}_subint_{network-role}_port_{index}_floating_v6_ip -- for ipV6
660 protected void buildVfModuleFloatingIpV6HeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
662 List<String> floatingV6 = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].floating-ips.floating-ip-v6[*]");
664 if (!floatingV6.isEmpty()) {
665 floatingV6 = Collections.singletonList(floatingV6.get(0));
667 addPairToMap(paramsMap, keyPrefix, FLOATING_V6_IP, floatingV6);
670 protected void addPairToMap(Map<String, String> paramsMap, String keyPrefix, String key, String value) {
672 addPairToMap(paramsMap, keyPrefix, key, Collections.singletonList(value));
675 protected void addPairToMap(Map<String, String> paramsMap, String keyPrefix, String key, List<String> value) {
677 if (!value.isEmpty()) {
678 paramsMap.put(keyPrefix + key, Joiner.on(",").join(value));
682 private void buildParamsMapFromSdncParams(Map<String,String> paramsMap, GenericResourceApiParam parametersData) {
683 if (parametersData != null) {
684 List<GenericResourceApiParamParam> paramsList = parametersData.getParam();
685 if (paramsList != null) {
686 for (int i = 0; i < paramsList.size(); i++) {
687 GenericResourceApiParamParam param = paramsList.get(i);
688 String parameterName = param.getName();
689 if (!sdncResponseParamsToSkip.contains(parameterName)) {
690 String parameterValue = param.getValue();
691 paramsMap.put(parameterName, parameterValue);
698 private Map<String,String> buildNetworkRoleMap(GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology) throws JsonParseException, JsonMappingException, IOException {
699 Map<String, String> networkRoleMap = new HashMap<>();
700 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments = vfModuleTopology.getVfModuleAssignments();
701 if (vfModuleAssignments != null) {
702 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
704 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
705 if (vmsList != null) {
706 for (GenericResourceApiVmTopologyData vm : vmsList){
707 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
708 if (vmNetworks != null) {
709 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
710 if (vmNetworksList != null) {
711 for(int n = 0; n < vmNetworksList.size(); n++){
712 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
713 String networkRole = network.getNetworkRole();
714 String networkRoleValue = network.getNetworkRoleTag();
715 if (networkRoleValue == null || networkRoleValue.isEmpty()) {
716 networkRoleValue = networkRole;
718 networkRoleMap.put(networkRole, networkRoleValue);
726 return networkRoleMap;
729 public DeleteVfModuleRequest deleteVfModuleRequestMapper(RequestContext requestContext,CloudRegion cloudRegion,
730 ServiceInstance serviceInstance, GenericVnf genericVnf,
731 VfModule vfModule) throws IOException {
732 DeleteVfModuleRequest deleteVfModuleRequest = new DeleteVfModuleRequest();
733 deleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
734 deleteVfModuleRequest.setTenantId(cloudRegion.getTenantId());
735 deleteVfModuleRequest.setVnfId(genericVnf.getVnfId());
736 deleteVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
737 deleteVfModuleRequest.setVfModuleStackId(vfModule.getHeatStackId());//DoDVfMod_heatStackId
738 deleteVfModuleRequest.setSkipAAI(true);
739 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
740 deleteVfModuleRequest.setMessageId(messageId);
741 deleteVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
742 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
743 deleteVfModuleRequest.setMsoRequest(msoRequest);
744 return deleteVfModuleRequest;
747 private String convertToString(Object obj) {
750 json = mapper.writeValueAsString(obj);
751 } catch (JsonProcessingException e) {
758 private VfModule getBaseVfModule(GenericVnf genericVnf) {
759 List<VfModule> vfModules = genericVnf.getVfModules();
760 VfModule baseVfModule = null;
761 if (vfModules != null) {
762 for(int i = 0; i < vfModules.size(); i++) {
763 if (vfModules.get(i).getModelInfoVfModule().getIsBaseBoolean()) {
764 baseVfModule = vfModules.get(i);