2023-04-13 07:33:10 +00:00
|
|
|
|
using DistTestCore.Codex;
|
|
|
|
|
using KubernetesWorkflow;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
|
|
namespace DistTestCore
|
|
|
|
|
{
|
|
|
|
|
public interface ICodexNodeGroup : IEnumerable<IOnlineCodexNode>
|
|
|
|
|
{
|
2023-04-13 09:07:36 +00:00
|
|
|
|
ICodexSetup BringOffline();
|
2023-04-13 07:33:10 +00:00
|
|
|
|
IOnlineCodexNode this[int index] { get; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CodexNodeGroup : ICodexNodeGroup
|
|
|
|
|
{
|
|
|
|
|
private readonly TestLifecycle lifecycle;
|
|
|
|
|
|
2023-08-07 08:44:48 +00:00
|
|
|
|
public CodexNodeGroup(TestLifecycle lifecycle, CodexSetup setup, RunningContainers[] containers, ICodexNodeFactory codexNodeFactory)
|
2023-04-13 07:33:10 +00:00
|
|
|
|
{
|
|
|
|
|
this.lifecycle = lifecycle;
|
|
|
|
|
Setup = setup;
|
|
|
|
|
Containers = containers;
|
2023-08-07 08:44:48 +00:00
|
|
|
|
Nodes = containers.Containers().Select(c => CreateOnlineCodexNode(c, codexNodeFactory)).ToArray();
|
2023-07-31 09:51:29 +00:00
|
|
|
|
Version = new CodexDebugVersionResponse();
|
2023-04-13 07:33:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IOnlineCodexNode this[int index]
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Nodes[index];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 09:07:36 +00:00
|
|
|
|
public ICodexSetup BringOffline()
|
|
|
|
|
{
|
2023-04-13 09:53:54 +00:00
|
|
|
|
lifecycle.CodexStarter.BringOffline(this);
|
2023-04-13 09:07:36 +00:00
|
|
|
|
|
2023-04-13 09:53:54 +00:00
|
|
|
|
var result = Setup;
|
2023-04-13 09:07:36 +00:00
|
|
|
|
// Clear everything. Prevent accidental use.
|
|
|
|
|
Setup = null!;
|
|
|
|
|
Nodes = Array.Empty<OnlineCodexNode>();
|
2023-04-13 09:53:54 +00:00
|
|
|
|
Containers = null!;
|
2023-04-13 09:07:36 +00:00
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2023-04-13 07:33:10 +00:00
|
|
|
|
|
2023-04-13 09:07:36 +00:00
|
|
|
|
public CodexSetup Setup { get; private set; }
|
2023-08-07 08:44:48 +00:00
|
|
|
|
public RunningContainers[] Containers { get; private set; }
|
2023-04-13 09:07:36 +00:00
|
|
|
|
public OnlineCodexNode[] Nodes { get; private set; }
|
2023-07-31 09:51:29 +00:00
|
|
|
|
public CodexDebugVersionResponse Version { get; private set; }
|
2023-04-13 07:33:10 +00:00
|
|
|
|
|
|
|
|
|
public IEnumerator<IOnlineCodexNode> GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
return Nodes.Cast<IOnlineCodexNode>().GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
return Nodes.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Describe()
|
|
|
|
|
{
|
2023-04-19 12:57:00 +00:00
|
|
|
|
return $"group:[{Containers.Describe()}]";
|
2023-04-13 07:33:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 09:34:43 +00:00
|
|
|
|
public void EnsureOnline()
|
2023-04-13 07:33:10 +00:00
|
|
|
|
{
|
2023-07-31 09:51:29 +00: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 14:07:49 +00:00
|
|
|
|
{
|
2023-07-31 09:51:29 +00:00
|
|
|
|
throw new Exception("Inconsistent version information received from one or more Codex nodes: " +
|
|
|
|
|
string.Join(",", versionResponses.Select(v => v.ToString())));
|
2023-06-29 14:07:49 +00:00
|
|
|
|
}
|
2023-07-31 09:51:29 +00:00
|
|
|
|
|
|
|
|
|
Version = first;
|
2023-04-13 07:33:10 +00:00
|
|
|
|
}
|
2023-04-17 07:10:39 +00:00
|
|
|
|
|
2023-05-04 09:34:43 +00:00
|
|
|
|
private OnlineCodexNode CreateOnlineCodexNode(RunningContainer c, ICodexNodeFactory factory)
|
2023-04-17 07:10:39 +00:00
|
|
|
|
{
|
2023-06-29 14:07:49 +00:00
|
|
|
|
var access = new CodexAccess(lifecycle.Log, c, lifecycle.TimeSet, lifecycle.Configuration.GetAddress(c));
|
2023-05-04 09:34:43 +00:00
|
|
|
|
return factory.CreateOnlineCodexNode(access, this);
|
2023-04-17 07:10:39 +00:00
|
|
|
|
}
|
2023-04-13 07:33:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|