Add reason for rApp priming/depriming failures 22/11822/1
authoraravind.est <aravindhan.a@est.tech>
Tue, 26 Sep 2023 13:12:10 +0000 (14:12 +0100)
committeraravind.est <aravindhan.a@est.tech>
Tue, 26 Sep 2023 13:12:10 +0000 (14:12 +0100)
Reason field added to show why rApp priming/depriming failed.
Priming/depriming failure shown with bad gateway http response code.

Issue-ID: NONRTRIC-913
Signed-off-by: aravind.est <aravindhan.a@est.tech>
Change-Id: I33f286120930c34c0898d891577cde4fc9bc2ce5

rapp-manager-acm/src/main/java/com/oransc/rappmanager/acm/service/AcmDeployer.java
rapp-manager-application/src/main/java/com/oransc/rappmanager/service/RappService.java
rapp-manager-application/src/test/java/com/oransc/rappmanager/rest/RappControllerTest.java
rapp-manager-application/src/test/java/com/oransc/rappmanager/service/RappServiceTest.java
rapp-manager-dme/src/main/java/com/oransc/rappmanager/dme/service/DmeDeployer.java
rapp-manager-dme/src/test/java/com/oransc/rappmanager/dme/service/DmeDeployerTest.java
rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/Rapp.java
rapp-manager-models/src/test/java/com/oransc/rappmanager/models/cache/RappCacheServiceTest.java

index eb93ed3..0bbf422 100755 (executable)
@@ -173,11 +173,12 @@ public class AcmDeployer implements RappDeployer {
                 primeACMComposition(commissioningResponse.getCompositionId(), PrimeOrder.PRIME);
                 return true;
             } else {
                 primeACMComposition(commissioningResponse.getCompositionId(), PrimeOrder.PRIME);
                 return true;
             } else {
-                logger.error("Failed to create automation composition");
+                logger.warn("Failed to create automation composition");
             }
         } catch (Exception e) {
             }
         } catch (Exception e) {
-            logger.error("Failed to create automation composition", e);
+            logger.warn("Error in creating automation composition", e);
         }
         }
+        rapp.setReason("Unable to create automation composition");
         return false;
     }
 
         return false;
     }
 
@@ -192,6 +193,7 @@ public class AcmDeployer implements RappDeployer {
         } catch (Exception e) {
             logger.error("Failed deprime automation composition", e);
         }
         } catch (Exception e) {
             logger.error("Failed deprime automation composition", e);
         }
+        rapp.setReason("Unable to delete automation composition");
         return false;
     }
 
         return false;
     }
 
