From 9cbac77c2abc45124f979dd414387e4e55d8e111 Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Fri, 21 Jul 2023 16:19:00 +0300 Subject: [PATCH] - Add check for "shouldShutdownService" before allowing to continue with a bulk-import request. - Add check for remaining background tasks (including bulkImports), before checking if the workers have shut down and then shut down the Service. --- .../urls_controller/components/ScheduledTasks.java | 6 +++++- .../urls_controller/controllers/BulkImportController.java | 7 +++++++ .../urls_controller/controllers/UrlsController.java | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/openaire/urls_controller/components/ScheduledTasks.java b/src/main/java/eu/openaire/urls_controller/components/ScheduledTasks.java index 468ce79..480a2b8 100644 --- a/src/main/java/eu/openaire/urls_controller/components/ScheduledTasks.java +++ b/src/main/java/eu/openaire/urls_controller/components/ScheduledTasks.java @@ -111,7 +111,9 @@ public class ScheduledTasks { if ( ! ShutdownController.shouldShutdownService ) return; // Either the service was never instructed to shut down, or the user canceled the request. - // If the workers have shutdown on their own, without been instructed to by the Controller, then the Controller will keep running. + // Check whether there are still background tasks to be processed. Either workerReport or Bulk-import requests. + if ( UrlsController.backgroundCallableTasks.size() > 0 ) + return; Set workerIds = UrlsController.workersInfoMap.keySet(); if ( workerIds.size() > 0 ) { @@ -122,6 +124,8 @@ public class ScheduledTasks { } else logger.info("No workers have participated in the service yet, so the Controller will shut-down immediately."); + // If one worker has crashed, then it will have not informed the Controller. So the controller will think that it is still running and will not shut down. + Application.gentleAppShutdown(); } diff --git a/src/main/java/eu/openaire/urls_controller/controllers/BulkImportController.java b/src/main/java/eu/openaire/urls_controller/controllers/BulkImportController.java index 75b9648..b0e4ce5 100644 --- a/src/main/java/eu/openaire/urls_controller/controllers/BulkImportController.java +++ b/src/main/java/eu/openaire/urls_controller/controllers/BulkImportController.java @@ -143,6 +143,13 @@ public class BulkImportController { return ResponseEntity.internalServerError().body(errorMsg); } + // After applying all the logic-checks and informing the user of any mistake, then we check and inform if the Service is about to shut down. + if ( ShutdownController.shouldShutdownService ) { + String warnMsg = "The Service is about to shutdown, after all under-processing assignments and/or bulkImport requests are handled. No new requests are accepted!"; + logger.warn(warnMsg); + return ResponseEntity.status(HttpStatus.CONFLICT).body(warnMsg); + } + // Detect if the same directory is scheduled for being processed. In that case, return a 429. if ( ! bulkImportDirs.add(bulkImportDir) ) { // We allow multiple jobs for the same provenance, running at the same time, but not multiple jobs for the same bulkImportDirectory. diff --git a/src/main/java/eu/openaire/urls_controller/controllers/UrlsController.java b/src/main/java/eu/openaire/urls_controller/controllers/UrlsController.java index dceb77e..38e6dbf 100644 --- a/src/main/java/eu/openaire/urls_controller/controllers/UrlsController.java +++ b/src/main/java/eu/openaire/urls_controller/controllers/UrlsController.java @@ -95,9 +95,9 @@ public class UrlsController { // There might be the case that the Controller has not sent shutDown requests to the Workers yet, or it has, BUT: // 1) A worker requests for new assignments before the shutDown request in handled by its side. // 2) A new Worker joins the Service (unexpected, but anyway). - String warnMsg = "The Service is about to shutdown, after all under-processing assignments are handled. No new requests are accepted!"; + String warnMsg = "The Service is about to shutdown, after all under-processing assignments and/or bulkImport requests are handled. No new requests are accepted!"; logger.warn(warnMsg); // It's likely not an actual error, but still it's not accepted. - return ResponseEntity.status(HttpStatus.CONFLICT).body(warnMsg); // The worker will wait 15 mins and upon going to retry it will notice that it should not do a new request or it may have shutdown in the meantime. + return ResponseEntity.status(HttpStatus.CONFLICT).body(warnMsg); // The worker will wait 15 mins and upon going to retry it will notice that it should not do a new request then or it may have already shutdown in the meantime. } if ( request == null ) {