summaryrefslogtreecommitdiffstats
path: root/node-maintainer/src/main/java/com
diff options
context:
space:
mode:
authorvalerijf <valerijf@yahoo-inc.com>2017-03-14 10:52:11 +0100
committervalerijf <valerijf@yahoo-inc.com>2017-03-14 10:52:11 +0100
commit32e759d5bf25249d82fd1d1c601e72ec813f420b (patch)
treee537e35458ab86e8cb670af117fcb0db820ea17d /node-maintainer/src/main/java/com
parent66da72ee09dd5934d796b06c0cfe91d78ee3b8e4 (diff)
handle-core-dumps deletes old core-dumps
Diffstat (limited to 'node-maintainer/src/main/java/com')
-rw-r--r--node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/CoredumpHandler.java41
-rw-r--r--node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/Maintainer.java7
2 files changed, 34 insertions, 14 deletions
diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/CoredumpHandler.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/CoredumpHandler.java
index 5794e5e5389..8e50feee506 100644
--- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/CoredumpHandler.java
+++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/CoredumpHandler.java
@@ -37,23 +37,42 @@ public class CoredumpHandler {
private final HttpClient httpClient;
private final CoreCollector coreCollector;
+ private final Path coredumpsPath;
+ private final Path doneCoredumpsPath;
+ private final Map<String, Object> nodeAttributes;
- public CoredumpHandler(HttpClient httpClient, CoreCollector coreCollector) {
+ public CoredumpHandler(HttpClient httpClient, CoreCollector coreCollector, Path coredumpsPath, Path doneCoredumpsPath,
+ Map<String, Object> nodeAttributes) {
this.httpClient = httpClient;
this.coreCollector = coreCollector;
+ this.coredumpsPath = coredumpsPath;
+ this.doneCoredumpsPath = doneCoredumpsPath;
+ this.nodeAttributes = nodeAttributes;
}
- public void processAndReportCoredumps(Path coredumpsPath, Path doneCoredumpPath, Map<String, Object> nodeAttributes) throws IOException {
- Path processingCoredumps = processCoredumps(coredumpsPath, nodeAttributes);
- reportCoredumps(processingCoredumps, doneCoredumpPath);
+ public void processAll() throws IOException {
+ removeJavaCoredumps();
+ processAndReportCoredumps();
+ removeOldCoredumps();
}
- public void removeJavaCoredumps(Path javaCoredumpsPath) throws IOException {
- if (! javaCoredumpsPath.toFile().isDirectory()) return;
- FileHelper.deleteFiles(javaCoredumpsPath, Duration.ZERO, Optional.of("^java_pid.*\\.hprof$"), false);
+ private void removeJavaCoredumps() throws IOException {
+ if (! coredumpsPath.toFile().isDirectory()) return;
+ FileHelper.deleteFiles(coredumpsPath, Duration.ZERO, Optional.of("^java_pid.*\\.hprof$"), false);
}
- Path processCoredumps(Path coredumpsPath, Map<String, Object> nodeAttributes) throws IOException {
+ private void removeOldCoredumps() throws IOException {
+ if (! doneCoredumpsPath.toFile().isDirectory()) return;
+ FileHelper.deleteDirectories(doneCoredumpsPath, Duration.ofDays(10), Optional.empty());
+ }
+
+ private void processAndReportCoredumps() throws IOException {
+ Path processingCoredumps = processCoredumps();
+ reportCoredumps(processingCoredumps);
+ }
+
+
+ Path processCoredumps() throws IOException {
Path processingCoredumpsPath = coredumpsPath.resolve(PROCESSING_DIRECTORY_NAME);
processingCoredumpsPath.toFile().mkdirs();
@@ -75,7 +94,7 @@ public class CoredumpHandler {
return processingCoredumpsPath;
}
- void reportCoredumps(Path processingCoredumpsPath, Path doneCoredumpsPath) throws IOException {
+ void reportCoredumps(Path processingCoredumpsPath) throws IOException {
doneCoredumpsPath.toFile().mkdirs();
Files.list(processingCoredumpsPath)
@@ -83,7 +102,7 @@ public class CoredumpHandler {
.forEach(coredumpDirectory -> {
try {
report(coredumpDirectory);
- finishProcessing(coredumpDirectory, doneCoredumpsPath);
+ finishProcessing(coredumpDirectory);
} catch (Throwable e) {
logger.log(Level.WARNING, "Failed to report coredump " + coredumpDirectory, e);
}
@@ -128,7 +147,7 @@ public class CoredumpHandler {
logger.info("Successfully reported coredump " + documentId);
}
- void finishProcessing(Path coredumpDirectory, Path doneCoredumpsPath) throws IOException {
+ void finishProcessing(Path coredumpDirectory) throws IOException {
Files.move(coredumpDirectory, doneCoredumpsPath.resolve(coredumpDirectory.getFileName()));
}
}
diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/Maintainer.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/Maintainer.java
index 4c9e80aaa8c..8447e04eb4b 100644
--- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/Maintainer.java
+++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/Maintainer.java
@@ -6,6 +6,7 @@ import com.yahoo.slime.Inspector;
import com.yahoo.slime.Type;
import com.yahoo.system.ProcessExecuter;
import com.yahoo.vespa.config.SlimeUtils;
+import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import java.io.IOException;
@@ -21,7 +22,7 @@ import java.util.Optional;
*/
public class Maintainer {
private static final CoreCollector coreCollector = new CoreCollector(new ProcessExecuter());
- private static final CoredumpHandler coredumpHandler = new CoredumpHandler(HttpClientBuilder.create().build(), coreCollector);
+ private static final HttpClient httpClient = HttpClientBuilder.create().build();
public static void main(String[] args) {
if (args.length != 1) {
@@ -125,8 +126,8 @@ public class Maintainer {
Map<String, Object> attributesMap = parseMap(arguments);
try {
- coredumpHandler.removeJavaCoredumps(coredumpsPath);
- coredumpHandler.processAndReportCoredumps(coredumpsPath, doneCoredumpsPath, attributesMap);
+ CoredumpHandler coredumpHandler = new CoredumpHandler(httpClient, coreCollector, coredumpsPath, doneCoredumpsPath, attributesMap);
+ coredumpHandler.processAll();
} catch (IOException e) {
throw new RuntimeException("Failed processing coredumps at " + coredumpsPath.toAbsolutePath() +
", moving fished dumps to " + doneCoredumpsPath.toAbsolutePath(), e);