2
0
mirror of synced 2025-01-13 01:54:07 +00:00

104 lines
2.9 KiB
C#
Raw Normal View History

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