From 326af0f12d2017962645c39bf11d37480c13beba Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Mon, 5 Dec 2022 21:58:16 +0200 Subject: [PATCH] - Return a success-message in the response-body, of the "shutdownWorkerGracefully" and "cancelShutdownWorkerGracefully" endpoints. - Apply the checks for the "totalZipBatches" param, before the Worker-related checks, in "FullTextsController.getMultipleFullTexts()" - Show the Heap-sizes in megabytes. --- .../urls_worker/UrlsWorkerApplication.java | 7 ++++--- .../controllers/FullTextsController.java | 20 +++++++++---------- .../controllers/GeneralController.java | 12 +++++------ 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/main/java/eu/openaire/urls_worker/UrlsWorkerApplication.java b/src/main/java/eu/openaire/urls_worker/UrlsWorkerApplication.java index a639ed2..1c91ed6 100644 --- a/src/main/java/eu/openaire/urls_worker/UrlsWorkerApplication.java +++ b/src/main/java/eu/openaire/urls_worker/UrlsWorkerApplication.java @@ -58,9 +58,10 @@ public class UrlsWorkerApplication { context = SpringApplication.run(UrlsWorkerApplication.class, args); Runtime javaRuntime = Runtime.getRuntime(); - logger.debug("HeapSize: " + javaRuntime.totalMemory()); - logger.debug("HeapMaxSize: " + javaRuntime.maxMemory()); - logger.debug("HeapFreeSize: " + javaRuntime.freeMemory()); + int mb = 1048576; + logger.debug("HeapSize: " + (javaRuntime.totalMemory() / mb) + " mb"); + logger.debug("HeapMaxSize: " + (javaRuntime.maxMemory() / mb) + " mb"); + logger.debug("HeapFreeSize: " + (javaRuntime.freeMemory() / mb) + " mb"); } diff --git a/src/main/java/eu/openaire/urls_worker/controllers/FullTextsController.java b/src/main/java/eu/openaire/urls_worker/controllers/FullTextsController.java index cd89c28..08fabbf 100644 --- a/src/main/java/eu/openaire/urls_worker/controllers/FullTextsController.java +++ b/src/main/java/eu/openaire/urls_worker/controllers/FullTextsController.java @@ -46,16 +46,6 @@ public class FullTextsController { return ResponseEntity.badRequest().body(errorMsg); } - logger.info("Received a \"getMultipleFullTexts\" request for returning a zip-file containing " + fileNamesListNum + " full-texts, from assignments_" + assignmentsCounter + ", for batch_" + zipBatchCounter + " (out of " + totalZipBatches + ")."); - - String currentAssignmentsBaseFullTextsPath = assignmentsBaseDir + "assignments_" + assignmentsCounter + "_fullTexts" + File.separator; - - if ( ! (new File(currentAssignmentsBaseFullTextsPath).isDirectory()) ) { - String errorMsg = "The base directory for assignments_" + assignmentsCounter + " was not found: " + currentAssignmentsBaseFullTextsPath; - logger.error(errorMsg); - return ResponseEntity.badRequest().body(errorMsg); - } - if ( totalZipBatches == 0 ) { String errorMsg = "The given \"totalZipBatches\" (" + totalZipBatches + ") was < 0 >!"; logger.error(errorMsg); @@ -67,6 +57,16 @@ public class FullTextsController { return ResponseEntity.badRequest().body(errorMsg); } + logger.info("Received a \"getMultipleFullTexts\" request for returning a zip-file containing " + fileNamesListNum + " full-texts, from assignments_" + assignmentsCounter + ", for batch_" + zipBatchCounter + " (out of " + totalZipBatches + ")."); + + String currentAssignmentsBaseFullTextsPath = assignmentsBaseDir + "assignments_" + assignmentsCounter + "_fullTexts" + File.separator; + + if ( ! (new File(currentAssignmentsBaseFullTextsPath).isDirectory()) ) { + String errorMsg = "The base directory for assignments_" + assignmentsCounter + " was not found: " + currentAssignmentsBaseFullTextsPath; + logger.error(errorMsg); + return ResponseEntity.badRequest().body(errorMsg); + } + File zipFile = FilesZipper.zipMultipleFilesAndGetZip(assignmentsCounter, zipBatchCounter, fileNamesWithExtensions, currentAssignmentsBaseFullTextsPath); if ( zipFile == null ) { String errorMsg = "Failed to create the zip file for \"zipBatchCounter\"-" + zipBatchCounter; diff --git a/src/main/java/eu/openaire/urls_worker/controllers/GeneralController.java b/src/main/java/eu/openaire/urls_worker/controllers/GeneralController.java index bf7d4f5..f43c80b 100644 --- a/src/main/java/eu/openaire/urls_worker/controllers/GeneralController.java +++ b/src/main/java/eu/openaire/urls_worker/controllers/GeneralController.java @@ -40,14 +40,14 @@ public class GeneralController { public ResponseEntity shutdownWorkerGracefully(@PathVariable String shutdownCode, HttpServletRequest request) { String initMsg = "Received a \"shutdownWorker\" request."; - ResponseEntity responseEntity = passSecurityChecks(request, shutdownCode, initMsg); if ( responseEntity != null ) return responseEntity; shouldShutdownWorker = true; - logger.info(initMsg + " The worker will shutdown, after finishing current work."); - return ResponseEntity.ok().build(); + String finalMsg = " The worker will shutdown, after finishing current work."; + logger.info(initMsg + finalMsg); + return ResponseEntity.ok().body(finalMsg); } @@ -55,14 +55,14 @@ public class GeneralController { public ResponseEntity cancelShutdownWorkerGracefully(@PathVariable String cancelCode, HttpServletRequest request) { String initMsg = "Received a \"cancelShutdownWorker\" request."; - ResponseEntity responseEntity = passSecurityChecks(request, cancelCode, initMsg); if ( responseEntity != null ) return responseEntity; shouldShutdownWorker = false; - logger.info(initMsg + " Any previous \"shutdownWorker\"-request is canceled. The \"maxAssignmentsBatchesToHandleBeforeShutdown\" will still be honored (if it's set)."); - return ResponseEntity.ok().build(); + String finalMsg = " Any previous \"shutdownWorker\"-request is canceled. The \"maxAssignmentsBatchesToHandleBeforeShutdown\" will still be honored (if it's set)."; + logger.info(initMsg + finalMsg); + return ResponseEntity.ok().body(finalMsg); }