From 0d63165b6d866e19afcf86af7bb0d58ad18e9827 Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Fri, 14 Jun 2024 13:32:44 +0300 Subject: [PATCH] - Add checks to verify that there are active workers in the Service, before proceeding to try posting "(cancel)Shutdown" requests to all known workers. - Add documentation in README. --- README.md | 6 +++ .../controllers/ShutdownController.java | 41 +++++++++++-------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 6c95a19..4639b49 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,12 @@ For managing and generating data, we use [**Impala**](https://impala.apache.org/ Once the Workers are about to shut down, they send a "shutdownReport" to the Controller. A scheduling task runs in the Controller, every 2 hours, and if the user has specified that the Controller must shut down and all the Workers participating in the Service have shutdown, then it gently shuts down the Controller. - "**cancelShutdownService**" endpoint: **http://localhost:\/api/cancelShutdownService**
This endpoint specifies that the Controller will not shut down, and sends "cancelShutdownWorker" requests to all the Workers which are actively participating in the Service (have not shut down yet), so that they can continue to request assignments. +- "**shutdownAllWorkers**" endpoint: **http://localhost:\/api/shutdownAllWorkers**
+ This endpoint sends "shutdownWorker" requests to all the Workers which are actively participating in the Service. The Workers will shut down after finishing their work-in-progress and all full-texts have been either transferred to the Controller or deleted, in case an error has appeared.
+ Once the Workers are about to shut down, they send a "shutdownReport" to the Controller.
+ This endpoint is helpful when we want to update only the Workers, while keeping the Service running for Bulk-import procedures. +- "**cancelShutdownAllWorkers**" endpoint: **http://localhost:\/api/cancelShutdownAllWorkers**
+ This endpoint specifies that the Workers will not shut down, and sends "cancelShutdownWorker" requests to all the Workers which are actively participating in the Service (have not shut down yet), so that they can continue to request assignments.
Note: The Shutdown Service API is accessible by the Controller's host machine. diff --git a/src/main/java/eu/openaire/urls_controller/controllers/ShutdownController.java b/src/main/java/eu/openaire/urls_controller/controllers/ShutdownController.java index 381e33d..3b146c6 100644 --- a/src/main/java/eu/openaire/urls_controller/controllers/ShutdownController.java +++ b/src/main/java/eu/openaire/urls_controller/controllers/ShutdownController.java @@ -46,10 +46,13 @@ public class ShutdownController { } else { shouldShutdownService = true; endingMsg = "The service will shutdown, after finishing current work."; - logger.info(initMsg + endingMsg); - - shutdownService.postShutdownOrCancelRequestsToAllWorkers(false); - + if ( UrlsController.numOfActiveWorkers.get() == 0 ) { + endingMsg += " None of the workers is active in order to post shutdown requests to."; + logger.info(initMsg + endingMsg); + } else { + logger.info(initMsg + endingMsg); // Show this message before the post-operation, as the following code may take some time to finish. + shutdownService.postShutdownOrCancelRequestsToAllWorkers(false); + } // That's it for now. The workers may take some hours to finish their work (including delivering the full-text files). // A scheduler monitors the shutdown of the workers. Once all worker have shutdown, the Controller shuts down as well. } @@ -70,11 +73,13 @@ public class ShutdownController { shouldShutdownService = false; String endingMsg = "Any previous \"shutdownService\"-request is canceled."; - logger.info(initMsg + endingMsg); - - // Cancel the shutdown of the workers, if we are able to catch up with them before they have already shutdown.. - shutdownService.postShutdownOrCancelRequestsToAllWorkers(true); - + if ( UrlsController.numOfActiveWorkers.get() == 0 ) { + endingMsg += " None of the workers is active in order to post cancel-shutdown requests to."; + logger.info(initMsg + endingMsg); + } else { + logger.info(initMsg + endingMsg); // Show this message before the post-operation, as the following code may take some time to finish. + shutdownService.postShutdownOrCancelRequestsToAllWorkers(true); // Cancel the shutdown of the workers, if we are able to catch up with them before they have already shutdown.. + } return ResponseEntity.ok().body(endingMsg + GenericUtils.endOfLine); } @@ -96,18 +101,18 @@ public class ShutdownController { if ( shouldShutdownAllWorkers ) { endingMsg = "The controller has already received a \"shutdownAllWorkers\" request (which was not canceled afterwards)."; logger.info(initMsg + endingMsg); + } else if ( UrlsController.numOfActiveWorkers.get() == 0 ) { + endingMsg = "None of the workers is active in order to post shutdown requests to."; + logger.info(initMsg + endingMsg); } else { shouldShutdownAllWorkers = true; endingMsg = "All workers will shutdown, after finishing current work."; logger.info(initMsg + endingMsg); - shutdownService.postShutdownOrCancelRequestsToAllWorkers(false); - // That's it for now. The workers may take some hours to finish their work (including delivering the full-text files). // The service will continue to run and handle bulk-import requests. // Once the workers are ready to work again, they can be started without any additional configuration. } - return ResponseEntity.ok().body(endingMsg + GenericUtils.endOfLine); } @@ -124,11 +129,13 @@ public class ShutdownController { shouldShutdownAllWorkers = false; String endingMsg = "Any previous \"shutdownAllWorkers\"-request is canceled."; - logger.info(initMsg + endingMsg); - - // Cancel the shutdown of the workers, if we are able to catch up with them before they have already shutdown.. - shutdownService.postShutdownOrCancelRequestsToAllWorkers(true); - + if ( UrlsController.numOfActiveWorkers.get() == 0 ) { + endingMsg += " None of the workers is active in order to post cancel-shutdown requests to."; + logger.info(initMsg + endingMsg); + } else { + logger.info(initMsg + endingMsg); // Show this message before the post-operation, as the following code may take some time to finish. + shutdownService.postShutdownOrCancelRequestsToAllWorkers(true); // Cancel the shutdown of the workers, if we are able to catch up with them before they have already shutdown.. + } return ResponseEntity.ok().body(endingMsg + GenericUtils.endOfLine); }