- Use the "POST" method for shutdown and cancelShutdown requests.

- Polish some messages.
This commit is contained in:
Lampros Smyrnaios 2023-05-23 22:24:49 +03:00
parent 9fdaa9503b
commit bfa569685a
1 changed files with 6 additions and 6 deletions

View File

@ -56,7 +56,7 @@ public class GeneralController {
public static boolean shouldShutdownWorker = false; public static boolean shouldShutdownWorker = false;
@GetMapping("shutdownWorker") @PostMapping("shutdownWorker")
public ResponseEntity<?> shutdownWorkerGracefully(HttpServletRequest request) public ResponseEntity<?> shutdownWorkerGracefully(HttpServletRequest request)
{ {
String initMsg = "Received a \"shutdownWorker\" request. "; String initMsg = "Received a \"shutdownWorker\" request. ";
@ -76,16 +76,16 @@ public class GeneralController {
} }
@GetMapping("cancelShutdownWorker") @PostMapping("cancelShutdownWorker")
public ResponseEntity<?> cancelShutdownWorkerGracefully(HttpServletRequest request) public ResponseEntity<?> cancelShutdownWorkerGracefully(HttpServletRequest request)
{ {
String initMsg = "Received a \"cancelShutdownWorker\" request."; String initMsg = "Received a \"cancelShutdownWorker\" request. ";
ResponseEntity<?> responseEntity = passSecurityChecks(request, initMsg); ResponseEntity<?> responseEntity = passSecurityChecks(request, initMsg);
if ( responseEntity != null ) if ( responseEntity != null )
return responseEntity; return responseEntity;
shouldShutdownWorker = false; shouldShutdownWorker = false;
String finalMsg = " Any previous \"shutdownWorker\"-request is canceled. The \"maxAssignmentsBatchesToHandleBeforeShutdown\" will still be honored (if it's set)."; String finalMsg = "Any previous \"shutdownWorker\"-request is canceled. The \"maxAssignmentsBatchesToHandleBeforeShutdown\" will still be honored (if it's set).";
logger.info(initMsg + finalMsg); logger.info(initMsg + finalMsg);
return ResponseEntity.ok().body(finalMsg + "\n"); return ResponseEntity.ok().body(finalMsg + "\n");
} }
@ -122,7 +122,7 @@ public class GeneralController {
public ResponseEntity<?> passSecurityChecks(HttpServletRequest request, String initMsg) public ResponseEntity<?> passSecurityChecks(HttpServletRequest request, String initMsg)
{ {
if ( request == null ) { if ( request == null ) {
logger.error(initMsg + " The \"HttpServletRequest\" is null!"); logger.error(initMsg + "The \"HttpServletRequest\" is null!");
return ResponseEntity.internalServerError().build(); return ResponseEntity.internalServerError().build();
} }
String remoteAddr = request.getHeader("X-FORWARDED-FOR"); String remoteAddr = request.getHeader("X-FORWARDED-FOR");
@ -130,7 +130,7 @@ public class GeneralController {
remoteAddr = request.getRemoteAddr(); remoteAddr = request.getRemoteAddr();
if ( ! (remoteAddr.equals("127.0.0.1") || remoteAddr.equals(UriBuilder.ip) || remoteAddr.equals(controllerIp)) ) { if ( ! (remoteAddr.equals("127.0.0.1") || remoteAddr.equals(UriBuilder.ip) || remoteAddr.equals(controllerIp)) ) {
logger.error(initMsg + " The request came from another IP: " + remoteAddr + " | while this worker has the IP: " + UriBuilder.ip); logger.error(initMsg + "The request came from another IP: " + remoteAddr + " | while this worker has the IP: " + UriBuilder.ip);
return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
} }
return null; // The checks are passing. return null; // The checks are passing.