- Add handling for the case, when the Controller could not retrieve any assignments from the database (without an error).
- Improve exception handling. - Remove obsolete code.
This commit is contained in:
parent
182d6153d4
commit
5f48f72f06
|
@ -1,16 +0,0 @@
|
|||
package eu.openaire.urls_worker.exceptions;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
public class FileStorageException extends RuntimeException {
|
||||
|
||||
public FileStorageException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public FileStorageException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
|
@ -69,6 +69,7 @@ public class PublicationsRetrieverPlugin {
|
|||
PublicationsRetriever.executor = Executors.newFixedThreadPool(workerThreadsCount);
|
||||
}
|
||||
|
||||
|
||||
private static final List<Callable<Boolean>> callableTasks = new ArrayList<>(FileUtils.jsonBatchSize);
|
||||
|
||||
public static void processAssignments(Long assignmentRequestCounter, Collection<Assignment> assignments) throws RuntimeException
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package eu.openaire.urls_worker.services;
|
||||
|
||||
import eu.openaire.urls_worker.exceptions.FileStorageException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -39,28 +36,20 @@ public class FileStorageService {
|
|||
} catch (IOException ioe) {
|
||||
logger.error("I/O error when reading the properties file!", ioe);
|
||||
System.exit(-11);
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
System.exit(-12);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
public FileStorageService() throws FileStorageException {
|
||||
public FileStorageService() {
|
||||
try {
|
||||
Files.createDirectories(assignmentsLocation);
|
||||
} catch (Exception ex) {
|
||||
throw new FileStorageException("Could not create the directory where the uploaded files will be stored.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Resource loadFileAsResource(String fullFileName) {
|
||||
try {
|
||||
Path filePath = assignmentsLocation.resolve(fullFileName).normalize();
|
||||
Resource resource = new UrlResource(filePath.toUri());
|
||||
return resource.exists() ? resource : null;
|
||||
} catch (Exception e) {
|
||||
logger.error("Error when loading file: " + fullFileName, e);
|
||||
return null;
|
||||
logger.error("Could not create the directory where the downloaded files will be stored.", e);
|
||||
System.exit(-13);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,8 +90,11 @@ public class AssignmentsHandler {
|
|||
Long assignmentRequestCounter = assignmentsRequest.getAssignmentsCounter();
|
||||
List<Assignment> assignments = assignmentsRequest.getAssignments();
|
||||
if ( assignments == null ) {
|
||||
logger.warn("The assignments were found to be null for assignmentRequestCounter = " + assignmentRequestCounter);
|
||||
return;
|
||||
if ( assignmentRequestCounter == -1 )
|
||||
logger.warn("The Controller could not retrieve and assignments from the database. It will increase the attempts-number and retry in the next request.");
|
||||
else
|
||||
logger.warn("The assignments were found to be null for assignmentRequestCounter = " + assignmentRequestCounter);
|
||||
return; // The Worker will just request the assignments again, immediately.
|
||||
}
|
||||
|
||||
int assignmentsSize = assignments.size();
|
||||
|
|
Loading…
Reference in New Issue