index 925d5d3..8546082 100755 (executable)
@@ -47,12 +47,14 @@ public class RappService {
     public ResponseEntity<String> primeRapp(Rapp rapp) {
         if (rapp.getState().equals(RappState.COMMISSIONED)) {
             rapp.setState(RappState.PRIMING);
     public ResponseEntity<String> primeRapp(Rapp rapp) {
         if (rapp.getState().equals(RappState.COMMISSIONED)) {
             rapp.setState(RappState.PRIMING);
+            rapp.setReason(null);
             if (acmDeployer.primeRapp(rapp) && dmeDeployer.primeRapp(rapp)) {
                 rapp.setState(RappState.PRIMED);
             if (acmDeployer.primeRapp(rapp) && dmeDeployer.primeRapp(rapp)) {
                 rapp.setState(RappState.PRIMED);
+                return ResponseEntity.ok().build();
             } else {
                 rapp.setState(RappState.COMMISSIONED);
             } else {
                 rapp.setState(RappState.COMMISSIONED);
+                return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
             }
             }
-            return ResponseEntity.ok().build();
         } else {
             return ResponseEntity.badRequest()
                            .body(String.format(STATE_TRANSITION_NOT_PERMITTED, RappState.PRIMED.name(),
         } else {
             return ResponseEntity.badRequest()
                            .body(String.format(STATE_TRANSITION_NOT_PERMITTED, RappState.PRIMED.name(),
@@ -63,12 +65,14 @@ public class RappService {
     public ResponseEntity<String> deprimeRapp(Rapp rapp) {
         if (rapp.getState().equals(RappState.PRIMED) && rapp.getRappInstances().isEmpty()) {
             rapp.setState(RappState.DEPRIMING);
     public ResponseEntity<String> deprimeRapp(Rapp rapp) {
         if (rapp.getState().equals(RappState.PRIMED) && rapp.getRappInstances().isEmpty()) {
             rapp.setState(RappState.DEPRIMING);
+            rapp.setReason(null);
             if (acmDeployer.deprimeRapp(rapp) && dmeDeployer.deprimeRapp(rapp)) {
                 rapp.setState(RappState.COMMISSIONED);
             if (acmDeployer.deprimeRapp(rapp) && dmeDeployer.deprimeRapp(rapp)) {
                 rapp.setState(RappState.COMMISSIONED);
+                return ResponseEntity.ok().build();
             } else {
                 rapp.setState(RappState.PRIMED);
             } else {
                 rapp.setState(RappState.PRIMED);
+                return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
             }
             }
-            return ResponseEntity.ok().build();
         } else {
             if (!rapp.getRappInstances().isEmpty()) {
                 return ResponseEntity.badRequest().body("Unable to deprime as there are active rapp instances,");
         } else {
             if (!rapp.getRappInstances().isEmpty()) {
                 return ResponseEntity.badRequest().body("Unable to deprime as there are active rapp instances,");
index 6d4b84c..072e205 100755 (executable)
@@ -8,6 +8,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.oransc.rappmanager.acm.service.AcmDeployer;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.oransc.rappmanager.acm.service.AcmDeployer;
+import com.oransc.rappmanager.dme.service.DmeDeployer;
 import com.oransc.rappmanager.models.cache.RappCacheService;
 import com.oransc.rappmanager.models.rapp.PrimeOrder;
 import com.oransc.rappmanager.models.rapp.Rapp;
 import com.oransc.rappmanager.models.cache.RappCacheService;
 import com.oransc.rappmanager.models.rapp.PrimeOrder;
 import com.oransc.rappmanager.models.rapp.Rapp;
@@ -43,6 +44,9 @@ class RappControllerTest {
     @MockBean
     AcmDeployer acmDeployer;
 
     @MockBean
     AcmDeployer acmDeployer;
 
+    @MockBean
+    DmeDeployer dmeDeployer;
+
     @MockBean
     SmeLifecycleManager smeLifecycleManager;
 
     @MockBean
     SmeLifecycleManager smeLifecycleManager;
 
@@ -109,6 +113,7 @@ class RappControllerTest {
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
         rappCacheService.putRapp(rapp);
         when(acmDeployer.primeRapp(any())).thenReturn(true);
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
         rappCacheService.putRapp(rapp);
         when(acmDeployer.primeRapp(any())).thenReturn(true);
+        when(dmeDeployer.primeRapp(any())).thenReturn(true);
         RappPrimeOrder rappPrimeOrder = new RappPrimeOrder();
         rappPrimeOrder.setPrimeOrder(PrimeOrder.PRIME);
         mockMvc.perform(MockMvcRequestBuilders.put("/rapps/{rapp_id}", rappId).contentType(MediaType.APPLICATION_JSON)
         RappPrimeOrder rappPrimeOrder = new RappPrimeOrder();
         rappPrimeOrder.setPrimeOrder(PrimeOrder.PRIME);
         mockMvc.perform(MockMvcRequestBuilders.put("/rapps/{rapp_id}", rappId).contentType(MediaType.APPLICATION_JSON)
@@ -133,6 +138,7 @@ class RappControllerTest {
                             .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
         rappCacheService.putRapp(rapp);
         when(acmDeployer.deprimeRapp(any())).thenReturn(true);
                             .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
         rappCacheService.putRapp(rapp);
         when(acmDeployer.deprimeRapp(any())).thenReturn(true);
+        when(dmeDeployer.deprimeRapp(any())).thenReturn(true);
         RappPrimeOrder rappPrimeOrder = new RappPrimeOrder();
         rappPrimeOrder.setPrimeOrder(PrimeOrder.DEPRIME);
         mockMvc.perform(MockMvcRequestBuilders.put("/rapps/{rapp_id}", rappId).contentType(MediaType.APPLICATION_JSON)
         RappPrimeOrder rappPrimeOrder = new RappPrimeOrder();
         rappPrimeOrder.setPrimeOrder(PrimeOrder.DEPRIME);
         mockMvc.perform(MockMvcRequestBuilders.put("/rapps/{rapp_id}", rappId).contentType(MediaType.APPLICATION_JSON)
index b45c289..6652dba 100755 (executable)
@@ -73,7 +73,7 @@ class RappServiceTest {
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
         when(acmDeployer.primeRapp(any())).thenReturn(false);
         when(dmeDeployer.primeRapp(any())).thenReturn(true);
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
         when(acmDeployer.primeRapp(any())).thenReturn(false);
         when(dmeDeployer.primeRapp(any())).thenReturn(true);
-        assertEquals(HttpStatus.OK, rappService.primeRapp(rapp).getStatusCode());
+        assertEquals(HttpStatus.BAD_GATEWAY, rappService.primeRapp(rapp).getStatusCode());
         assertEquals(RappState.COMMISSIONED, rapp.getState());
     }
 
         assertEquals(RappState.COMMISSIONED, rapp.getState());
     }
 
@@ -83,7 +83,7 @@ class RappServiceTest {
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
         when(acmDeployer.primeRapp(any())).thenReturn(true);
         when(dmeDeployer.primeRapp(any())).thenReturn(false);
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
         when(acmDeployer.primeRapp(any())).thenReturn(true);
         when(dmeDeployer.primeRapp(any())).thenReturn(false);
-        assertEquals(HttpStatus.OK, rappService.primeRapp(rapp).getStatusCode());
+        assertEquals(HttpStatus.BAD_GATEWAY, rappService.primeRapp(rapp).getStatusCode());
         assertEquals(RappState.COMMISSIONED, rapp.getState());
     }
 
         assertEquals(RappState.COMMISSIONED, rapp.getState());
     }
 
@@ -104,7 +104,7 @@ class RappServiceTest {
                             .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
         when(acmDeployer.deprimeRapp(any())).thenReturn(false);
         when(dmeDeployer.deprimeRapp(any())).thenReturn(true);
                             .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
         when(acmDeployer.deprimeRapp(any())).thenReturn(false);
         when(dmeDeployer.deprimeRapp(any())).thenReturn(true);
-        assertEquals(HttpStatus.OK, rappService.deprimeRapp(rapp).getStatusCode());
+        assertEquals(HttpStatus.BAD_GATEWAY, rappService.deprimeRapp(rapp).getStatusCode());
         assertEquals(RappState.PRIMED, rapp.getState());
     }
 
         assertEquals(RappState.PRIMED, rapp.getState());
     }
 
@@ -114,7 +114,7 @@ class RappServiceTest {
                             .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
         when(acmDeployer.deprimeRapp(any())).thenReturn(true);
         when(dmeDeployer.deprimeRapp(any())).thenReturn(false);
                             .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
         when(acmDeployer.deprimeRapp(any())).thenReturn(true);
         when(dmeDeployer.deprimeRapp(any())).thenReturn(false);
-        assertEquals(HttpStatus.OK, rappService.deprimeRapp(rapp).getStatusCode());
+        assertEquals(HttpStatus.BAD_GATEWAY, rappService.deprimeRapp(rapp).getStatusCode());
         assertEquals(RappState.PRIMED, rapp.getState());
     }
 
         assertEquals(RappState.PRIMED, rapp.getState());
     }
 
index 388a565..d82ef47 100755 (executable)
@@ -127,19 +127,14 @@ public class DmeDeployer implements RappDeployer {
                 allInfoTypes.addAll(dataProducerRegistrationApiClient.getInfoTypdentifiers());
                 requiredInfoTypes.removeAll(allInfoTypes);
                 if (!requiredInfoTypes.isEmpty()) {
                 allInfoTypes.addAll(dataProducerRegistrationApiClient.getInfoTypdentifiers());
                 requiredInfoTypes.removeAll(allInfoTypes);
                 if (!requiredInfoTypes.isEmpty()) {
-                    logger.info("Invalid rapp package as the following info types cannot be found {}",
-                            requiredInfoTypes);
-                    rapp.setIsDmeValid(false);
-                } else {
-                    rapp.setIsDmeValid(true);
+                    rapp.setReason(String.format("Invalid rapp package as the following info types cannot be found %s",
+                                    requiredInfoTypes));
                 }
                 }
-            } else {
-                rapp.setIsDmeValid(true);
             }
             return true;
         } catch (Exception e) {
             logger.warn("Failed to prime DME", e);
             }
             return true;
         } catch (Exception e) {
             logger.warn("Failed to prime DME", e);
-            rapp.setIsDmeValid(false);
+            rapp.setReason("Failed to prime DME");
             return false;
         }
     }
             return false;
         }
     }
@@ -147,7 +142,6 @@ public class DmeDeployer implements RappDeployer {
     @Override
     public boolean deprimeRapp(Rapp rapp) {
         logger.debug("Depriming DME functions for rApp {}", rapp.getRappId());
     @Override
     public boolean deprimeRapp(Rapp rapp) {
         logger.debug("Depriming DME functions for rApp {}", rapp.getRappId());
-        rapp.setIsDmeValid(null);
         return true;
     }
 
         return true;
     }
 
index 5b97b2d..d5fb291 100755 (executable)
@@ -18,8 +18,8 @@
 
 package com.oransc.rappmanager.dme.service;
 
 
 package com.oransc.rappmanager.dme.service;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
@@ -51,6 +51,7 @@ import org.junit.jupiter.api.TestInstance;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
 import org.springframework.boot.test.context.SpringBootTest;
@@ -103,7 +104,8 @@ class DmeDeployerTest {
 
     @ParameterizedTest
     @MethodSource("getSuccessParamsWithUnavailableInfoTypes")
 
     @ParameterizedTest
     @MethodSource("getSuccessParamsWithUnavailableInfoTypes")
-    void testPrimeRappSuccessWithUnavailableInfoType(String rappFile, boolean result) throws JsonProcessingException {
+    void testPrimeRappSuccessWithUnavailableInfoType(String rappFile, boolean isSuccess)
+            throws JsonProcessingException {
         RappResources rappResources = rappDmeResourceBuilder.getResources();
         Rapp rapp = getRapp(Optional.empty());
         rapp.setPackageName(rappFile);
         RappResources rappResources = rappDmeResourceBuilder.getResources();
         Rapp rapp = getRapp(Optional.empty());
         rapp.setPackageName(rappFile);
@@ -116,7 +118,11 @@ class DmeDeployerTest {
         if (rappFile.equals(validRappFileNewInfoType)) {
             mockServer.verify();
         }
         if (rappFile.equals(validRappFileNewInfoType)) {
             mockServer.verify();
         }
-        assertEquals(rapp.getIsDmeValid(), result);
+        if (isSuccess) {
+            assertNull(rapp.getReason());
+        } else {
+            assertNotNull(rapp.getReason());
+        }
     }
 
     private static Stream<Arguments> getSuccessParamsWithUnavailableInfoTypes() {
     }
 
     private static Stream<Arguments> getSuccessParamsWithUnavailableInfoTypes() {
@@ -124,8 +130,8 @@ class DmeDeployerTest {
     }
 
     @ParameterizedTest
     }
 
     @ParameterizedTest
-    @MethodSource("getSuccessParamsWithAvailableInfoTypes")
-    void testPrimeRappSuccessWithValidInfoType(String rappFile, boolean result) throws JsonProcessingException {
+    @ValueSource(strings = {validRappFile, validRappFileNewInfoType})
+    void testPrimeRappSuccessWithValidInfoType(String rappFile) throws JsonProcessingException {
         RappResources rappResources = rappDmeResourceBuilder.getResources();
         Rapp rapp = getRapp(Optional.empty());
         rapp.setPackageName(rappFile);
         RappResources rappResources = rappDmeResourceBuilder.getResources();
         Rapp rapp = getRapp(Optional.empty());
         rapp.setPackageName(rappFile);
@@ -138,11 +144,7 @@ class DmeDeployerTest {
         if (rappFile.equals(validRappFileNewInfoType)) {
             mockServer.verify();
         }
         if (rappFile.equals(validRappFileNewInfoType)) {
             mockServer.verify();
         }
-        assertEquals(rapp.getIsDmeValid(), result);
-    }
-
-    private static Stream<Arguments> getSuccessParamsWithAvailableInfoTypes() {
-        return Stream.of(Arguments.of(validRappFile, true), Arguments.of(validRappFileNewInfoType, true));
+        assertNull(rapp.getReason());
     }
 
     @Test
     }
 
     @Test
@@ -156,15 +158,14 @@ class DmeDeployerTest {
         Rapp rapp = getRapp(Optional.empty());
         rapp.setRappResources(rappResources);
         assertFalse(dmeDeployer.primeRapp(rapp));
         Rapp rapp = getRapp(Optional.empty());
         rapp.setRappResources(rappResources);
         assertFalse(dmeDeployer.primeRapp(rapp));
-        assertFalse(rapp.getIsDmeValid());
+        assertFalse(rapp.getReason().isEmpty());
     }
 
     @Test
     void testDeprimeRapp() {
         Rapp rapp = getRapp(Optional.empty());
     }
 
     @Test
     void testDeprimeRapp() {
         Rapp rapp = getRapp(Optional.empty());
-        rapp.setIsDmeValid(true);
         assertTrue(dmeDeployer.deprimeRapp(rapp));
         assertTrue(dmeDeployer.deprimeRapp(rapp));
-        assertNull(rapp.getIsDmeValid());
+        assertNull(rapp.getReason());
     }
 
     @Test
     }
 
     @Test
index a845fac..39e9ec9 100755 (executable)
@@ -34,6 +34,7 @@ public class Rapp {
     UUID rappId = UUID.randomUUID();
     String name;
     RappState state;
     UUID rappId = UUID.randomUUID();
     String name;
     RappState state;
+    String reason;
     String packageLocation;
     String packageName;
     RappResources rappResources;
     String packageLocation;
     String packageName;
     RappResources rappResources;
@@ -41,5 +42,4 @@ public class Rapp {
     Map<UUID, RappInstance> rappInstances = new HashMap<>();
 
     UUID compositionId;
     Map<UUID, RappInstance> rappInstances = new HashMap<>();
 
     UUID compositionId;
-    Boolean isDmeValid;
 }
 }
index 4ef0253..3f1dba8 100755 (executable)
@@ -16,7 +16,6 @@ class RappCacheServiceTest {
     @Autowired
     RappCacheService rappCacheService;
 
     @Autowired
     RappCacheService rappCacheService;
 
-
     @Test
     void testPutRapp() {
         UUID rappId = UUID.randomUUID();
     @Test
     void testPutRapp() {
         UUID rappId = UUID.randomUUID();