Add support to upload deployment helm artifacts to chartmuseum
[nonrtric/plt/rappmanager.git] / rapp-manager-application / src / main / java / com / oransc / rappmanager / service / RappService.java
index 1e606d1..23ab2d8 100755 (executable)
@@ -44,18 +44,24 @@ public class RappService {
     private final List<RappDeployer> rappDeployers;
     private final RappInstanceStateMachine rappInstanceStateMachine;
     private final RappCacheService rappCacheService;
+    private final DeploymentArtifactsService deploymentArtifactsService;
     private static final String STATE_TRANSITION_NOT_PERMITTED = "State transition from %s to %s is not permitted.";
 
     public ResponseEntity<String> primeRapp(Rapp rapp) {
         if (rapp.getState().equals(RappState.COMMISSIONED)) {
             rapp.setState(RappState.PRIMING);
             rapp.setReason(null);
-            if (rappDeployers.parallelStream().allMatch(rappDeployer -> rappDeployer.primeRapp(rapp))) {
+            //Configuring the deployment artifact needs to be done before starting the priming with other components
+            //If there are additional conditions needs to be checked before priming, This needs handled as part of pre-priming stage.
+            if (deploymentArtifactsService.configureDeploymentArtifacts(rapp) && rappDeployers.parallelStream()
+                                                                                         .allMatch(
+                                                                                                 rappDeployer -> rappDeployer.primeRapp(
+                                                                                                         rapp))) {
                 rapp.setState(RappState.PRIMED);
                 return ResponseEntity.ok().build();
             }
             rapp.setState(RappState.COMMISSIONED);
-            return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
+            throw new RappHandlerException(HttpStatus.BAD_GATEWAY, rapp.getReason());
         }
         throw new RappHandlerException(HttpStatus.BAD_REQUEST,
                 String.format(STATE_TRANSITION_NOT_PERMITTED, rapp.getState().name(), RappState.PRIMED.name()));
@@ -71,7 +77,7 @@ public class RappService {
                 return ResponseEntity.ok().build();
             }
             rapp.setState(RappState.PRIMED);
-            return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
+            throw new RappHandlerException(HttpStatus.BAD_GATEWAY, rapp.getReason());
         }
         if (!rapp.getRappInstances().isEmpty()) {
             throw new RappHandlerException(HttpStatus.BAD_REQUEST,
@@ -106,7 +112,7 @@ public class RappService {
                         .allMatch(rappDeployer -> rappDeployer.deployRappInstance(rapp, rappInstance))) {
                 return ResponseEntity.accepted().build();
             }
-            return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
+            throw new RappHandlerException(HttpStatus.BAD_GATEWAY, rappInstance.getReason());
         }
         throw new RappHandlerException(HttpStatus.BAD_REQUEST,
                 String.format("Unable to deploy rApp instance %s as it is not in UNDEPLOYED state",
@@ -122,7 +128,7 @@ public class RappService {
                         .allMatch(rappDeployer -> rappDeployer.undeployRappInstance(rapp, rappInstance))) {
                 return ResponseEntity.accepted().build();
             }
-            return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
+            throw new RappHandlerException(HttpStatus.BAD_GATEWAY, rappInstance.getReason());
         }
         throw new RappHandlerException(HttpStatus.BAD_REQUEST,
                 String.format("Unable to undeploy rApp instance %s as it is not in DEPLOYED state",