From aa9b667940291bd8d1966eea2f149c1fa1b2567b Mon Sep 17 00:00:00 2001 From: benbierens Date: Fri, 23 Jun 2023 08:44:27 +0200 Subject: [PATCH] Writes codex-deployment.json which can be used by the test running. --- CodexNetDeployer/CodexNodeStarter.cs | 75 +++++++++++++++++++++++++++ CodexNetDeployer/Deployer.cs | 45 +++------------- CodexNetDeployer/Program.cs | 7 ++- DistTestCore/Codex/CodexDeployment.cs | 17 ++++++ 4 files changed, 106 insertions(+), 38 deletions(-) create mode 100644 CodexNetDeployer/CodexNodeStarter.cs create mode 100644 DistTestCore/Codex/CodexDeployment.cs diff --git a/CodexNetDeployer/CodexNodeStarter.cs b/CodexNetDeployer/CodexNodeStarter.cs new file mode 100644 index 0000000..ee071db --- /dev/null +++ b/CodexNetDeployer/CodexNodeStarter.cs @@ -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; + } + } +} diff --git a/CodexNetDeployer/Deployer.cs b/CodexNetDeployer/Deployer.cs index 137ce88..b6a1df2 100644 --- a/CodexNetDeployer/Deployer.cs +++ b/CodexNetDeployer/Deployer.cs @@ -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(); 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() diff --git a/CodexNetDeployer/Program.cs b/CodexNetDeployer/Program.cs index 805b654..8c29f3d 100644 --- a/CodexNetDeployer/Program.cs +++ b/CodexNetDeployer/Program.cs @@ -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!"); } diff --git a/DistTestCore/Codex/CodexDeployment.cs b/DistTestCore/Codex/CodexDeployment.cs new file mode 100644 index 0000000..f86ad31 --- /dev/null +++ b/DistTestCore/Codex/CodexDeployment.cs @@ -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; } + } +}