2023-04-10 07:05:27 +00:00
|
|
|
|
using CodexDistTestCore.Marketplace;
|
|
|
|
|
|
|
|
|
|
namespace CodexDistTestCore
|
2023-03-19 09:49:03 +00:00
|
|
|
|
{
|
2023-03-21 14:17:48 +00:00
|
|
|
|
public interface IOfflineCodexNodes
|
2023-03-19 09:49:03 +00:00
|
|
|
|
{
|
2023-03-24 13:16:59 +00:00
|
|
|
|
IOfflineCodexNodes At(Location location);
|
2023-03-21 14:17:48 +00:00
|
|
|
|
IOfflineCodexNodes WithLogLevel(CodexLogLevel level);
|
|
|
|
|
IOfflineCodexNodes WithBootstrapNode(IOnlineCodexNode node);
|
|
|
|
|
IOfflineCodexNodes WithStorageQuota(ByteSize storageQuota);
|
2023-03-27 08:27:08 +00:00
|
|
|
|
IOfflineCodexNodes EnableMetrics();
|
2023-04-10 07:05:27 +00:00
|
|
|
|
IOfflineCodexNodes EnableMarketplace(int initialBalance);
|
2023-03-22 08:22:18 +00:00
|
|
|
|
ICodexNodeGroup BringOnline();
|
2023-03-19 09:49:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum CodexLogLevel
|
|
|
|
|
{
|
|
|
|
|
Trace,
|
|
|
|
|
Debug,
|
|
|
|
|
Info,
|
|
|
|
|
Warn,
|
|
|
|
|
Error
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-24 13:16:59 +00:00
|
|
|
|
public enum Location
|
2023-03-23 11:41:34 +00:00
|
|
|
|
{
|
|
|
|
|
Unspecified,
|
|
|
|
|
BensLaptop,
|
|
|
|
|
BensOldGamingMachine,
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 14:17:48 +00:00
|
|
|
|
public class OfflineCodexNodes : IOfflineCodexNodes
|
2023-03-19 09:49:03 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly IK8sManager k8SManager;
|
2023-03-21 14:17:48 +00:00
|
|
|
|
|
|
|
|
|
public int NumberOfNodes { get; }
|
2023-03-24 13:16:59 +00:00
|
|
|
|
public Location Location { get; private set; }
|
2023-03-19 09:49:03 +00:00
|
|
|
|
public CodexLogLevel? LogLevel { get; private set; }
|
|
|
|
|
public IOnlineCodexNode? BootstrapNode { get; private set; }
|
2023-03-21 08:20:09 +00:00
|
|
|
|
public ByteSize? StorageQuota { get; private set; }
|
2023-03-27 08:27:08 +00:00
|
|
|
|
public bool MetricsEnabled { get; private set; }
|
2023-04-10 07:05:27 +00:00
|
|
|
|
public MarketplaceInitialConfig? MarketplaceConfig { get; private set; }
|
2023-03-19 09:49:03 +00:00
|
|
|
|
|
2023-03-21 14:17:48 +00:00
|
|
|
|
public OfflineCodexNodes(IK8sManager k8SManager, int numberOfNodes)
|
2023-03-19 09:49:03 +00:00
|
|
|
|
{
|
|
|
|
|
this.k8SManager = k8SManager;
|
2023-03-21 14:17:48 +00:00
|
|
|
|
NumberOfNodes = numberOfNodes;
|
2023-03-24 13:16:59 +00:00
|
|
|
|
Location = Location.Unspecified;
|
2023-03-27 08:27:08 +00:00
|
|
|
|
MetricsEnabled = false;
|
2023-03-19 09:49:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-22 08:22:18 +00:00
|
|
|
|
public ICodexNodeGroup BringOnline()
|
2023-03-19 09:49:03 +00:00
|
|
|
|
{
|
|
|
|
|
return k8SManager.BringOnline(this);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-24 13:16:59 +00:00
|
|
|
|
public IOfflineCodexNodes At(Location location)
|
2023-03-23 11:41:34 +00:00
|
|
|
|
{
|
|
|
|
|
Location = location;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 14:17:48 +00:00
|
|
|
|
public IOfflineCodexNodes WithBootstrapNode(IOnlineCodexNode node)
|
2023-03-19 09:49:03 +00:00
|
|
|
|
{
|
|
|
|
|
BootstrapNode = node;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 14:17:48 +00:00
|
|
|
|
public IOfflineCodexNodes WithLogLevel(CodexLogLevel level)
|
2023-03-19 09:49:03 +00:00
|
|
|
|
{
|
|
|
|
|
LogLevel = level;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 14:17:48 +00:00
|
|
|
|
public IOfflineCodexNodes WithStorageQuota(ByteSize storageQuota)
|
2023-03-19 09:49:03 +00:00
|
|
|
|
{
|
2023-03-21 08:20:09 +00:00
|
|
|
|
StorageQuota = storageQuota;
|
2023-03-19 09:49:03 +00:00
|
|
|
|
return this;
|
|
|
|
|
}
|
2023-03-20 10:37:02 +00:00
|
|
|
|
|
2023-03-27 08:27:08 +00:00
|
|
|
|
public IOfflineCodexNodes EnableMetrics()
|
|
|
|
|
{
|
|
|
|
|
MetricsEnabled = true;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-10 07:05:27 +00:00
|
|
|
|
public IOfflineCodexNodes EnableMarketplace(int initialBalance)
|
|
|
|
|
{
|
|
|
|
|
MarketplaceConfig = new MarketplaceInitialConfig(initialBalance);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-20 10:37:02 +00:00
|
|
|
|
public string Describe()
|
|
|
|
|
{
|
2023-03-22 08:22:18 +00:00
|
|
|
|
var args = string.Join(',', DescribeArgs());
|
|
|
|
|
return $"{NumberOfNodes} CodexNodes with [{args}]";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<string> DescribeArgs()
|
|
|
|
|
{
|
|
|
|
|
if (LogLevel != null) yield return ($"LogLevel={LogLevel}");
|
2023-04-10 07:05:27 +00:00
|
|
|
|
if (BootstrapNode != null) yield return ("BootstrapNode=set-not-shown-here");
|
2023-03-22 08:22:18 +00:00
|
|
|
|
if (StorageQuota != null) yield return ($"StorageQuote={StorageQuota.SizeInBytes}");
|
2023-03-20 10:37:02 +00:00
|
|
|
|
}
|
2023-03-19 09:49:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|