From 54dca75507277ff5bf3009d482e6bf0c8a053743 Mon Sep 17 00:00:00 2001 From: "aravind.est" Date: Tue, 26 Sep 2023 15:58:06 +0100 Subject: [PATCH] Add reason for rApp instance deploy/undeploy failure Reason field added to show why rApp instance deploy failed. Issue-ID: NONRTRIC-913 Signed-off-by: aravind.est Change-Id: Icb1779888bfbdea0f97a6059bba0a4c5a9ec01fb --- .../rappmanager/acm/service/AcmDeployer.java | 6 ++- .../rappmanager/acm/service/AcmDeployerTest.java | 43 ++++++++++++++++++++-- .../oransc/rappmanager/service/RappService.java | 2 + .../rappmanager/dme/service/DmeDeployer.java | 2 + .../models/rappinstance/RappInstance.java | 1 + .../rappmanager/sme/service/SmeDeployer.java | 5 +++ .../rappmanager/sme/service/SmeDeployerTest.java | 1 + 7 files changed, 55 insertions(+), 5 deletions(-) diff --git a/rapp-manager-acm/src/main/java/com/oransc/rappmanager/acm/service/AcmDeployer.java b/rapp-manager-acm/src/main/java/com/oransc/rappmanager/acm/service/AcmDeployer.java index 0bbf422..0cfeb9b 100755 --- a/rapp-manager-acm/src/main/java/com/oransc/rappmanager/acm/service/AcmDeployer.java +++ b/rapp-manager-acm/src/main/java/com/oransc/rappmanager/acm/service/AcmDeployer.java @@ -139,6 +139,8 @@ public class AcmDeployer implements RappDeployer { } catch (Exception e) { logger.warn("Error in deploying Rapp", e); } + rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.ACMDEPLOYFAILED); + rappInstance.setReason("Unable to deploy ACM"); return false; } @@ -158,6 +160,8 @@ public class AcmDeployer implements RappDeployer { return true; } } + rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.ACMUNDEPLOYFAILED); + rappInstance.setReason("Unable to undeploy ACM"); return false; } @@ -191,7 +195,7 @@ public class AcmDeployer implements RappDeployer { return true; } } catch (Exception e) { - logger.error("Failed deprime automation composition", e); + logger.warn("Failed deprime automation composition", e); } rapp.setReason("Unable to delete automation composition"); return false; diff --git a/rapp-manager-acm/src/test/java/com/oransc/rappmanager/acm/service/AcmDeployerTest.java b/rapp-manager-acm/src/test/java/com/oransc/rappmanager/acm/service/AcmDeployerTest.java index b4dd295..b866b5a 100755 --- a/rapp-manager-acm/src/test/java/com/oransc/rappmanager/acm/service/AcmDeployerTest.java +++ b/rapp-manager-acm/src/test/java/com/oransc/rappmanager/acm/service/AcmDeployerTest.java @@ -170,18 +170,36 @@ class AcmDeployerTest { } @Test - void testDeployRappInstanceFailure() throws Exception { + void testDeployRappInstanceFailureWithNoInstanceId() throws JsonProcessingException { UUID compositionId = UUID.randomUUID(); UUID rappId = UUID.randomUUID(); - UUID instanceId = UUID.randomUUID(); Rapp rapp = Rapp.builder().name(rappId.toString()).packageName(validRappFile).compositionId(compositionId) .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); + RappInstance rappInstance = rappResourceBuilder.getRappInstance(); + rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); InstantiationResponse instantiationResponse = new InstantiationResponse(); - instantiationResponse.setInstanceId(instanceId); + mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_ACM_INSTANCES, compositionId))) + .andExpect(method(HttpMethod.POST)).andRespond( + withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON) + .body(objectMapper.writeValueAsString(instantiationResponse))); + + boolean rappDeployStateActual = acmDeployer.deployRappInstance(rapp, rappInstance); + mockServer.verify(); + assertFalse(rappDeployStateActual); + } + + @Test + void testDeployRappInstanceFailure() { + UUID compositionId = UUID.randomUUID(); + UUID rappId = UUID.randomUUID(); + Rapp rapp = Rapp.builder().name(rappId.toString()).packageName(validRappFile).compositionId(compositionId) + .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); + RappInstance rappInstance = rappResourceBuilder.getRappInstance(); + rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_ACM_INSTANCES, compositionId))) .andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.BAD_GATEWAY)); - boolean rappDeployStateActual = acmDeployer.deployRappInstance(rapp, rappResourceBuilder.getRappInstance()); + boolean rappDeployStateActual = acmDeployer.deployRappInstance(rapp, rappInstance); mockServer.verify(); assertFalse(rappDeployStateActual); } @@ -310,6 +328,23 @@ class AcmDeployerTest { assertEquals(RappState.COMMISSIONED, rapp.getState()); } + @Test + void testPrimeRappFailureWithoutCompositionId() throws JsonProcessingException { + UUID compositionId = UUID.randomUUID(); + RappResources rappResources = rappResourceBuilder.getResources(); + Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) + .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED) + .compositionId(compositionId).rappResources(rappResources).build(); + + CommissioningResponse commissioningResponseExpected = new CommissioningResponse(); + mockServer.expect(ExpectedCount.once(), requestTo(URI_ACM_COMPOSITIONS)).andExpect(method(HttpMethod.POST)) + .andRespond(withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON) + .body(objectMapper.writeValueAsString(commissioningResponseExpected))); + boolean primeRapp = acmDeployer.primeRapp(rapp); + mockServer.verify(); + assertFalse(primeRapp); + } + @Test void testDeprimeRapp() throws JsonProcessingException { UUID compositionId = UUID.randomUUID(); diff --git a/rapp-manager-application/src/main/java/com/oransc/rappmanager/service/RappService.java b/rapp-manager-application/src/main/java/com/oransc/rappmanager/service/RappService.java index 8546082..6df12d4 100755 --- a/rapp-manager-application/src/main/java/com/oransc/rappmanager/service/RappService.java +++ b/rapp-manager-application/src/main/java/com/oransc/rappmanager/service/RappService.java @@ -101,6 +101,7 @@ public class RappService { public ResponseEntity deployRappInstance(Rapp rapp, RappInstance rappInstance) { if (rappInstance.getState().equals(RappInstanceState.UNDEPLOYED)) { + rappInstance.setReason(null); rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.DEPLOYING); if (acmDeployer.deployRappInstance(rapp, rappInstance) && smeDeployer.deployRappInstance(rapp, rappInstance) && dmeDeployer.deployRappInstance(rapp, rappInstance)) { @@ -116,6 +117,7 @@ public class RappService { public ResponseEntity undeployRappInstance(Rapp rapp, RappInstance rappInstance) { if (rappInstance.getState().equals(RappInstanceState.DEPLOYED)) { + rappInstance.setReason(null); rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.UNDEPLOYING); if (acmDeployer.undeployRappInstance(rapp, rappInstance) && smeDeployer.undeployRappInstance(rapp, rappInstance) && dmeDeployer.undeployRappInstance(rapp, rappInstance)) { diff --git a/rapp-manager-dme/src/main/java/com/oransc/rappmanager/dme/service/DmeDeployer.java b/rapp-manager-dme/src/main/java/com/oransc/rappmanager/dme/service/DmeDeployer.java index d82ef47..329841f 100755 --- a/rapp-manager-dme/src/main/java/com/oransc/rappmanager/dme/service/DmeDeployer.java +++ b/rapp-manager-dme/src/main/java/com/oransc/rappmanager/dme/service/DmeDeployer.java @@ -80,6 +80,7 @@ public class DmeDeployer implements RappDeployer { if (deployState) { rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.DMEDEPLOYED); } else { + rappInstance.setReason("Unable to deploy DME"); rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.DMEDEPLOYFAILED); } return deployState; @@ -98,6 +99,7 @@ public class DmeDeployer implements RappDeployer { if (undeployState) { rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.DMEUNDEPLOYED); } else { + rappInstance.setReason("Unable to undeploy DME"); rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.DMEUNDEPLOYFAILED); } return undeployState; diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rappinstance/RappInstance.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rappinstance/RappInstance.java index 39d2709..463baa2 100755 --- a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rappinstance/RappInstance.java +++ b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rappinstance/RappInstance.java @@ -26,6 +26,7 @@ public class RappInstance { UUID rappInstanceId = UUID.randomUUID(); RappInstanceState state = RappInstanceState.UNDEPLOYED; + String reason; RappACMInstance acm; RappSMEInstance sme; RappDMEInstance dme; diff --git a/rapp-manager-sme/src/main/java/com/oransc/rappmanager/sme/service/SmeDeployer.java b/rapp-manager-sme/src/main/java/com/oransc/rappmanager/sme/service/SmeDeployer.java index fc42f4d..adbf8fe 100755 --- a/rapp-manager-sme/src/main/java/com/oransc/rappmanager/sme/service/SmeDeployer.java +++ b/rapp-manager-sme/src/main/java/com/oransc/rappmanager/sme/service/SmeDeployer.java @@ -96,12 +96,15 @@ public class SmeDeployer implements RappDeployer { if (deployState) { rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEDEPLOYED); } else { + rappInstance.setReason("Unable to deploy SME"); rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEDEPLOYFAILED); } return deployState; } catch (JsonProcessingException e) { logger.warn("Failed to deploy SME functions for Rapp {}", rapp.getName(), e); } + rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEDEPLOYFAILED); + rappInstance.setReason("Unable to deploy SME"); return false; } @@ -118,6 +121,8 @@ public class SmeDeployer implements RappDeployer { } catch (Exception e) { logger.warn("Failed to Undeploy SME functions for Rapp {}", rapp.getName(), e); } + rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEUNDEPLOYFAILED); + rappInstance.setReason("Unable to undeploy SME"); return false; } diff --git a/rapp-manager-sme/src/test/java/com/oransc/rappmanager/sme/service/SmeDeployerTest.java b/rapp-manager-sme/src/test/java/com/oransc/rappmanager/sme/service/SmeDeployerTest.java index 28814da..ffa5457 100755 --- a/rapp-manager-sme/src/test/java/com/oransc/rappmanager/sme/service/SmeDeployerTest.java +++ b/rapp-manager-sme/src/test/java/com/oransc/rappmanager/sme/service/SmeDeployerTest.java @@ -391,6 +391,7 @@ class SmeDeployerTest { rappInstance.getSme().setProviderFunctionIds(providerFuncs.values().stream().toList()); rappInstance.getSme().setServiceApiIds(serviceApis); rappInstance.getSme().setInvokerIds(invokers); + rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); boolean undeployRapp = smeDeployer.undeployRappInstance(rapp, rappInstance); mockServer.verify(); assertFalse(undeployRapp); -- 2.16.6