- return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
- } else {
- return ResponseEntity.badRequest()
- .body(String.format(STATE_TRANSITION_NOT_PERMITTED, rappInstance.getState().name(),
- RappInstanceState.UNDEPLOYED.name()));
+ 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",
+ rappInstance.getRappInstanceId()));
+ }
+
+ public ResponseEntity<String> deleteRappInstance(Rapp rApp, UUID rappInstanceId) {
+ if (rApp.getRappInstances().get(rappInstanceId).getState().equals(RappInstanceState.UNDEPLOYED)) {
+ rappInstanceStateMachine.deleteRappInstance(rApp.getRappInstances().get(rappInstanceId));
+ rApp.getRappInstances().remove(rappInstanceId);
+ return ResponseEntity.noContent().build();