diff options
author | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2018-08-23 14:57:35 +0200 |
---|---|---|
committer | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2018-08-23 14:57:35 +0200 |
commit | 21e95c8db5ae40ab1e93070b3490629f57450f7c (patch) | |
tree | 60abbd1b289c8490b87caaf55328ea775089df06 /controller-api/src | |
parent | 366fb4304f150b2aec83ab7fa5a673f3876696d3 (diff) |
Get sub-list of LogEntry from TesterCloud
Diffstat (limited to 'controller-api/src')
3 files changed, 94 insertions, 8 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/LogEntry.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/LogEntry.java new file mode 100644 index 00000000000..7424b0409c9 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/LogEntry.java @@ -0,0 +1,75 @@ +package com.yahoo.vespa.hosted.controller.api.integration; + +import com.yahoo.log.LogLevel; + +import java.util.Objects; +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; + } + + @Override + public String toString() { + return "LogEntry{" + + "id=" + id + + ", at=" + at + + ", level=" + level + + ", message='" + message + '\'' + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof LogEntry)) return false; + LogEntry entry = (LogEntry) o; + return id == entry.id && + at == entry.at && + Objects.equals(level, entry.level) && + Objects.equals(message, entry.message); + } + + @Override + public int hashCode() { + return Objects.hash(id, at, level, message); + } + +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/TesterCloud.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/TesterCloud.java index f1d07fc9097..f2dbcda54b6 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/TesterCloud.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/TesterCloud.java @@ -1,6 +1,9 @@ package com.yahoo.vespa.hosted.controller.api.integration.deployment; +import com.yahoo.vespa.hosted.controller.api.integration.LogEntry; + import java.net.URI; +import java.util.List; /** * Allows running some predefined tests -- typically remotely. @@ -12,8 +15,8 @@ public interface TesterCloud { /** Signals the tester to run its tests. */ void startTests(URI testerUrl, Suite suite, byte[] config); - /** Returns the currently stored logs from the tester. */ - byte[] getLogs(URI testerUrl); + /** Returns the log entries from the tester with ids after the given threshold. */ + List<LogEntry> getLog(URI testerUrl, long after); /** Returns the current status of the tester. */ Status getStatus(URI testerUrl); diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockTesterCloud.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockTesterCloud.java index ff3f168a978..176fa8ae683 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockTesterCloud.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockTesterCloud.java @@ -1,16 +1,21 @@ package com.yahoo.vespa.hosted.controller.api.integration.stubs; +import com.google.common.collect.ImmutableList; +import com.yahoo.vespa.hosted.controller.api.integration.LogEntry; import com.yahoo.vespa.hosted.controller.api.integration.deployment.TesterCloud; import java.net.URI; -import java.util.Arrays; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; import static com.yahoo.vespa.hosted.controller.api.integration.deployment.TesterCloud.Status.NOT_STARTED; import static com.yahoo.vespa.hosted.controller.api.integration.deployment.TesterCloud.Status.RUNNING; public class MockTesterCloud implements TesterCloud { - private byte[] logs = new byte[0]; + private List<LogEntry> log = new ArrayList<>(); private Status status = NOT_STARTED; private byte[] config; private URI testerUrl; @@ -23,8 +28,8 @@ public class MockTesterCloud implements TesterCloud { } @Override - public byte[] getLogs(URI testerUrl) { - return Arrays.copyOf(logs, logs.length); + public List<LogEntry> getLog(URI testerUrl, long after) { + return log.stream().filter(entry -> entry.id() > after).collect(Collectors.toList()); } @Override @@ -32,8 +37,11 @@ public class MockTesterCloud implements TesterCloud { return status; } - public void set(byte[] logs, Status status) { - this.logs = Arrays.copyOf(logs, logs.length); + public void add(LogEntry entry) { + log.add(entry); + } + + public void set(Status status) { this.status = status; } |