2
0
mirror of synced 2025-02-23 21:48:09 +00:00

Applies BaseStarter type

This commit is contained in:
benbierens 2023-04-18 13:45:48 +02:00
parent 98f5e481d1
commit e36d910f2f
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
6 changed files with 26 additions and 55 deletions

View File

@ -41,13 +41,12 @@ namespace DistTestCore.Codex
var companionNode = gethConfig.CompanionNodes[Index]; var companionNode = gethConfig.CompanionNodes[Index];
Additional(companionNode); Additional(companionNode);
// Bootstrap node access from within the cluster: var ip = companionNode.RunningContainer.Pod.Ip;
//var ip = gethConfig.BootstrapNode.RunningContainers.RunningPod.Ip; var port = companionNode.RunningContainer.Recipe.GetPortByTag(GethContainerRecipe.WsPortTag).Number;
//var port = gethConfig.BootstrapNode.RunningContainers.Containers[0].Recipe.GetPortByTag(GethContainerRecipe.HttpPortTag);
//AddEnvVar("ETH_PROVIDER", "todo"); AddEnvVar("ETH_PROVIDER", $"ws://{ip}:{port}");
//AddEnvVar("ETH_ACCOUNT", companionNode.Account); AddEnvVar("ETH_ACCOUNT", companionNode.Account);
//AddEnvVar("ETH_DEPLOYMENT", "todo"); AddEnvVar("ETH_MARKETPLACE_ADDRESS", gethConfig.MarketplaceNetwork.Marketplace.Address);
} }
} }
} }

View File

@ -3,22 +3,18 @@ using KubernetesWorkflow;
namespace DistTestCore namespace DistTestCore
{ {
public class CodexStarter // basestarter public class CodexStarter : BaseStarter
{ {
private readonly TestLifecycle lifecycle;
private readonly WorkflowCreator workflowCreator;
public CodexStarter(TestLifecycle lifecycle, WorkflowCreator workflowCreator) public CodexStarter(TestLifecycle lifecycle, WorkflowCreator workflowCreator)
: base(lifecycle, workflowCreator)
{ {
this.lifecycle = lifecycle;
this.workflowCreator = workflowCreator;
} }
public List<CodexNodeGroup> RunningGroups { get; } = new List<CodexNodeGroup>(); public List<CodexNodeGroup> RunningGroups { get; } = new List<CodexNodeGroup>();
public ICodexNodeGroup BringOnline(CodexSetup codexSetup) public ICodexNodeGroup BringOnline(CodexSetup codexSetup)
{ {
Log($"Starting {codexSetup.Describe()}..."); LogStart($"Starting {codexSetup.Describe()}...");
var gethStartResult = lifecycle.GethStarter.BringOnlineMarketplaceFor(codexSetup); var gethStartResult = lifecycle.GethStarter.BringOnlineMarketplaceFor(codexSetup);
var startupConfig = new StartupConfig(); var startupConfig = new StartupConfig();
@ -32,17 +28,17 @@ namespace DistTestCore
var codexNodeFactory = new CodexNodeFactory(lifecycle, metricAccessFactory, gethStartResult.MarketplaceAccessFactory); var codexNodeFactory = new CodexNodeFactory(lifecycle, metricAccessFactory, gethStartResult.MarketplaceAccessFactory);
var group = CreateCodexGroup(codexSetup, containers, codexNodeFactory); var group = CreateCodexGroup(codexSetup, containers, codexNodeFactory);
Log($"Started at '{group.Containers.RunningPod.Ip}'"); LogEnd($"Started at '{group.Containers.RunningPod.Ip}'");
return group; return group;
} }
public void BringOffline(CodexNodeGroup group) public void BringOffline(CodexNodeGroup group)
{ {
Log($"Stopping {group.Describe()}..."); LogStart($"Stopping {group.Describe()}...");
var workflow = CreateWorkflow(); var workflow = CreateWorkflow();
workflow.Stop(group.Containers); workflow.Stop(group.Containers);
RunningGroups.Remove(group); RunningGroups.Remove(group);
Log("Stopped."); LogEnd("Stopped.");
} }
public void DeleteAllResources() public void DeleteAllResources()
@ -76,10 +72,5 @@ namespace DistTestCore
{ {
return workflowCreator.CreateWorkflow(); return workflowCreator.CreateWorkflow();
} }
private void Log(string msg)
{
lifecycle.Log.Log(msg);
}
} }
} }

View File

