/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2023 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved.
* ===============================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
if (acmDeployer.primeRapp(rapp) && dmeDeployer.primeRapp(rapp)) {
rapp.setState(RappState.PRIMED);
return ResponseEntity.ok().build();
- } else {
- rapp.setState(RappState.COMMISSIONED);
- return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
}
- } else {
- return ResponseEntity.badRequest()
- .body(String.format(STATE_TRANSITION_NOT_PERMITTED, RappState.PRIMED.name(),
- rapp.getState().name()));
+ rapp.setState(RappState.COMMISSIONED);
+ return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
}
+ throw new RappHandlerException(HttpStatus.BAD_REQUEST,
+ String.format(STATE_TRANSITION_NOT_PERMITTED, rapp.getState().name(), RappState.PRIMED.name()));
+
}
public ResponseEntity<String> deprimeRapp(Rapp rapp) {
if (acmDeployer.deprimeRapp(rapp) && dmeDeployer.deprimeRapp(rapp)) {
rapp.setState(RappState.COMMISSIONED);
return ResponseEntity.ok().build();
- } else {
- rapp.setState(RappState.PRIMED);
- return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
}
+ rapp.setState(RappState.PRIMED);
+ return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
+ }
+ if (!rapp.getRappInstances().isEmpty()) {
+ throw new RappHandlerException(HttpStatus.BAD_REQUEST,
+ "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,");
- } else {
- return ResponseEntity.badRequest()
- .body(String.format(STATE_TRANSITION_NOT_PERMITTED, RappState.COMMISSIONED.name(),
- rapp.getState().name()));
- }
+ throw new RappHandlerException(HttpStatus.BAD_REQUEST,
+ String.format(STATE_TRANSITION_NOT_PERMITTED, RappState.COMMISSIONED.name(),
+ rapp.getState().name()));
}
}
if (rApp.getRappInstances().isEmpty() && rApp.getState().equals(RappState.COMMISSIONED)) {
rappCacheService.deleteRapp(rApp);
return ResponseEntity.ok().build();
+ }
+ if (!rApp.getRappInstances().isEmpty()) {
+ throw new RappHandlerException(HttpStatus.BAD_REQUEST,
+ String.format("Unable to delete %s as there are active rApp instances.", rApp.getName()));
} else {
- if (!rApp.getRappInstances().isEmpty()) {
- return ResponseEntity.badRequest()
- .body("Unable to delete '" + rApp.getName() + "' as there are active rApp instances.");
- } else {
- return ResponseEntity.badRequest().body("Unable to delete '" + rApp.getName()
- + "' as the rApp is not in COMMISSIONED state.");
- }
+ throw new RappHandlerException(HttpStatus.BAD_REQUEST,
+ String.format("Unable to delete %s as the rApp is not in COMMISSIONED state.", rApp.getName()));
}
+
}
public ResponseEntity<String> 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)) {
+ if (acmDeployer.deployRappInstance(rapp, rappInstance) && smeDeployer.deployRappInstance(rapp,
+ rappInstance)) {
return ResponseEntity.accepted().build();
}
return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
- } else {
- return ResponseEntity.badRequest()
- .body(String.format(STATE_TRANSITION_NOT_PERMITTED, rappInstance.getState().name(),
- RappInstanceState.DEPLOYED.name()));
}
+ throw new RappHandlerException(HttpStatus.BAD_REQUEST,
+ String.format("Unable to deploy rApp instance %s as it is not in UNDEPLOYED state",
+ rappInstance.getRappInstanceId()));
+
}
public ResponseEntity<String> undeployRappInstance(Rapp rapp, RappInstance rappInstance) {
rappInstance.setReason(null);
rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.UNDEPLOYING);
if (acmDeployer.undeployRappInstance(rapp, rappInstance) && smeDeployer.undeployRappInstance(rapp,
- rappInstance) && dmeDeployer.undeployRappInstance(rapp, rappInstance)) {
+ rappInstance)) {
return ResponseEntity.accepted().build();
}
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_REQUEST,
+ String.format("Unable to undeploy rApp instance %s as it is not in DEPLOYED state",
+ rappInstance.getRappInstanceId()));
}
- public ResponseEntity<Object> deleteRappInstance(Rapp rApp, UUID rappInstanceId) {
+ 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);