- Move the "shutdownOrCancelCode" input in the "inputDataFile" provided by the user, for convenience and to be able to make this "auth-code" mandatory. Previously, it was optional and the app could not be made to stop in a normal-manner, if this code was not provided.
- Improve the instructions and the error-messages for the "inputDataFile".
This commit is contained in:
parent
d91732bc16
commit
5035094e44
|
@ -6,8 +6,11 @@ The Worker responds by compressing and sending the requested files in each batch
|
|||
<br>
|
||||
To install and run the application:
|
||||
- Run ```git clone``` and then ```cd UrlsWorker```.
|
||||
- [Optional] Create the file ```inputData.txt``` , which contains just one line with the ___workerId___, the __maxAssignmentsLimitPerBatch__, the __maxAssignmentsBatchesToHandleBeforeRestart__ and the ___controller's base api-url___, all seperated by a _comma_ ```,``` . For example: ```worker_1,1000,0,http://IP:PORT/api/```.
|
||||
- Execute the ```installAndRun.sh``` script. In case the above file (_inputData.txt_) does not exist, it will request the required data from the user, and then it will create the _inputData.txt_ file.<br>
|
||||
- [Optional] Create the file ```inputData.txt``` , which contains just one line with the ___workerId___, the ___maxAssignmentsLimitPerBatch___, the ___maxAssignmentsBatchesToHandleBeforeRestart___, the ___controller's base api-url___ and the ___shutdownOrCancelCode___, all seperated by a _comma_ "```,```" .<br>
|
||||
For example: ```worker_1,1000,0,http://IP:PORT/api/,stopOrCancelCode```.<br>
|
||||
The ___shutdownOrCancelCode___ is kind of an "auth-code", when receiving "__shutdown__" and "__cancel-shutdown__" requests.
|
||||
- Execute the ```installAndRun.sh``` script.<br>
|
||||
In case the above file (_inputData.txt_) does not exist, the script will request the required data from the user, and then it will create the _inputData.txt_ file.<br>
|
||||
<br>
|
||||
|
||||
Notes:
|
||||
|
|
|
@ -26,8 +26,11 @@ if [[ ! -f $inputDataFile ]]; then
|
|||
echo -e "\nGive the baseUrl of the controller (e.g.: http://IP:PORT/api/):"
|
||||
read -r controllerBaseUrl
|
||||
|
||||
echo -e "\nGive the shutdownOrCancelCode, as an \"auth-code\", when receiving \"shutdown\" and \"cancel-shutdown\" requests.:"
|
||||
read -r shutdownOrCancelCode
|
||||
|
||||
touch $inputDataFile
|
||||
echo "$workerId,$maxAssignmentsLimitPerBatch,$maxAssignmentsBatchesToHandleBeforeRestart,$controllerBaseUrl" >> $inputDataFile
|
||||
echo "$workerId,$maxAssignmentsLimitPerBatch,$maxAssignmentsBatchesToHandleBeforeRestart,$controllerBaseUrl,$shutdownOrCancelCode" >> $inputDataFile
|
||||
echo -e "\n\n"
|
||||
fi
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ public class UrlsWorkerApplication {
|
|||
public static int maxAssignmentsLimitPerBatch = 0;
|
||||
public static int maxAssignmentsBatchesToHandleBeforeShutdown = -1; // Default value: -1 = argument-absent, 0 = infinite-batches
|
||||
public static String controllerBaseUrl = null; // BaseUrl template: "http://IP:PORT/api/"
|
||||
public static String shutdownOrCancelCode = null;
|
||||
|
||||
private static ConfigurableApplicationContext context;
|
||||
|
||||
|
@ -129,8 +130,10 @@ public class UrlsWorkerApplication {
|
|||
myReader = new Scanner(inputDataFile);
|
||||
if ( myReader.hasNextLine() ) {
|
||||
String[] data = myReader.nextLine().split(",");
|
||||
if ( data.length < 4 ) {
|
||||
String errorMsg = "Not all data were retrieved from file \"" + inputDataFilePath + "\"!";
|
||||
if ( data.length < 5 ) {
|
||||
String errorMsg = "Not all data was retrieved from file \"" + inputDataFilePath + "\"!\n"
|
||||
+ "The file should contain the \"workerId\", the \"maxAssignmentsLimitPerBatch\", the \"maxAssignmentsBatchesToHandleBeforeShutdown\", "
|
||||
+ "the \"controllerBaseUrl\" and the \"shutdownOrCancelCode\", all seperated by a comma \",\".";
|
||||
logger.error(errorMsg);
|
||||
System.err.println(errorMsg);
|
||||
System.exit(61);
|
||||
|
@ -161,19 +164,24 @@ public class UrlsWorkerApplication {
|
|||
}
|
||||
if ( !controllerBaseUrl.endsWith("/") )
|
||||
controllerBaseUrl += "/"; // Make sure the other urls will not break later.
|
||||
|
||||
shutdownOrCancelCode = data[4].trim();
|
||||
}
|
||||
|
||||
if ( (workerId == null) || (maxAssignmentsLimitPerBatch == 0) || (maxAssignmentsBatchesToHandleBeforeShutdown == -1) || (controllerBaseUrl == null) ) {
|
||||
String errorMsg = "No \"workerId\" or/and \"maxAssignmentsLimitPerBatch\" or/and \"maxAssignmentsBatchesToHandleBeforeRestart\" or/and \"controllerBaseUrl\" could be retrieved from the file: " + inputDataFilePath;
|
||||
if ( (workerId == null) || (maxAssignmentsLimitPerBatch == 0) || (maxAssignmentsBatchesToHandleBeforeShutdown == -1) || (controllerBaseUrl == null)
|
||||
|| (shutdownOrCancelCode == null) )
|
||||
{
|
||||
String errorMsg = "No \"workerId\" or/and \"maxAssignmentsLimitPerBatch\" or/and \"maxAssignmentsBatchesToHandleBeforeRestart\" or/and \"controllerBaseUrl\" or/and \"shutdownOrCancelCode\" could be retrieved from the file: " + inputDataFilePath;
|
||||
logger.error(errorMsg);
|
||||
System.err.println(errorMsg);
|
||||
System.exit(63);
|
||||
}
|
||||
|
||||
logger.info("workerId: " + workerId + ", maxAssignmentsLimitPerBatch: " + maxAssignmentsLimitPerBatch + ", maxAssignmentsBatchesToHandleBeforeRestart: " + maxAssignmentsBatchesToHandleBeforeShutdown + ", controllerBaseUrl: " + controllerBaseUrl); // It's safe and helpful to show them in the logs.
|
||||
logger.info("workerId: " + workerId + ", maxAssignmentsLimitPerBatch: " + maxAssignmentsLimitPerBatch + ", maxAssignmentsBatchesToHandleBeforeRestart: " + maxAssignmentsBatchesToHandleBeforeShutdown + ", controllerBaseUrl: " + controllerBaseUrl + ", shutdownOrCancelCode: <PRIVATE FOR SECURITY REASONS>");
|
||||
// It's safe and helpful to show all but the last variable, in the logs (keep in mind that the developer might not always be the end-user).
|
||||
|
||||
} catch (Exception e) {
|
||||
String errorMsg = "An error prevented the retrieval of the workerId and the controllerBaseUrl from the file: " + inputDataFilePath + "\n" + e.getMessage();
|
||||
String errorMsg = "An error prevented the retrieval of data from the file: " + inputDataFilePath + "\n" + e.getMessage();
|
||||
logger.error(errorMsg, e);
|
||||
System.err.println(errorMsg);
|
||||
System.exit(64);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package eu.openaire.urls_worker.controllers;
|
||||
|
||||
import eu.openaire.urls_worker.UrlsWorkerApplication;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -21,9 +21,6 @@ public class GeneralController {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GeneralController.class);
|
||||
|
||||
@Value("${security.shutdownOrCancelCode}")
|
||||
private String shutdownOrCancelCode;
|
||||
|
||||
|
||||
public GeneralController() {}
|
||||
|
||||
|
@ -41,7 +38,7 @@ public class GeneralController {
|
|||
public ResponseEntity<?> shutdownWorkerGracefully(@PathVariable String shutdownCode)
|
||||
{
|
||||
String initMsg = "Received a \"shutdownWorker\" request.";
|
||||
if ( shutdownCode.equals(shutdownOrCancelCode) ) {
|
||||
if ( shutdownCode.equals(UrlsWorkerApplication.shutdownOrCancelCode) ) {
|
||||
shouldShutdownWorker = true;
|
||||
logger.info(initMsg + " The worker will shutdown, after finishing current work.");
|
||||
return ResponseEntity.ok().build();
|
||||
|
@ -57,7 +54,7 @@ public class GeneralController {
|
|||
public ResponseEntity<?> cancelShutdownWorkerGracefully(@PathVariable String cancelCode)
|
||||
{
|
||||
String initMsg = "Received a \"cancelShutdownWorker\" request.";
|
||||
if ( cancelCode.equals(shutdownOrCancelCode) ) {
|
||||
if ( cancelCode.equals(UrlsWorkerApplication.shutdownOrCancelCode) ) {
|
||||
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();
|
||||
|
|
|
@ -15,9 +15,6 @@ server.port = 1881
|
|||
# Server api path
|
||||
server.servlet.context-path=/api
|
||||
|
||||
# Here set the code to be checked, when receiving "shutdown" and "cancel-shutdown" requests.
|
||||
security.shutdownOrCancelCode=
|
||||
|
||||
|
||||
# LOGGING LEVELS
|
||||
logging.config=classpath:logback-spring.xml
|
||||
|
|
Loading…
Reference in New Issue