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.northbound.client.model.GenericResourceApiParam;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubInterfaceNetworkData;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfModuleAssignments;
51 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms;
52 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
53 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmNetworkData;
54 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmTopologyData;
55 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataFloatingIps;
56 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataInterfaceRoutePrefixes;
57 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkInformationItems;
58 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem;
59 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps;
60 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNames;
61 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmNetworks;
62 import org.onap.sdnc.northbound.client.model.GenericResourceApiVmtopologydataVmnamesVnfcNames;
63 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfNetworkData;
64 import org.onap.sdnc.northbound.client.model.*;
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 com.fasterxml.jackson.core.JsonParseException;
71 import com.fasterxml.jackson.core.JsonProcessingException;
72 import com.fasterxml.jackson.databind.JsonMappingException;
73 import com.fasterxml.jackson.databind.ObjectMapper;
75 import jersey.repackaged.com.google.common.base.Joiner;
78 public class VnfAdapterVfModuleObjectMapper {
80 protected VnfAdapterObjectMapperUtils vnfAdapterObjectMapperUtils;
81 private static List<String> sdncResponseParamsToSkip = asList("vnf_id", "vf_module_id", "vnf_name", "vf_module_name");
83 private ObjectMapper mapper = new ObjectMapper();
84 private static final JsonPathUtil jsonPath = JsonPathUtil.getInstance();
85 private static final String SUB_INT = "subint";
86 private static final String SUBNET_ID = "_subnet_id";
87 private static final String V6_SUBNET_ID = "_v6_subnet_id";
88 private static final String PORT = "port";
89 private static final String SUB_INT_COUNT = "_subintcount";
90 private static final String VLAN_IDS = "_vlan_ids";
91 private static final String NET_NAMES = "_net_names";
92 private static final String NET_IDS = "_net_ids";
93 private static final String IP = "_ip";
94 private static final String V6_IP = "_v6_ip";
95 private static final String FLOATING_IP = "_floating_ip";
96 private static final String FLOATING_V6_IP = "_floating_v6_ip";
97 private static final String UNDERSCORE = "_";
99 public CreateVfModuleRequest createVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion, OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
100 VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
101 CreateVfModuleRequest createVfModuleRequest = new CreateVfModuleRequest();
103 createVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
104 createVfModuleRequest.setTenantId(cloudRegion.getTenantId());
105 createVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
106 createVfModuleRequest.setVfModuleName(vfModule.getVfModuleName());
107 createVfModuleRequest.setVnfType(genericVnf.getVnfType());
108 createVfModuleRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
109 createVfModuleRequest.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
110 createVfModuleRequest.setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
112 createVfModuleRequest.setVfModuleParams(buildVfModuleParamsMap(requestContext, serviceInstance, genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse));
114 createVfModuleRequest.setSkipAAI(true);
115 createVfModuleRequest.setBackout(orchestrationContext.getIsRollbackEnabled());
116 createVfModuleRequest.setFailIfExists(true);
118 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
119 createVfModuleRequest.setMsoRequest(msoRequest);
121 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
122 createVfModuleRequest.setMessageId(messageId);
123 createVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
125 return createVfModuleRequest;
128 private MsoRequest buildMsoRequest(RequestContext requestContext,ServiceInstance serviceInstance) {
129 MsoRequest msoRequest = new MsoRequest();
130 msoRequest.setRequestId(requestContext.getMsoRequestId());
131 msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
135 private Map<String,String> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
136 VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
137 GenericResourceApiVnftopologyVnfTopology vnfTopology = mapper.readValue(sdncVnfQueryResponse, GenericResourceApiVnftopologyVnfTopology.class);
138 GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = mapper.readValue(sdncVfModuleQueryResponse, GenericResourceApiVfmoduletopologyVfModuleTopology.class);
139 Map<String,String> paramsMap = new HashMap<>();
141 if(vnfTopology.getSdncGeneratedCloudResources() && vfModuleTopology.getSdncGeneratedCloudResources()) {
142 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, true);
143 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, null, true);
146 Map<String,String> networkRoleMap = buildNetworkRoleMap(vfModuleTopology);
147 buildParamsMapFromVfModuleSdncResponse(paramsMap, vfModuleTopology, false);
148 buildParamsMapFromVnfSdncResponse(paramsMap, vnfTopology, networkRoleMap, false);
151 buildMandatoryParamsMap(paramsMap, serviceInstance, genericVnf, vfModule);
153 // Parameters received from the request should overwrite any parameters received from SDNC
154 paramsMap.putAll(requestContext.getUserParams());
158 private void buildMandatoryParamsMap(Map<String,String> paramsMap, ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule) {
159 paramsMap.put("vnf_id", genericVnf.getVnfId());
160 paramsMap.put("vnf_name", genericVnf.getVnfName());
161 paramsMap.put("vf_module_id", vfModule.getVfModuleId());
162 paramsMap.put("vf_module_name", vfModule.getVfModuleName());
163 paramsMap.put("environment_context",serviceInstance.getModelInfoServiceInstance().getEnvironmentContext());
164 paramsMap.put("workload_context", serviceInstance.getModelInfoServiceInstance().getWorkloadContext());
165 Integer vfModuleIndex = vfModule.getModuleIndex();
166 if (vfModuleIndex != null) {
167 paramsMap.put("vf_module_index", vfModuleIndex.toString());
171 private void buildParamsMapFromVnfSdncResponse(Map<String,String> paramsMap, GenericResourceApiVnftopologyVnfTopology vnfTopology, Map<String,String> networkRoleMap, boolean skipVnfResourceAssignments) throws JsonParseException, JsonMappingException, IOException {
172 // Get VNF parameters from SDNC response
173 GenericResourceApiParam vnfParametersData = vnfTopology.getVnfParametersData();
174 buildParamsMapFromSdncParams(paramsMap, vnfParametersData);
176 if(!skipVnfResourceAssignments) {
177 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments = vnfTopology.getVnfResourceAssignments();
178 if (vnfResourceAssignments != null) {
179 // Availability Zones
180 buildAvailabilityZones(paramsMap, vnfResourceAssignments);
182 buildVnfNetworks(paramsMap, vnfResourceAssignments, networkRoleMap);
187 private void buildAvailabilityZones (Map<String,String> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments) {
188 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsAvailabilityZones availabilityZones = vnfResourceAssignments.getAvailabilityZones();
189 if (availabilityZones != null) {
190 List<String> availabilityZonesList = availabilityZones.getAvailabilityZone();
191 if (availabilityZonesList != null) {
192 for(int i = 0; i < availabilityZonesList.size(); i++) {
193 paramsMap.put("availability_zone_" + i, availabilityZonesList.get(i));
199 private void buildVnfNetworks (Map<String,String> paramsMap, GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments, Map<String,String> networkRoleMap) {
200 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworks = vnfResourceAssignments.getVnfNetworks();
201 if (vnfNetworks != null) {
202 List<GenericResourceApiVnfNetworkData> vnfNetworksList = vnfNetworks.getVnfNetwork();
203 if (vnfNetworksList != null) {
204 for (int i = 0; i < vnfNetworksList.size(); i++) {
205 GenericResourceApiVnfNetworkData vnfNetwork = vnfNetworksList.get(i);
206 String networkRole = vnfNetwork.getNetworkRole();
207 String vnfNetworkKey = networkRoleMap.get(networkRole);
208 if (vnfNetworkKey == null || vnfNetworkKey.isEmpty()) {
209 vnfNetworkKey = networkRole;
212 String vnfNetworkNeutronIdValue = vnfNetwork.getNeutronId();
213 paramsMap.put(vnfNetworkKey + "_net_id", vnfNetworkNeutronIdValue);
214 String vnfNetworkNetNameValue = vnfNetwork.getNetworkName();
215 paramsMap.put(vnfNetworkKey + "_net_name", vnfNetworkNetNameValue);
216 String vnfNetworkNetFqdnValue = vnfNetwork.getContrailNetworkFqdn();
217 paramsMap.put(vnfNetworkKey + "_net_fqdn", vnfNetworkNetFqdnValue);
219 buildVnfNetworkSubnets(paramsMap, vnfNetwork, vnfNetworkKey);
226 private void buildVnfNetworkSubnets(Map<String,String> paramsMap, GenericResourceApiVnfNetworkData vnfNetwork, String vnfNetworkKey) {
227 String vnfNetworkString = convertToString(vnfNetwork);
228 Optional<String> ipv4Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv4' && @.dhcp-enabled == 'Y')].subnet-id");
229 if(ipv4Ips.isPresent())
230 addPairToMap(paramsMap, vnfNetworkKey, SUBNET_ID, ipv4Ips.get());
232 Optional<String> ipv6Ips = jsonPath.locateResult(vnfNetworkString, "$.subnets-data.subnet-data[*].[?(@.ip-version == 'ipv6' && @.dhcp-enabled == 'Y')].subnet-id");
233 if(ipv6Ips.isPresent())
234 addPairToMap(paramsMap, vnfNetworkKey, V6_SUBNET_ID, ipv6Ips.get());
237 private void buildParamsMapFromVfModuleSdncResponse(Map<String,String> paramsMap, GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology, boolean skipVfModuleAssignments) throws JsonParseException, JsonMappingException, IOException {
238 // Get VF Module parameters from SDNC response
239 GenericResourceApiParam vfModuleParametersData = vfModuleTopology.getVfModuleParameters();
240 buildParamsMapFromSdncParams(paramsMap, vfModuleParametersData);
242 if(!skipVfModuleAssignments) {
243 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments = vfModuleTopology.getVfModuleAssignments();
244 if (vfModuleAssignments != null) {
246 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
248 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
249 if (vmsList != null) {
250 for (GenericResourceApiVmTopologyData vm : vmsList){
251 String key = vm.getVmType();
252 buildVfModuleVmNames(paramsMap, vm, key);
253 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
254 if (vmNetworks != null) {
255 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
256 if (vmNetworksList != null) {
257 for(int n = 0; n < vmNetworksList.size(); n++){
258 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
259 network.getNetworkRoleTag();
260 String networkKey = network.getNetworkRole();
262 buildVfModuleFloatingIps(paramsMap, network, key, networkKey);
263 // Interface Route Prefixes
264 buildVfModuleInterfaceRoutePrefixes(paramsMap, network, key, networkKey);
266 buildVfModuleSriovParameters(paramsMap, network, networkKey);
267 // IPV4 and IPV6 Addresses
268 buildVfModuleNetworkInformation(paramsMap, network, key, networkKey);
273 buildParamsMapFromVfModuleForHeatTemplate(paramsMap, vm);
281 private void buildVfModuleVmNames(Map<String,String> paramsMap, GenericResourceApiVmTopologyData vm, String key) {
283 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
284 if (vmNames != null) {
285 List<String> valueList = vmNames.getVmName();
286 if (valueList != null) {
287 for(int i = 0; i < valueList.size(); i++){
288 String value = valueList.get(i);
289 if (i != valueList.size() - 1) {
290 values += value + ",";
295 paramsMap.put(key + "_name_" + i, value);
297 paramsMap.put(key + "_names", values);
302 private void buildVfModuleFloatingIps(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
303 GenericResourceApiVmnetworkdataFloatingIps floatingIps = network.getFloatingIps();
304 if (floatingIps != null) {
305 List<String> floatingIpV4List = floatingIps.getFloatingIpV4();
306 if (floatingIpV4List != null) {
307 // add only one ipv4 floating ip for now
308 String floatingIPKey = key + UNDERSCORE + networkKey + FLOATING_IP;
309 String floatingIPKeyValue = floatingIpV4List.get(0);
310 if (floatingIPKeyValue != null && !floatingIPKeyValue.isEmpty()) {
311 paramsMap.put(floatingIPKey, floatingIPKeyValue);
314 // add only one ipv6 floating ip for now
315 List<String> floatingIpV6List = floatingIps.getFloatingIpV6();
316 if (floatingIpV6List != null) {
317 String floatingIPV6Key = key + UNDERSCORE + networkKey + FLOATING_V6_IP;
318 String floatingIPV6KeyValue = floatingIpV6List.get(0);
319 if (floatingIPV6KeyValue != null && !floatingIPV6KeyValue.isEmpty()) {
320 paramsMap.put(floatingIPV6Key, floatingIPV6KeyValue);
326 private void buildVfModuleInterfaceRoutePrefixes(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
327 GenericResourceApiVmnetworkdataInterfaceRoutePrefixes interfaceRoutePrefixes = network.getInterfaceRoutePrefixes();
328 if (interfaceRoutePrefixes != null) {
329 List<String> interfaceRoutePrefixesList = interfaceRoutePrefixes.getInterfaceRoutePrefix();
330 StringBuilder sbInterfaceRoutePrefixes = new StringBuilder();
331 sbInterfaceRoutePrefixes.append("[");
332 if (interfaceRoutePrefixesList != null) {
333 for(int a = 0; a < interfaceRoutePrefixesList.size(); a++){
334 String interfaceRoutePrefixValue = interfaceRoutePrefixesList.get(a);
335 if (a != interfaceRoutePrefixesList.size() - 1) {
336 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}" + ",");
339 sbInterfaceRoutePrefixes.append("{\"interface_route_table_routes_route_prefix\": \"" + interfaceRoutePrefixValue + "\"}");
342 sbInterfaceRoutePrefixes.append("]");
343 if (interfaceRoutePrefixesList.size() > 0) {
344 paramsMap.put(key + UNDERSCORE + networkKey + "_route_prefixes", sbInterfaceRoutePrefixes.toString());
350 private void buildVfModuleSriovParameters(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String networkKey) {
352 GenericResourceApiVmnetworkdataSriovParameters sriovParameters = network.getSriovParameters();
353 if (sriovParameters != null) {
354 GenericResourceApiVmnetworkdataSriovparametersHeatVlanFilters heatVlanFilters = sriovParameters.getHeatVlanFilters();
355 if (heatVlanFilters != null) {
356 List<String> heatVlanFiltersList = heatVlanFilters.getHeatVlanFilter();
357 StringBuilder sriovFilterBuf = new StringBuilder();
358 if (heatVlanFiltersList != null) {
359 for(int a = 0; a < heatVlanFiltersList.size(); a++){
360 String heatVlanFilterValue = heatVlanFiltersList.get(a);
361 if (a != heatVlanFiltersList.size() - 1) {
362 sriovFilterBuf.append(heatVlanFilterValue).append(",");
365 sriovFilterBuf.append(heatVlanFilterValue);
368 if (heatVlanFiltersList.size() > 0) {
369 paramsMap.put(networkKey + "_ATT_VF_VLAN_FILTER", sriovFilterBuf.toString());
377 private void buildVfModuleNetworkInformation(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) {
379 GenericResourceApiVmnetworkdataNetworkInformationItems networkInformationItems = network.getNetworkInformationItems();
380 StringBuilder sbIpv4Ips = new StringBuilder();
381 StringBuilder sbIpv6Ips = new StringBuilder();
383 if (networkInformationItems != null) {
384 List<GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem> networkInformationItemList = networkInformationItems.getNetworkInformationItem();
385 if (networkInformationItemList != null) {
386 for(int a = 0; a < networkInformationItemList.size(); a++){
387 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkInformationItem ipAddress = networkInformationItemList.get(a);
388 if (ipAddress != null) {
389 GenericResourceApiVmnetworkdataNetworkinformationitemsNetworkinformationitemNetworkIps ips = ipAddress.getNetworkIps();
391 List<String> ipsList = ips.getNetworkIp();
392 if (ipsList != null) {
393 String ipVersion = ipAddress.getIpVersion();
394 for (int b = 0; b < ipsList.size(); b++) {
395 String ipAddressValue = ipsList.get(b);
396 if (ipVersion.equals("ipv4")) {
397 if (b != ipsList.size() - 1) {
398 sbIpv4Ips.append(ipAddressValue + ",");
401 sbIpv4Ips.append(ipAddressValue);
403 paramsMap.put(key + UNDERSCORE + networkKey + IP + UNDERSCORE + b, ipAddressValue);
405 else if (ipVersion.equals("ipv6")) {
406 if (b != ipsList.size() - 1) {
407 sbIpv6Ips.append(ipAddressValue + ",");
410 sbIpv6Ips.append(ipAddressValue);
412 paramsMap.put(key + UNDERSCORE + networkKey + V6_IP + UNDERSCORE + b, ipAddressValue);
415 paramsMap.put(key + UNDERSCORE + networkKey + "_ips", sbIpv4Ips.toString());
416 paramsMap.put(key + UNDERSCORE + networkKey + "_v6_ips", sbIpv6Ips.toString());
426 * Build Mapping from GenericResourceApi SDNC for Heat Template so that AIC - PO gets accurate requests for vf module assignments.
427 * Build Count of SubInterfaces, VLAN Tag, network_name, network_id,
428 * ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6) for Heat Template
430 private void buildParamsMapFromVfModuleForHeatTemplate(Map<String,String> paramsMap, GenericResourceApiVmTopologyData vm) {
431 GenericResourceApiVmtopologydataVmNames vmNames = vm.getVmNames();
433 if (vmNames != null) {
435 List<GenericResourceApiVmtopologydataVmnamesVnfcNames> vnfcNamesList = vmNames.getVnfcNames();
436 if (vnfcNamesList != null) {
438 for(int i = 0; i < vnfcNamesList.size(); i++){
440 GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames = vnfcNamesList.get(i);
441 parseVnfcNamesData(paramsMap, vnfcNames);
448 * Parse vnfcNames data to build Mapping from GenericResourceApi SDNC for Heat Template.
450 private void parseVnfcNamesData(Map<String,String> paramsMap, GenericResourceApiVmtopologydataVmnamesVnfcNames vnfcNames) {
452 if (vnfcNames != null) {
453 GenericResourceApiVnfcNetworkData vnfcNetworks = vnfcNames.getVnfcNetworks();
454 if (vnfcNetworks != null) {
455 List<GenericResourceApiVnfcnetworkdataVnfcNetworkData> vnfcNetworkdataList = vnfcNetworks.getVnfcNetworkData();
457 if (vnfcNetworkdataList != null) {
459 for(int networkDataIdx = 0; networkDataIdx < vnfcNetworkdataList.size(); networkDataIdx++){
461 GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata = vnfcNetworkdataList.get(networkDataIdx);
462 parseVnfcNetworkData(paramsMap, vnfcNetworkdata, networkDataIdx);
470 * Parse VnfcNetworkData to build Mapping from GenericResourceApi SDNC for Heat Template.
471 * Build Count of SubInterfaces, VLAN Tag, network_name, network_id,
472 * ip_address (V4 and V6) and Floating IPs Addresses (V4 and V6) for Heat Template
474 private void parseVnfcNetworkData(Map<String,String> paramsMap, GenericResourceApiVnfcnetworkdataVnfcNetworkData vnfcNetworkdata, int networkDataIdx) {
476 String vmTypeKey = vnfcNetworkdata.getVnfcType();
477 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcPorts vnfcPorts = vnfcNetworkdata.getVnfcPorts();
478 List<GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort> vnfcPortList = vnfcPorts.getVnfcPort();
479 if (vnfcPortList != null) {
480 for(int portIdx = 0; portIdx < vnfcPortList.size(); portIdx++){
482 GenericResourceApiVnfcnetworkdataVnfcnetworkdataVnfcportsVnfcPort vnfcPort = vnfcPortList.get(portIdx);
483 GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces = vnfcPort.getVnicSubInterfaces();
485 String vnicSubInterfacesString = convertToString(vnicSubInterfaces);
486 String networkRoleKey = vnfcPort.getCommonSubInterfaceRole();
487 String subInterfaceKey = createVnfcSubInterfaceKey(vmTypeKey, networkDataIdx, networkRoleKey, portIdx);
488 String globalSubInterfaceKey = createGlobalVnfcSubInterfaceKey(vmTypeKey, networkRoleKey, portIdx);
490 buildVfModuleSubInterfacesCount(paramsMap, globalSubInterfaceKey, vnicSubInterfaces);
492 buildVfModuleVlanTag(paramsMap, subInterfaceKey, vnicSubInterfacesString);
494 buildVfModuleNetworkName(paramsMap, subInterfaceKey, vnicSubInterfacesString);
496 buildVfModuleNetworkId(paramsMap, subInterfaceKey, vnicSubInterfacesString);
498 buildVfModuleIpV4AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
500 buildVfModuleIpV6AddressHeatTemplate(paramsMap, subInterfaceKey, vnicSubInterfacesString);
502 buildVfModuleFloatingIpV4HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
504 buildVfModuleFloatingIpV6HeatTemplate(paramsMap, globalSubInterfaceKey, vnicSubInterfacesString);
510 * Build "count" (calculating the total number of sub-interfaces) for Heat Template
511 * Building Criteria : {vm-type}_subint_{network-role}_port_{index}_subintcount
512 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
513 * Example: fw_subint_ctrl_port_0_subintcount
516 private void buildVfModuleSubInterfacesCount(Map<String,String> paramsMap, String keyPrefix, GenericResourceApiSubInterfaceNetworkData vnicSubInterfaces) {
518 List<GenericResourceApiSubinterfacenetworkdataSubInterfaceNetworkData> subInterfaceNetworkDataList = vnicSubInterfaces.getSubInterfaceNetworkData();
520 if ( (subInterfaceNetworkDataList != null) && !subInterfaceNetworkDataList.isEmpty() ) {
521 addPairToMap(paramsMap, keyPrefix, SUB_INT_COUNT, String.valueOf(subInterfaceNetworkDataList.size()));
525 protected String createVnfcSubInterfaceKey(String vmTypeKey, int networkDataIdx, String networkRoleKey, int portIdx) {
527 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, networkDataIdx, SUB_INT, networkRoleKey, PORT, portIdx));
530 protected String createGlobalVnfcSubInterfaceKey(String vmTypeKey,String networkRoleKey, int portIdx) {
532 return Joiner.on(UNDERSCORE).join(Arrays.asList(vmTypeKey, SUB_INT, networkRoleKey, PORT, portIdx));
536 * Build VLAN Tag for Heat Template
537 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_vlan_ids
538 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
539 * Example: fw_0_subint_ctrl_port_0_vlan_ids
542 protected void buildVfModuleVlanTag(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
544 List<String> vlanTagIds = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].vlan-tag-id");
546 addPairToMap(paramsMap, keyPrefix, VLAN_IDS, vlanTagIds);
549 * Build "network_name" for Heat Template
550 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_net_names
551 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
552 * Example: fw_0_subint_ctrl_port_0_net_names
555 protected void buildVfModuleNetworkName(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
557 List<String> neworkNames = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-name");
559 addPairToMap(paramsMap, keyPrefix, NET_NAMES, neworkNames);
563 * Build "network_id" for Heat Template
564 * Building Criteria : {vm-type}_{index}_subint_{network-role}_port_{index}_net_ids
565 * vmTypeKey = vm-type, networkRoleKey = common-sub-interface-role
566 * Example: fw_0_subint_ctrl_port_0_net_ids
569 protected void buildVfModuleNetworkId(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
571 List<String> neworkIds = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-id");
573 addPairToMap(paramsMap, keyPrefix, NET_IDS, neworkIds);
577 * Build ip_address for V4 for Heat Template
578 * Building Criteria :
579 * {vm-type}_{index}_subint_{network-role}_port_{index}_ip_{index} -- for ipV4
580 * key = vm-type, networkRoleKey = NetWork-Role
582 protected void buildVfModuleIpV4AddressHeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
584 List<String> ipv4Ips = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv4')].network-ips.network-ip[*]");
586 addPairToMap(paramsMap, keyPrefix, IP, ipv4Ips);
588 for (int i = 0; i < ipv4Ips.size(); i++) {
589 addPairToMap(paramsMap, keyPrefix, IP + UNDERSCORE + i, ipv4Ips.get(i));
595 * Build ip_address for Heat Template
596 * Building Criteria :
597 * {vm-type}_{index}_subint_{network-role}_port_{index}_v6_ip_{index} -- for ipV6
598 * key = vm-type, networkRoleKey = NetWork-Role
600 protected void buildVfModuleIpV6AddressHeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
602 List<String> ipv6Ips = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].network-information-items.network-information-item[?(@.ip-version == 'ipv6')].network-ips.network-ip[*]");
604 addPairToMap(paramsMap, keyPrefix, V6_IP, ipv6Ips);
606 for (int i = 0; i < ipv6Ips.size(); i++) {
607 addPairToMap(paramsMap, keyPrefix, V6_IP + UNDERSCORE + i, ipv6Ips.get(i));
612 * Build floatingip_address for Heat Template
613 * Building Criteria :
614 * {vm-type}_subint_{network-role}_port_{index}_floating_ip -- for ipV4
616 protected void buildVfModuleFloatingIpV4HeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
618 List<String> floatingV4 = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].floating-ips.floating-ip-v4[*]");
620 if (!floatingV4.isEmpty()) {
621 floatingV4 = Collections.singletonList(floatingV4.get(0));
623 addPairToMap(paramsMap, keyPrefix, FLOATING_IP, floatingV4);
628 * Build floatingip_address for Heat Template
629 * Building Criteria :
630 * {vm-type}_subint_{network-role}_port_{index}_floating_v6_ip -- for ipV6
632 protected void buildVfModuleFloatingIpV6HeatTemplate(Map<String,String> paramsMap, String keyPrefix, String vnicSubInterfaces) {
634 List<String> floatingV6 = jsonPath.locateResultList(vnicSubInterfaces, "$.sub-interface-network-data[*].floating-ips.floating-ip-v6[*]");
636 if (!floatingV6.isEmpty()) {
637 floatingV6 = Collections.singletonList(floatingV6.get(0));
639 addPairToMap(paramsMap, keyPrefix, FLOATING_V6_IP, floatingV6);
642 protected void addPairToMap(Map<String, String> paramsMap, String keyPrefix, String key, String value) {
644 addPairToMap(paramsMap, keyPrefix, key, Collections.singletonList(value));
647 protected void addPairToMap(Map<String, String> paramsMap, String keyPrefix, String key, List<String> value) {
649 if (!value.isEmpty()) {
650 paramsMap.put(keyPrefix + key, Joiner.on(",").join(value));
654 private void buildParamsMapFromSdncParams(Map<String,String> paramsMap, GenericResourceApiParam parametersData) {
655 if (parametersData != null) {
656 List<GenericResourceApiParamParam> paramsList = parametersData.getParam();
657 if (paramsList != null) {
658 for (int i = 0; i < paramsList.size(); i++) {
659 GenericResourceApiParamParam param = paramsList.get(i);
660 String parameterName = param.getName();
661 if (!sdncResponseParamsToSkip.contains(parameterName)) {
662 String parameterValue = param.getValue();
663 paramsMap.put(parameterName, parameterValue);
670 private Map<String,String> buildNetworkRoleMap(GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology) throws JsonParseException, JsonMappingException, IOException {
671 Map<String, String> networkRoleMap = new HashMap<>();
672 GenericResourceApiVfmoduleassignmentsVfModuleAssignments vfModuleAssignments = vfModuleTopology.getVfModuleAssignments();
673 if (vfModuleAssignments != null) {
674 GenericResourceApiVfmoduleassignmentsVfmoduleassignmentsVms vms = vfModuleAssignments.getVms();
676 List<GenericResourceApiVmTopologyData> vmsList = vms.getVm();
677 if (vmsList != null) {
678 for (GenericResourceApiVmTopologyData vm : vmsList){
679 GenericResourceApiVmtopologydataVmNetworks vmNetworks = vm.getVmNetworks();
680 if (vmNetworks != null) {
681 List<GenericResourceApiVmNetworkData> vmNetworksList = vmNetworks.getVmNetwork();
682 if (vmNetworksList != null) {
683 for(int n = 0; n < vmNetworksList.size(); n++){
684 GenericResourceApiVmNetworkData network = vmNetworksList.get(n);
685 String networkRole = network.getNetworkRole();
686 String networkRoleValue = network.getNetworkRoleTag();
687 if (networkRoleValue == null || networkRoleValue.isEmpty()) {
688 networkRoleValue = networkRole;
690 networkRoleMap.put(networkRole, networkRoleValue);
698 return networkRoleMap;
701 public DeleteVfModuleRequest deleteVfModuleRequestMapper(RequestContext requestContext,CloudRegion cloudRegion,
702 ServiceInstance serviceInstance, GenericVnf genericVnf,
703 VfModule vfModule) throws IOException {
704 DeleteVfModuleRequest deleteVfModuleRequest = new DeleteVfModuleRequest();
705 deleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
706 deleteVfModuleRequest.setTenantId(cloudRegion.getTenantId());
707 deleteVfModuleRequest.setVnfId(genericVnf.getVnfId());
708 deleteVfModuleRequest.setVfModuleId(vfModule.getVfModuleId());
709 deleteVfModuleRequest.setVfModuleStackId(vfModule.getHeatStackId());//DoDVfMod_heatStackId
710 deleteVfModuleRequest.setSkipAAI(true);
711 String messageId = vnfAdapterObjectMapperUtils.getRandomUuid();
712 deleteVfModuleRequest.setMessageId(messageId);
713 deleteVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId));
714 MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance);
715 deleteVfModuleRequest.setMsoRequest(msoRequest);
716 return deleteVfModuleRequest;
719 private String convertToString(Object obj) {
722 json = mapper.writeValueAsString(obj);
723 } catch (JsonProcessingException e) {