Writes codex-deployment.json which can be used by the test running.

This commit is contained in:
benbierens 2023-06-23 08:44:27 +02:00
parent 4f0a278df1
commit aa9b667940
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 106 additions and 38 deletions

View File

@ -0,0 +1,75 @@
using DistTestCore;
using DistTestCore.Codex;
using DistTestCore.Marketplace;
using KubernetesWorkflow;
using Logging;
namespace CodexNetDeployer
{
public class CodexNodeStarter
{
private readonly Configuration config;
private readonly WorkflowCreator workflowCreator;
private readonly TestLifecycle lifecycle;
private readonly BaseLog log;
private readonly ITimeSet timeSet;
private readonly GethStartResult gethResult;
private string bootstrapSpr = "";
private int validatorsLeft;
public CodexNodeStarter(Configuration config, WorkflowCreator workflowCreator, TestLifecycle lifecycle, BaseLog log, ITimeSet timeSet, GethStartResult gethResult, int numberOfValidators)
{
this.config = config;
this.workflowCreator = workflowCreator;
this.lifecycle = lifecycle;
this.log = log;
this.timeSet = timeSet;
this.gethResult = gethResult;
this.validatorsLeft = numberOfValidators;
}
public RunningContainer? Start(int i)
{
Console.Write($" - {i} = ");
var workflow = workflowCreator.CreateWorkflow();
var workflowStartup = new StartupConfig();
workflowStartup.Add(gethResult);
workflowStartup.Add(CreateCodexStartupConfig(bootstrapSpr, i, validatorsLeft));
var containers = workflow.Start(1, Location.Unspecified, new CodexContainerRecipe(), workflowStartup);
var container = containers.Containers.First();
var address = lifecycle.Configuration.GetAddress(container);
var codexNode = new CodexNode(log, timeSet, address);
var debugInfo = codexNode.GetDebugInfo();
if (!string.IsNullOrWhiteSpace(debugInfo.spr))
{
var pod = container.Pod.PodInfo;
Console.Write($"Online ({pod.Name} at {pod.Ip} on '{pod.K8SNodeName}')" + Environment.NewLine);
if (string.IsNullOrEmpty(bootstrapSpr)) bootstrapSpr = debugInfo.spr;
validatorsLeft--;
return container;
}
else
{
Console.Write("Unknown failure." + Environment.NewLine);
return null;
}
}
private CodexStartupConfig CreateCodexStartupConfig(string bootstrapSpr, int i, int validatorsLeft)
{
var codexStart = new CodexStartupConfig(config.CodexLogLevel);
if (!string.IsNullOrEmpty(bootstrapSpr)) codexStart.BootstrapSpr = bootstrapSpr;
codexStart.StorageQuota = config.StorageQuota!.Value.MB();
var marketplaceConfig = new MarketplaceInitialConfig(100000.Eth(), 0.TestTokens(), validatorsLeft > 0);
marketplaceConfig.AccountIndexOverride = i;
codexStart.MarketplaceConfig = marketplaceConfig;
return codexStart;
}
}
}

View File

@ -1,8 +1,6 @@
using DistTestCore;
using DistTestCore.Codex;
using DistTestCore.Marketplace;
using KubernetesWorkflow;
using System.ComponentModel;
namespace CodexNetDeployer
{
@ -19,7 +17,7 @@ namespace CodexNetDeployer
timeset = new DefaultTimeSet();
}
public void Deploy()
public CodexDeployment Deploy()
{
Log("Initializing...");
var (workflowCreator, lifecycle) = CreateFacilities();
@ -34,47 +32,20 @@ namespace CodexNetDeployer
var gethResults = gethStarter.BringOnlineMarketplaceFor(setup);
Log("Geth started. Codex contracts deployed.");
Log("Warning: It can take up to 45 minutes for the Geth node to finish unlocking all if its 1000 preconfigured accounts.");
Log("Starting Codex nodes...");
// Each node must have its own IP, so it needs it own pod. Start them 1 at a time.
var bootstrapSpr = ""; // The first one will be used to bootstrap the others.
int validatorsLeft = config.NumberOfValidators!.Value;
var codexStarter = new CodexNodeStarter(config, workflowCreator, lifecycle, log, timeset, gethResults, config.NumberOfValidators!.Value);
var codexContainers = new List<RunningContainer>();
for (var i = 0; i < config.NumberOfCodexNodes; i++)
{
Console.Write($" - {i} = ");
var workflow = workflowCreator.CreateWorkflow();
var workflowStartup = new StartupConfig();
var codexStart = new CodexStartupConfig(config.CodexLogLevel);
workflowStartup.Add(gethResults);
workflowStartup.Add(codexStart);
if (!string.IsNullOrEmpty(bootstrapSpr)) codexStart.BootstrapSpr = bootstrapSpr;
codexStart.StorageQuota = config.StorageQuota.Value.MB();
var marketplaceConfig = new MarketplaceInitialConfig(100000.Eth(), 0.TestTokens(), validatorsLeft > 0);
marketplaceConfig.AccountIndexOverride = i;
codexStart.MarketplaceConfig = marketplaceConfig;
var containers = workflow.Start(1, Location.Unspecified, new CodexContainerRecipe(), workflowStartup);
var container = containers.Containers.First();
var address = lifecycle.Configuration.GetAddress(container);
var codexNode = new CodexNode(log, timeset, address);
var debugInfo = codexNode.GetDebugInfo();
if (!string.IsNullOrWhiteSpace(debugInfo.spr))
{
var pod = container.Pod.PodInfo;
Console.Write($"Online ({pod.Name} at {pod.Ip} on '{pod.K8SNodeName}')" + Environment.NewLine);
if (string.IsNullOrEmpty(bootstrapSpr)) bootstrapSpr = debugInfo.spr;
validatorsLeft--;
}
else
{
Console.Write("Unknown failure." + Environment.NewLine);
}
var container = codexStarter.Start(i);
if (container != null) codexContainers.Add(container);
}
return new CodexDeployment(gethResults, codexContainers.ToArray());
}
private (WorkflowCreator, TestLifecycle) CreateFacilities()

View File

@ -2,6 +2,7 @@
using DistTestCore;
using DistTestCore.Codex;
using DistTestCore.Marketplace;
using Newtonsoft.Json;
using Utils;
using Configuration = CodexNetDeployer.Configuration;
@ -64,7 +65,11 @@ public class Program
}
var deployer = new Deployer(config);
deployer.Deploy();
var deployment = deployer.Deploy();
Console.WriteLine("Writing codex-deployment.json...");
File.WriteAllText("codex-deployment.json", JsonConvert.SerializeObject(deployment, Formatting.Indented));
Console.WriteLine("Done!");
}

View File

@ -0,0 +1,17 @@
using DistTestCore.Marketplace;
using KubernetesWorkflow;
namespace DistTestCore.Codex
{
public class CodexDeployment
{
public CodexDeployment(GethStartResult gethStartResult, RunningContainer[] codexContainers)
{
GethStartResult = gethStartResult;
CodexContainers = codexContainers;
}
public GethStartResult GethStartResult { get; }
public RunningContainer[] CodexContainers { get; }
}
}