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 org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
34 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
39 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
40 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
41 import org.onap.so.entity.MsoRequest;
42 import org.onap.so.jsonpath.JsonPathUtil;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.stereotype.Component;
46 import org.onap.sdnc.apps.client.model.GenericResourceApiParam;
47 import org.onap.sdnc.apps.client.model.GenericResourceApiParamParam;
48 import org.onap.sdnc.apps.client.model.GenericResourceApiSubInterfaceNetworkData;
49 import org.onap.sdnc.apps.client.model.GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData;
50 import org.onap.sdnc.apps.client.model.GenericResourceApiVfmoduleassignmentsVfModuleAssignments;
51 import org.onap.sdnc.apps.client.model.GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms;
52 import org.onap.sdnc.apps.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
53 import org.onap.sdnc.apps.client.model.GenericResourceApiVmNetworkData;
54 import org.onap.sdnc.apps.client.model.GenericResourceApiVmTopologyData;
55 import org.onap.sdnc.apps.client.model.GenericResourceApiVmnetworkdataFloatingIps;
56 import org.onap.sdnc.apps.client.model.GenericResourceApiVmnetworkdataInterfaceRoutePrefixes;
57 import org.onap.sdnc.apps.client.model.GenericResourceApiVmnetworkdataNetworkInformationItems;
58 import org.onap.sdnc.apps.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem;
59 import org.onap.sdnc.apps.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps;
60 import org.onap.sdnc.apps.client.model.GenericResourceApiVmnetworkdataSriovParameters;
61 import org.onap.sdnc.apps.client.model.GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters;
62 import org.onap.sdnc.apps.client.model.GenericResourceApiVmtopologydataVmNames;
63 import org.onap.sdnc.apps.client.model.GenericResourceApiVmtopologydataVmNetworks;
64 import org.onap.sdnc.apps.client.model.GenericResourceApiVmtopologydataVmnamesVnfcNames;
65 import org.onap.sdnc.apps.client.model.GenericResourceApiVnfNetworkData;
66 import org.onap.sdnc.apps.client.model.*;
68 import org.onap.sdnc.apps.client.model.GenericResourceApiVnfresourceassignmentsVnfResourceAssignments;
69 import org.onap.sdnc.apps.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones;
70 import org.onap.sdnc.apps.client.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks;
71 import org.onap.sdnc.apps.client.model.GenericResourceApiVnftopologyVnfTopology;
72 import com.fasterxml.jackson.core.JsonParseException;
73 import com.fasterxml.jackson.core.JsonProcessingException;
74 import com.fasterxml.jackson.databind.JsonMappingException;
75 import com.fasterxml.jackson.databind.ObjectMapper;
77 import jersey.repackaged.com.google.common.base.Joiner;
80 public class VnfAdapterVfModuleObjectMapper {
82 protected VnfAdapterObjectMapperUtils vnfAdapterObjectMapperUtils;
83 private static List<String> sdncResponseParamsToSkip = asList("vnf_id", "vf_module_id", "vnf_name", "vf_module_name");
85 private ObjectMapper mapper = new ObjectMapper();
86 private static final JsonPathUtil jsonPath = JsonPathUtil.getInstance();
87 private static final String SUB_INT = "subint";
88 private static final String SUBNET_ID = "_subnet_id";
89 private static final String V6_SUBNET_ID = "_v6_subnet_id";
90 private static final String PORT = "port";
91 private static final String SUB_INT_COUNT = "_subintcount";
92 private static final String VLAN_IDS = "_vlan_ids";
93 private static final String NET_NAMES = "_net_names";
94 private static final String NET_IDS = "_net_ids";
95 private static final String IP = "_ip";
96 private static final String V6_IP = "_v6_ip";
97 private static final String FLOATING_IP = "_floating_ip";
98 private static final String FLOATING_V6_IP = "_floating_v6_ip";
99 private static final String UNDERSCORE = "_";
101 public CreateVfModuleRequest createVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion, OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
102 VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
103 CreateVfModuleRequest createVfModuleRequest = new CreateVfModuleRequest();
105 createVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
106 createVfModuleRequest.setTenantId(cloudRegion.getTenantId());
107 createVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
108 createVfModuleRequest.setVfModuleName(vfModule.getVfModuleName());
109 createVfModuleRequest.setVnfType(genericVnf.getVnfType());
110 createVfModuleRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
111 createVfModuleRequest.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
112 createVfModuleRequest.setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
114 createVfModuleRequest.setVfModuleParams(buildVfModuleParamsMap(requestContext, serviceInstance, genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse));
116 createVfModuleRequest.setSkipAAI(true);
117 createVfModuleRequest.setBackout(orchestrationContext.getIsRollbackEnabled());
118 createVfModuleRequest.setFailIfExists(true);
120 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
121 createVfModuleRequest.setMsoRequest(msoRequest);
123 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
124 createVfModuleRequest.setMessageId(messageId);
125 createVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
127 return createVfModuleRequest;
130 private MsoRequest buildMsoRequest(RequestContext requestContext,ServiceInstance serviceInstance) {
131 MsoRequest msoRequest = new MsoRequest();
132 msoRequest.setRequestId(requestContext.getMsoRequestId());
133 msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
137 private Map<String,String> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
138 VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
139 GenericResourceApiVnftopologyVnfTopology vnfTopology = mapper.readValue(sdncVnfQueryResponse, GenericResourceApiVnftopologyVnfTopology.class);
140 GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = mapper.readValue(sdncVfModuleQueryResponse, GenericResourceApiVfmoduletopologyVfModuleTopology.class);
141 Map<String,String> paramsMap = new HashMap<>();
143 if(vnfTopology.getSdncGeneratedCloudResources() && vfModuleTopology.getSdncGeneratedCloudResources()) {
144 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, true);
145 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, null, true);
148 Map<String,String> networkRoleMap = buildNetworkRoleMap(vfModuleTopology);
149 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, false);
150 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, networkRoleMap, false);
153 buildMandatoryParamsMap(paramsMap, serviceInstance, genericVnf, vfModule);
155 // Parameters received from the request should overwrite any parameters received from SDNC
156 paramsMap.putAll(requestContext.getUserParams());
160 private void buildMandatoryParamsMap(Map<String,String> paramsMap, ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule) {
161 paramsMap.put("vnf_id", genericVnf.getVnfId());
162 paramsMap.put("vnf_name", genericVnf.getVnfName());
163 paramsMap.put("vf_module_id", vfModule.getVfModuleId());
164 paramsMap.put("vf_module_name", vfModule.getVfModuleName());
165 paramsMap.put("environment_context",serviceInstance.getModelInfoServiceInstance().getEnvironmentContext());
166 paramsMap.put("workload_context", serviceInstance.getModelInfoServiceInstance().getWorkloadContext());
167 Integer vfModuleIndex = vfModule.getModuleIndex();
168 if (vfModuleIndex != null) {
169 paramsMap.put("vf_module_index", vfModuleIndex.toString());
173 private void buildParamsMapFromVnfSdncResponse(Map<String,String> paramsMap, GenericResourceApiVnftopologyVnfTopology vnfTopology, Map<String,String> networkRoleMap, boolean skipVnfResourceAssignments) throws JsonParseException, JsonMappingException, IOException {
174 // Get VNF parameters from SDNC response
175 GenericResourceApiParam vnfParametersData = vnfTopology.getVnfParametersData();
176 buildParamsMapFromSdncParams(paramsMap, vnfParametersData);
178 if(!skipVnfResourceAssignments) {
179 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments = vnfTopology.getVnfResourceAssignments();
180 if (vnfResourceAssignments != null) {
181 // Availability Zones
182 buildAvailabilityZones(paramsMap, vnfResourceAssignments);
184 buildVnfNetworks(paramsMap, vnfResourceAssignments, networkRoleMap);
189 private void buildAvailabilityZones (Map<String,String> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments) {
190 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones availabilityZones = vnfResourceAssignments.getAvailabilityZones();
191 if (availabilityZones != null) {
192 List<String> availabilityZonesList = availabilityZones.getAvailabilityZone();
193 if (availabilityZonesList != null) {
194 for(int i = 0; i < availabilityZonesList.size(); i++) {
195 paramsMap.put("availability_zone_" + i, availabilityZonesList.get(i));
201 private void buildVnfNetworks (Map<String,String> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments, Map<String,String> networkRoleMap) {
202 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworks = vnfResourceAssignments.getVnfNetworks();
203 if (vnfNetworks != null) {
204 List<GenericResourceApiVnfNetworkData> vnfNetworksList = vnfNetworks.getVnfNetwork();
205 if (vnfNetworksList != null) {
206 for (int i = 0; i < vnfNetworksList.size(); i++) {
207 GenericResourceApiVnfNetworkData vnfNetwork = vnfNetworksList.get(i);
208 String networkRole = vnfNetwork.getNetworkRole();
209 String vnfNetworkKey = networkRoleMap.get(networkRole);
210 if (vnfNetworkKey == null || vnfNetworkKey.isEmpty()) {
211 vnfNetworkKey = networkRole;
214 String vnfNetworkNeutronIdValue = vnfNetwork.getNeutronId();
215 paramsMap.put(vnfNetworkKey + "_net_id", vnfNetworkNeutronIdValue);
216 String vnfNetworkNetNameValue = vnfNetwork.getNetworkName();
217 paramsMap.put(vnfNetworkKey + "_net_name", vnfNetworkNetNameValue);
218 String vnfNetworkNetFqdnValue = vnfNetwork.getContrailNetworkFqdn();
219 paramsMap.put(vnfNetworkKey + "_net_fqdn", vnfNetworkNetFqdnValue);
221 buildVnfNetworkSubnets(paramsMap, vnfNetwork, vnfNetworkKey);
228 private void buildVnfNetworkSubnets(Map<String,String> paramsMap, GenericResourceApiVnfNetworkData vnfNetwork, String vnfNetworkKey) {
229 String vnfNetworkString = convertToString(vnfNetwork);
230 Optional<String> ipv4Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv4' && @.dhcp-enabled == 'Y')].subnet-id");
231 if(ipv4Ips.isPresent())
232 addPairToMap(paramsMap, vnfNetworkKey, SUBNET_ID, ipv4Ips.get());
234 Optional<String> ipv6Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv6' && @.dhcp-enabled == 'Y')].subnet-id");
235 if(ipv6Ips.isPresent())
236 addPairToMap(paramsMap, vnfNetworkKey, V6_SUBNET_ID, ipv6Ips.get());
239 private void buildParamsMapFromVfModuleSdncResponse(Map<String,String> paramsMap, GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology, boolean skipVfModuleAssignments) throws JsonParseException, JsonMappingException, IOException {
240 // Get VF Module parameters from SDNC response
241 GenericResourceApiParam vfModuleParametersData = vfModuleTopology.getVfModuleParameters();
242 buildParamsMapFromSdncParams(paramsMap, vfModuleParametersData);
244 if(!skipVfModuleAssignments) {
245 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments = vfModuleTopology.getVfModuleAssignments();
246 if (vfModuleAssignments != null) {
248 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
250 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
251 if (vmsList != null) {
252 for (GenericResourceApiVmTopologyData vm : vmsList){
253 String key = vm.getVmType();
254 buildVfModuleVmNames(paramsMap, vm, key);
255 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
256 if (vmNetworks != null) {
257 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
258 if (vmNetworksList != null) {
259 for(int n = 0; n < vmNetworksList.size(); n++){
260 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
261 network.getNetworkRoleTag();
262 String networkKey = network.getNetworkRole();
264 buildVfModuleFloatingIps(paramsMap, network, key, networkKey);
265 // Interface Route Prefixes
266 buildVfModuleInterfaceRoutePrefixes(paramsMap, network, key, networkKey);
268 buildVfModuleSriovParameters(paramsMap, network, networkKey);
269 // IPV4 and IPV6 Addresses
270 buildVfModuleNetworkInformation(paramsMap, network, key, networkKey);
275 buildParamsMapFromVfModuleForHeatTemplate(paramsMap, vm);
283 private void buildVfModuleVmNames(Map<String,String> paramsMap, GenericResourceApiVmTopologyData vm, String key) {
285 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
286 if (vmNames != null) {
287 List<String> valueList = vmNames.getVmName();
288 if (valueList != null) {
289 for(int i = 0; i < valueList.size(); i++){
290 String value = valueList.get(i);
291 if (i != valueList.size() - 1) {
292 values += value + ",";
297 paramsMap.put(key + "_name_" + i, value);
299 paramsMap.put(key + "_names", values);
304 private void buildVfModuleFloatingIps(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
305 GenericResourceApiVmnetworkdataFloatingIps floatingIps = network.getFloatingIps();
306 if (floatingIps != null) {
307 List<String> floatingIpV4List = floatingIps.getFloatingIpV4();
308 if (floatingIpV4List != null) {
309 // add only one ipv4 floating ip for now
310 String floatingIPKey = key + UNDERSCORE + networkKey + FLOATING_IP;
311 String floatingIPKeyValue = floatingIpV4List.get(0);
312 if (floatingIPKeyValue != null && !floatingIPKeyValue.isEmpty()) {
313 paramsMap.put(floatingIPKey, floatingIPKeyValue);
316 // add only one ipv6 floating ip for now
317 List<String> floatingIpV6List = floatingIps.getFloatingIpV6();
318 if (floatingIpV6List != null) {
319 String floatingIPV6Key = key + UNDERSCORE + networkKey + FLOATING_V6_IP;
320 String floatingIPV6KeyValue = floatingIpV6List.get(0);
321 if (floatingIPV6KeyValue != null && !floatingIPV6KeyValue.isEmpty()) {
322 paramsMap.put(floatingIPV6Key, floatingIPV6KeyValue);
328 private void buildVfModuleInterfaceRoutePrefixes(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
329 GenericResourceApiVmnetworkdataInterfaceRoutePrefixes interfaceRoutePrefixes = network.getInterfaceRoutePrefixes();
330 if (interfaceRoutePrefixes != null) {
331 List<String> interfaceRoutePrefixesList = interfaceRoutePrefixes.getInterfaceRoutePrefix();
332 StringBuilder sbInterfaceRoutePrefixes = new StringBuilder();
333 sbInterfaceRoutePrefixes.append("[");
334 if (interfaceRoutePrefixesList != null) {
335 for(int a = 0; a < interfaceRoutePrefixesList.size(); a++){
336 String interfaceRoutePrefixValue = interfaceRoutePrefixesList.get(a);
337 if (a != interfaceRoutePrefixesList.size() - 1) {
338 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}" + ",");
341 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}");
344 sbInterfaceRoutePrefixes.append("]");
345 if (interfaceRoutePrefixesList.size() > 0) {
346 paramsMap.put(key + UNDERSCORE + networkKey + "_route_prefixes", sbInterfaceRoutePrefixes.toString());
352 private void buildVfModuleSriovParameters(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String networkKey) {
354 GenericResourceApiVmnetworkdataSriovParameters sriovParameters = network.getSriovParameters();
355 if (sriovParameters != null) {
356 GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters heatVlanFilters = sriovParameters.getHeatVlanFilters();
357 if (heatVlanFilters != null) {
358 List<String> heatVlanFiltersList = heatVlanFilters.getHeatVlanFilter();
359 StringBuilder sriovFilterBuf = new StringBuilder();
360 if (heatVlanFiltersList != null) {
361 for(int a = 0; a < heatVlanFiltersList.size(); a++){
362 String heatVlanFilterValue = heatVlanFiltersList.get(a);
363 if (a != heatVlanFiltersList.size() - 1) {
364 sriovFilterBuf.append(heatVlanFilterValue).append(",");
367 sriovFilterBuf.append(heatVlanFilterValue);
370 if (heatVlanFiltersList.size() > 0) {
371 paramsMap.put(networkKey + "_ATT_VF_VLAN_FILTER", sriovFilterBuf.toString());
378 private void buildVfModuleNetworkInformation(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
380 GenericResourceApiVmnetworkdataNetworkInformationItems networkInformationItems = network.getNetworkInformationItems();
381 StringBuilder sbIpv4Ips = new StringBuilder();
382 StringBuilder sbIpv6Ips = new StringBuilder();
384 if (networkInformationItems != null) {
385 List<GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem> networkInformationItemList = networkInformationItems.getNetworkInformationItem();
386 if (networkInformationItemList != null) {
387 for(int a = 0; a < networkInformationItemList.size(); a++){
388 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem ipAddress = networkInformationItemList.get(a);
389 if (ipAddress != null) {
390 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps ips = ipAddress.getNetworkIps();
392 List<String> ipsList = ips.getNetworkIp();
393 if (ipsList != null) {
394 String ipVersion = ipAddress.getIpVersion();
395 for (int b = 0; b < ipsList.size(); b++) {
396 String ipAddressValue = ipsList.get(b);
397 if (ipVersion.equals("ipv4")) {
398 if (b != ipsList.size() - 1) {
399 sbIpv4Ips.append(ipAddressValue + ",");
402 sbIpv4Ips.append(ipAddressValue);
404 paramsMap.put(key + UNDERSCORE + networkKey + IP + UNDERSCORE + b, ipAddressValue);
406 else if (ipVersion.equals("ipv6")) {
407 if (b != ipsList.size() - 1) {
408 sbIpv6Ips.append(ipAddressValue + ",");
411 sbIpv6Ips.append(ipAddressValue);
413 paramsMap.put(key + UNDERSCORE + networkKey + V6_IP + UNDERSCORE + b, ipAddressValue);
416 paramsMap.put(key + UNDERSCORE + networkKey + "_ips", sbIpv4Ips.toString());
417 paramsMap.put(key + UNDERSCORE + networkKey + "_v6_ips", sbIpv6Ips.toString());
427 * Build Mapping from GenericResourceApi SDNC for Heat Template so that AIC - PO gets accurate requests for vf module assignments.
428 * Build Count of SubInterfaces, VLAN Tag, network_name, network_id,
429 * ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6) for Heat Template
431 private void buildParamsMapFromVfModuleForHeatTemplate(Map<String,String> paramsMap, GenericResourceApiVmTopologyData vm) {
432 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
434 if (vmNames != null) {
436 List<GenericResourceApiVmtopologydataVmnamesVnfcNames> vnfcNamesList = vmNames.getVnfcNames();
437 if (vnfcNamesList != null) {
439 for(int i = 0; i < vnfcNamesList.size(); i++){
441 GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames = vnfcNamesList.get(i);
442 parseVnfcNamesData(paramsMap, vnfcNames);
449 * Parse vnfcNames data to build Mapping from GenericResourceApi SDNC for Heat Template.
451 private void parseVnfcNamesData(Map<String,String> paramsMap, GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames) {
453 if (vnfcNames != null) {
454 GenericResourceApiVnfcNetworkData vnfcNetworks = vnfcNames.getVnfcNetworks();
455 if (vnfcNetworks != null) {
456 List<GenericResourceApiVnfcnetworkdataVnfcNetworkData> vnfcNetworkdataList = vnfcNetworks.getVnfcNetworkData();
458 if (vnfcNetworkdataList != null) {
460 for(int networkDataIdx = 0; networkDataIdx < vnfcNetworkdataList.size(); networkDataIdx++){
462 GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata = vnfcNetworkdataList.get(networkDataIdx);
463 parseVnfcNetworkData(paramsMap, vnfcNetworkdata, networkDataIdx);
471 * Parse VnfcNetworkData to build Mapping from GenericResourceApi SDNC for Heat Template.
472 * Build Count of SubInterfaces, VLAN Tag, network_name, network_id,
473 * ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6) for Heat Template
475 private void parseVnfcNetworkData(Map<String,String> paramsMap, GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata, int networkDataIdx) {
477 String vmTypeKey = vnfcNetworkdata.getVnfcType();
478 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts vnfcPorts = vnfcNetworkdata.getVnfcPorts();
479 List<GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort> vnfcPortList = vnfcPorts.getVnfcPort();
480 if (vnfcPortList != null) {
481 for(int portIdx = 0; portIdx < vnfcPortList.size(); portIdx++){
483 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort vnfcPort = vnfcPortList.get(portIdx);
484 GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces = vnfcPort.getVnicSubInterfaces();
486 String vnicSubInterfacesString = convertToString(vnicSubInterfaces);
487 String networkRoleKey = vnfcPort.getCommonSubInterfaceRole();
488 String subInterfaceKey = createVnfcSubInterfaceKey(vmTypeKey, networkDataIdx, networkRoleKey, portIdx);
489 String globalSubInterfaceKey = createGlobalVnfcSubInterfaceKey(vmTypeKey, networkRoleKey, portIdx);
491 buildVfModuleSubInterfacesCount(paramsMap, globalSubInterfaceKey, vnicSubInterfaces);
493 buildVfModuleVlanTag(paramsMap, subInterfaceKey, vnicSubInterfacesString);
495 buildVfModuleNetworkName(paramsMap, subInterfaceKey, vnicSubInterfacesString);
497 buildVfModuleNetworkId(paramsMap, subInterfaceKey, vnicSubInterfacesString);
499 buildVfModuleIpV4AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
501 buildVfModuleIpV6AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
503 buildVfModuleFloatingIpV4HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
505 buildVfModuleFloatingIpV6HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
511 * Build "count" (calculating the total number of sub-interfaces) for Heat Template
512 * Building Criteria : {vm-type}_subint_{network-role}_port_{index}_subintcount
513 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
514 * Example: fw_subint_ctrl_port_0_subintcount
517 private void buildVfModuleSubInterfacesCount(Map<String,String> paramsMap, String keyPrefix, GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces) {
519 List<GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData> subInterfaceNetworkDataList = vnicSubInterfaces.getSubInterfaceNetworkData();
521 if ( (subInterfaceNetworkDataList != null) && !subInterfaceNetworkDataList.isEmpty() ) {
522 addPairToMap(paramsMap, keyPrefix, SUB_INT_COUNT, String.valueOf(subInterfaceNetworkDataList.size()));
526 protected String createVnfcSubInterfaceKey(String vmTypeKey, int networkDataIdx, String networkRoleKey, int portIdx) {
528 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, networkDataIdx, SUB_INT, networkRoleKey, PORT, portIdx));
531 protected String createGlobalVnfcSubInterfaceKey(String vmTypeKey,String networkRoleKey, int portIdx) {
533 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, SUB_INT, networkRoleKey, PORT, portIdx));
537 * Build VLAN Tag for Heat Template
538 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_vlan_ids
539 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
540 * Example: fw_0_subint_ctrl_port_0_vlan_ids
543 protected void buildVfModuleVlanTag(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
545 List<String> vlanTagIds = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].vlan-tag-id");
547 addPairToMap(paramsMap, keyPrefix, VLAN_IDS, vlanTagIds);
550 * Build "network_name" for Heat Template
551 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_net_names
552 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
553 * Example: fw_0_subint_ctrl_port_0_net_names
556 protected void buildVfModuleNetworkName(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
558 List<String> neworkNames = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-name");
560 addPairToMap(paramsMap, keyPrefix, NET_NAMES, neworkNames);
564 * Build "network_id" for Heat Template
565 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_net_ids
566 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
567 * Example: fw_0_subint_ctrl_port_0_net_ids
570 protected void buildVfModuleNetworkId(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
572 List<String> neworkIds = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-id");
574 addPairToMap(paramsMap, keyPrefix, NET_IDS, neworkIds);
578 * Build ip_address for V4 for Heat Template
579 * Building Criteria :
580 * {vm-type}_{index}_subint_{network-role}_port_{index}_ip_{index} -- for ipV4
581 * key = vm-type, networkRoleKey = NetWork-Role
583 protected void buildVfModuleIpV4AddressHeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
585 List<String> ipv4Ips = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv4')].network-ips.network-ip[*]");
587 addPairToMap(paramsMap, keyPrefix, IP, ipv4Ips);
589 for (int i = 0; i < ipv4Ips.size(); i++) {
590 addPairToMap(paramsMap, keyPrefix, IP + UNDERSCORE + i, ipv4Ips.get(i));
596 * Build ip_address for Heat Template
597 * Building Criteria :
598 * {vm-type}_{index}_subint_{network-role}_port_{index}_v6_ip_{index} -- for ipV6
599 * key = vm-type, networkRoleKey = NetWork-Role
601 protected void buildVfModuleIpV6AddressHeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
603 List<String> ipv6Ips = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv6')].network-ips.network-ip[*]");
605 addPairToMap(paramsMap, keyPrefix, V6_IP, ipv6Ips);
607 for (int i = 0; i < ipv6Ips.size(); i++) {
608 addPairToMap(paramsMap, keyPrefix, V6_IP + UNDERSCORE + i, ipv6Ips.get(i));
613 * Build floatingip_address for Heat Template
614 * Building Criteria :
615 * {vm-type}_subint_{network-role}_port_{index}_floating_ip -- for ipV4
617 protected void buildVfModuleFloatingIpV4HeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
619 List<String> floatingV4 = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].floating-ips.floating-ip-v4[*]");
621 if (!floatingV4.isEmpty()) {
622 floatingV4 = Collections.singletonList(floatingV4.get(0));
624 addPairToMap(paramsMap, keyPrefix, FLOATING_IP, floatingV4);
629 * Build floatingip_address for Heat Template
630 * Building Criteria :
631 * {vm-type}_subint_{network-role}_port_{index}_floating_v6_ip -- for ipV6
633 protected void buildVfModuleFloatingIpV6HeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
635 List<String> floatingV6 = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].floating-ips.floating-ip-v6[*]");
637 if (!floatingV6.isEmpty()) {
638 floatingV6 = Collections.singletonList(floatingV6.get(0));
640 addPairToMap(paramsMap, keyPrefix, FLOATING_V6_IP, floatingV6);
643 protected void addPairToMap(Map<String, String> paramsMap, String keyPrefix, String key, String value) {
645 addPairToMap(paramsMap, keyPrefix, key, Collections.singletonList(value));
648 protected void addPairToMap(Map<String, String> paramsMap, String keyPrefix, String key, List<String> value) {
650 if (!value.isEmpty()) {
651 paramsMap.put(keyPrefix + key, Joiner.on(",").join(value));
655 private void buildParamsMapFromSdncParams(Map<String,String> paramsMap, GenericResourceApiParam parametersData) {
656 if (parametersData != null) {
657 List<GenericResourceApiParamParam> paramsList = parametersData.getParam();
658 if (paramsList != null) {
659 for (int i = 0; i < paramsList.size(); i++) {
660 GenericResourceApiParamParam param = paramsList.get(i);
661 String parameterName = param.getName();
662 if (!sdncResponseParamsToSkip.contains(parameterName)) {
663 String parameterValue = param.getValue();
664 paramsMap.put(parameterName, parameterValue);
671 private Map<String,String> buildNetworkRoleMap(GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology) throws JsonParseException, JsonMappingException, IOException {
672 Map<String, String> networkRoleMap = new HashMap<>();
673 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments = vfModuleTopology.getVfModuleAssignments();
674 if (vfModuleAssignments != null) {
675 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
677 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
678 if (vmsList != null) {
679 for (GenericResourceApiVmTopologyData vm : vmsList){
680 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
681 if (vmNetworks != null) {
682 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
683 if (vmNetworksList != null) {
684 for(int n = 0; n < vmNetworksList.size(); n++){
685 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
686 String networkRole = network.getNetworkRole();
687 String networkRoleValue = network.getNetworkRoleTag();
688 if (networkRoleValue == null || networkRoleValue.isEmpty()) {
689 networkRoleValue = networkRole;
691 networkRoleMap.put(networkRole, networkRoleValue);
699 return networkRoleMap;
702 public DeleteVfModuleRequest deleteVfModuleRequestMapper(RequestContext requestContext,CloudRegion cloudRegion,
703 ServiceInstance serviceInstance, GenericVnf genericVnf,
704 VfModule vfModule) throws IOException {
705 DeleteVfModuleRequest deleteVfModuleRequest = new DeleteVfModuleRequest();
706 deleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
707 deleteVfModuleRequest.setTenantId(cloudRegion.getTenantId());
708 deleteVfModuleRequest.setVnfId(genericVnf.getVnfId());
709 deleteVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
710 deleteVfModuleRequest.setVfModuleStackId(vfModule.getHeatStackId());//DoDVfMod_heatStackId
711 deleteVfModuleRequest.setSkipAAI(true);
712 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
713 deleteVfModuleRequest.setMessageId(messageId);
714 deleteVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
715 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
716 deleteVfModuleRequest.setMsoRequest(msoRequest);
717 return deleteVfModuleRequest;
720 private String convertToString(Object obj) {
723 json = mapper.writeValueAsString(obj);
724 } catch (JsonProcessingException e) {