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

90 lines
3.1 KiB
C#
Raw Normal View History

2023-04-11 10:17:21 +00:00
using CodexDistTestCore.Marketplace;
namespace CodexDistTestCore
2023-03-21 14:17:48 +00:00
{
public class CodexNodeContainer
{
2023-04-11 09:00:39 +00:00
public CodexNodeContainer(string name, int servicePort, string servicePortName, int apiPort, string containerPortName, int discoveryPort, int listenPort, string dataDir, int metricsPort)
2023-03-21 14:17:48 +00:00
{
Name = name;
ServicePort = servicePort;
2023-03-22 09:38:10 +00:00
ServicePortName = servicePortName;
2023-03-21 14:17:48 +00:00
ApiPort = apiPort;
ContainerPortName = containerPortName;
DiscoveryPort = discoveryPort;
ListenPort = listenPort;
DataDir = dataDir;
MetricsPort = metricsPort;
2023-03-21 14:17:48 +00:00
}
public string Name { get; }
public int ServicePort { get; }
2023-03-22 09:38:10 +00:00
public string ServicePortName { get; }
2023-03-21 14:17:48 +00:00
public int ApiPort { get; }
public string ContainerPortName { get; }
public int DiscoveryPort { get; }
public int ListenPort { get; }
public string DataDir { get; }
public int MetricsPort { get; }
2023-04-11 10:17:21 +00:00
public GethCompanionNodeContainer? GethCompanionNodeContainer { get; set; } // :C
2023-03-21 14:17:48 +00:00
}
2023-03-22 13:49:01 +00:00
public class CodexGroupNumberSource
{
private readonly NumberSource codexNodeGroupNumberSource = new NumberSource(0);
private readonly NumberSource groupContainerNameSource = new NumberSource(1);
private readonly NumberSource servicePortSource = new NumberSource(30001);
public int GetNextCodexNodeGroupNumber()
{
return codexNodeGroupNumberSource.GetNextNumber();
}
public string GetNextServicePortName()
{
return $"node{groupContainerNameSource.GetNextNumber()}";
}
public int GetNextServicePort()
{
return servicePortSource.GetNextNumber();
}
}
2023-03-21 14:17:48 +00:00
public class CodexNodeContainerFactory
{
private readonly NumberSource containerNameSource = new NumberSource(1);
private readonly NumberSource codexPortSource = new NumberSource(8080);
2023-04-11 09:00:39 +00:00
private readonly CodexGroupNumberSource numberSource;
2023-03-22 13:49:01 +00:00
2023-04-11 09:00:39 +00:00
public CodexNodeContainerFactory(CodexGroupNumberSource numberSource)
2023-03-22 13:49:01 +00:00
{
2023-04-11 09:00:39 +00:00
this.numberSource = numberSource;
2023-03-22 13:49:01 +00:00
}
2023-03-21 14:17:48 +00:00
public CodexNodeContainer CreateNext(OfflineCodexNodes offline)
2023-03-21 14:17:48 +00:00
{
var n = containerNameSource.GetNextNumber();
return new CodexNodeContainer(
name: $"codex-node{n}",
2023-04-11 09:00:39 +00:00
servicePort: numberSource.GetNextServicePort(),
servicePortName: numberSource.GetNextServicePortName(),
2023-03-21 14:17:48 +00:00
apiPort: codexPortSource.GetNextNumber(),
containerPortName: $"api-{n}",
discoveryPort: codexPortSource.GetNextNumber(),
listenPort: codexPortSource.GetNextNumber(),
dataDir: $"datadir{n}",
2023-04-11 09:00:39 +00:00
metricsPort: GetMetricsPort(offline)
2023-03-21 14:17:48 +00:00
);
}
private int GetMetricsPort(OfflineCodexNodes offline)
{
if (offline.MetricsEnabled) return codexPortSource.GetNextNumber();
return 0;
}
2023-03-21 14:17:48 +00:00
}
}