From 7ef3f615e11f2f965f90803ed8470ac1a0b41b76 Mon Sep 17 00:00:00 2001 From: ThatBen Date: Thu, 14 Sep 2023 15:26:46 +0200 Subject: [PATCH] Moves log downloading to core. --- CodexPlugin/OnlineCodexNode.cs | 13 +------------ Core/CoreInterface.cs | 23 ++++++++++++++++++++++- Tests/BasicTests/ContinuousSubstitute.cs | 4 ++-- Tests/BasicTests/ExampleTests.cs | 2 +- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/CodexPlugin/OnlineCodexNode.cs b/CodexPlugin/OnlineCodexNode.cs index 6a1d376..4ee798a 100644 --- a/CodexPlugin/OnlineCodexNode.cs +++ b/CodexPlugin/OnlineCodexNode.cs @@ -8,16 +8,14 @@ using Utils; namespace CodexPlugin { - public interface IOnlineCodexNode + public interface IOnlineCodexNode : IHasContainer { string GetName(); - RunningContainer Container { get; } CodexDebugResponse GetDebugInfo(); CodexDebugPeerResponse GetDebugPeer(string peerId); ContentId UploadFile(TrackedFile file); TrackedFile? DownloadContent(ContentId contentId, string fileLabel = ""); void ConnectToPeer(IOnlineCodexNode node); - IDownloadedLog DownloadLog(int? tailLines = null); CodexDebugVersionResponse Version { get; } void BringOffline(); IMetricsScrapeTarget MetricsScrapeTarget { get; } @@ -109,15 +107,6 @@ namespace CodexPlugin Log($"Successfully connected to peer {peer.GetName()}."); } - public IDownloadedLog DownloadLog(int? tailLines = null) - { - var workflow = tools.CreateWorkflow(); - var file = tools.GetLog().CreateSubfile(); - var logHandler = new LogDownloadHandler(CodexAccess.GetName(), file); - workflow.DownloadContainerLog(CodexAccess.Container, logHandler); - return logHandler.DownloadLog(); - } - public void BringOffline() { if (Group.Count() > 1) throw new InvalidOperationException("Codex-nodes that are part of a group cannot be " + diff --git a/Core/CoreInterface.cs b/Core/CoreInterface.cs index cad0eea..8b6b1b4 100644 --- a/Core/CoreInterface.cs +++ b/Core/CoreInterface.cs @@ -1,4 +1,6 @@ -namespace Core +using KubernetesWorkflow; + +namespace Core { public sealed class CoreInterface { @@ -13,5 +15,24 @@ { return entryPoint.GetPlugin(); } + + public IDownloadedLog DownloadLog(IHasContainer containerSource, int? tailLines = null) + { + return DownloadLog(containerSource.Container, tailLines); + } + + public IDownloadedLog DownloadLog(RunningContainer container, int? tailLines = null) + { + var workflow = entryPoint.Tools.CreateWorkflow(); + var file = entryPoint.Tools.GetLog().CreateSubfile(); + var logHandler = new LogDownloadHandler(container.Name, file); + workflow.DownloadContainerLog(container, logHandler, tailLines); + return logHandler.DownloadLog(); + } + } + + public interface IHasContainer + { + RunningContainer Container { get; } } } diff --git a/Tests/BasicTests/ContinuousSubstitute.cs b/Tests/BasicTests/ContinuousSubstitute.cs index 41b8da6..cdcf2d3 100644 --- a/Tests/BasicTests/ContinuousSubstitute.cs +++ b/Tests/BasicTests/ContinuousSubstitute.cs @@ -160,7 +160,7 @@ namespace Tests.BasicTests var cidTag = cid.Id.Substring(cid.Id.Length - 6); Measure("upload-log-asserts", () => { - var uploadLog = node.DownloadLog(tailLines: 50000); + var uploadLog = Ci.DownloadLog(node, tailLines: 50000); var storeLines = uploadLog.FindLinesThatContain("Stored data", "topics=\"codex node\""); uploadLog.DeleteFile(); @@ -181,7 +181,7 @@ namespace Tests.BasicTests Measure("download-log-asserts", () => { - var downloadLog = node.DownloadLog(tailLines: 50000); + var downloadLog = Ci.DownloadLog(node, tailLines: 50000); var sentLines = downloadLog.FindLinesThatContain("Sent bytes", "topics=\"codex restapi\""); downloadLog.DeleteFile(); diff --git a/Tests/BasicTests/ExampleTests.cs b/Tests/BasicTests/ExampleTests.cs index f9e76de..861a8af 100644 --- a/Tests/BasicTests/ExampleTests.cs +++ b/Tests/BasicTests/ExampleTests.cs @@ -16,7 +16,7 @@ namespace Tests.BasicTests primary.UploadFile(GenerateTestFile(5.MB())); - var log = primary.DownloadLog(); + var log = Ci.DownloadLog(primary); log.AssertLogContains("Uploaded file"); }