@ -3,19 +3,18 @@ using KubernetesWorkflow;
namespace DistTestCore namespace DistTestCore
{ {
public class GethStarter // basestarter public class GethStarter : BaseStarter
{ {
private readonly MarketplaceNetworkCache marketplaceNetworkCache; private readonly MarketplaceNetworkCache marketplaceNetworkCache;
private readonly GethCompanionNodeStarter companionNodeStarter; private readonly GethCompanionNodeStarter companionNodeStarter;
private readonly TestLifecycle lifecycle;
public GethStarter(TestLifecycle lifecycle, WorkflowCreator workflowCreator) public GethStarter(TestLifecycle lifecycle, WorkflowCreator workflowCreator)
: base(lifecycle, workflowCreator)
{ {
marketplaceNetworkCache = new MarketplaceNetworkCache( marketplaceNetworkCache = new MarketplaceNetworkCache(
new GethBootstrapNodeStarter(lifecycle, workflowCreator), new GethBootstrapNodeStarter(lifecycle, workflowCreator),
new CodexContractsStarter(lifecycle, workflowCreator)); new CodexContractsStarter(lifecycle, workflowCreator));
companionNodeStarter = new GethCompanionNodeStarter(lifecycle, workflowCreator); companionNodeStarter = new GethCompanionNodeStarter(lifecycle, workflowCreator);
this.lifecycle = lifecycle;
} }
public GethStartResult BringOnlineMarketplaceFor(CodexSetup codexSetup) public GethStartResult BringOnlineMarketplaceFor(CodexSetup codexSetup)
@ -33,12 +32,11 @@ namespace DistTestCore
private void TransferInitialBalance(MarketplaceNetwork marketplaceNetwork, MarketplaceInitialConfig marketplaceConfig, GethCompanionNodeInfo[] companionNodes) private void TransferInitialBalance(MarketplaceNetwork marketplaceNetwork, MarketplaceInitialConfig marketplaceConfig, GethCompanionNodeInfo[] companionNodes)
{ {
var interaction = marketplaceNetwork.StartInteraction(lifecycle.Log); var interaction = marketplaceNetwork.StartInteraction(lifecycle.Log);
var tokenAddress = interaction.GetTokenAddress(marketplaceNetwork.Marketplace.Address);
foreach (var node in companionNodes) foreach (var node in companionNodes)
{ {
interaction.TransferTo(node.Account, marketplaceConfig.InitialEth.Wei); interaction.TransferTo(node.Account, marketplaceConfig.InitialEth.Wei);
var tokenAddress = interaction.GetTokenAddress(marketplaceNetwork.Marketplace.Address);
interaction.MintTestTokens(node.Account, marketplaceConfig.InitialTestTokens.Amount, tokenAddress); interaction.MintTestTokens(node.Account, marketplaceConfig.InitialTestTokens.Amount, tokenAddress);
} }
} }

View File

@ -2,20 +2,16 @@
namespace DistTestCore.Marketplace namespace DistTestCore.Marketplace
{ {
public class GethCompanionNodeStarter public class GethCompanionNodeStarter : BaseStarter
{ {
private readonly TestLifecycle lifecycle;
private readonly WorkflowCreator workflowCreator;
public GethCompanionNodeStarter(TestLifecycle lifecycle, WorkflowCreator workflowCreator) public GethCompanionNodeStarter(TestLifecycle lifecycle, WorkflowCreator workflowCreator)
: base(lifecycle, workflowCreator)
{ {
this.lifecycle = lifecycle;
this.workflowCreator = workflowCreator;
} }
public GethCompanionNodeInfo[] StartCompanionNodesFor(CodexSetup codexSetup, GethBootstrapNodeInfo bootstrapNode) public GethCompanionNodeInfo[] StartCompanionNodesFor(CodexSetup codexSetup, GethBootstrapNodeInfo bootstrapNode)
{ {
Log($"Initializing companions for {codexSetup.NumberOfNodes} Codex nodes."); LogStart($"Initializing companions for {codexSetup.NumberOfNodes} Codex nodes.");
var startupConfig = CreateCompanionNodeStartupConfig(bootstrapNode); var startupConfig = CreateCompanionNodeStartupConfig(bootstrapNode);
@ -23,7 +19,7 @@ namespace DistTestCore.Marketplace
var containers = workflow.Start(codexSetup.NumberOfNodes, Location.Unspecified, new GethContainerRecipe(), startupConfig); var containers = workflow.Start(codexSetup.NumberOfNodes, Location.Unspecified, new GethContainerRecipe(), startupConfig);
if (containers.Containers.Length != codexSetup.NumberOfNodes) throw new InvalidOperationException("Expected a Geth companion node to be created for each Codex node. Test infra failure."); if (containers.Containers.Length != codexSetup.NumberOfNodes) throw new InvalidOperationException("Expected a Geth companion node to be created for each Codex node. Test infra failure.");
Log("Initialized companion nodes."); LogEnd("Initialized companion nodes.");
return containers.Containers.Select(c => CreateCompanionInfo(workflow, c)).ToArray(); return containers.Containers.Select(c => CreateCompanionInfo(workflow, c)).ToArray();
} }
@ -41,10 +37,5 @@ namespace DistTestCore.Marketplace
config.Add(new GethStartupConfig(false, bootstrapNode.GenesisJsonBase64, bootstrapNode)); config.Add(new GethStartupConfig(false, bootstrapNode.GenesisJsonBase64, bootstrapNode));
return config; return config;
} }
private void Log(string msg)
{
lifecycle.Log.Log(msg);
}
} }
} }

View File

@ -6,6 +6,7 @@ namespace DistTestCore.Marketplace
{ {
public const string DockerImage = "thatbenbierens/geth-confenv:latest"; public const string DockerImage = "thatbenbierens/geth-confenv:latest";
public const string HttpPortTag = "http_port"; public const string HttpPortTag = "http_port";
public const string WsPortTag = "ws_port";
public const string DiscoveryPortTag = "disc_port"; public const string DiscoveryPortTag = "disc_port";
public const string AccountFilename = "account_string.txt"; public const string AccountFilename = "account_string.txt";
public const string GenesisFilename = "genesis.json"; public const string GenesisFilename = "genesis.json";
@ -37,14 +38,14 @@ namespace DistTestCore.Marketplace
var port = AddInternalPort(); var port = AddInternalPort();
var authRpc = AddInternalPort(); var authRpc = AddInternalPort();
var httpPort = AddInternalPort(tag: HttpPortTag); var httpPort = AddInternalPort(tag: HttpPortTag);
var wsPort = AddInternalPort(tag: WsPortTag);
var bootPubKey = config.BootstrapNode.PubKey; var bootPubKey = config.BootstrapNode.PubKey;
var bootIp = config.BootstrapNode.RunningContainers.Containers[0].Pod.Ip; var bootIp = config.BootstrapNode.RunningContainers.Containers[0].Pod.Ip;
var bootPort = config.BootstrapNode.DiscoveryPort.Number; var bootPort = config.BootstrapNode.DiscoveryPort.Number;
var bootstrapArg = $"--bootnodes enode://{bootPubKey}@{bootIp}:{bootPort}"; var bootstrapArg = $"--bootnodes enode://{bootPubKey}@{bootIp}:{bootPort}";
// geth --bootnodes enode://pubkey1@ip1:port1
return $"--port {port.Number} --discovery.port {discovery.Number} --authrpc.port {authRpc.Number} --http.port {httpPort.Number} --nodiscover {bootstrapArg}"; return $"--port {port.Number} --discovery.port {discovery.Number} --authrpc.port {authRpc.Number} --http.port {httpPort.Number} --ws --ws.port {wsPort.Number} --nodiscover {bootstrapArg}";
} }
} }
} }

