Fix issue with attempt of delete of non-existing instance 06/125206/1
authorLukasz Rajewski <lukasz.rajewski@orange.com>
Wed, 20 Oct 2021 21:48:07 +0000 (23:48 +0200)
committerLukasz Rajewski <lukasz.rajewski@orange.com>
Wed, 20 Oct 2021 21:48:07 +0000 (23:48 +0200)
Issue-ID: SO-3404
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
Change-Id: I4735737380efaf7ba4cf40f6280a7dc744f98c88

so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java
so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiService.java

index b870a1d..9aaf439 100644 (file)
@@ -283,6 +283,11 @@ public class CnfAdapterRest {
             throws JsonParseException, JsonMappingException, IOException {
 
         logger.info("deleteInstanceByInstanceId called.");
+        if (instanceID == null || instanceID.isEmpty() || instanceID.equals("null")) {
+            //we skip deletion of instance that was not created properly and instance id was not stored in AAI
+            logger.warn("Undefined instance ID delete attempt. Skipping delete");
+            return "";
+        }
         return cnfAdapterService.deleteInstanceByInstanceId(instanceID);
 
     }
index db8998e..9c80bf0 100644 (file)
@@ -60,7 +60,14 @@ public class AaiService {
     }
 
     public void aaiDelete(AaiRequest aaiRequest) throws BadResponseException {
-        IAaiRepository aaiRepository = IAaiRepository.instance(configuration.isEnabled());
+        String instanceID = aaiRequest.getInstanceId();
+        boolean enabled = configuration.isEnabled();
+        if (instanceID == null || instanceID.isEmpty() || instanceID.equals("null")) {
+            //we skip deletion of resources instance that was not created properly and instance id was not stored in AAI
+            log.warn("Undefined instance ID aai-delete attempt. Skipping aai-delete");
+            enabled = false;
+        }
+        IAaiRepository aaiRepository = IAaiRepository.instance(enabled);
         aaiRepository.delete(aaiRequest, List.of());
         aaiRepository.commit(false);
     }