use of com.hubspot.singularity.runner.base.shared.CompressionType in project Singularity by HubSpot.
the class SingularityExecutorCleanup method checkForUncompressedLogrotatedFile.
private void checkForUncompressedLogrotatedFile(SingularityExecutorTaskDefinition taskDefinition) {
final Iterator<Path> iterator = getUncompressedLogrotatedFileIterator(taskDefinition);
final Set<String> emptyPaths = new HashSet<>();
final List<Path> uncompressedFiles = new ArrayList<>();
while (iterator.hasNext()) {
Path path = iterator.next();
final String fileName = Objects.toString(path.getFileName());
Optional<CompressionType> maybeCompressionType = getFileCompressionType(fileName);
if (maybeCompressionType.isPresent()) {
try {
if (Files.size(path) == 0) {
Files.deleteIfExists(path);
emptyPaths.add(fileName.substring(0, fileName.length() - maybeCompressionType.get().getExtention().length()));
}
} catch (IOException ioe) {
LOG.error("Failed to handle empty {} file {}", maybeCompressionType.get(), path, ioe);
exceptionNotifier.notify(String.format("Error handling empty file (%s)", ioe.getMessage()), ioe, ImmutableMap.of("file", path.toString()));
}
} else {
uncompressedFiles.add(path);
}
}
for (Path path : uncompressedFiles) {
if (emptyPaths.contains(Objects.toString(path.getFileName()))) {
LOG.info("Compressing abandoned file {}", path);
try {
new SimpleProcessManager(LOG).runCommand(ImmutableList.<String>of(cleanupConfiguration.getCompressionType().getCommand(), path.toString()));
} catch (InterruptedException | ProcessFailedException e) {
LOG.error("Failed to {} {}", cleanupConfiguration.getCompressionType(), path, e);
exceptionNotifier.notify(String.format("Failed to gzip (%s)", e.getMessage()), e, ImmutableMap.of("file", path.toString()));
}
} else {
LOG.debug("Didn't find matched empty {} file for {}", cleanupConfiguration.getCompressionType(), path);
}
}
}
Aggregations