View File

@ -5,22 +5,18 @@ using System.Text;
namespace DistTestCore namespace DistTestCore
{ {
public class PrometheusStarter // basestarter public class PrometheusStarter : BaseStarter
{ {
private readonly TestLifecycle lifecycle;
private readonly WorkflowCreator workflowCreator;
public PrometheusStarter(TestLifecycle lifecycle, WorkflowCreator workflowCreator) public PrometheusStarter(TestLifecycle lifecycle, WorkflowCreator workflowCreator)
: base(lifecycle, workflowCreator)
{ {
this.lifecycle = lifecycle;
this.workflowCreator = workflowCreator;
} }
public IMetricsAccessFactory CollectMetricsFor(CodexSetup codexSetup, RunningContainers containers) public IMetricsAccessFactory CollectMetricsFor(CodexSetup codexSetup, RunningContainers containers)
{ {
if (!codexSetup.MetricsEnabled) return new MetricsUnavailableAccessFactory(); if (!codexSetup.MetricsEnabled) return new MetricsUnavailableAccessFactory();
Log($"Starting metrics server for {containers.Describe()}"); LogStart($"Starting metrics server for {containers.Describe()}");
var startupConfig = new StartupConfig(); var startupConfig = new StartupConfig();
startupConfig.Add(new PrometheusStartupConfig(GeneratePrometheusConfig(containers.Containers))); startupConfig.Add(new PrometheusStartupConfig(GeneratePrometheusConfig(containers.Containers)));
@ -28,7 +24,7 @@ namespace DistTestCore
var runningContainers = workflow.Start(1, Location.Unspecified, new PrometheusContainerRecipe(), startupConfig); var runningContainers = workflow.Start(1, Location.Unspecified, new PrometheusContainerRecipe(), startupConfig);
if (runningContainers.Containers.Length != 1) throw new InvalidOperationException("Expected only 1 Prometheus container to be created."); if (runningContainers.Containers.Length != 1) throw new InvalidOperationException("Expected only 1 Prometheus container to be created.");
Log("Metrics server started."); LogEnd("Metrics server started.");
return new CodexNodeMetricsAccessFactory(runningContainers); return new CodexNodeMetricsAccessFactory(runningContainers);
} }
@ -56,10 +52,5 @@ namespace DistTestCore
var bytes = Encoding.ASCII.GetBytes(config); var bytes = Encoding.ASCII.GetBytes(config);
return Convert.ToBase64String(bytes); return Convert.ToBase64String(bytes);
} }
private void Log(string msg)
{
lifecycle.Log.Log(msg);
}
} }
} }