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;
34 import javax.validation.Valid;
36 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
37 import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
38 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubInterfaceNetworkData;
39 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleTopology;
41 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfModuleAssignments;
42 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms;
43 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
44 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmNetworkData;
45 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmTopologyData;
46 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataFloatingIps;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataInterfaceRoutePrefixes;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkInformationItems;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps;
51 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovParameters;
52 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters;
53 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNames;
54 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNetworks;
55 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmnamesVnfcNames;
56 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfNetworkData;
57 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfTopology;
58 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcNetworkData;
59 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcNetworkData;
60 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts;
61 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort;
62 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfResourceAssignments;
63 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones;
64 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks;
65 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyVnfTopology;
66 import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
67 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
68 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
69 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
70 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
71 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
72 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
73 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
74 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
75 import org.onap.so.entity.MsoRequest;
76 import org.onap.so.jsonpath.JsonPathUtil;
77 import org.springframework.beans.factory.annotation.Autowired;
78 import org.springframework.stereotype.Component;
80 import com.fasterxml.jackson.core.JsonParseException;
81 import com.fasterxml.jackson.core.JsonProcessingException;
82 import com.fasterxml.jackson.databind.DeserializationFeature;
83 import com.fasterxml.jackson.databind.JsonMappingException;
84 import com.fasterxml.jackson.databind.ObjectMapper;
86 import jersey.repackaged.com.google.common.base.Joiner;
89 public class VnfAdapterVfModuleObjectMapper {
91 protected VnfAdapterObjectMapperUtils vnfAdapterObjectMapperUtils;
92 private static List<String> sdncResponseParamsToSkip = asList("vnf_id", "vf_module_id", "vnf_name", "vf_module_name");
94 private ObjectMapper mapper = new ObjectMapper();
95 private static final JsonPathUtil jsonPath = JsonPathUtil.getInstance();
96 private static final String SUB_INT = "subint";
97 private static final String SUBNET_ID = "_subnet_id";
98 private static final String V6_SUBNET_ID = "_v6_subnet_id";
99 private static final String PORT = "port";
100 private static final String SUB_INT_COUNT = "_subintcount";
101 private static final String VLAN_IDS = "_vlan_ids";
102 private static final String NET_NAMES = "_net_names";
103 private static final String NET_IDS = "_net_ids";
104 private static final String IP = "_ip";
105 private static final String V6_IP = "_v6_ip";
106 private static final String FLOATING_IP = "_floating_ip";
107 private static final String FLOATING_V6_IP = "_floating_v6_ip";
108 private static final String UNDERSCORE = "_";
111 public void init () {
112 mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
115 public CreateVfModuleRequest createVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion, OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
116 VfModule vfModule, VolumeGroup volumeGroup, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
117 CreateVfModuleRequest createVfModuleRequest = new CreateVfModuleRequest();
119 createVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
120 createVfModuleRequest.setTenantId(cloudRegion.getTenantId());
121 createVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
122 createVfModuleRequest.setVfModuleName(vfModule.getVfModuleName());
123 createVfModuleRequest.setVnfId(genericVnf.getVnfId());
124 createVfModuleRequest.setVnfType(genericVnf.getVnfType());
125 createVfModuleRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
126 createVfModuleRequest.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
127 createVfModuleRequest.setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
128 if (volumeGroup != null) {
129 createVfModuleRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId());
130 createVfModuleRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId());
132 VfModule baseVfModule = getBaseVfModule(genericVnf);
133 if (baseVfModule != null) {
134 createVfModuleRequest.setBaseVfModuleId(baseVfModule.getVfModuleId());
135 createVfModuleRequest.setBaseVfModuleStackId(baseVfModule.getHeatStackId());
137 createVfModuleRequest.setVfModuleParams(buildVfModuleParamsMap(requestContext, serviceInstance, genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse));
139 createVfModuleRequest.setSkipAAI(true);
140 createVfModuleRequest.setBackout(orchestrationContext.getIsRollbackEnabled());
141 createVfModuleRequest.setFailIfExists(true);
143 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
144 createVfModuleRequest.setMsoRequest(msoRequest);
146 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
147 createVfModuleRequest.setMessageId(messageId);
148 createVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
150 return createVfModuleRequest;
153 private MsoRequest buildMsoRequest(RequestContext requestContext,ServiceInstance serviceInstance) {
154 MsoRequest msoRequest = new MsoRequest();
155 msoRequest.setRequestId(requestContext.getMsoRequestId());
156 msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
160 private Map<String,String> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
161 VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
164 GenericResourceApiVnfTopology vnfTop= mapper.readValue(sdncVnfQueryResponse, GenericResourceApiVnfTopology.class);
165 GenericResourceApiVfModuleTopology vfModuleTop = mapper.readValue(sdncVfModuleQueryResponse, GenericResourceApiVfModuleTopology.class);
166 GenericResourceApiVnftopologyVnfTopology vnfTopology = vnfTop.getVnfTopology();
167 GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = vfModuleTop.getVfModuleTopology();
168 Map<String,String> paramsMap = new HashMap<>();
170 if( vfModuleTopology.getSdncGeneratedCloudResources()) {
171 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, true);
172 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, null, true);
175 Map<String,String> networkRoleMap = buildNetworkRoleMap(vfModuleTopology);
176 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, false);
177 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, networkRoleMap, false);
180 buildMandatoryParamsMap(paramsMap, serviceInstance, genericVnf, vfModule);
182 // Parameters received from the request should overwrite any parameters received from SDNC
184 if (requestContext.getUserParams() != null) {
185 paramsMap.putAll(requestContext.getUserParams());
187 if (vfModule.getCloudParams() != null) {
188 paramsMap.putAll(vfModule.getCloudParams());
193 private void buildMandatoryParamsMap(Map<String,String> paramsMap, ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule) {
194 paramsMap.put("vnf_id", genericVnf.getVnfId());
195 paramsMap.put("vnf_name", genericVnf.getVnfName());
196 paramsMap.put("vf_module_id", vfModule.getVfModuleId());
197 paramsMap.put("vf_module_name", vfModule.getVfModuleName());
198 paramsMap.put("environment_context",serviceInstance.getModelInfoServiceInstance().getEnvironmentContext());
199 paramsMap.putIfAbsent("environment_context", "");
200 paramsMap.put("workload_context", serviceInstance.getModelInfoServiceInstance().getWorkloadContext());
201 paramsMap.putIfAbsent("workload_context", "");
202 Integer vfModuleIndex = vfModule.getModuleIndex();
203 if (vfModuleIndex != null) {
204 paramsMap.put("vf_module_index", vfModuleIndex.toString());
208 private void buildParamsMapFromVnfSdncResponse(Map<String,String> paramsMap, GenericResourceApiVnftopologyVnfTopology vnfTopology, Map<String,String> networkRoleMap, boolean skipVnfResourceAssignments) throws JsonParseException, JsonMappingException, IOException {
209 // Get VNF parameters from SDNC response
210 GenericResourceApiParam vnfParametersData = vnfTopology.getVnfParametersData();
211 buildParamsMapFromSdncParams(paramsMap, vnfParametersData);
213 if(!skipVnfResourceAssignments) {
214 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments = vnfTopology.getVnfResourceAssignments();
215 if (vnfResourceAssignments != null) {
216 // Availability Zones
217 buildAvailabilityZones(paramsMap, vnfResourceAssignments);
219 buildVnfNetworks(paramsMap, vnfResourceAssignments, networkRoleMap);
224 private void buildAvailabilityZones (Map<String,String> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments) {
225 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones availabilityZones = vnfResourceAssignments.getAvailabilityZones();
226 if (availabilityZones != null) {
227 List<String> availabilityZonesList = availabilityZones.getAvailabilityZone();
228 if (availabilityZonesList != null) {
229 for(int i = 0; i < availabilityZonesList.size(); i++) {
230 paramsMap.put("availability_zone_" + i, availabilityZonesList.get(i));
236 private void buildVnfNetworks (Map<String,String> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments, Map<String,String> networkRoleMap) {
237 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworks = vnfResourceAssignments.getVnfNetworks();
238 if (vnfNetworks != null) {
239 List<GenericResourceApiVnfNetworkData> vnfNetworksList = vnfNetworks.getVnfNetwork();
240 if (vnfNetworksList != null) {
241 for (int i = 0; i < vnfNetworksList.size(); i++) {
242 GenericResourceApiVnfNetworkData vnfNetwork = vnfNetworksList.get(i);
243 String networkRole = vnfNetwork.getNetworkRole();
244 String vnfNetworkKey = networkRoleMap.get(networkRole);
245 if (vnfNetworkKey == null || vnfNetworkKey.isEmpty()) {
246 vnfNetworkKey = networkRole;
249 String vnfNetworkNeutronIdValue = vnfNetwork.getNeutronId();
250 paramsMap.put(vnfNetworkKey + "_net_id", vnfNetworkNeutronIdValue);
251 String vnfNetworkNetNameValue = vnfNetwork.getNetworkName();
252 paramsMap.put(vnfNetworkKey + "_net_name", vnfNetworkNetNameValue);
253 String vnfNetworkNetFqdnValue = vnfNetwork.getContrailNetworkFqdn();
254 paramsMap.put(vnfNetworkKey + "_net_fqdn", vnfNetworkNetFqdnValue);
256 buildVnfNetworkSubnets(paramsMap, vnfNetwork, vnfNetworkKey);
263 private void buildVnfNetworkSubnets(Map<String,String> paramsMap, GenericResourceApiVnfNetworkData vnfNetwork, String vnfNetworkKey) {
264 String vnfNetworkString = convertToString(vnfNetwork);
265 Optional<String> ipv4Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv4' && @.dhcp-enabled == 'Y')].subnet-id");
266 if(ipv4Ips.isPresent())
267 addPairToMap(paramsMap, vnfNetworkKey, SUBNET_ID, ipv4Ips.get());
269 Optional<String> ipv6Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv6' && @.dhcp-enabled == 'Y')].subnet-id");
270 if(ipv6Ips.isPresent())
271 addPairToMap(paramsMap, vnfNetworkKey, V6_SUBNET_ID, ipv6Ips.get());
274 private void buildParamsMapFromVfModuleSdncResponse(Map<String,String> paramsMap, GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology, boolean skipVfModuleAssignments) throws JsonParseException, JsonMappingException, IOException {
275 // Get VF Module parameters from SDNC response
276 GenericResourceApiParam vfModuleParametersData = vfModuleTopology.getVfModuleParameters();
277 buildParamsMapFromSdncParams(paramsMap, vfModuleParametersData);
279 if(!skipVfModuleAssignments) {
280 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments = vfModuleTopology.getVfModuleAssignments();
281 if (vfModuleAssignments != null) {
283 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
285 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
286 if (vmsList != null) {
287 for (GenericResourceApiVmTopologyData vm : vmsList){
288 String key = vm.getVmType();
289 buildVfModuleVmNames(paramsMap, vm, key);
290 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
291 if (vmNetworks != null) {
292 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
293 if (vmNetworksList != null) {
294 for(int n = 0; n < vmNetworksList.size(); n++){
295 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
296 network.getNetworkRoleTag();
297 String networkKey = network.getNetworkRole();
299 buildVfModuleFloatingIps(paramsMap, network, key, networkKey);
300 // Interface Route Prefixes
301 buildVfModuleInterfaceRoutePrefixes(paramsMap, network, key, networkKey);
303 buildVfModuleSriovParameters(paramsMap, network, networkKey);
304 // IPV4 and IPV6 Addresses
305 buildVfModuleNetworkInformation(paramsMap, network, key, networkKey);
310 buildParamsMapFromVfModuleForHeatTemplate(paramsMap, vm);
318 private void buildVfModuleVmNames(Map<String,String> paramsMap, GenericResourceApiVmTopologyData vm, String key) {
320 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
321 if (vmNames != null) {
322 List<String> valueList = vmNames.getVmName();
323 if (valueList != null) {
324 for(int i = 0; i < valueList.size(); i++){
325 String value = valueList.get(i);
326 if (i != valueList.size() - 1) {
327 values += value + ",";
332 paramsMap.put(key + "_name_" + i, value);
334 paramsMap.put(key + "_names", values);
339 private void buildVfModuleFloatingIps(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
340 GenericResourceApiVmnetworkdataFloatingIps floatingIps = network.getFloatingIps();
341 if (floatingIps != null) {
342 List<String> floatingIpV4List = floatingIps.getFloatingIpV4();
343 if (floatingIpV4List != null) {
344 // add only one ipv4 floating ip for now
345 String floatingIPKey = key + UNDERSCORE + networkKey + FLOATING_IP;
346 String floatingIPKeyValue = floatingIpV4List.get(0);
347 if (floatingIPKeyValue != null && !floatingIPKeyValue.isEmpty()) {
348 paramsMap.put(floatingIPKey, floatingIPKeyValue);
351 // add only one ipv6 floating ip for now
352 List<String> floatingIpV6List = floatingIps.getFloatingIpV6();
353 if (floatingIpV6List != null) {
354 String floatingIPV6Key = key + UNDERSCORE + networkKey + FLOATING_V6_IP;
355 String floatingIPV6KeyValue = floatingIpV6List.get(0);
356 if (floatingIPV6KeyValue != null && !floatingIPV6KeyValue.isEmpty()) {
357 paramsMap.put(floatingIPV6Key, floatingIPV6KeyValue);
363 private void buildVfModuleInterfaceRoutePrefixes(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
364 GenericResourceApiVmnetworkdataInterfaceRoutePrefixes interfaceRoutePrefixes = network.getInterfaceRoutePrefixes();
365 if (interfaceRoutePrefixes != null) {
366 List<String> interfaceRoutePrefixesList = interfaceRoutePrefixes.getInterfaceRoutePrefix();
367 StringBuilder sbInterfaceRoutePrefixes = new StringBuilder();
368 sbInterfaceRoutePrefixes.append("[");
369 if (interfaceRoutePrefixesList != null) {
370 for(int a = 0; a < interfaceRoutePrefixesList.size(); a++){
371 String interfaceRoutePrefixValue = interfaceRoutePrefixesList.get(a);
372 if (a != interfaceRoutePrefixesList.size() - 1) {
373 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}" + ",");
376 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}");
379 sbInterfaceRoutePrefixes.append("]");
380 if (interfaceRoutePrefixesList.size() > 0) {
381 paramsMap.put(key + UNDERSCORE + networkKey + "_route_prefixes", sbInterfaceRoutePrefixes.toString());
387 private void buildVfModuleSriovParameters(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String networkKey) {
389 GenericResourceApiVmnetworkdataSriovParameters sriovParameters = network.getSriovParameters();
390 if (sriovParameters != null) {
391 GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters heatVlanFilters = sriovParameters.getHeatVlanFilters();
392 if (heatVlanFilters != null) {
393 List<String> heatVlanFiltersList = heatVlanFilters.getHeatVlanFilter();
394 StringBuilder sriovFilterBuf = new StringBuilder();
395 if (heatVlanFiltersList != null) {
396 for(int a = 0; a < heatVlanFiltersList.size(); a++){
397 String heatVlanFilterValue = heatVlanFiltersList.get(a);
398 if (a != heatVlanFiltersList.size() - 1) {
399 sriovFilterBuf.append(heatVlanFilterValue).append(",");
402 sriovFilterBuf.append(heatVlanFilterValue);
405 if (heatVlanFiltersList.size() > 0) {
406 paramsMap.put(networkKey + "_ATT_VF_VLAN_FILTER", sriovFilterBuf.toString());
414 private void buildVfModuleNetworkInformation(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
416 GenericResourceApiVmnetworkdataNetworkInformationItems networkInformationItems = network.getNetworkInformationItems();
417 StringBuilder sbIpv4Ips = new StringBuilder();
418 StringBuilder sbIpv6Ips = new StringBuilder();
420 if (networkInformationItems != null) {
421 List<GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem> networkInformationItemList = networkInformationItems.getNetworkInformationItem();
422 if (networkInformationItemList != null) {
423 for(int a = 0; a < networkInformationItemList.size(); a++){
424 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem ipAddress = networkInformationItemList.get(a);
425 if (ipAddress != null) {
426 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps ips = ipAddress.getNetworkIps();
428 List<String> ipsList = ips.getNetworkIp();
429 if (ipsList != null) {
430 String ipVersion = ipAddress.getIpVersion();
431 for (int b = 0; b < ipsList.size(); b++) {
432 String ipAddressValue = ipsList.get(b);
433 if (ipVersion.equals("ipv4")) {
434 if (b != ipsList.size() - 1) {
435 sbIpv4Ips.append(ipAddressValue + ",");
438 sbIpv4Ips.append(ipAddressValue);
440 paramsMap.put(key + UNDERSCORE + networkKey + IP + UNDERSCORE + b, ipAddressValue);
442 else if (ipVersion.equals("ipv6")) {
443 if (b != ipsList.size() - 1) {
444 sbIpv6Ips.append(ipAddressValue + ",");
447 sbIpv6Ips.append(ipAddressValue);
449 paramsMap.put(key + UNDERSCORE + networkKey + V6_IP + UNDERSCORE + b, ipAddressValue);
452 paramsMap.put(key + UNDERSCORE + networkKey + "_ips", sbIpv4Ips.toString());
453 paramsMap.put(key + UNDERSCORE + networkKey + "_v6_ips", sbIpv6Ips.toString());
463 * Build Mapping from GenericResourceApi SDNC for Heat Template so that AIC - PO gets accurate requests for vf module assignments.
464 * Build Count of SubInterfaces, VLAN Tag, network_name, network_id,
465 * ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6) for Heat Template
467 private void buildParamsMapFromVfModuleForHeatTemplate(Map<String,String> paramsMap, GenericResourceApiVmTopologyData vm) {
468 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
470 if (vmNames != null) {
472 List<GenericResourceApiVmtopologydataVmnamesVnfcNames> vnfcNamesList = vmNames.getVnfcNames();
473 if (vnfcNamesList != null) {
475 for(int i = 0; i < vnfcNamesList.size(); i++){
477 GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames = vnfcNamesList.get(i);
478 parseVnfcNamesData(paramsMap, vnfcNames);
485 * Parse vnfcNames data to build Mapping from GenericResourceApi SDNC for Heat Template.
487 private void parseVnfcNamesData(Map<String,String> paramsMap, GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames) {
489 if (vnfcNames != null) {
490 GenericResourceApiVnfcNetworkData vnfcNetworks = vnfcNames.getVnfcNetworks();
491 if (vnfcNetworks != null) {
492 List<GenericResourceApiVnfcnetworkdataVnfcNetworkData> vnfcNetworkdataList = vnfcNetworks.getVnfcNetworkData();
494 if (vnfcNetworkdataList != null) {
496 for(int networkDataIdx = 0; networkDataIdx < vnfcNetworkdataList.size(); networkDataIdx++){
498 GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata = vnfcNetworkdataList.get(networkDataIdx);
499 parseVnfcNetworkData(paramsMap, vnfcNetworkdata, networkDataIdx);
507 * Parse VnfcNetworkData to build Mapping from GenericResourceApi SDNC for Heat Template.
508 * Build Count of SubInterfaces, VLAN Tag, network_name, network_id,
509 * ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6) for Heat Template
511 private void parseVnfcNetworkData(Map<String,String> paramsMap, GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata, int networkDataIdx) {
513 String vmTypeKey = vnfcNetworkdata.getVnfcType();
514 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts vnfcPorts = vnfcNetworkdata.getVnfcPorts();
515 if (vnfcPorts != null) {
516 List<GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort> vnfcPortList = vnfcPorts.getVnfcPort();
517 if (vnfcPortList != null) {
518 for(int portIdx = 0; portIdx < vnfcPortList.size(); portIdx++){
520 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort vnfcPort = vnfcPortList.get(portIdx);
521 GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces = vnfcPort.getVnicSubInterfaces();
523 String vnicSubInterfacesString = convertToString(vnicSubInterfaces);
524 String networkRoleKey = vnfcPort.getCommonSubInterfaceRole();
525 String subInterfaceKey = createVnfcSubInterfaceKey(vmTypeKey, networkDataIdx, networkRoleKey, portIdx);
526 String globalSubInterfaceKey = createGlobalVnfcSubInterfaceKey(vmTypeKey, networkRoleKey, portIdx);
528 buildVfModuleSubInterfacesCount(paramsMap, globalSubInterfaceKey, vnicSubInterfaces);
530 buildVfModuleVlanTag(paramsMap, subInterfaceKey, vnicSubInterfacesString);
532 buildVfModuleNetworkName(paramsMap, subInterfaceKey, vnicSubInterfacesString);
534 buildVfModuleNetworkId(paramsMap, subInterfaceKey, vnicSubInterfacesString);
536 buildVfModuleIpV4AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
538 buildVfModuleIpV6AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
540 buildVfModuleFloatingIpV4HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
542 buildVfModuleFloatingIpV6HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
549 * Build "count" (calculating the total number of sub-interfaces) for Heat Template
550 * Building Criteria : {vm-type}_subint_{network-role}_port_{index}_subintcount
551 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
552 * Example: fw_subint_ctrl_port_0_subintcount
555 private void buildVfModuleSubInterfacesCount(Map<String,String> paramsMap, String keyPrefix, GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces) {
557 List<GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData> subInterfaceNetworkDataList = vnicSubInterfaces.getSubInterfaceNetworkData();
559 if ( (subInterfaceNetworkDataList != null) && !subInterfaceNetworkDataList.isEmpty() ) {
560 addPairToMap(paramsMap, keyPrefix, SUB_INT_COUNT, String.valueOf(subInterfaceNetworkDataList.size()));
564 protected String createVnfcSubInterfaceKey(String vmTypeKey, int networkDataIdx, String networkRoleKey, int portIdx) {
566 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, networkDataIdx, SUB_INT, networkRoleKey, PORT, portIdx));
569 protected String createGlobalVnfcSubInterfaceKey(String vmTypeKey,String networkRoleKey, int portIdx) {
571 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, SUB_INT, networkRoleKey, PORT, portIdx));
575 * Build VLAN Tag for Heat Template
576 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_vlan_ids
577 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
578 * Example: fw_0_subint_ctrl_port_0_vlan_ids
581 protected void buildVfModuleVlanTag(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
583 List<String> vlanTagIds = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].vlan-tag-id");
585 addPairToMap(paramsMap, keyPrefix, VLAN_IDS, vlanTagIds);
588 * Build "network_name" for Heat Template
589 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_net_names
590 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
591 * Example: fw_0_subint_ctrl_port_0_net_names
594 protected void buildVfModuleNetworkName(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
596 List<String> neworkNames = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-name");
598 addPairToMap(paramsMap, keyPrefix, NET_NAMES, neworkNames);
602 * Build "network_id" for Heat Template
603 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_net_ids
604 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
605 * Example: fw_0_subint_ctrl_port_0_net_ids
608 protected void buildVfModuleNetworkId(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
610 List<String> neworkIds = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-id");
612 addPairToMap(paramsMap, keyPrefix, NET_IDS, neworkIds);
616 * Build ip_address for V4 for Heat Template
617 * Building Criteria :
618 * {vm-type}_{index}_subint_{network-role}_port_{index}_ip_{index} -- for ipV4
619 * key = vm-type, networkRoleKey = NetWork-Role
621 protected void buildVfModuleIpV4AddressHeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
623 List<String> ipv4Ips = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv4')].network-ips.network-ip[*]");
625 addPairToMap(paramsMap, keyPrefix, IP, ipv4Ips);
627 for (int i = 0; i < ipv4Ips.size(); i++) {
628 addPairToMap(paramsMap, keyPrefix, IP + UNDERSCORE + i, ipv4Ips.get(i));
634 * Build ip_address for Heat Template
635 * Building Criteria :
636 * {vm-type}_{index}_subint_{network-role}_port_{index}_v6_ip_{index} -- for ipV6
637 * key = vm-type, networkRoleKey = NetWork-Role
639 protected void buildVfModuleIpV6AddressHeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
641 List<String> ipv6Ips = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv6')].network-ips.network-ip[*]");
643 addPairToMap(paramsMap, keyPrefix, V6_IP, ipv6Ips);
645 for (int i = 0; i < ipv6Ips.size(); i++) {
646 addPairToMap(paramsMap, keyPrefix, V6_IP + UNDERSCORE + i, ipv6Ips.get(i));
651 * Build floatingip_address for Heat Template
652 * Building Criteria :
653 * {vm-type}_subint_{network-role}_port_{index}_floating_ip -- for ipV4
655 protected void buildVfModuleFloatingIpV4HeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
657 List<String> floatingV4 = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].floating-ips.floating-ip-v4[*]");
659 if (!floatingV4.isEmpty()) {
660 floatingV4 = Collections.singletonList(floatingV4.get(0));
662 addPairToMap(paramsMap, keyPrefix, FLOATING_IP, floatingV4);
667 * Build floatingip_address for Heat Template
668 * Building Criteria :
669 * {vm-type}_subint_{network-role}_port_{index}_floating_v6_ip -- for ipV6
671 protected void buildVfModuleFloatingIpV6HeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
673 List<String> floatingV6 = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].floating-ips.floating-ip-v6[*]");
675 if (!floatingV6.isEmpty()) {
676 floatingV6 = Collections.singletonList(floatingV6.get(0));
678 addPairToMap(paramsMap, keyPrefix, FLOATING_V6_IP, floatingV6);
681 protected void addPairToMap(Map<String, String> paramsMap, String keyPrefix, String key, String value) {
683 addPairToMap(paramsMap, keyPrefix, key, Collections.singletonList(value));
686 protected void addPairToMap(Map<String, String> paramsMap, String keyPrefix, String key, List<String> value) {
688 if (!value.isEmpty()) {
689 paramsMap.put(keyPrefix + key, Joiner.on(",").join(value));
693 private void buildParamsMapFromSdncParams(Map<String,String> paramsMap, GenericResourceApiParam parametersData) {
694 if (parametersData != null) {
695 List<GenericResourceApiParamParam> paramsList = parametersData.getParam();
696 if (paramsList != null) {
697 for (int i = 0; i < paramsList.size(); i++) {
698 GenericResourceApiParamParam param = paramsList.get(i);
699 String parameterName = param.getName();
700 if (!sdncResponseParamsToSkip.contains(parameterName)) {
701 String parameterValue = param.getValue();
702 paramsMap.put(parameterName, parameterValue);
709 private Map<String,String> buildNetworkRoleMap(GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology) throws JsonParseException, JsonMappingException, IOException {
710 Map<String, String> networkRoleMap = new HashMap<>();
711 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments = vfModuleTopology.getVfModuleAssignments();
712 if (vfModuleAssignments != null) {
713 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
715 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
716 if (vmsList != null) {
717 for (GenericResourceApiVmTopologyData vm : vmsList){
718 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
719 if (vmNetworks != null) {
720 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
721 if (vmNetworksList != null) {
722 for(int n = 0; n < vmNetworksList.size(); n++){
723 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
724 String networkRole = network.getNetworkRole();
725 String networkRoleValue = network.getNetworkRoleTag();
726 if (networkRoleValue == null || networkRoleValue.isEmpty()) {
727 networkRoleValue = networkRole;
729 networkRoleMap.put(networkRole, networkRoleValue);
737 return networkRoleMap;
740 public DeleteVfModuleRequest deleteVfModuleRequestMapper(RequestContext requestContext,CloudRegion cloudRegion,
741 ServiceInstance serviceInstance, GenericVnf genericVnf,
742 VfModule vfModule) throws IOException {
743 DeleteVfModuleRequest deleteVfModuleRequest = new DeleteVfModuleRequest();
744 deleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
745 deleteVfModuleRequest.setTenantId(cloudRegion.getTenantId());
746 deleteVfModuleRequest.setVnfId(genericVnf.getVnfId());
747 deleteVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
748 deleteVfModuleRequest.setVfModuleStackId(vfModule.getHeatStackId());//DoDVfMod_heatStackId
749 deleteVfModuleRequest.setSkipAAI(true);
750 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
751 deleteVfModuleRequest.setMessageId(messageId);
752 deleteVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
753 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
754 deleteVfModuleRequest.setMsoRequest(msoRequest);
755 return deleteVfModuleRequest;
758 private String convertToString(Object obj) {
761 json = mapper.writeValueAsString(obj);
762 } catch (JsonProcessingException e) {
769 private VfModule getBaseVfModule(GenericVnf genericVnf) {
770 List<VfModule> vfModules = genericVnf.getVfModules();
771 VfModule baseVfModule = null;
772 if (vfModules != null) {
773 for(int i = 0; i < vfModules.size(); i++) {
774 if (vfModules.get(i).getModelInfoVfModule().getIsBaseBoolean()) {
775 baseVfModule = vfModules.get(i);