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.Map.Entry;
35 import java.util.Optional;
37 import javax.annotation.PostConstruct;
39 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
41 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubInterfaceNetworkData;
42 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData;
43 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleTopology;
44 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfModuleAssignments;
45 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms;
46 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmNetworkData;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmTopologyData;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataFloatingIps;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataInterfaceRoutePrefixes;
51 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkInformationItems;
52 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem;
53 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps;
54 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovParameters;
55 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters;
56 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNames;
57 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNetworks;
58 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmnamesVnfcNames;
59 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfNetworkData;
60 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfTopology;
61 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcNetworkData;
62 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcNetworkData;
63 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts;
64 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort;
65 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfResourceAssignments;
66 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones;
67 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks;
68 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyVnfTopology;
69 import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
70 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
71 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
72 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
73 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
74 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
75 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
76 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
77 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
78 import org.onap.so.entity.MsoRequest;
79 import org.onap.so.jsonpath.JsonPathUtil;
80 import org.springframework.beans.factory.annotation.Autowired;
81 import org.springframework.stereotype.Component;
83 import com.fasterxml.jackson.core.JsonParseException;
84 import com.fasterxml.jackson.core.JsonProcessingException;
85 import com.fasterxml.jackson.databind.DeserializationFeature;
86 import com.fasterxml.jackson.databind.JsonMappingException;
87 import com.fasterxml.jackson.databind.ObjectMapper;
89 import jersey.repackaged.com.google.common.base.Joiner;
92 public class VnfAdapterVfModuleObjectMapper {
94 protected VnfAdapterObjectMapperUtils vnfAdapterObjectMapperUtils;
95 private static List<String> sdncResponseParamsToSkip = asList("vnf_id", "vf_module_id", "vnf_name", "vf_module_name");
97 private ObjectMapper mapper = new ObjectMapper();
98 private static final JsonPathUtil jsonPath = JsonPathUtil.getInstance();
99 private static final String SUB_INT = "subint";
100 private static final String SUBNET_ID = "_subnet_id";
101 private static final String V6_SUBNET_ID = "_v6_subnet_id";
102 private static final String PORT = "port";
103 private static final String SUB_INT_COUNT = "_subintcount";
104 private static final String VLAN_IDS = "_vlan_ids";
105 private static final String NET_NAMES = "_net_names";
106 private static final String NET_IDS = "_net_ids";
107 private static final String IP = "_ip";
108 private static final String V6_IP = "_v6_ip";
109 private static final String FLOATING_IP = "_floating_ip";
110 private static final String FLOATING_V6_IP = "_floating_v6_ip";
111 private static final String UNDERSCORE = "_";
114 public void init () {
115 mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
118 public CreateVfModuleRequest createVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion, OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
119 VfModule vfModule, VolumeGroup volumeGroup, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
120 CreateVfModuleRequest createVfModuleRequest = new CreateVfModuleRequest();
122 createVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
123 createVfModuleRequest.setTenantId(cloudRegion.getTenantId());
124 createVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
125 createVfModuleRequest.setVfModuleName(vfModule.getVfModuleName());
126 createVfModuleRequest.setVnfId(genericVnf.getVnfId());
127 createVfModuleRequest.setVnfType(genericVnf.getVnfType());
128 createVfModuleRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
129 createVfModuleRequest.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
130 createVfModuleRequest.setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
131 if (volumeGroup != null) {
132 createVfModuleRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId());
133 createVfModuleRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId());
135 VfModule baseVfModule = getBaseVfModule(genericVnf);
136 if (baseVfModule != null) {
137 createVfModuleRequest.setBaseVfModuleId(baseVfModule.getVfModuleId());
138 createVfModuleRequest.setBaseVfModuleStackId(baseVfModule.getHeatStackId());
140 createVfModuleRequest.setVfModuleParams(buildVfModuleParamsMap(requestContext, serviceInstance, genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse));
142 createVfModuleRequest.setSkipAAI(true);
143 createVfModuleRequest.setBackout(Boolean.TRUE.equals(orchestrationContext.getIsRollbackEnabled()));
144 createVfModuleRequest.setFailIfExists(true);
146 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
147 createVfModuleRequest.setMsoRequest(msoRequest);
149 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
150 createVfModuleRequest.setMessageId(messageId);
151 createVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
153 return createVfModuleRequest;
156 private MsoRequest buildMsoRequest(RequestContext requestContext,ServiceInstance serviceInstance) {
157 MsoRequest msoRequest = new MsoRequest();
158 msoRequest.setRequestId(requestContext.getMsoRequestId());
159 msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
163 private Map<String,String> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
164 VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
167 GenericResourceApiVnfTopology vnfTop= mapper.readValue(sdncVnfQueryResponse, GenericResourceApiVnfTopology.class);
168 GenericResourceApiVfModuleTopology vfModuleTop = mapper.readValue(sdncVfModuleQueryResponse, GenericResourceApiVfModuleTopology.class);
169 GenericResourceApiVnftopologyVnfTopology vnfTopology = vnfTop.getVnfTopology();
170 GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = vfModuleTop.getVfModuleTopology();
171 Map<String,String> paramsMap = new HashMap<>();
173 if( vfModuleTopology.getSdncGeneratedCloudResources()) {
174 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, true);
175 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, null, true);
178 Map<String,String> networkRoleMap = buildNetworkRoleMap(vfModuleTopology);
179 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, false);
180 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, networkRoleMap, false);
183 buildMandatoryParamsMap(paramsMap, serviceInstance, genericVnf, vfModule);
185 // Parameters received from the request should overwrite any parameters received from SDNC
187 if (requestContext.getUserParams() != null) {
188 paramsMap.putAll(requestContext.getUserParams());
190 if (vfModule.getCloudParams() != null) {
191 paramsMap.putAll(vfModule.getCloudParams());
196 private void buildMandatoryParamsMap(Map<String,String> paramsMap, ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule) {
197 paramsMap.put("vnf_id", genericVnf.getVnfId());
198 paramsMap.put("vnf_name", genericVnf.getVnfName());
199 paramsMap.put("vf_module_id", vfModule.getVfModuleId());
200 paramsMap.put("vf_module_name", vfModule.getVfModuleName());
201 paramsMap.put("environment_context",serviceInstance.getModelInfoServiceInstance().getEnvironmentContext());
202 paramsMap.putIfAbsent("environment_context", "");
203 paramsMap.put("workload_context", serviceInstance.getModelInfoServiceInstance().getWorkloadContext());
204 paramsMap.putIfAbsent("workload_context", "");
205 Integer vfModuleIndex = vfModule.getModuleIndex();
206 if (vfModuleIndex != null) {
207 paramsMap.put("vf_module_index", vfModuleIndex.toString());
211 private void buildParamsMapFromVnfSdncResponse(Map<String,String> paramsMap, GenericResourceApiVnftopologyVnfTopology vnfTopology, Map<String,String> networkRoleMap, boolean skipVnfResourceAssignments) throws JsonParseException, JsonMappingException, IOException {
212 // Get VNF parameters from SDNC response
213 GenericResourceApiParam vnfParametersData = vnfTopology.getVnfParametersData();
214 buildParamsMapFromSdncParams(paramsMap, vnfParametersData);
216 if(!skipVnfResourceAssignments) {
217 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments = vnfTopology.getVnfResourceAssignments();
218 if (vnfResourceAssignments != null) {
219 // Availability Zones
220 buildAvailabilityZones(paramsMap, vnfResourceAssignments);
222 buildVnfNetworks(paramsMap, vnfResourceAssignments, networkRoleMap);
227 private void buildAvailabilityZones (Map<String,String> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments) {
228 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones availabilityZones = vnfResourceAssignments.getAvailabilityZones();
229 if (availabilityZones != null) {
230 List<String> availabilityZonesList = availabilityZones.getAvailabilityZone();
231 if (availabilityZonesList != null) {
232 for(int i = 0; i < availabilityZonesList.size(); i++) {
233 paramsMap.put("availability_zone_" + i, availabilityZonesList.get(i));
239 private void buildVnfNetworks (Map<String,String> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments, Map<String,String> networkRoleMap) {
240 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworks = vnfResourceAssignments.getVnfNetworks();
241 if (vnfNetworks != null) {
242 List<GenericResourceApiVnfNetworkData> vnfNetworksList = vnfNetworks.getVnfNetwork();
243 if (vnfNetworksList != null) {
244 for (int i = 0; i < vnfNetworksList.size(); i++) {
245 GenericResourceApiVnfNetworkData vnfNetwork = vnfNetworksList.get(i);
246 String networkRole = vnfNetwork.getNetworkRole();
247 String vnfNetworkKey = networkRoleMap.get(networkRole);
248 if (vnfNetworkKey == null || vnfNetworkKey.isEmpty()) {
249 vnfNetworkKey = networkRole;
252 String vnfNetworkNeutronIdValue = vnfNetwork.getNeutronId();
253 paramsMap.put(vnfNetworkKey + "_net_id", vnfNetworkNeutronIdValue);
254 String vnfNetworkNetNameValue = vnfNetwork.getNetworkName();
255 paramsMap.put(vnfNetworkKey + "_net_name", vnfNetworkNetNameValue);
256 String vnfNetworkNetFqdnValue = vnfNetwork.getContrailNetworkFqdn();
257 paramsMap.put(vnfNetworkKey + "_net_fqdn", vnfNetworkNetFqdnValue);
259 buildVnfNetworkSubnets(paramsMap, vnfNetwork, vnfNetworkKey);
266 private void buildVnfNetworkSubnets(Map<String,String> paramsMap, GenericResourceApiVnfNetworkData vnfNetwork, String vnfNetworkKey) {
267 String vnfNetworkString = convertToString(vnfNetwork);
268 Optional<String> ipv4Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv4' && @.dhcp-enabled == 'Y')].subnet-id");
269 if(ipv4Ips.isPresent())
270 addPairToMap(paramsMap, vnfNetworkKey, SUBNET_ID, ipv4Ips.get());
272 Optional<String> ipv6Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv6' && @.dhcp-enabled == 'Y')].subnet-id");
273 if(ipv6Ips.isPresent())
274 addPairToMap(paramsMap, vnfNetworkKey, V6_SUBNET_ID, ipv6Ips.get());
277 private void buildParamsMapFromVfModuleSdncResponse(Map<String,String> paramsMap, GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology, boolean skipVfModuleAssignments) throws JsonParseException, JsonMappingException, IOException {
278 // Get VF Module parameters from SDNC response
279 GenericResourceApiParam vfModuleParametersData = vfModuleTopology.getVfModuleParameters();
280 buildParamsMapFromSdncParams(paramsMap, vfModuleParametersData);
282 if(!skipVfModuleAssignments) {
283 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments = vfModuleTopology.getVfModuleAssignments();
284 if (vfModuleAssignments != null) {
286 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
288 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
289 if (vmsList != null) {
290 for (GenericResourceApiVmTopologyData vm : vmsList){
291 String key = vm.getVmType();
292 buildVfModuleVmNames(paramsMap, vm, key);
293 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
294 if (vmNetworks != null) {
295 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
296 if (vmNetworksList != null) {
297 for(int n = 0; n < vmNetworksList.size(); n++){
298 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
299 network.getNetworkRoleTag();
300 String networkKey = network.getNetworkRole();
302 buildVfModuleFloatingIps(paramsMap, network, key, networkKey);
303 // Interface Route Prefixes
304 buildVfModuleInterfaceRoutePrefixes(paramsMap, network, key, networkKey);
306 buildVfModuleSriovParameters(paramsMap, network, networkKey);
307 // IPV4 and IPV6 Addresses
308 buildVfModuleNetworkInformation(paramsMap, network, key, networkKey);
310 buildVlanInformation(paramsMap, network, key, networkKey);
316 buildParamsMapFromVfModuleForHeatTemplate(paramsMap, vm);
324 protected void buildVlanInformation(Map<String, String> paramsMap,
325 GenericResourceApiVmNetworkData network, String key, String networkKey) {
327 String networkString = convertToString(network);
328 String vlanFilterKey = key + UNDERSCORE + networkKey + UNDERSCORE + "vlan_filter";
329 String privateVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "private_vlans";
330 String publicVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "public_vlans";
331 String guestVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "guest_vlans";
333 if (network.getSegmentationId() != null) {
334 paramsMap.put(vlanFilterKey, network.getSegmentationId());
337 List<String> privateVlans = jsonPath.locateResultList(networkString, "$.related-networks.related-network[?(@.vlan-tags.is-private == true)].vlan-tags.upper-tag-id");
338 List<String> publicVlans = jsonPath.locateResultList(networkString, "$.related-networks.related-network[?(@.vlan-tags.is-private == false)].vlan-tags.upper-tag-id");
339 List<String> concat = new ArrayList<>(privateVlans);
340 concat.addAll(publicVlans);
341 Collection<String> guestVlans = new HashSet<>(concat);
343 if (!privateVlans.isEmpty()) {
344 paramsMap.put(privateVlansKey, Joiner.on(",").join(privateVlans));
346 if (!publicVlans.isEmpty()) {
347 paramsMap.put(publicVlansKey, Joiner.on(",").join(publicVlans));
349 if (!guestVlans.isEmpty()) {
350 paramsMap.put(guestVlansKey, Joiner.on(",").join(guestVlans));
354 private void buildVfModuleVmNames(Map<String,String> paramsMap, GenericResourceApiVmTopologyData vm, String key) {
356 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
357 if (vmNames != null) {
358 List<String> valueList = vmNames.getVmName();
359 if (valueList != null) {
360 for(int i = 0; i < valueList.size(); i++){
361 String value = valueList.get(i);
362 if (i != valueList.size() - 1) {
363 values += value + ",";
368 paramsMap.put(key + "_name_" + i, value);
370 paramsMap.put(key + "_names", values);
375 private void buildVfModuleFloatingIps(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
376 GenericResourceApiVmnetworkdataFloatingIps floatingIps = network.getFloatingIps();
377 if (floatingIps != null) {
378 List<String> floatingIpV4List = floatingIps.getFloatingIpV4();
379 if (floatingIpV4List != null) {
380 // add only one ipv4 floating ip for now
381 String floatingIPKey = key + UNDERSCORE + networkKey + FLOATING_IP;
382 String floatingIPKeyValue = floatingIpV4List.get(0);
383 if (floatingIPKeyValue != null && !floatingIPKeyValue.isEmpty()) {
384 paramsMap.put(floatingIPKey, floatingIPKeyValue);
387 // add only one ipv6 floating ip for now
388 List<String> floatingIpV6List = floatingIps.getFloatingIpV6();
389 if (floatingIpV6List != null) {
390 String floatingIPV6Key = key + UNDERSCORE + networkKey + FLOATING_V6_IP;
391 String floatingIPV6KeyValue = floatingIpV6List.get(0);
392 if (floatingIPV6KeyValue != null && !floatingIPV6KeyValue.isEmpty()) {
393 paramsMap.put(floatingIPV6Key, floatingIPV6KeyValue);
399 private void buildVfModuleInterfaceRoutePrefixes(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
400 GenericResourceApiVmnetworkdataInterfaceRoutePrefixes interfaceRoutePrefixes = network.getInterfaceRoutePrefixes();
401 if (interfaceRoutePrefixes != null) {
402 List<String> interfaceRoutePrefixesList = interfaceRoutePrefixes.getInterfaceRoutePrefix();
403 StringBuilder sbInterfaceRoutePrefixes = new StringBuilder();
404 sbInterfaceRoutePrefixes.append("[");
405 if (interfaceRoutePrefixesList != null) {
406 for(int a = 0; a < interfaceRoutePrefixesList.size(); a++){
407 String interfaceRoutePrefixValue = interfaceRoutePrefixesList.get(a);
408 if (a != interfaceRoutePrefixesList.size() - 1) {
409 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}" + ",");
412 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}");
415 sbInterfaceRoutePrefixes.append("]");
416 if (interfaceRoutePrefixesList.size() > 0) {
417 paramsMap.put(key + UNDERSCORE + networkKey + "_route_prefixes", sbInterfaceRoutePrefixes.toString());
423 private void buildVfModuleSriovParameters(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String networkKey) {
425 GenericResourceApiVmnetworkdataSriovParameters sriovParameters = network.getSriovParameters();
426 if (sriovParameters != null) {
427 GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters heatVlanFilters = sriovParameters.getHeatVlanFilters();
428 if (heatVlanFilters != null) {
429 List<String> heatVlanFiltersList = heatVlanFilters.getHeatVlanFilter();
430 StringBuilder sriovFilterBuf = new StringBuilder();
431 if (heatVlanFiltersList != null) {
432 for(int a = 0; a < heatVlanFiltersList.size(); a++){
433 String heatVlanFilterValue = heatVlanFiltersList.get(a);
434 if (a != heatVlanFiltersList.size() - 1) {
435 sriovFilterBuf.append(heatVlanFilterValue).append(",");
438 sriovFilterBuf.append(heatVlanFilterValue);
441 if (heatVlanFiltersList.size() > 0) {
442 paramsMap.put(networkKey + "_ATT_VF_VLAN_FILTER", sriovFilterBuf.toString());
450 private void buildVfModuleNetworkInformation(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
452 GenericResourceApiVmnetworkdataNetworkInformationItems networkInformationItems = network.getNetworkInformationItems();
453 StringBuilder sbIpv4Ips = new StringBuilder();
454 StringBuilder sbIpv6Ips = new StringBuilder();
456 if (networkInformationItems != null) {
457 List<GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem> networkInformationItemList = networkInformationItems.getNetworkInformationItem();
458 if (networkInformationItemList != null) {
459 for(int a = 0; a < networkInformationItemList.size(); a++){
460 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem ipAddress = networkInformationItemList.get(a);
461 if (ipAddress != null) {
462 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps ips = ipAddress.getNetworkIps();
464 List<String> ipsList = ips.getNetworkIp();
465 if (ipsList != null) {
466 String ipVersion = ipAddress.getIpVersion();
467 for (int b = 0; b < ipsList.size(); b++) {
468 String ipAddressValue = ipsList.get(b);
469 if (ipVersion.equals("ipv4")) {
470 if (b != ipsList.size() - 1) {
471 sbIpv4Ips.append(ipAddressValue + ",");
474 sbIpv4Ips.append(ipAddressValue);
476 paramsMap.put(key + UNDERSCORE + networkKey + IP + UNDERSCORE + b, ipAddressValue);
478 else if (ipVersion.equals("ipv6")) {
479 if (b != ipsList.size() - 1) {
480 sbIpv6Ips.append(ipAddressValue + ",");
483 sbIpv6Ips.append(ipAddressValue);
485 paramsMap.put(key + UNDERSCORE + networkKey + V6_IP + UNDERSCORE + b, ipAddressValue);
488 paramsMap.put(key + UNDERSCORE + networkKey + "_ips", sbIpv4Ips.toString());
489 paramsMap.put(key + UNDERSCORE + networkKey + "_v6_ips", sbIpv6Ips.toString());
499 * Build Mapping from GenericResourceApi SDNC for Heat Template so that AIC - PO gets accurate requests for vf module assignments.
500 * Build Count of SubInterfaces, VLAN Tag, network_name, network_id,
501 * ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6) for Heat Template
503 private void buildParamsMapFromVfModuleForHeatTemplate(Map<String,String> paramsMap, GenericResourceApiVmTopologyData vm) {
504 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
506 if (vmNames != null) {
508 List<GenericResourceApiVmtopologydataVmnamesVnfcNames> vnfcNamesList = vmNames.getVnfcNames();
509 if (vnfcNamesList != null) {
511 for(int i = 0; i < vnfcNamesList.size(); i++){
513 GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames = vnfcNamesList.get(i);
514 parseVnfcNamesData(paramsMap, vnfcNames);
521 * Parse vnfcNames data to build Mapping from GenericResourceApi SDNC for Heat Template.
523 private void parseVnfcNamesData(Map<String,String> paramsMap, GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames) {
525 if (vnfcNames != null) {
526 GenericResourceApiVnfcNetworkData vnfcNetworks = vnfcNames.getVnfcNetworks();
527 if (vnfcNetworks != null) {
528 List<GenericResourceApiVnfcnetworkdataVnfcNetworkData> vnfcNetworkdataList = vnfcNetworks.getVnfcNetworkData();
530 if (vnfcNetworkdataList != null) {
532 for(int networkDataIdx = 0; networkDataIdx < vnfcNetworkdataList.size(); networkDataIdx++){
534 GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata = vnfcNetworkdataList.get(networkDataIdx);
535 parseVnfcNetworkData(paramsMap, vnfcNetworkdata, networkDataIdx);
543 * Parse VnfcNetworkData to build Mapping from GenericResourceApi SDNC for Heat Template.
544 * Build Count of SubInterfaces, VLAN Tag, network_name, network_id,
545 * ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6) for Heat Template
547 private void parseVnfcNetworkData(Map<String,String> paramsMap, GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata, int networkDataIdx) {
549 String vmTypeKey = vnfcNetworkdata.getVnfcType();
550 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts vnfcPorts = vnfcNetworkdata.getVnfcPorts();
551 if (vnfcPorts != null) {
552 List<GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort> vnfcPortList = vnfcPorts.getVnfcPort();
553 if (vnfcPortList != null) {
554 for(int portIdx = 0; portIdx < vnfcPortList.size(); portIdx++){
556 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort vnfcPort = vnfcPortList.get(portIdx);
557 GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces = vnfcPort.getVnicSubInterfaces();
559 String vnicSubInterfacesString = convertToString(vnicSubInterfaces);
560 String networkRoleKey = vnfcPort.getCommonSubInterfaceRole();
561 String subInterfaceKey = createVnfcSubInterfaceKey(vmTypeKey, networkDataIdx, networkRoleKey, portIdx);
562 String globalSubInterfaceKey = createGlobalVnfcSubInterfaceKey(vmTypeKey, networkRoleKey, portIdx);
564 buildVfModuleSubInterfacesCount(paramsMap, globalSubInterfaceKey, vnicSubInterfaces);
566 buildVfModuleVlanTag(paramsMap, subInterfaceKey, vnicSubInterfacesString);
568 buildVfModuleNetworkName(paramsMap, subInterfaceKey, vnicSubInterfacesString);
570 buildVfModuleNetworkId(paramsMap, subInterfaceKey, vnicSubInterfacesString);
572 buildVfModuleIpV4AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
574 buildVfModuleIpV6AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
576 buildVfModuleFloatingIpV4HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
578 buildVfModuleFloatingIpV6HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
585 * Build "count" (calculating the total number of sub-interfaces) for Heat Template
586 * Building Criteria : {vm-type}_subint_{network-role}_port_{index}_subintcount
587 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
588 * Example: fw_subint_ctrl_port_0_subintcount
591 private void buildVfModuleSubInterfacesCount(Map<String,String> paramsMap, String keyPrefix, GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces) {
593 List<GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData> subInterfaceNetworkDataList = vnicSubInterfaces.getSubInterfaceNetworkData();
595 if ( (subInterfaceNetworkDataList != null) && !subInterfaceNetworkDataList.isEmpty() ) {
596 addPairToMap(paramsMap, keyPrefix, SUB_INT_COUNT, String.valueOf(subInterfaceNetworkDataList.size()));
600 protected String createVnfcSubInterfaceKey(String vmTypeKey, int networkDataIdx, String networkRoleKey, int portIdx) {
602 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, networkDataIdx, SUB_INT, networkRoleKey, PORT, portIdx));
605 protected String createGlobalVnfcSubInterfaceKey(String vmTypeKey,String networkRoleKey, int portIdx) {
607 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, SUB_INT, networkRoleKey, PORT, portIdx));
611 * Build VLAN Tag for Heat Template
612 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_vlan_ids
613 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
614 * Example: fw_0_subint_ctrl_port_0_vlan_ids
617 protected void buildVfModuleVlanTag(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
619 List<String> vlanTagIds = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].vlan-tag-id");
621 addPairToMap(paramsMap, keyPrefix, VLAN_IDS, vlanTagIds);
624 * Build "network_name" for Heat Template
625 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_net_names
626 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
627 * Example: fw_0_subint_ctrl_port_0_net_names
630 protected void buildVfModuleNetworkName(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
632 List<String> neworkNames = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-name");
634 addPairToMap(paramsMap, keyPrefix, NET_NAMES, neworkNames);
638 * Build "network_id" for Heat Template
639 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_net_ids
640 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
641 * Example: fw_0_subint_ctrl_port_0_net_ids
644 protected void buildVfModuleNetworkId(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
646 List<String> neworkIds = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-id");
648 addPairToMap(paramsMap, keyPrefix, NET_IDS, neworkIds);
652 * Build ip_address for V4 for Heat Template
653 * Building Criteria :
654 * {vm-type}_{index}_subint_{network-role}_port_{index}_ip_{index} -- for ipV4
655 * key = vm-type, networkRoleKey = NetWork-Role
657 protected void buildVfModuleIpV4AddressHeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
659 List<String> ipv4Ips = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv4')].network-ips.network-ip[*]");
661 addPairToMap(paramsMap, keyPrefix, IP, ipv4Ips);
663 for (int i = 0; i < ipv4Ips.size(); i++) {
664 addPairToMap(paramsMap, keyPrefix, IP + UNDERSCORE + i, ipv4Ips.get(i));
670 * Build ip_address for Heat Template
671 * Building Criteria :
672 * {vm-type}_{index}_subint_{network-role}_port_{index}_v6_ip_{index} -- for ipV6
673 * key = vm-type, networkRoleKey = NetWork-Role
675 protected void buildVfModuleIpV6AddressHeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
677 List<String> ipv6Ips = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv6')].network-ips.network-ip[*]");
679 addPairToMap(paramsMap, keyPrefix, V6_IP, ipv6Ips);
681 for (int i = 0; i < ipv6Ips.size(); i++) {
682 addPairToMap(paramsMap, keyPrefix, V6_IP + UNDERSCORE + i, ipv6Ips.get(i));
687 * Build floatingip_address for Heat Template
688 * Building Criteria :
689 * {vm-type}_subint_{network-role}_port_{index}_floating_ip -- for ipV4
691 protected void buildVfModuleFloatingIpV4HeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
693 List<String> floatingV4 = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].floating-ips.floating-ip-v4[*]");
695 if (!floatingV4.isEmpty()) {
696 floatingV4 = Collections.singletonList(floatingV4.get(0));
698 addPairToMap(paramsMap, keyPrefix, FLOATING_IP, floatingV4);
703 * Build floatingip_address for Heat Template
704 * Building Criteria :
705 * {vm-type}_subint_{network-role}_port_{index}_floating_v6_ip -- for ipV6
707 protected void buildVfModuleFloatingIpV6HeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
709 List<String> floatingV6 = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].floating-ips.floating-ip-v6[*]");
711 if (!floatingV6.isEmpty()) {
712 floatingV6 = Collections.singletonList(floatingV6.get(0));
714 addPairToMap(paramsMap, keyPrefix, FLOATING_V6_IP, floatingV6);
717 protected void addPairToMap(Map<String, String> paramsMap, String keyPrefix, String key, String value) {
719 addPairToMap(paramsMap, keyPrefix, key, Collections.singletonList(value));
722 protected void addPairToMap(Map<String, String> paramsMap, String keyPrefix, String key, List<String> value) {
724 if (!value.isEmpty()) {
725 paramsMap.put(keyPrefix + key, Joiner.on(",").join(value));
729 private void buildParamsMapFromSdncParams(Map<String,String> paramsMap, GenericResourceApiParam parametersData) {
730 if (parametersData != null) {
731 List<GenericResourceApiParamParam> paramsList = parametersData.getParam();
732 if (paramsList != null) {
733 for (int i = 0; i < paramsList.size(); i++) {
734 GenericResourceApiParamParam param = paramsList.get(i);
735 String parameterName = param.getName();
736 if (!sdncResponseParamsToSkip.contains(parameterName)) {
737 String parameterValue = param.getValue();
738 paramsMap.put(parameterName, parameterValue);
745 private Map<String,String> buildNetworkRoleMap(GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology) throws JsonParseException, JsonMappingException, IOException {
746 Map<String, String> networkRoleMap = new HashMap<>();
747 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments = vfModuleTopology.getVfModuleAssignments();
748 if (vfModuleAssignments != null) {
749 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
751 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
752 if (vmsList != null) {
753 for (GenericResourceApiVmTopologyData vm : vmsList){
754 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
755 if (vmNetworks != null) {
756 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
757 if (vmNetworksList != null) {
758 for(int n = 0; n < vmNetworksList.size(); n++){
759 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
760 String networkRole = network.getNetworkRole();
761 String networkRoleValue = network.getNetworkRoleTag();
762 if (networkRoleValue == null || networkRoleValue.isEmpty()) {
763 networkRoleValue = networkRole;
765 networkRoleMap.put(networkRole, networkRoleValue);
773 return networkRoleMap;
776 public DeleteVfModuleRequest deleteVfModuleRequestMapper(RequestContext requestContext,CloudRegion cloudRegion,
777 ServiceInstance serviceInstance, GenericVnf genericVnf,
778 VfModule vfModule) throws IOException {
779 DeleteVfModuleRequest deleteVfModuleRequest = new DeleteVfModuleRequest();
780 deleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
781 deleteVfModuleRequest.setTenantId(cloudRegion.getTenantId());
782 deleteVfModuleRequest.setVnfId(genericVnf.getVnfId());
783 deleteVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
784 deleteVfModuleRequest.setVfModuleStackId(vfModule.getHeatStackId());//DoDVfMod_heatStackId
785 deleteVfModuleRequest.setSkipAAI(true);
786 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
787 deleteVfModuleRequest.setMessageId(messageId);
788 deleteVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
789 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
790 deleteVfModuleRequest.setMsoRequest(msoRequest);
791 return deleteVfModuleRequest;
794 private String convertToString(Object obj) {
797 json = mapper.writeValueAsString(obj);
798 } catch (JsonProcessingException e) {
805 private VfModule getBaseVfModule(GenericVnf genericVnf) {
806 List<VfModule> vfModules = genericVnf.getVfModules();
807 VfModule baseVfModule = null;
808 if (vfModules != null) {
809 for(int i = 0; i < vfModules.size(); i++) {
810 if (vfModules.get(i).getModelInfoVfModule().getIsBaseBoolean()) {
811 baseVfModule = vfModules.get(i);