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.io.UnsupportedEncodingException;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.Collection;
30 import java.util.Collections;
31 import java.util.HashMap;
32 import java.util.HashSet;
33 import java.util.List;
35 import java.util.Optional;
37 import javax.annotation.PostConstruct;
39 import org.apache.commons.lang3.StringUtils;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
41 import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
42 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubInterfaceNetworkData;
43 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData;
44 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleTopology;
45 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfModuleAssignments;
46 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmNetworkData;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmTopologyData;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataFloatingIps;
51 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataInterfaceRoutePrefixes;
52 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkInformationItems;
53 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem;
54 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps;
55 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovParameters;
56 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters;
57 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNames;
58 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNetworks;
59 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmnamesVnfcNames;
60 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfNetworkData;
61 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfTopology;
62 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcNetworkData;
63 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcNetworkData;
64 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts;
65 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort;
66 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfResourceAssignments;
67 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones;
68 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks;
69 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyVnfTopology;
70 import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
71 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
72 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
73 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
74 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
75 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
76 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
77 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
78 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
79 import org.onap.so.entity.MsoRequest;
80 import org.onap.so.jsonpath.JsonPathUtil;
81 import org.springframework.beans.factory.annotation.Autowired;
82 import org.springframework.stereotype.Component;
84 import com.fasterxml.jackson.core.JsonParseException;
85 import com.fasterxml.jackson.core.JsonProcessingException;
86 import com.fasterxml.jackson.databind.DeserializationFeature;
87 import com.fasterxml.jackson.databind.JsonMappingException;
88 import com.fasterxml.jackson.databind.ObjectMapper;
89 import com.google.common.base.Joiner;
93 public class VnfAdapterVfModuleObjectMapper {
95 protected VnfAdapterObjectMapperUtils vnfAdapterObjectMapperUtils;
96 private static List<String> sdncResponseParamsToSkip = asList("vnf_id", "vf_module_id", "vnf_name", "vf_module_name");
98 private ObjectMapper mapper = new ObjectMapper();
99 private static final JsonPathUtil jsonPath = JsonPathUtil.getInstance();
100 private static final String SUB_INT = "subint";
101 private static final String SUBNET_ID = "_subnet_id";
102 private static final String V6_SUBNET_ID = "_v6_subnet_id";
103 private static final String PORT = "port";
104 private static final String SUB_INT_COUNT = "_subintcount";
105 private static final String VLAN_IDS = "_vlan_ids";
106 private static final String NET_NAMES = "_net_names";
107 private static final String NET_IDS = "_net_ids";
108 private static final String IP = "_ip";
109 private static final String V6_IP = "_v6_ip";
110 private static final String FLOATING_IP = "_floating_ip";
111 private static final String FLOATING_V6_IP = "_floating_v6_ip";
112 private static final String UNDERSCORE = "_";
115 public void init () {
116 mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
119 public CreateVfModuleRequest createVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion, OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
120 VfModule vfModule, VolumeGroup volumeGroup, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
121 CreateVfModuleRequest createVfModuleRequest = new CreateVfModuleRequest();
123 createVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
124 createVfModuleRequest.setTenantId(cloudRegion.getTenantId());
125 createVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
126 createVfModuleRequest.setVfModuleName(vfModule.getVfModuleName());
127 createVfModuleRequest.setVnfId(genericVnf.getVnfId());
128 createVfModuleRequest.setVnfType(genericVnf.getVnfType());
129 createVfModuleRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
130 createVfModuleRequest.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
131 createVfModuleRequest.setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
132 if (volumeGroup != null) {
133 createVfModuleRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId());
134 createVfModuleRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId());
136 VfModule baseVfModule = getBaseVfModule(genericVnf);
137 if (baseVfModule != null) {
138 createVfModuleRequest.setBaseVfModuleId(baseVfModule.getVfModuleId());
139 createVfModuleRequest.setBaseVfModuleStackId(baseVfModule.getHeatStackId());
141 createVfModuleRequest.setVfModuleParams(buildVfModuleParamsMap(requestContext, serviceInstance, genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse));
143 createVfModuleRequest.setSkipAAI(true);
144 createVfModuleRequest.setBackout(Boolean.TRUE.equals(orchestrationContext.getIsRollbackEnabled()));
145 createVfModuleRequest.setFailIfExists(true);
147 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
148 createVfModuleRequest.setMsoRequest(msoRequest);
150 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
151 createVfModuleRequest.setMessageId(messageId);
152 createVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
154 return createVfModuleRequest;
157 private MsoRequest buildMsoRequest(RequestContext requestContext,ServiceInstance serviceInstance) {
158 MsoRequest msoRequest = new MsoRequest();
159 msoRequest.setRequestId(requestContext.getMsoRequestId());
160 msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
164 private Map<String,String> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
165 VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
168 GenericResourceApiVnfTopology vnfTop= mapper.readValue(sdncVnfQueryResponse, GenericResourceApiVnfTopology.class);
169 GenericResourceApiVfModuleTopology vfModuleTop = mapper.readValue(sdncVfModuleQueryResponse, GenericResourceApiVfModuleTopology.class);
170 GenericResourceApiVnftopologyVnfTopology vnfTopology = vnfTop.getVnfTopology();
171 GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = vfModuleTop.getVfModuleTopology();
172 Map<String,String> paramsMap = new HashMap<>();
174 if( vfModuleTopology.getSdncGeneratedCloudResources()) {
175 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, true);
176 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, null, true);
179 Map<String,String> networkRoleMap = buildNetworkRoleMap(vfModuleTopology);
180 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, false);
181 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, networkRoleMap, false);
184 buildMandatoryParamsMap(paramsMap, serviceInstance, genericVnf, vfModule);
186 // Parameters received from the request should overwrite any parameters received from SDNC
188 if (requestContext.getUserParams() != null) {
189 paramsMap.putAll(requestContext.getUserParams());
191 if (vfModule.getCloudParams() != null) {
192 paramsMap.putAll(vfModule.getCloudParams());
197 private void buildMandatoryParamsMap(Map<String,String> paramsMap, ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule) {
198 paramsMap.put("vnf_id", genericVnf.getVnfId());
199 paramsMap.put("vnf_name", genericVnf.getVnfName());
200 paramsMap.put("vf_module_id", vfModule.getVfModuleId());
201 paramsMap.put("vf_module_name", vfModule.getVfModuleName());
202 paramsMap.put("environment_context",serviceInstance.getModelInfoServiceInstance().getEnvironmentContext());
203 paramsMap.putIfAbsent("environment_context", "");
204 paramsMap.put("workload_context", serviceInstance.getModelInfoServiceInstance().getWorkloadContext());
205 paramsMap.putIfAbsent("workload_context", "");
206 Integer vfModuleIndex = vfModule.getModuleIndex();
207 if (vfModuleIndex != null) {
208 paramsMap.put("vf_module_index", vfModuleIndex.toString());
212 private void buildParamsMapFromVnfSdncResponse(Map<String,String> paramsMap, GenericResourceApiVnftopologyVnfTopology vnfTopology, Map<String,String> networkRoleMap, boolean skipVnfResourceAssignments) throws JsonParseException, JsonMappingException, IOException {
213 // Get VNF parameters from SDNC response
214 GenericResourceApiParam vnfParametersData = vnfTopology.getVnfParametersData();
215 buildParamsMapFromSdncParams(paramsMap, vnfParametersData);
217 if(!skipVnfResourceAssignments) {
218 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments = vnfTopology.getVnfResourceAssignments();
219 if (vnfResourceAssignments != null) {
220 // Availability Zones
221 buildAvailabilityZones(paramsMap, vnfResourceAssignments);
223 buildVnfNetworks(paramsMap, vnfResourceAssignments, networkRoleMap);
228 private void buildAvailabilityZones (Map<String,String> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments) {
229 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones availabilityZones = vnfResourceAssignments.getAvailabilityZones();
230 if (availabilityZones != null) {
231 List<String> availabilityZonesList = availabilityZones.getAvailabilityZone();
232 if (availabilityZonesList != null) {
233 for(int i = 0; i < availabilityZonesList.size(); i++) {
234 paramsMap.put("availability_zone_" + i, availabilityZonesList.get(i));
240 private void buildVnfNetworks (Map<String,String> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments, Map<String,String> networkRoleMap) {
241 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworks = vnfResourceAssignments.getVnfNetworks();
242 if (vnfNetworks != null) {
243 List<GenericResourceApiVnfNetworkData> vnfNetworksList = vnfNetworks.getVnfNetwork();
244 if (vnfNetworksList != null) {
245 for (int i = 0; i < vnfNetworksList.size(); i++) {
246 GenericResourceApiVnfNetworkData vnfNetwork = vnfNetworksList.get(i);
247 String networkRole = vnfNetwork.getNetworkRole();
248 String vnfNetworkKey = networkRoleMap.get(networkRole);
249 if (vnfNetworkKey == null || vnfNetworkKey.isEmpty()) {
250 vnfNetworkKey = networkRole;
253 String vnfNetworkNeutronIdValue = vnfNetwork.getNeutronId();
254 paramsMap.put(vnfNetworkKey + "_net_id", vnfNetworkNeutronIdValue);
255 String vnfNetworkNetNameValue = vnfNetwork.getNetworkName();
256 paramsMap.put(vnfNetworkKey + "_net_name", vnfNetworkNetNameValue);
257 String vnfNetworkNetFqdnValue = vnfNetwork.getContrailNetworkFqdn();
258 paramsMap.put(vnfNetworkKey + "_net_fqdn", vnfNetworkNetFqdnValue);
260 buildVnfNetworkSubnets(paramsMap, vnfNetwork, vnfNetworkKey);
267 private void buildVnfNetworkSubnets(Map<String,String> paramsMap, GenericResourceApiVnfNetworkData vnfNetwork, String vnfNetworkKey) {
268 String vnfNetworkString = convertToString(vnfNetwork);
269 Optional<String> ipv4Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv4' && @.dhcp-enabled == 'Y')].subnet-id");
270 if(ipv4Ips.isPresent())
271 addPairToMap(paramsMap, vnfNetworkKey, SUBNET_ID, ipv4Ips.get());
273 Optional<String> ipv6Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv6' && @.dhcp-enabled == 'Y')].subnet-id");
274 if(ipv6Ips.isPresent())
275 addPairToMap(paramsMap, vnfNetworkKey, V6_SUBNET_ID, ipv6Ips.get());
278 private void buildParamsMapFromVfModuleSdncResponse(Map<String,String> paramsMap, GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology, boolean skipVfModuleAssignments) throws JsonParseException, JsonMappingException, IOException {
279 // Get VF Module parameters from SDNC response
280 GenericResourceApiParam vfModuleParametersData = vfModuleTopology.getVfModuleParameters();
281 buildParamsMapFromSdncParams(paramsMap, vfModuleParametersData);
283 if(!skipVfModuleAssignments) {
284 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments = vfModuleTopology.getVfModuleAssignments();
285 if (vfModuleAssignments != null) {
287 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
289 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
290 if (vmsList != null) {
291 for (GenericResourceApiVmTopologyData vm : vmsList){
292 String key = vm.getVmType();
293 buildVfModuleVmNames(paramsMap, vm, key);
294 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
295 if (vmNetworks != null) {
296 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
297 if (vmNetworksList != null) {
298 for(int n = 0; n < vmNetworksList.size(); n++){
299 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
300 network.getNetworkRoleTag();
301 String networkKey = network.getNetworkRole();
303 buildVfModuleFloatingIps(paramsMap, network, key, networkKey);
304 // Interface Route Prefixes
305 buildVfModuleInterfaceRoutePrefixes(paramsMap, network, key, networkKey);
307 buildVfModuleSriovParameters(paramsMap, network, networkKey);
308 // IPV4 and IPV6 Addresses
309 buildVfModuleNetworkInformation(paramsMap, network, key, networkKey);
311 buildVlanInformation(paramsMap, network, key, networkKey);
317 buildParamsMapFromVfModuleForHeatTemplate(paramsMap, vm);
325 protected void buildVlanInformation(Map<String, String> paramsMap,
326 GenericResourceApiVmNetworkData network, String key, String networkKey) {
328 String networkString = convertToString(network);
329 String vlanFilterKey = key + UNDERSCORE + networkKey + UNDERSCORE + "vlan_filter";
330 String privateVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "private_vlans";
331 String publicVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "public_vlans";
332 String guestVlansKey = key + UNDERSCORE + networkKey + UNDERSCORE + "guest_vlans";
334 if (network.getSegmentationId() != null) {
335 paramsMap.put(vlanFilterKey, network.getSegmentationId());
338 List<String> privateVlans = jsonPath.locateResultList(networkString, "$.related-networks.related-network[?(@.vlan-tags.is-private == true)].vlan-tags.upper-tag-id");
339 List<String> publicVlans = jsonPath.locateResultList(networkString, "$.related-networks.related-network[?(@.vlan-tags.is-private == false)].vlan-tags.upper-tag-id");
340 List<String> concat = new ArrayList<>(privateVlans);
341 concat.addAll(publicVlans);
342 Collection<String> guestVlans = new HashSet<>(concat);
344 if (!privateVlans.isEmpty()) {
345 paramsMap.put(privateVlansKey, Joiner.on(",").join(privateVlans));
347 if (!publicVlans.isEmpty()) {
348 paramsMap.put(publicVlansKey, Joiner.on(",").join(publicVlans));
350 if (!guestVlans.isEmpty()) {
351 paramsMap.put(guestVlansKey, Joiner.on(",").join(guestVlans));
355 private void buildVfModuleVmNames(Map<String,String> paramsMap, GenericResourceApiVmTopologyData vm, String key) {
357 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
358 if (vmNames != null) {
359 List<String> valueList = vmNames.getVmName();
360 if (valueList != null) {
361 for(int i = 0; i < valueList.size(); i++){
362 String value = valueList.get(i);
363 if (i != valueList.size() - 1) {
364 values += value + ",";
369 paramsMap.put(key + "_name_" + i, value);
371 paramsMap.put(key + "_names", values);
376 private void buildVfModuleFloatingIps(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
377 GenericResourceApiVmnetworkdataFloatingIps floatingIps = network.getFloatingIps();
378 if (floatingIps != null) {
379 List<String> floatingIpV4List = floatingIps.getFloatingIpV4();
380 if (floatingIpV4List != null) {
381 // add only one ipv4 floating ip for now
382 String floatingIPKey = key + UNDERSCORE + networkKey + FLOATING_IP;
383 String floatingIPKeyValue = floatingIpV4List.get(0);
384 if (floatingIPKeyValue != null && !floatingIPKeyValue.isEmpty()) {
385 paramsMap.put(floatingIPKey, floatingIPKeyValue);
388 // add only one ipv6 floating ip for now
389 List<String> floatingIpV6List = floatingIps.getFloatingIpV6();
390 if (floatingIpV6List != null) {
391 String floatingIPV6Key = key + UNDERSCORE + networkKey + FLOATING_V6_IP;
392 String floatingIPV6KeyValue = floatingIpV6List.get(0);
393 if (floatingIPV6KeyValue != null && !floatingIPV6KeyValue.isEmpty()) {
394 paramsMap.put(floatingIPV6Key, floatingIPV6KeyValue);
400 private void buildVfModuleInterfaceRoutePrefixes(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
401 GenericResourceApiVmnetworkdataInterfaceRoutePrefixes interfaceRoutePrefixes = network.getInterfaceRoutePrefixes();
402 if (interfaceRoutePrefixes != null) {
403 List<String> interfaceRoutePrefixesList = interfaceRoutePrefixes.getInterfaceRoutePrefix();
404 StringBuilder sbInterfaceRoutePrefixes = new StringBuilder();
405 sbInterfaceRoutePrefixes.append("[");
406 if (interfaceRoutePrefixesList != null) {
407 for(int a = 0; a < interfaceRoutePrefixesList.size(); a++){
408 String interfaceRoutePrefixValue = interfaceRoutePrefixesList.get(a);
409 if (a != interfaceRoutePrefixesList.size() - 1) {
410 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}" + ",");
413 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}");
416 sbInterfaceRoutePrefixes.append("]");
417 if (interfaceRoutePrefixesList.size() > 0) {
418 paramsMap.put(key + UNDERSCORE + networkKey + "_route_prefixes", sbInterfaceRoutePrefixes.toString());
424 private void buildVfModuleSriovParameters(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String networkKey) {
426 GenericResourceApiVmnetworkdataSriovParameters sriovParameters = network.getSriovParameters();
427 if (sriovParameters != null) {
428 GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters heatVlanFilters = sriovParameters.getHeatVlanFilters();
429 if (heatVlanFilters != null) {
430 List<String> heatVlanFiltersList = heatVlanFilters.getHeatVlanFilter();
431 StringBuilder sriovFilterBuf = new StringBuilder();
432 if (heatVlanFiltersList != null) {
433 for(int a = 0; a < heatVlanFiltersList.size(); a++){
434 String heatVlanFilterValue = heatVlanFiltersList.get(a);
435 if (a != heatVlanFiltersList.size() - 1) {
436 sriovFilterBuf.append(heatVlanFilterValue).append(",");
439 sriovFilterBuf.append(heatVlanFilterValue);
442 if (heatVlanFiltersList.size() > 0) {
443 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 if (!StringUtils.isEmpty(vfModule.getHeatStackId())){
785 deleteVfModuleRequest.setVfModuleStackId(vfModule.getHeatStackId());//DoDVfMod_heatStackId
788 deleteVfModuleRequest.setVfModuleStackId(vfModule.getVfModuleName());
791 deleteVfModuleRequest.setSkipAAI(true);
792 setIdAndUrl(deleteVfModuleRequest);
793 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
794 deleteVfModuleRequest.setMsoRequest(msoRequest);
795 return deleteVfModuleRequest;
798 protected void setIdAndUrl(DeleteVfModuleRequest deleteVfModuleRequest) throws UnsupportedEncodingException{
799 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
800 deleteVfModuleRequest.setMessageId(messageId);
801 deleteVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
804 private String convertToString(Object obj) {
807 json = mapper.writeValueAsString(obj);
808 } catch (JsonProcessingException e) {
815 private VfModule getBaseVfModule(GenericVnf genericVnf) {
816 List<VfModule> vfModules = genericVnf.getVfModules();
817 VfModule baseVfModule = null;
818 if (vfModules != null) {
819 for(int i = 0; i < vfModules.size(); i++) {
820 if (vfModules.get(i).getModelInfoVfModule().getIsBaseBoolean()) {
821 baseVfModule = vfModules.get(i);