From b69059fd370955351db8a98c1f11efacda6bd333 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 26 Mar 2024 08:58:16 +0100 Subject: [PATCH] restoring debug-info --- Framework/Core/Http.cs | 16 ++++++++-------- ProjectPlugins/CodexPlugin/CodexAccess.cs | 10 ++++++++-- ProjectPlugins/CodexPlugin/CodexDeployment.cs | 4 ++-- ProjectPlugins/CodexPlugin/CodexNodeGroup.cs | 6 +++--- ProjectPlugins/CodexPlugin/CodexPlugin.csproj | 2 +- ProjectPlugins/CodexPlugin/CodexSetup.cs | 2 +- ProjectPlugins/CodexPlugin/CodexStarter.cs | 6 +++--- ProjectPlugins/CodexPlugin/CodexTypes.cs | 7 ++++++- ProjectPlugins/CodexPlugin/Mapper.cs | 18 ++++++++++++++++++ .../BasicTests/TestInfraTests.cs | 4 ++-- .../Helpers/FullConnectivityHelper.cs | 6 +++--- .../PeerDiscoveryTests/PeerDiscoveryTests.cs | 6 +++--- Tools/CodexNetDeployer/CodexNodeStarter.cs | 2 +- 13 files changed, 59 insertions(+), 30 deletions(-) create mode 100644 ProjectPlugins/CodexPlugin/Mapper.cs diff --git a/Framework/Core/Http.cs b/Framework/Core/Http.cs index b3feca3..252a300 100644 --- a/Framework/Core/Http.cs +++ b/Framework/Core/Http.cs @@ -9,14 +9,14 @@ namespace Core { public interface IHttp { - //string HttpGetString(string route); - //T HttpGetJson(string route); - //TResponse HttpPostJson(string route, TRequest body); - //string HttpPostJson(string route, TRequest body); - //TResponse HttpPostString(string route, string body); - //string HttpPostStream(string route, Stream stream); - //Stream HttpGetStream(string route); - //T Deserialize(string json); + string HttpGetString(string route); + T HttpGetJson(string route); + TResponse HttpPostJson(string route, TRequest body); + string HttpPostJson(string route, TRequest body); + TResponse HttpPostString(string route, string body); + string HttpPostStream(string route, Stream stream); + Stream HttpGetStream(string route); + T Deserialize(string json); T OnClient(Func action); } diff --git a/ProjectPlugins/CodexPlugin/CodexAccess.cs b/ProjectPlugins/CodexPlugin/CodexAccess.cs index 9434f21..f576cfd 100644 --- a/ProjectPlugins/CodexPlugin/CodexAccess.cs +++ b/ProjectPlugins/CodexPlugin/CodexAccess.cs @@ -9,6 +9,7 @@ namespace CodexPlugin public class CodexAccess : ILogHandler { private readonly IPluginTools tools; + private readonly Mapper mapper = new Mapper(); private bool hasContainerCrashed; public CodexAccess(IPluginTools tools, RunningContainer container, CrashWatcher crashWatcher) @@ -24,9 +25,9 @@ namespace CodexPlugin public RunningContainer Container { get; } public CrashWatcher CrashWatcher { get; } - public CodexOpenApi.DebugInfo GetDebugInfo() + public DebugInfo GetDebugInfo() { - return OnCodex(api => api.GetDebugInfoAsync()); + return Map(OnCodex(api => api.GetDebugInfoAsync())); } public CodexDebugPeerResponse GetDebugPeer(string peerId) @@ -108,6 +109,11 @@ namespace CodexPlugin return workflow.GetPodInfo(Container); } + private dynamic Map(dynamic input) + { + return mapper.Map(input); + } + private T OnCodex(Func> action) { var address = GetAddress(); diff --git a/ProjectPlugins/CodexPlugin/CodexDeployment.cs b/ProjectPlugins/CodexPlugin/CodexDeployment.cs index ccf5ef2..9f74dd3 100644 --- a/ProjectPlugins/CodexPlugin/CodexDeployment.cs +++ b/ProjectPlugins/CodexPlugin/CodexDeployment.cs @@ -31,14 +31,14 @@ namespace CodexPlugin public class CodexInstance { - public CodexInstance(RunningContainers containers, CodexDebugResponse info) + public CodexInstance(RunningContainers containers, DebugInfo info) { Containers = containers; Info = info; } public RunningContainers Containers { get; } - public CodexDebugResponse Info { get; } + public DebugInfo Info { get; } } public class DeploymentMetadata diff --git a/ProjectPlugins/CodexPlugin/CodexNodeGroup.cs b/ProjectPlugins/CodexPlugin/CodexNodeGroup.cs index e9eceb7..8b6264c 100644 --- a/ProjectPlugins/CodexPlugin/CodexNodeGroup.cs +++ b/ProjectPlugins/CodexPlugin/CodexNodeGroup.cs @@ -20,7 +20,7 @@ namespace CodexPlugin this.starter = starter; Containers = containers; Nodes = containers.Containers().Select(c => CreateOnlineCodexNode(c, tools, codexNodeFactory)).ToArray(); - Version = new CodexDebugVersionResponse(); + Version = new DebugVersion(); } public ICodexNode this[int index] @@ -41,7 +41,7 @@ namespace CodexPlugin public RunningContainers[] Containers { get; private set; } public CodexNode[] Nodes { get; private set; } - public CodexDebugVersionResponse Version { get; private set; } + public DebugVersion Version { get; private set; } public IMetricsScrapeTarget[] ScrapeTargets => Nodes.Select(n => n.MetricsScrapeTarget).ToArray(); public IEnumerator GetEnumerator() @@ -65,7 +65,7 @@ namespace CodexPlugin var versionResponses = Nodes.Select(n => n.Version); var first = versionResponses.First(); - if (!versionResponses.All(v => v.version == first.version && v.revision == first.revision)) + if (!versionResponses.All(v => v.Version == first.Version && v.Revision == first.Revision)) { throw new Exception("Inconsistent version information received from one or more Codex nodes: " + string.Join(",", versionResponses.Select(v => v.ToString()))); diff --git a/ProjectPlugins/CodexPlugin/CodexPlugin.csproj b/ProjectPlugins/CodexPlugin/CodexPlugin.csproj index 2bb1256..ffdff42 100644 --- a/ProjectPlugins/CodexPlugin/CodexPlugin.csproj +++ b/ProjectPlugins/CodexPlugin/CodexPlugin.csproj @@ -35,7 +35,7 @@ - + diff --git a/ProjectPlugins/CodexPlugin/CodexSetup.cs b/ProjectPlugins/CodexPlugin/CodexSetup.cs index 54be6a9..a7afc9f 100644 --- a/ProjectPlugins/CodexPlugin/CodexSetup.cs +++ b/ProjectPlugins/CodexPlugin/CodexSetup.cs @@ -75,7 +75,7 @@ namespace CodexPlugin public ICodexSetup WithBootstrapNode(ICodexNode node) { - BootstrapSpr = node.GetDebugInfo().spr; + BootstrapSpr = node.GetDebugInfo().Spr; return this; } diff --git a/ProjectPlugins/CodexPlugin/CodexStarter.cs b/ProjectPlugins/CodexPlugin/CodexStarter.cs index 57045cc..7a202f8 100644 --- a/ProjectPlugins/CodexPlugin/CodexStarter.cs +++ b/ProjectPlugins/CodexPlugin/CodexStarter.cs @@ -9,7 +9,7 @@ namespace CodexPlugin { private readonly IPluginTools pluginTools; private readonly CodexContainerRecipe recipe = new CodexContainerRecipe(); - private CodexDebugVersionResponse? versionResponse; + private DebugVersion? versionResponse; public CodexStarter(IPluginTools pluginTools) { @@ -62,13 +62,13 @@ namespace CodexPlugin public string GetCodexId() { - if (versionResponse != null) return versionResponse.version; + if (versionResponse != null) return versionResponse.Version; return recipe.Image; } public string GetCodexRevision() { - if (versionResponse != null) return versionResponse.revision; + if (versionResponse != null) return versionResponse.Revision; return "unknown"; } diff --git a/ProjectPlugins/CodexPlugin/CodexTypes.cs b/ProjectPlugins/CodexPlugin/CodexTypes.cs index f9848ea..5a54f9e 100644 --- a/ProjectPlugins/CodexPlugin/CodexTypes.cs +++ b/ProjectPlugins/CodexPlugin/CodexTypes.cs @@ -3,10 +3,14 @@ public class DebugInfo { public string[] Addrs { get; set; } = Array.Empty(); + public string Spr { get; set; } = string.Empty; + public string Id { get; set; } = string.Empty; + public string[] AnnounceAddresses { get; set; } = Array.Empty(); } public class DebugPeer { + public bool IsPeerFound { get; set; } } @@ -17,7 +21,8 @@ public class DebugVersion { - + public string Version { get; internal set; } = string.Empty; + public string Revision { get; internal set; } = string.Empty; } public class ContentId diff --git a/ProjectPlugins/CodexPlugin/Mapper.cs b/ProjectPlugins/CodexPlugin/Mapper.cs new file mode 100644 index 0000000..d7905ab --- /dev/null +++ b/ProjectPlugins/CodexPlugin/Mapper.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json.Linq; + +namespace CodexPlugin +{ + public class Mapper + { + public DebugInfo Map(CodexOpenApi.DebugInfo debugInfo) + { + return new DebugInfo + { + Id = debugInfo.Id, + Spr = debugInfo.Spr, + Addrs = debugInfo.Addrs.ToArray(), + AnnounceAddresses = ((JArray) debugInfo.AdditionalProperties["announceAddresses"]).Select(x => x.ToString()).ToArray(), + }; + } + } +} diff --git a/Tests/CodexLongTests/BasicTests/TestInfraTests.cs b/Tests/CodexLongTests/BasicTests/TestInfraTests.cs index 832f13a..5720457 100644 --- a/Tests/CodexLongTests/BasicTests/TestInfraTests.cs +++ b/Tests/CodexLongTests/BasicTests/TestInfraTests.cs @@ -11,7 +11,7 @@ namespace CodexLongTests.BasicTests { var group = AddCodex(1000, s => s.EnableMetrics()); - var nodeIds = group.Select(n => n.GetDebugInfo().id).ToArray(); + var nodeIds = group.Select(n => n.GetDebugInfo().Id).ToArray(); Assert.That(nodeIds.Length, Is.EqualTo(nodeIds.Distinct().Count()), "Not all created nodes provided a unique id."); @@ -24,7 +24,7 @@ namespace CodexLongTests.BasicTests { var n = AddCodex(); - Assert.That(!string.IsNullOrEmpty(n.GetDebugInfo().id)); + Assert.That(!string.IsNullOrEmpty(n.GetDebugInfo().Id)); } } } diff --git a/Tests/CodexTests/Helpers/FullConnectivityHelper.cs b/Tests/CodexTests/Helpers/FullConnectivityHelper.cs index 1504c78..8db17ed 100644 --- a/Tests/CodexTests/Helpers/FullConnectivityHelper.cs +++ b/Tests/CodexTests/Helpers/FullConnectivityHelper.cs @@ -114,12 +114,12 @@ namespace CodexTests.Helpers } public ICodexNode Node { get; } - public CodexDebugResponse Response { get; } + public DebugInfo Response { get; } public override string ToString() { - if (Response == null || string.IsNullOrEmpty(Response.id)) return "UNKNOWN"; - return Response.id; + if (Response == null || string.IsNullOrEmpty(Response.Id)) return "UNKNOWN"; + return Response.Id; } } diff --git a/Tests/CodexTests/PeerDiscoveryTests/PeerDiscoveryTests.cs b/Tests/CodexTests/PeerDiscoveryTests/PeerDiscoveryTests.cs index 10c1cde..53d78d2 100644 --- a/Tests/CodexTests/PeerDiscoveryTests/PeerDiscoveryTests.cs +++ b/Tests/CodexTests/PeerDiscoveryTests/PeerDiscoveryTests.cs @@ -70,7 +70,7 @@ namespace CodexTests.PeerDiscoveryTests } } - private string AreAllPresent(CodexDebugResponse info, CodexDebugResponse[] allResponses) + private string AreAllPresent(DebugInfo info, DebugInfo[] allResponses) { var knownIds = info.table.nodes.Select(n => n.nodeId).ToArray(); var allOthers = GetAllOtherResponses(info, allResponses); @@ -84,9 +84,9 @@ namespace CodexTests.PeerDiscoveryTests return string.Empty; } - private CodexDebugResponse[] GetAllOtherResponses(CodexDebugResponse exclude, CodexDebugResponse[] allResponses) + private DebugInfo[] GetAllOtherResponses(DebugInfo exclude, DebugInfo[] allResponses) { - return allResponses.Where(r => r.id != exclude.id).ToArray(); + return allResponses.Where(r => r.Id != exclude.Id).ToArray(); } } } diff --git a/Tools/CodexNetDeployer/CodexNodeStarter.cs b/Tools/CodexNetDeployer/CodexNodeStarter.cs index 663659b..73e3c68 100644 --- a/Tools/CodexNetDeployer/CodexNodeStarter.cs +++ b/Tools/CodexNetDeployer/CodexNodeStarter.cs @@ -61,7 +61,7 @@ namespace CodexNetDeployer }); var debugInfo = codexNode.GetDebugInfo(); - if (!string.IsNullOrWhiteSpace(debugInfo.spr)) + if (!string.IsNullOrWhiteSpace(debugInfo.Spr)) { Console.Write("Online\t");