2025-01-16 13:24:57 +01:00
|
|
|
|
using CodexClient;
|
|
|
|
|
|
using Core;
|
2023-09-13 11:59:21 +02:00
|
|
|
|
using MetricsPlugin;
|
2023-04-13 09:33:10 +02:00
|
|
|
|
using System.Collections;
|
2025-01-15 15:00:25 +01:00
|
|
|
|
using Utils;
|
2023-04-13 09:33:10 +02:00
|
|
|
|
|
2023-09-11 11:59:33 +02:00
|
|
|
|
namespace CodexPlugin
|
2023-04-13 09:33:10 +02:00
|
|
|
|
{
|
2023-09-19 11:51:59 +02:00
|
|
|
|
public interface ICodexNodeGroup : IEnumerable<ICodexNode>, IHasManyMetricScrapeTargets
|
2023-04-13 09:33:10 +02:00
|
|
|
|
{
|
2025-01-15 15:43:50 +01:00
|
|
|
|
void Stop(bool waitTillStopped);
|
2023-09-19 11:51:59 +02:00
|
|
|
|
ICodexNode this[int index] { get; }
|
2023-04-13 09:33:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class CodexNodeGroup : ICodexNodeGroup
|
|
|
|
|
|
{
|
2025-01-16 13:51:29 +01:00
|
|
|
|
private readonly ICodexNode[] nodes;
|
2023-09-13 12:09:44 +02:00
|
|
|
|
|
2025-01-16 13:51:29 +01:00
|
|
|
|
public CodexNodeGroup(IPluginTools tools, ICodexNode[] nodes)
|
2023-04-13 09:33:10 +02:00
|
|
|
|
{
|
2025-01-15 15:00:25 +01:00
|
|
|
|
this.nodes = nodes;
|
2024-03-26 10:03:52 +01:00
|
|
|
|
Version = new DebugInfoVersion();
|
2023-04-13 09:33:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-19 11:51:59 +02:00
|
|
|
|
public ICodexNode this[int index]
|
2023-04-13 09:33:10 +02:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return Nodes[index];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-15 15:43:50 +01:00
|
|
|
|
public void Stop(bool waitTillStopped)
|
2023-04-13 11:07:36 +02:00
|
|
|
|
{
|
2025-01-15 15:43:50 +01:00
|
|
|
|
foreach (var node in Nodes) node.Stop(waitTillStopped);
|
2023-04-13 11:07:36 +02:00
|
|
|
|
}
|
2023-04-13 09:33:10 +02:00
|
|
|
|
|
2024-04-13 17:09:17 +03:00
|
|
|
|
public void Stop(CodexNode node, bool waitTillStopped)
|
|
|
|
|
|
{
|
2025-01-15 15:43:50 +01:00
|
|
|
|
node.Stop(waitTillStopped);
|
2024-04-13 17:09:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-15 15:00:25 +01:00
|
|
|
|
public ICodexNode[] Nodes => nodes;
|
2024-03-26 10:03:52 +01:00
|
|
|
|
public DebugInfoVersion Version { get; private set; }
|
2025-01-16 13:24:57 +01:00
|
|
|
|
public Address[] ScrapeTargets => Nodes.Select(n => n.GetMetricsScrapeTarget()).ToArray();
|
2023-04-13 09:33:10 +02:00
|
|
|
|
|
2023-09-19 11:51:59 +02:00
|
|
|
|
public IEnumerator<ICodexNode> GetEnumerator()
|
2023-04-13 09:33:10 +02:00
|
|
|
|
{
|
2023-09-19 11:51:59 +02:00
|
|
|
|
return Nodes.Cast<ICodexNode>().GetEnumerator();
|
2023-04-13 09:33:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Nodes.GetEnumerator();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string Describe()
|
|
|
|
|
|
{
|
2025-01-15 15:00:25 +01:00
|
|
|
|
return $"group:[{string.Join(",", Nodes.Select(n => n.GetName()))}]";
|
2023-04-13 09:33:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-04 11:34:43 +02:00
|
|
|
|
public void EnsureOnline()
|
2023-04-13 09:33:10 +02:00
|
|
|
|
{
|
2023-07-31 11:51:29 +02:00
|
|
|
|
var versionResponses = Nodes.Select(n => n.Version);
|
|
|
|
|
|
|
|
|
|
|
|
var first = versionResponses.First();
|
2024-03-26 08:58:16 +01:00
|
|
|
|
if (!versionResponses.All(v => v.Version == first.Version && v.Revision == first.Revision))
|
2023-06-29 16:07:49 +02:00
|
|
|
|
{
|
2023-07-31 11:51:29 +02:00
|
|
|
|
throw new Exception("Inconsistent version information received from one or more Codex nodes: " +
|
|
|
|
|
|
string.Join(",", versionResponses.Select(v => v.ToString())));
|
2023-06-29 16:07:49 +02:00
|
|
|
|
}
|
2023-07-31 11:51:29 +02:00
|
|
|
|
|
|
|
|
|
|
Version = first;
|
2023-04-17 09:10:39 +02:00
|
|
|
|
}
|
2023-04-13 09:33:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|