- Improve error-handling in "ConnWithController.postShutdownReportToController()".

- Update dependencies.
This commit is contained in:
Lampros Smyrnaios 2024-05-22 16:14:45 +03:00
parent b40c72f78f
commit c242f65518
3 changed files with 17 additions and 6 deletions

View File

@ -1,6 +1,6 @@
plugins {
id 'org.springframework.boot' version '2.7.18'
id 'io.spring.dependency-management' version '1.1.4'
id 'io.spring.dependency-management' version '1.1.5'
id 'java'
}
@ -44,7 +44,7 @@ dependencies {
exclude group: 'io.minio' // This is not used in the Worker, since it's the Controller which uploads the full-texts to S3. It also includes an older "commons-compress" version which causes problems.
}
implementation group: 'com.google.guava', name: 'guava', version: '33.1.0-jre'
implementation group: 'com.google.guava', name: 'guava', version: '33.2.0-jre'
// https://mvnrepository.com/artifact/com.google.code.gson/gson
implementation 'com.google.code.gson:gson:2.10.1'

View File

@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;
@ -26,8 +27,9 @@ public class ConnWithController {
public boolean postShutdownReportToController(String workerId)
{
logger.info("Going to \"postShutdownReportToController\".");
String url = this.controllerBaseUrl + "workerShutdownReport?workerId=" + workerId;
try {
ResponseEntity<String> responseEntity = new RestTemplate().postForEntity(this.controllerBaseUrl + "workerShutdownReport?workerId=" + workerId, null, String.class);
ResponseEntity<String> responseEntity = new RestTemplate().postForEntity(url, null, String.class);
int responseCode = responseEntity.getStatusCodeValue();
if ( responseCode != HttpStatus.OK.value() ) {
logger.error("HTTP-Connection problem with the submission of the \"postShutdownReportToController\"! Error-code was: " + responseCode);
@ -36,8 +38,17 @@ public class ConnWithController {
} catch (HttpServerErrorException hsee) {
logger.error("The Controller failed to handle the \"postShutdownReportToController\": " + hsee.getMessage());
return false;
} catch (HttpClientErrorException hcee) {
logger.error("The Worker did something wrong when sending the report result to the Controller. | url: " + url + "\n" + hcee.getMessage());
return false;
} catch (Exception e) {
logger.error("Error for \"postShutdownReportToController\" to the Controller.", e);
String errorMsg = "Error for \"postShutdownReportToController\", to the Controller.";
Throwable cause = e.getCause();
String exMsg;
if ( (cause != null) && ((exMsg = cause.getMessage()) != null) && exMsg.contains("Connection refused") )
logger.error(errorMsg + " | The Controller has probably crashed, since we received a \"Connection refused\" message!");
else
logger.error(errorMsg, e);
return false;
}
return true;

View File

@ -73,7 +73,7 @@ public class GeneralController {
finalMsg = "The worker has already received a \"shutdownWorker\" request (which was not canceled afterwards). ";
else {
shouldShutdownWorker = true;
AssignmentsHandler.shouldNotRequestMore = true;
AssignmentsHandler.shouldNotRequestMore = true; // Make sure the worker shuts-down, in case the user sends the relevant request, while the worker is stuck in a data-request error-loop.
}
finalMsg += "The worker will shutdown, after finishing current work.";
@ -92,7 +92,7 @@ public class GeneralController {
shouldShutdownWorker = false;
if ( AssignmentsHandler.numHandledAssignmentsBatches < assignmentsHandler.maxAssignmentsBatchesToHandleBeforeShutdown )
AssignmentsHandler.shouldNotRequestMore = false; // Make sure the worker shuts-down, in case the user sends the relevant request, while the worker is stuck in a data-request error-loop.
AssignmentsHandler.shouldNotRequestMore = false;
String finalMsg = "Any previous \"shutdownWorker\"-request is canceled. The \"maxAssignmentsBatchesToHandleBeforeShutdown\" will still be honored (if it's set).";
logger.info(initMsg + finalMsg);