2
0
mirror of synced 2025-01-13 10:04:29 +00:00
cs-codex-dist-tests/CodexPlugin/CodexNodeGroup.cs

82 lines
2.5 KiB
C#
Raw Normal View History

2023-09-12 13:32:06 +02:00
using Core;
2023-09-11 16:57:57 +02:00
using KubernetesWorkflow;
2023-04-13 09:33:10 +02:00
using System.Collections;
namespace CodexPlugin
2023-04-13 09:33:10 +02:00
{
public interface ICodexNodeGroup : IEnumerable<IOnlineCodexNode>
{
2023-09-11 16:57:57 +02:00
void BringOffline();
2023-04-13 09:33:10 +02:00
IOnlineCodexNode this[int index] { get; }
}
public class CodexNodeGroup : ICodexNodeGroup
{
2023-09-12 10:31:55 +02:00
public CodexNodeGroup(IPluginTools tools, RunningContainers[] containers, ICodexNodeFactory codexNodeFactory)
2023-04-13 09:33:10 +02:00
{
Containers = containers;
2023-09-12 10:31:55 +02:00
Nodes = containers.Containers().Select(c => CreateOnlineCodexNode(c, tools, codexNodeFactory)).ToArray();
2023-07-31 11:51:29 +02:00
Version = new CodexDebugVersionResponse();
2023-04-13 09:33:10 +02:00
}
public IOnlineCodexNode this[int index]
{
get
{
return Nodes[index];
}
}
2023-09-11 16:57:57 +02:00
public void BringOffline()
2023-04-13 11:07:36 +02:00
{
//lifecycle.CodexStarter.BringOffline(this);
2023-04-13 11:07:36 +02:00
2023-09-11 16:57:57 +02:00
//var result = Setup;
2023-04-13 11:07:36 +02:00
// Clear everything. Prevent accidental use.
2023-09-11 16:57:57 +02:00
//Setup = null!;
2023-04-13 11:07:36 +02:00
Nodes = Array.Empty<OnlineCodexNode>();
Containers = null!;
2023-04-13 11:07:36 +02:00
}
2023-04-13 09:33:10 +02:00
public RunningContainers[] Containers { get; private set; }
2023-04-13 11:07:36 +02:00
public OnlineCodexNode[] Nodes { get; private set; }
2023-07-31 11:51:29 +02:00
public CodexDebugVersionResponse Version { get; private set; }
2023-04-13 09:33:10 +02:00
public IEnumerator<IOnlineCodexNode> GetEnumerator()
{
return Nodes.Cast<IOnlineCodexNode>().GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return Nodes.GetEnumerator();
}
public string Describe()
{
2023-04-19 14:57:00 +02:00
return $"group:[{Containers.Describe()}]";
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
foreach (var node in Nodes) node.EnsureOnlineGetVersionResponse();
var versionResponses = Nodes.Select(n => n.Version);
var first = versionResponses.First();
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-13 09:33:10 +02:00
}
2023-09-12 10:31:55 +02:00
private OnlineCodexNode CreateOnlineCodexNode(RunningContainer c, IPluginTools tools, ICodexNodeFactory factory)
{
2023-09-12 10:31:55 +02:00
var access = new CodexAccess(tools, c);
2023-09-11 16:57:57 +02:00
return factory.CreateOnlineCodexNode(access, this);
}
2023-04-13 09:33:10 +02:00
}
}