98 lines
2.6 KiB
C#
Raw Permalink Normal View History

using LogosStorageClient;
2025-01-16 13:24:57 +01:00
using Core;
2023-04-13 09:33:10 +02:00
using System.Collections;
using Utils;
2023-04-13 09:33:10 +02:00
namespace StoragePlugin
2023-04-13 09:33:10 +02:00
{
public interface IStorageNodeGroup : IEnumerable<IStorageNode>, IHasManyMetricScrapeTargets
2023-04-13 09:33:10 +02:00
{
2025-01-15 15:43:50 +01:00
void Stop(bool waitTillStopped);
IStorageNode this[int index] { get; }
2023-04-13 09:33:10 +02:00
}
public class StorageNodeGroup : IStorageNodeGroup
2023-04-13 09:33:10 +02:00
{
private readonly IStorageNode[] nodes;
public StorageNodeGroup(IPluginTools tools, IStorageNode[] nodes)
2023-04-13 09:33:10 +02:00
{
this.nodes = nodes;
2024-03-26 10:03:52 +01:00
Version = new DebugInfoVersion();
2023-04-13 09:33:10 +02:00
}
public IStorageNode 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
public void Stop(StorageNode node, bool waitTillStopped)
2024-04-13 17:09:17 +03:00
{
2025-01-15 15:43:50 +01:00
node.Stop(waitTillStopped);
2024-04-13 17:09:17 +03:00
}
public IStorageNode[] Nodes => nodes;
2024-03-26 10:03:52 +01:00
public DebugInfoVersion Version { get; private set; }
2025-01-16 15:13:16 +01:00
public Address[] GetMetricsScrapeTargets()
{
return Nodes.Select(n => n.GetMetricsScrapeTarget()).ToArray();
}
2023-04-13 09:33:10 +02:00
public IEnumerator<IStorageNode> GetEnumerator()
2023-04-13 09:33:10 +02:00
{
return Nodes.Cast<IStorageNode>().GetEnumerator();
2023-04-13 09:33:10 +02:00
}
IEnumerator IEnumerable.GetEnumerator()
{
return Nodes.GetEnumerator();
}
2025-08-13 11:35:03 +02:00
public string Names()
2023-04-13 09:33:10 +02:00
{
2025-08-13 11:35:03 +02:00
return $"[{string.Join(",", Nodes.Select(n => n.GetName()))}]";
}
public override string ToString()
{
return Names();
2023-04-13 09:33:10 +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
{
throw new Exception("Inconsistent version information received from one or more Logos Storage nodes: " +
2023-07-31 11:51:29 +02:00
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-13 09:33:10 +02:00
}
2025-08-13 11:35:03 +02:00
public static class StorageNodeGroupExtensions
2025-08-13 11:35:03 +02:00
{
public static string Names(this IStorageNode[] nodes)
2025-08-13 11:35:03 +02:00
{
return $"[{string.Join(",", nodes.Select(n => n.GetName()))}]";
}
public static string Names(this List<IStorageNode> nodes)
2025-08-13 11:35:03 +02:00
{
return $"[{string.Join(",", nodes.Select(n => n.GetName()))}]";
}
}
2023-04-13 09:33:10 +02:00
}