cs-codex-dist-tests/CodexDistTestCore/CodexNodeGroup.cs

104 lines
2.9 KiB
C#
Raw Normal View History

using CodexDistTestCore.Config;
using CodexDistTestCore.Marketplace;
using k8s.Models;
2023-03-22 09:38:10 +00:00
using System.Collections;
2023-03-21 14:44:21 +00:00
namespace CodexDistTestCore
2023-03-21 14:17:48 +00:00
{
2023-03-22 09:38:10 +00:00
public interface ICodexNodeGroup : IEnumerable<IOnlineCodexNode>
2023-03-21 14:17:48 +00:00
{
IOfflineCodexNodes BringOffline();
IOnlineCodexNode this[int index] { get; }
}
2023-03-22 08:22:18 +00:00
public class CodexNodeGroup : ICodexNodeGroup
2023-03-21 14:17:48 +00:00
{
private readonly TestLog log;
2023-03-21 14:17:48 +00:00
private readonly IK8sManager k8SManager;
public CodexNodeGroup(TestLog log, int orderNumber, OfflineCodexNodes origin, IK8sManager k8SManager, OnlineCodexNode[] nodes)
2023-03-21 14:17:48 +00:00
{
this.log = log;
2023-03-21 14:44:21 +00:00
OrderNumber = orderNumber;
Origin = origin;
2023-03-21 14:17:48 +00:00
this.k8SManager = k8SManager;
2023-03-21 14:44:21 +00:00
Nodes = nodes;
2023-03-22 13:49:01 +00:00
foreach (var n in nodes) n.Group = this;
2023-03-21 14:17:48 +00:00
}
public IOnlineCodexNode this[int index]
{
get
{
2023-03-21 14:44:21 +00:00
return Nodes[index];
2023-03-21 14:17:48 +00:00
}
}
2023-03-21 15:09:41 +00:00
public IOfflineCodexNodes BringOffline()
{
return k8SManager.BringOffline(this);
}
2023-03-21 14:44:21 +00:00
public int OrderNumber { get; }
public OfflineCodexNodes Origin { get; }
public OnlineCodexNode[] Nodes { get; }
public V1Deployment? Deployment { get; set; }
public V1Service? Service { get; set; }
2023-03-22 13:49:01 +00:00
public PodInfo? PodInfo { get; set; }
2023-04-11 10:06:33 +00:00
public GethCompanionGroup? GethCompanionGroup { get; set; }
2023-03-21 14:44:21 +00:00
public CodexNodeContainer[] GetContainers()
{
return Nodes.Select(n => n.Container).ToArray();
}
2023-03-22 09:38:10 +00:00
public IEnumerator<IOnlineCodexNode> GetEnumerator()
{
return Nodes.Cast<IOnlineCodexNode>().GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return Nodes.GetEnumerator();
}
2023-03-21 14:44:21 +00:00
public V1ObjectMeta GetServiceMetadata()
{
return new V1ObjectMeta
{
Name = "codex-test-entrypoint-" + OrderNumber,
NamespaceProperty = K8sCluster.K8sNamespace
2023-03-21 14:44:21 +00:00
};
}
public V1ObjectMeta GetDeploymentMetadata()
{
return new V1ObjectMeta
{
Name = "codex-test-node-" + OrderNumber,
NamespaceProperty = K8sCluster.K8sNamespace
2023-03-21 14:44:21 +00:00
};
}
public CodexNodeLog DownloadLog(IOnlineCodexNode node)
{
var logDownloader = new PodLogDownloader(log, k8SManager);
var n = (OnlineCodexNode)node;
return logDownloader.DownloadLog(n);
}
2023-03-21 14:44:21 +00:00
public Dictionary<string, string> GetSelector()
{
return new Dictionary<string, string> { { "codex-test-node", "dist-test-" + OrderNumber } };
}
public string Describe()
{
2023-03-22 08:22:18 +00:00
return $"CodexNodeGroup#{OrderNumber}-{Origin.Describe()}";
2023-03-21 14:44:21 +00:00
}
2023-03-21 14:17:48 +00:00
}
2023-03-22 13:49:01 +00:00
2023-03-21 14:17:48 +00:00
}