summaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/Cgroup.java
diff options
context:
space:
mode:
Diffstat (limited to 'node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/Cgroup.java')
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/Cgroup.java19
1 files changed, 3 insertions, 16 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/Cgroup.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/Cgroup.java
index c7616abd508..1d87415b78e 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/Cgroup.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/Cgroup.java
@@ -5,12 +5,7 @@ package com.yahoo.vespa.hosted.node.admin.container;
import com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentContext;
import com.yahoo.vespa.hosted.node.admin.task.util.file.UnixPath;
-import java.io.IOException;
-import java.io.UncheckedIOException;
-import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
-import java.nio.file.Files;
-import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.OptionalInt;
import java.util.logging.Logger;
@@ -85,17 +80,9 @@ public class Cgroup {
}
private OptionalInt readCgroupsCpuInt(UnixPath unixPath) {
- final byte[] currentContentBytes;
- try {
- currentContentBytes = Files.readAllBytes(unixPath.toPath());
- } catch (NoSuchFileException e) {
- return OptionalInt.empty();
- } catch (IOException e) {
- throw new UncheckedIOException(e);
- }
-
- String currentContent = new String(currentContentBytes, StandardCharsets.UTF_8).strip();
- return OptionalInt.of(Integer.parseInt(currentContent));
+ return unixPath.readUtf8FileIfExists()
+ .map(s -> OptionalInt.of(Integer.parseInt(s.strip())))
+ .orElseGet(OptionalInt::empty);
}
private boolean writeCgroupsCpuInt(NodeAgentContext context, UnixPath unixPath, int value) {