summaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorJon Marius Venstad <jvenstad@yahoo-inc.com>2018-08-23 11:04:32 +0200
committerJon Marius Venstad <jvenstad@yahoo-inc.com>2018-08-23 11:06:36 +0200
commitc1230b52de0f86705a606d9aeae9cd4be510bbaa (patch)
tree66f1ba39b2d4ea1344961ed9ce7cb22a8505d2f6 /controller-server
parent3c65eb984c89d26fb38243bc8c76b1ae917922a6 (diff)
Use Optional for get and delete on appliation level in RunDataStore
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/LogEntry.java48
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/LogStore.java5
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/RunDetails.java26
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/RunLog.java55
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStore.java5
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/LogSerializer.java (renamed from controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/LogRecordSerializer.java)0
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStoreTest.java5
7 files changed, 113 insertions, 31 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/LogEntry.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/LogEntry.java
new file mode 100644
index 00000000000..e224a9c277a
--- /dev/null
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/LogEntry.java
@@ -0,0 +1,48 @@
+package com.yahoo.vespa.hosted.controller.deployment;
+
+import com.yahoo.log.LogLevel;
+
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+import static java.util.Objects.requireNonNull;
+
+/** Immutable, simple log entries. */
+public class LogEntry {
+
+ private final long id;
+ private final long at;
+ private final Level level;
+ private final String message;
+
+ public LogEntry(long id, long at, Level level, String message) {
+ if (id < 0)
+ throw new IllegalArgumentException("Id must be non-negative, but was " + id + ".");
+
+ this.id = id;
+ this.at = at;
+ this.level = LogLevel.getVespaLogLevel(requireNonNull(level));
+ this.message = requireNonNull(message);
+ }
+
+ public static LogEntry of(LogRecord record) {
+ return new LogEntry(record.getSequenceNumber(), record.getMillis(), record.getLevel(), record.getMessage());
+ }
+
+ public long id() {
+ return id;
+ }
+
+ public long at() {
+ return at;
+ }
+
+ public Level level() {
+ return level;
+ }
+
+ public String message() {
+ return message;
+ }
+
+}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/LogStore.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/LogStore.java
deleted file mode 100644
index 9579da67803..00000000000
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/LogStore.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.yahoo.vespa.hosted.controller.deployment;
-
-public class LogStore {
-
-}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/RunDetails.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/RunDetails.java
deleted file mode 100644
index 60d7a6a8f04..00000000000
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/RunDetails.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.yahoo.vespa.hosted.controller.deployment;
-
-import com.google.common.collect.ImmutableMap;
-
-import java.util.Map;
-import java.util.Optional;
-
-/**
- * Contains details about a deployment job run.
- *
- * @author jonmv
- */
-public class RunDetails {
-
- // TODO jvenstad: Store a serialised structure, rather than a flat text.
- private final Map<Step, byte[]> logs;
-
- public RunDetails(Map<Step, byte[]> logs) {
- this.logs = ImmutableMap.copyOf(logs);
- }
-
- public Optional<byte[]> get(Step step) {
- return Optional.ofNullable(logs.get(step));
- }
-
-}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/RunLog.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/RunLog.java
new file mode 100644
index 00000000000..615d6e444da
--- /dev/null
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/RunLog.java
@@ -0,0 +1,55 @@
+package com.yahoo.vespa.hosted.controller.deployment;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.OptionalLong;
+
+/**
+ * Immutable class which contains details about a deployment job run.
+ *
+ * @author jonmv
+ */
+public class RunDetails {
+
+ private static final RunDetails empty = RunDetails.of(Collections.emptyMap());
+
+ private final Map<Step, List<LogEntry>> log;
+ private final OptionalLong lastId;
+
+ private RunDetails(OptionalLong lastId, Map<Step, List<LogEntry>> log) {
+ this.log = log;
+ this.lastId = lastId;
+ }
+
+ /** Creates a RunDetails which contains a deep copy of the given logs. */
+ public static RunDetails of(Map<Step, List<LogEntry>> logs) {
+ ImmutableMap.Builder<Step, List<LogEntry>> builder = ImmutableMap.builder();
+ logs.forEach((step, entries) -> builder.put(step, ImmutableList.copyOf(entries)));
+ OptionalLong lastId = logs.values().stream()
+ .flatMap(List::stream)
+ .mapToLong(LogEntry::id)
+ .max();
+ return new RunDetails(lastId, builder.build());
+ }
+
+ /** Returns an empty RunDetails. */
+ public static RunDetails empty() {
+ return empty;
+ }
+
+ /** Returns the log entries for the given step, if any are recorded. */
+ public Optional<List<LogEntry>> get(Step step) {
+ return Optional.ofNullable(log.get(step));
+ }
+
+ /** Returns the id of the last log entry in this. */
+ public OptionalLong lastId() {
+ return lastId;
+ }
+
+}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStore.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStore.java
new file mode 100644
index 00000000000..f87cfef373c
--- /dev/null
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStore.java
@@ -0,0 +1,5 @@
+package com.yahoo.vespa.hosted.controller.persistence;
+
+public class BufferingLogStore {
+
+}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/LogRecordSerializer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/LogSerializer.java
index f582b240260..f582b240260 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/LogRecordSerializer.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/LogSerializer.java
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStoreTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStoreTest.java
new file mode 100644
index 00000000000..2438bbbd947
--- /dev/null
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStoreTest.java
@@ -0,0 +1,5 @@
+package com.yahoo.vespa.hosted.controller.persistence;
+
+public class BufferedLogStoreTest {
+
+}