aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHÃ¥kon Hallingstad <hakon@yahooinc.com>2022-01-17 22:59:36 +0100
committerGitHub <noreply@github.com>2022-01-17 22:59:36 +0100
commit7e0c5b69ff9e99447dd7cf223321e760f4f2a130 (patch)
treea5629387fa401756c6f5b7dc77fd06c9c4db054e
parent13babe5abd3ecb8ffe95124662d835df157c4bea (diff)
parent4f16a16b9d6b182a22b7ba2134bd8df29c3c04d2 (diff)
Merge pull request #20844 from vespa-engine/freva/report-host-admin-cores
Create StoredDouble
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/StoredDouble.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/StoredDouble.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/StoredDouble.java
new file mode 100644
index 00000000000..3249dab1ca8
--- /dev/null
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/StoredDouble.java
@@ -0,0 +1,46 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.node.admin.task.util.file;
+
+import com.yahoo.vespa.hosted.node.admin.component.TaskContext;
+
+import java.nio.file.Path;
+import java.time.Instant;
+import java.util.Optional;
+import java.util.OptionalDouble;
+import java.util.function.Supplier;
+import java.util.logging.Logger;
+
+/**
+ * Class wrapping a float stored on disk
+ *
+ * @author freva
+ */
+public class StoredDouble implements Supplier<OptionalDouble> {
+
+ private static final Logger logger = Logger.getLogger(StoredDouble.class.getName());
+
+ private final UnixPath path;
+
+ public StoredDouble(Path path) {
+ this.path = new UnixPath(path);
+ }
+
+ @Override
+ public OptionalDouble get() {
+ return path.readUtf8FileIfExists().stream().mapToDouble(Double::parseDouble).findAny();
+ }
+
+ public void write(TaskContext taskContext, double value) {
+ path.writeUtf8File(Double.toString(value));
+ taskContext.log(logger, "Stored new double in %s: %f", path, value);
+ }
+
+ public void clear() {
+ path.deleteIfExists();
+ }
+
+ public Optional<Instant> getLastModifiedTime() {
+ return path.getAttributesIfExists().map(FileAttributes::lastModifiedTime);
+ }
+
+}