- Add handling for the "EmptyResultDataAccessException" in "UrlsServiceImpl.getAssignments()", which is thrown when no assignments are returned from the query.

- Code polishing.
This commit is contained in:
Lampros Smyrnaios 2023-06-22 12:39:11 +03:00
parent b9712bed85
commit d52601e819
4 changed files with 13 additions and 7 deletions

View File

@ -4,6 +4,7 @@ services:
urls_controller:
image: 'pdf_aggregation_service/urls_controller:latest'
container_name: urls_controller
ports:
- '1880:1880'
volumes:

View File

@ -66,8 +66,8 @@ if [[ justInstall -eq 0 ]]; then
echo -e "Waiting 65 seconds before getting the status..\n"
sleep 65
sudo docker ps -a || handle_error "Could not get the status of docker-containers!" 6 # Using -a to get the status of failed containers as well.
echo -e "\n\nGetting the logs of docker-container \"urlscontroller-urls_controller-1\":\n"
sudo docker logs "$(sudo docker ps -aqf "name=^urlscontroller-urls_controller-1$")" || handle_error "Could not get the logs of docker-container \"urlscontroller-urls_controller-1\"!" 7 # Using "regex anchors" to avoid false-positives. Works even if the container is not running, thus showing the error-log.
echo -e "\n\nGetting the logs of docker-container \"urls_controller\":\n"
sudo docker logs "$(sudo docker ps -aqf "name=^urls_controller$")" || handle_error "Could not get the logs of docker-container \"urls_controller\"!" 7 # Using "regex anchors" to avoid false-positives. Works even if the container is not running, thus showing the error-log.
fi
else
export PATH=/opt/gradle/gradle-${gradleVersion}/bin:$PATH # Make sure the gradle is still accessible (it usually isn't without the "export").

View File

@ -6,7 +6,6 @@ import eu.openaire.urls_controller.payloads.requests.WorkerReport;
import eu.openaire.urls_controller.services.UrlsService;
import eu.openaire.urls_controller.util.FileUtils;
import eu.openaire.urls_controller.util.GenericUtils;
import eu.openaire.urls_controller.util.ParquetFileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -41,9 +40,6 @@ public class UrlsController {
@Autowired
private FileUtils fileUtils;
@Autowired
private ParquetFileUtils parquetFileUtils;
private static final Pattern MALICIOUS_INPUT_STRING = Pattern.compile(".*[';`\"]+.*");
@Value("${services.pdfaggregation.controller.assignmentLimit}")

View File

@ -12,6 +12,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
@ -170,12 +171,20 @@ public class UrlsServiceImpl implements UrlsService {
assignment.setDatasource(datasource);
assignments.add(assignment);
});
} catch (EmptyResultDataAccessException erdae) {
errorMsg = "No results were returned for \"getAssignmentsQuery\":\n" + getAssignmentsQuery;
String tmpErrMsg = dropCurrentAssignmentTable();
ImpalaConnector.databaseLock.unlock();
if ( tmpErrMsg != null )
errorMsg += "\n" + tmpErrMsg;
logger.warn(errorMsg);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(errorMsg);
} catch (Exception e) {
errorMsg = ImpalaConnector.handleQueryException("getAssignmentsQuery", getAssignmentsQuery, e);
String tmpErrMsg = dropCurrentAssignmentTable();
ImpalaConnector.databaseLock.unlock();
if ( tmpErrMsg != null )
errorMsg += "\n" + tmpErrMsg;
ImpalaConnector.databaseLock.unlock();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorMsg);
}