2021-03-16 17:38:53 +01:00
|
|
|
package eu.openaire.urls_worker.controllers;
|
|
|
|
|
2021-09-22 15:36:48 +02:00
|
|
|
import eu.openaire.urls_worker.UrlsWorkerApplication;
|
2021-05-20 02:28:48 +02:00
|
|
|
import eu.openaire.urls_worker.payloads.responces.WorkerResponse;
|
|
|
|
import eu.openaire.urls_worker.util.AssignmentHandler;
|
|
|
|
import eu.openaire.urls_worker.util.WorkerConstants;
|
2021-03-16 17:38:53 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2021-05-20 02:28:48 +02:00
|
|
|
import org.springframework.http.HttpStatus;
|
2021-03-16 17:38:53 +01:00
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("")
|
|
|
|
public class GeneralController {
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(GeneralController.class);
|
|
|
|
|
|
|
|
|
2021-09-21 15:21:39 +02:00
|
|
|
public GeneralController() {}
|
2021-03-16 17:38:53 +01:00
|
|
|
|
|
|
|
@GetMapping("isAlive")
|
|
|
|
public ResponseEntity<?> isWorkerAlive() {
|
|
|
|
|
|
|
|
logger.info("Received an \"isAlive\" request.");
|
|
|
|
|
|
|
|
return ResponseEntity.ok().build();
|
|
|
|
}
|
|
|
|
|
2021-05-20 02:28:48 +02:00
|
|
|
|
|
|
|
@GetMapping("isAvailableForWork")
|
|
|
|
public ResponseEntity<?> isWorkerAvailableForWork() {
|
|
|
|
|
|
|
|
logger.info("Received an \"isWorkerAvailableForWork\" request.");
|
|
|
|
|
|
|
|
if ( AssignmentHandler.isAvailableForWork ) {
|
|
|
|
logger.info("The worker is available for an assignment.");
|
2021-09-22 15:36:48 +02:00
|
|
|
return ResponseEntity.status(200).body(new WorkerResponse(UrlsWorkerApplication.workerId, WorkerConstants.ASSIGNMENTS_LIMIT));
|
2021-05-20 02:28:48 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
logger.info("The worker is busy with another assignment.");
|
|
|
|
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 17:38:53 +01:00
|
|
|
}
|