From 145705d63d17870a6743c29d273dc1ba09f67f49 Mon Sep 17 00:00:00 2001 From: christophe mangeat Date: Fri, 12 Jan 2024 16:52:26 +0100 Subject: [PATCH] 'improve' logs outputs --- .../api/maintenance/DatadirCleaner.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/services/src/main/java/org/fao/geonet/api/maintenance/DatadirCleaner.java b/services/src/main/java/org/fao/geonet/api/maintenance/DatadirCleaner.java index 8dc74875ab..76649288e4 100644 --- a/services/src/main/java/org/fao/geonet/api/maintenance/DatadirCleaner.java +++ b/services/src/main/java/org/fao/geonet/api/maintenance/DatadirCleaner.java @@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; -import java.io.BufferedWriter; import java.io.IOException; import java.io.PrintWriter; import java.nio.file.Files; @@ -37,6 +36,8 @@ public class DatadirCleaner { private final AtomicInteger counter = new AtomicInteger(); + PrintWriter pwToFlush; + @io.swagger.v3.oas.annotations.Operation(summary = "Clean data dir") @RequestMapping( path = "/cleanDatadir", @@ -54,9 +55,10 @@ public ObjectNode cleanFile() throws IOException { Path orphanedDataFilePath = rootPath.resolve("orphanedDataFiles.txt"); counter.set(0); try(PrintWriter pw = new PrintWriter(Files.newBufferedWriter(orphanedDataFilePath))) { + pwToFlush = pw; listFilesEatingException(rootPath) // - .flatMap(this::listFilesEatingException) - .flatMap(this::processPath) + .flatMap(this::listFilesEatingException) // + .flatMap(this::processPath) // .forEach(pw::println); } ObjectNode status = new ObjectMapper().createObjectNode() @@ -67,12 +69,20 @@ public ObjectNode cleanFile() throws IOException { private Stream processPath(Path path) { List toReturn = new ArrayList<>(); int i = counter.incrementAndGet(); - if (i % 3 == 0) { - toReturn.add(String.format("got %d", i)); + boolean orphanedPath = false; + try { + orphanedPath = isOrphanedPath(path); + } catch (RuntimeException e) { + toReturn.add(String.format("ERROR# %s", path.toString())); } - if (isOrphanedPath(path)) { + if (orphanedPath) { String toLog = path.toAbsolutePath().toString(); toReturn.add(toLog); + toReturn.add(String.format("SQL# select count(*) from metadata where id = %s", path.getFileName().toString())); + } + if (i % 100 == 0) { + toReturn.add(String.format("got %d", i)); + pwToFlush.flush(); } return toReturn.stream(); }