diff options
author | Dan Timoney <dtimoney@att.com> | 2021-04-07 13:24:53 -0400 |
---|---|---|
committer | Dan Timoney <dtimoney@att.com> | 2021-04-07 13:24:53 -0400 |
commit | c17ea9680e6029128de5c935550079345f416d02 (patch) | |
tree | 30f77b9082ebf69e0cf9e7fda4568928d2f86f65 /ms/generic-resource-api/src/main/java | |
parent | d1f45bb6a7d3af61d9f6325a0fb729b37d4421cc (diff) |
Fix bugs in delete
Fixed bugs in delete of items from existing services
Change-Id: Iaeeb8b6622276b5183f5f386763526cd15b0becb
Issue-ID: SDNC-1516
Signed-off-by: Dan Timoney <dtimoney@att.com>
Diffstat (limited to 'ms/generic-resource-api/src/main/java')
2 files changed, 57 insertions, 15 deletions
diff --git a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiController.java b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiController.java index cbf571d..6b0a463 100644 --- a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiController.java +++ b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiController.java @@ -838,7 +838,7 @@ public class OperationsApiController implements OperationsApi { try { serviceDataHelper.saveService(configService, ctxSvcDataJson); } catch (JsonProcessingException e) { - log.error("exiting {} due to error saving service data", svcOperation); + log.error("exiting {} due to error saving service data", svcOperation, e); resp.setResponseCode("500"); resp.setResponseMessage("internal error"); resp.setAckFinalIndicator("Y"); diff --git a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ServiceDataHelper.java b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ServiceDataHelper.java index 1fbf02b..f04a3ac 100644 --- a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ServiceDataHelper.java +++ b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ServiceDataHelper.java @@ -298,7 +298,7 @@ public class ServiceDataHelper { String svcInstanceId = configService.getSvcInstanceId(); String svcDataAsString = configService.getSvcData(); - if (svcDataAsString != null) { + if ((svcDataAsString != null) && !svcDataAsString.isEmpty()) { svcData = objectMapper.readValue(svcDataAsString, GenericResourceApiServicedataServiceData.class); } else { svcData = new GenericResourceApiServicedataServiceData(); @@ -371,18 +371,17 @@ public class ServiceDataHelper { } } - // Remove any vf Modules for this vnf id not in this list - for (ConfigVfModules vfModuleToRemove : vfModuleMap.values()) { - if (transaction != null) { - transaction.remove(vfModuleToRemove); - } else { - configVfModulesRepository.delete(vfModuleToRemove); - } - } - // Clear vf modules from vnfData before saving to avoid duplication vnfData.setVfModules(null); } + // Remove any vf Modules for this vnf id not in this list + for (ConfigVfModules vfModuleToRemove : vfModuleMap.values()) { + if (transaction != null) { + transaction.remove(vfModuleToRemove); + } else { + configVfModulesRepository.delete(vfModuleToRemove); + } + } // Save Vnf itself List<ConfigVnfs> configVnfs = configVnfsRepository.findBySvcInstanceIdAndVnfId(svcInstanceId, vnf.getVnfId()); @@ -425,7 +424,8 @@ public class ServiceDataHelper { public void saveService(ConfigServices configService, String svcDataAsString, ServiceDataTransaction transaction) throws JsonMappingException, JsonProcessingException { - if (svcDataAsString == null) { + if ((svcDataAsString == null) || (svcDataAsString.length() == 0)) { + configService.setSvcData(null); configServicesRepository.save(configService); } else { saveService(configService, objectMapper.readValue(svcDataAsString, GenericResourceApiServicedataServiceData.class), transaction); @@ -438,36 +438,78 @@ public class ServiceDataHelper { public void saveService(ConfigServices configService, GenericResourceApiServicedataServiceData svcData, ServiceDataTransaction transaction) throws JsonProcessingException { - if (svcData != null) { + if (svcData == null) { + configService.setSvcData(null); + } else { String svcInstanceId = configService.getSvcInstanceId(); + // Make a list of current networks for this service + HashMap<String, ConfigNetworks> networkMap = new HashMap<>(); + List<ConfigNetworks> configNetworkList = configNetworksRepository.findBySvcInstanceId(svcInstanceId); + if ((configNetworkList != null) && !configNetworkList.isEmpty()) { + for (ConfigNetworks configNetworkItem : configNetworkList) { + networkMap.put(configNetworkItem.getNetworkId(), configNetworkItem); + } + } // Save networks GenericResourceApiServicedataServicedataNetworks networks = svcData.getNetworks(); if (networks != null) { List<GenericResourceApiServicedataServicedataNetworksNetwork> networkList = networks.getNetwork(); if ((networkList != null) && !networkList.isEmpty()) { for (GenericResourceApiServicedataServicedataNetworksNetwork networkItem : networkList) { + if (networkMap.containsKey(networkItem.getNetworkId())) { + networkMap.remove(networkItem.getNetworkId()); + } saveNetwork(svcInstanceId, networkItem, transaction); } } } + + // Remove networks removed from service object + for (ConfigNetworks networkToRemove : networkMap.values()) { + if (transaction != null) { + transaction.remove(networkToRemove); + } else { + configNetworksRepository.delete(networkToRemove); + } + } + svcData.setNetworks(null); + + // Remove any networks no longer associated with this svcInstanceId + HashMap<String, ConfigVnfs> vnfMap = new HashMap<>(); + List<ConfigVnfs> configVnfList = configVnfsRepository.findBySvcInstanceId(svcInstanceId); + if ((configVnfList != null) && !configVnfList.isEmpty()) { + for (ConfigVnfs configVnfItem : configVnfList) { + vnfMap.put(configVnfItem.getVnfId(), configVnfItem); + } + } // Save vnfs / vfModules + + // Save current vnfs associated with this service GenericResourceApiServicedataServicedataVnfs vnfs = svcData.getVnfs(); if (vnfs != null) { List<GenericResourceApiServicedataServicedataVnfsVnf> vnfList = vnfs.getVnf(); if ((vnfList != null) && !vnfList.isEmpty()) { for (GenericResourceApiServicedataServicedataVnfsVnf vnfItem : vnfList) { + if (vnfMap.containsKey(vnfItem.getVnfId())) { + vnfMap.remove(vnfItem.getVnfId()); + } saveVnf(svcInstanceId, vnfItem, transaction); } } } + for (ConfigVnfs vnfToRemove : vnfMap.values()) { + if (transaction != null) { + transaction.remove(vnfToRemove); + } else { + configVnfsRepository.delete(vnfToRemove); + } + } svcData.setVnfs(null); configService.setSvcData(objectMapper.writeValueAsString(svcData)); - } else { - } if (transaction != null) { transaction.save(configService); |