From 75369d68f724194762924133cd5272927acd303c Mon Sep 17 00:00:00 2001 From: benbierens Date: Wed, 20 Sep 2023 12:02:32 +0200 Subject: [PATCH] Restores CodexNetDeployer --- ProjectPlugins/CodexPlugin/CodexDeployment.cs | 11 +- ProjectPlugins/CodexPlugin/CodexPlugin.cs | 2 +- .../CodexPlugin/CoreInterfaceExtensions.cs | 20 ++-- .../CodexPlugin/MarketplaceAccess.cs | 2 +- Tests/CodexTests/BasicTests/ExampleTests.cs | 2 +- .../BasicTests/NetworkIsolationTest.cs | 4 +- Tests/CodexTests/BasicTests/OneClientTests.cs | 6 +- Tests/CodexTests/BasicTests/TwoClientTests.cs | 6 +- Tests/CodexTests/CodexDistTest.cs | 2 +- .../LayeredDiscoveryTests.cs | 22 ++-- .../CodexNetDeployer/CodexNetDeployer.csproj | 6 +- Tools/CodexNetDeployer/CodexNodeStarter.cs | 107 +++++++---------- Tools/CodexNetDeployer/Configuration.cs | 7 +- Tools/CodexNetDeployer/Deployer.cs | 110 +++++++++--------- .../PeerConnectivityChecker.cs | 4 +- Tools/CodexNetDeployer/Program.cs | 12 +- .../deploy-continuous-testnet.sh | 2 +- 17 files changed, 146 insertions(+), 179 deletions(-) diff --git a/ProjectPlugins/CodexPlugin/CodexDeployment.cs b/ProjectPlugins/CodexPlugin/CodexDeployment.cs index 3bca60b1..6dbf961b 100644 --- a/ProjectPlugins/CodexPlugin/CodexDeployment.cs +++ b/ProjectPlugins/CodexPlugin/CodexDeployment.cs @@ -1,22 +1,21 @@ -using KubernetesWorkflow; +using GethPlugin; +using KubernetesWorkflow; namespace CodexPlugin { public class CodexDeployment { - public CodexDeployment(/*GethStartResult gethStartResult,*/ RunningContainer[] codexContainers, RunningContainer? prometheusContainer, /*GrafanaStartInfo? grafanaStartInfo,*/ DeploymentMetadata metadata) + public CodexDeployment(RunningContainer[] codexContainers, GethDeployment gethDeployment, RunningContainer? prometheusContainer, DeploymentMetadata metadata) { - //GethStartResult = gethStartResult; CodexContainers = codexContainers; + GethDeployment = gethDeployment; PrometheusContainer = prometheusContainer; - //GrafanaStartInfo = grafanaStartInfo; Metadata = metadata; } - //public GethStartResult GethStartResult { get; } public RunningContainer[] CodexContainers { get; } + public GethDeployment GethDeployment { get; } public RunningContainer? PrometheusContainer { get; } - //public GrafanaStartInfo? GrafanaStartInfo { get; } public DeploymentMetadata Metadata { get; } } diff --git a/ProjectPlugins/CodexPlugin/CodexPlugin.cs b/ProjectPlugins/CodexPlugin/CodexPlugin.cs index 2cfb8825..2f670dec 100644 --- a/ProjectPlugins/CodexPlugin/CodexPlugin.cs +++ b/ProjectPlugins/CodexPlugin/CodexPlugin.cs @@ -31,7 +31,7 @@ namespace CodexPlugin { } - public RunningContainers[] StartCodexNodes(int numberOfNodes, Action setup) + public RunningContainers[] DeployCodexNodes(int numberOfNodes, Action setup) { var codexSetup = GetSetup(numberOfNodes, setup); return codexStarter.BringOnline(codexSetup); diff --git a/ProjectPlugins/CodexPlugin/CoreInterfaceExtensions.cs b/ProjectPlugins/CodexPlugin/CoreInterfaceExtensions.cs index c9cd6a4d..a79615e6 100644 --- a/ProjectPlugins/CodexPlugin/CoreInterfaceExtensions.cs +++ b/ProjectPlugins/CodexPlugin/CoreInterfaceExtensions.cs @@ -5,9 +5,9 @@ namespace CodexPlugin { public static class CoreInterfaceExtensions { - public static RunningContainers[] StartCodexNodes(this CoreInterface ci, int number, Action setup) + public static RunningContainers[] DeployCodexNodes(this CoreInterface ci, int number, Action setup) { - return Plugin(ci).StartCodexNodes(number, setup); + return Plugin(ci).DeployCodexNodes(number, setup); } public static ICodexNodeGroup WrapCodexContainers(this CoreInterface ci, RunningContainers[] containers) @@ -15,27 +15,27 @@ namespace CodexPlugin return Plugin(ci).WrapCodexContainers(ci, containers); } - public static ICodexNode SetupCodexNode(this CoreInterface ci) + public static ICodexNode StartCodexNode(this CoreInterface ci) { - return ci.SetupCodexNodes(1)[0]; + return ci.StartCodexNodes(1)[0]; } - public static ICodexNode SetupCodexNode(this CoreInterface ci, Action setup) + public static ICodexNode StartCodexNode(this CoreInterface ci, Action setup) { - return ci.SetupCodexNodes(1, setup)[0]; + return ci.StartCodexNodes(1, setup)[0]; } - public static ICodexNodeGroup SetupCodexNodes(this CoreInterface ci, int number, Action setup) + public static ICodexNodeGroup StartCodexNodes(this CoreInterface ci, int number, Action setup) { - var rc = ci.StartCodexNodes(number, setup); + var rc = ci.DeployCodexNodes(number, setup); var result = ci.WrapCodexContainers(rc); Plugin(ci).WireUpMarketplace(result, setup); return result; } - public static ICodexNodeGroup SetupCodexNodes(this CoreInterface ci, int number) + public static ICodexNodeGroup StartCodexNodes(this CoreInterface ci, int number) { - return ci.SetupCodexNodes(number, s => { }); + return ci.StartCodexNodes(number, s => { }); } private static CodexPlugin Plugin(CoreInterface ci) diff --git a/ProjectPlugins/CodexPlugin/MarketplaceAccess.cs b/ProjectPlugins/CodexPlugin/MarketplaceAccess.cs index 5734c4f0..e331b66f 100644 --- a/ProjectPlugins/CodexPlugin/MarketplaceAccess.cs +++ b/ProjectPlugins/CodexPlugin/MarketplaceAccess.cs @@ -8,7 +8,7 @@ namespace CodexPlugin { public interface IMarketplaceAccess { - string MakeStorageAvailable(ByteSize size, TestToken minPricePerBytePerSecond, TestToken maxCollateral, TimeSpan maxDuration); + string MakeStorageAvailable(ByteSize size, TestToken minPriceForTotalSpace, TestToken maxCollateral, TimeSpan maxDuration); StoragePurchaseContract RequestStorage(ContentId contentId, TestToken pricePerSlotPerSecond, TestToken requiredCollateral, uint minRequiredNumberOfNodes, int proofProbability, TimeSpan duration); } diff --git a/Tests/CodexTests/BasicTests/ExampleTests.cs b/Tests/CodexTests/BasicTests/ExampleTests.cs index 2858c6e9..39814a5d 100644 --- a/Tests/CodexTests/BasicTests/ExampleTests.cs +++ b/Tests/CodexTests/BasicTests/ExampleTests.cs @@ -61,7 +61,7 @@ namespace Tests.BasicTests AssertBalance(geth, contracts, seller, Is.EqualTo(sellerInitialBalance)); seller.Marketplace.MakeStorageAvailable( size: 10.GB(), - minPricePerBytePerSecond: 1.TestTokens(), + minPriceForTotalSpace: 1.TestTokens(), maxCollateral: 20.TestTokens(), maxDuration: TimeSpan.FromMinutes(3)); diff --git a/Tests/CodexTests/BasicTests/NetworkIsolationTest.cs b/Tests/CodexTests/BasicTests/NetworkIsolationTest.cs index c6e54911..7388e4ae 100644 --- a/Tests/CodexTests/BasicTests/NetworkIsolationTest.cs +++ b/Tests/CodexTests/BasicTests/NetworkIsolationTest.cs @@ -17,7 +17,7 @@ namespace Tests.BasicTests [Test] public void SetUpANodeAndWait() { - node = Ci.SetupCodexNode(); + node = Ci.StartCodexNode(); Time.WaitUntil(() => node == null, TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(5)); } @@ -25,7 +25,7 @@ namespace Tests.BasicTests [Test] public void ForeignNodeConnects() { - var myNode = Ci.SetupCodexNode(); + var myNode = Ci.StartCodexNode(); Time.WaitUntil(() => node != null, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(5)); diff --git a/Tests/CodexTests/BasicTests/OneClientTests.cs b/Tests/CodexTests/BasicTests/OneClientTests.cs index e878e14d..22fe0dd3 100644 --- a/Tests/CodexTests/BasicTests/OneClientTests.cs +++ b/Tests/CodexTests/BasicTests/OneClientTests.cs @@ -11,7 +11,7 @@ namespace Tests.BasicTests [Test] public void OneClientTest() { - var primary = Ci.SetupCodexNode(); + var primary = Ci.StartCodexNode(); PerformOneClientTest(primary); } @@ -19,11 +19,11 @@ namespace Tests.BasicTests [Test] public void RestartTest() { - var primary = Ci.SetupCodexNode(); + var primary = Ci.StartCodexNode(); primary.Stop(); - primary = Ci.SetupCodexNode(); + primary = Ci.StartCodexNode(); PerformOneClientTest(primary); } diff --git a/Tests/CodexTests/BasicTests/TwoClientTests.cs b/Tests/CodexTests/BasicTests/TwoClientTests.cs index 5f0db786..69084949 100644 --- a/Tests/CodexTests/BasicTests/TwoClientTests.cs +++ b/Tests/CodexTests/BasicTests/TwoClientTests.cs @@ -12,7 +12,7 @@ namespace Tests.BasicTests [Test] public void TwoClientTest() { - var group = Ci.SetupCodexNodes(2); + var group = Ci.StartCodexNodes(2); var primary = group[0]; var secondary = group[1]; @@ -23,8 +23,8 @@ namespace Tests.BasicTests [Test] public void TwoClientsTwoLocationsTest() { - var primary = Ci.SetupCodexNode(s => s.At(Location.One)); - var secondary = Ci.SetupCodexNode(s => s.At(Location.Two)); + var primary = Ci.StartCodexNode(s => s.At(Location.One)); + var secondary = Ci.StartCodexNode(s => s.At(Location.Two)); PerformTwoClientTest(primary, secondary); } diff --git a/Tests/CodexTests/CodexDistTest.cs b/Tests/CodexTests/CodexDistTest.cs index 6c336762..2af737d5 100644 --- a/Tests/CodexTests/CodexDistTest.cs +++ b/Tests/CodexTests/CodexDistTest.cs @@ -29,7 +29,7 @@ namespace Tests public ICodexNodeGroup AddCodex(int numberOfNodes, Action setup) { - var group = Ci.SetupCodexNodes(numberOfNodes, s => + var group = Ci.StartCodexNodes(numberOfNodes, s => { setup(s); OnCodexSetup(s); diff --git a/Tests/CodexTests/PeerDiscoveryTests/LayeredDiscoveryTests.cs b/Tests/CodexTests/PeerDiscoveryTests/LayeredDiscoveryTests.cs index 088fbcbd..97675af5 100644 --- a/Tests/CodexTests/PeerDiscoveryTests/LayeredDiscoveryTests.cs +++ b/Tests/CodexTests/PeerDiscoveryTests/LayeredDiscoveryTests.cs @@ -9,10 +9,10 @@ namespace Tests.PeerDiscoveryTests [Test] public void TwoLayersTest() { - var root = Ci.SetupCodexNode(); - var l1Source = Ci.SetupCodexNode(s => s.WithBootstrapNode(root)); - var l1Node = Ci.SetupCodexNode(s => s.WithBootstrapNode(root)); - var l2Target = Ci.SetupCodexNode(s => s.WithBootstrapNode(l1Node)); + var root = Ci.StartCodexNode(); + var l1Source = Ci.StartCodexNode(s => s.WithBootstrapNode(root)); + var l1Node = Ci.StartCodexNode(s => s.WithBootstrapNode(root)); + var l2Target = Ci.StartCodexNode(s => s.WithBootstrapNode(l1Node)); AssertAllNodesConnected(); } @@ -20,11 +20,11 @@ namespace Tests.PeerDiscoveryTests [Test] public void ThreeLayersTest() { - var root = Ci.SetupCodexNode(); - var l1Source = Ci.SetupCodexNode(s => s.WithBootstrapNode(root)); - var l1Node = Ci.SetupCodexNode(s => s.WithBootstrapNode(root)); - var l2Node = Ci.SetupCodexNode(s => s.WithBootstrapNode(l1Node)); - var l3Target = Ci.SetupCodexNode(s => s.WithBootstrapNode(l2Node)); + var root = Ci.StartCodexNode(); + var l1Source = Ci.StartCodexNode(s => s.WithBootstrapNode(root)); + var l1Node = Ci.StartCodexNode(s => s.WithBootstrapNode(root)); + var l2Node = Ci.StartCodexNode(s => s.WithBootstrapNode(l1Node)); + var l3Target = Ci.StartCodexNode(s => s.WithBootstrapNode(l2Node)); AssertAllNodesConnected(); } @@ -35,10 +35,10 @@ namespace Tests.PeerDiscoveryTests [TestCase(20)] public void NodeChainTest(int chainLength) { - var node = Ci.SetupCodexNode(); + var node = Ci.StartCodexNode(); for (var i = 1; i < chainLength; i++) { - node = Ci.SetupCodexNode(s => s.WithBootstrapNode(node)); + node = Ci.StartCodexNode(s => s.WithBootstrapNode(node)); } AssertAllNodesConnected(); diff --git a/Tools/CodexNetDeployer/CodexNetDeployer.csproj b/Tools/CodexNetDeployer/CodexNetDeployer.csproj index 48bca3ad..9168ae7d 100644 --- a/Tools/CodexNetDeployer/CodexNetDeployer.csproj +++ b/Tools/CodexNetDeployer/CodexNetDeployer.csproj @@ -8,8 +8,10 @@ - - + + + + diff --git a/Tools/CodexNetDeployer/CodexNodeStarter.cs b/Tools/CodexNetDeployer/CodexNodeStarter.cs index c6b38502..f7cdd946 100644 --- a/Tools/CodexNetDeployer/CodexNodeStarter.cs +++ b/Tools/CodexNetDeployer/CodexNodeStarter.cs @@ -1,7 +1,7 @@ -using DistTestCore; -using DistTestCore.Codex; -using DistTestCore.Marketplace; -using KubernetesWorkflow; +using CodexContractsPlugin; +using CodexPlugin; +using Core; +using GethPlugin; using Utils; namespace CodexNetDeployer @@ -9,49 +9,49 @@ namespace CodexNetDeployer public class CodexNodeStarter { private readonly Configuration config; - private readonly TestLifecycle lifecycle; - private readonly GethStartResult gethResult; + private readonly CoreInterface ci; + private readonly IGethNode gethNode; + private readonly ICodexContracts contracts; private string bootstrapSpr = ""; private int validatorsLeft; - public CodexNodeStarter(Configuration config, TestLifecycle lifecycle, GethStartResult gethResult, int numberOfValidators) + public CodexNodeStarter(Configuration config, CoreInterface ci, IGethNode gethNode, ICodexContracts contracts, int numberOfValidators) { this.config = config; - this.lifecycle = lifecycle; - this.gethResult = gethResult; + this.ci = ci; + this.gethNode = gethNode; + this.contracts = contracts; validatorsLeft = numberOfValidators; } public CodexNodeStartResult? Start(int i) { - Console.Write($" - {i} = "); - var workflow = lifecycle.WorkflowCreator.CreateWorkflow(); - var workflowStartup = new StartupConfig(); - workflowStartup.Add(gethResult); - workflowStartup.Add(CreateCodexStartupConfig(bootstrapSpr, i, validatorsLeft)); - workflowStartup.NameOverride = GetCodexContainerName(i); - - var containers = workflow.Start(1, Location.Unspecified, new CodexContainerRecipe(), workflowStartup); - - var container = containers.Containers.First(); - var codexAccess = new CodexAccess(lifecycle.Log, container, lifecycle.TimeSet, lifecycle.Configuration.GetAddress(container)); - var account = gethResult.MarketplaceNetwork.Bootstrap.AllAccounts.Accounts[i]; - var tokenAddress = gethResult.MarketplaceNetwork.Marketplace.TokenAddress; - var marketAccess = new MarketplaceAccess(lifecycle, gethResult.MarketplaceNetwork, account, codexAccess); + var name = GetCodexContainerName(i); + Console.Write($" - {i} ({name}) = "); + ICodexNode? codexNode = null; try { - var debugInfo = codexAccess.GetDebugInfo(); + codexNode = ci.StartCodexNode(s => + { + s.WithName(name); + s.WithLogLevel(config.CodexLogLevel); + s.WithStorageQuota(config.StorageQuota!.Value.MB()); + s.EnableMarketplace(gethNode, contracts, 100.Eth(), config.InitialTestTokens.TestTokens(), validatorsLeft > 0); + s.EnableMetrics(); + + if (config.BlockTTL != Configuration.SecondsIn1Day) s.WithBlockTTL(TimeSpan.FromSeconds(config.BlockTTL)); + if (config.BlockMI != Configuration.TenMinutes) s.WithBlockMaintenanceInterval(TimeSpan.FromSeconds(config.BlockMI)); + if (config.BlockMN != 1000) s.WithBlockMaintenanceNumber(config.BlockMN); + }); + + var debugInfo = codexNode.GetDebugInfo(); if (!string.IsNullOrWhiteSpace(debugInfo.spr)) { Console.Write("Online\t"); - var interaction = gethResult.MarketplaceNetwork.Bootstrap.StartInteraction(lifecycle); - interaction.MintTestTokens(new[] { account.Account }, config.InitialTestTokens, tokenAddress); - Console.Write("Tokens minted\t"); - - var response = marketAccess.MakeStorageAvailable( - totalSpace: config.StorageSell!.Value.MB(), + var response = codexNode.Marketplace.MakeStorageAvailable( + size: config.StorageSell!.Value.MB(), minPriceForTotalSpace: config.MinPrice.TestTokens(), maxCollateral: config.MaxCollateral.TestTokens(), maxDuration: TimeSpan.FromSeconds(config.MaxDuration)); @@ -62,7 +62,7 @@ namespace CodexNetDeployer if (string.IsNullOrEmpty(bootstrapSpr)) bootstrapSpr = debugInfo.spr; validatorsLeft--; - return new CodexNodeStartResult(workflow, container, codexAccess); + return new CodexNodeStartResult(codexNode); } } } @@ -71,8 +71,12 @@ namespace CodexNetDeployer Console.WriteLine("Exception:" + ex.ToString()); } - Console.Write("Unknown failure. Downloading container log." + Environment.NewLine); - lifecycle.DownloadLog(container); + Console.WriteLine("Unknown failure."); + if (codexNode != null) + { + Console.WriteLine("Downloading container log."); + ci.DownloadLog(codexNode); + } return null; } @@ -82,46 +86,15 @@ namespace CodexNetDeployer if (i == 0) return "BOOTSTRAP"; return "CODEX" + i; } - - 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; - codexStart.MetricsMode = config.Metrics; - - if (config.BlockTTL != Configuration.SecondsIn1Day) - { - codexStart.BlockTTL = config.BlockTTL; - } - if (config.BlockMI != Configuration.TenMinutes) - { - codexStart.BlockMaintenanceInterval = TimeSpan.FromSeconds(config.BlockMI); - } - if (config.BlockMN != 1000) - { - codexStart.BlockMaintenanceNumber = config.BlockMN; - } - - return codexStart; - } } public class CodexNodeStartResult { - public CodexNodeStartResult(StartupWorkflow workflow, RunningContainer container, CodexAccess access) + public CodexNodeStartResult(ICodexNode codexNode) { - Workflow = workflow; - Container = container; - Access = access; + CodexNode = codexNode; } - public StartupWorkflow Workflow { get; } - public RunningContainer Container { get; } - public CodexAccess Access { get; } + public ICodexNode CodexNode { get; } } } diff --git a/Tools/CodexNetDeployer/Configuration.cs b/Tools/CodexNetDeployer/Configuration.cs index 7ad241a3..9eb107fb 100644 --- a/Tools/CodexNetDeployer/Configuration.cs +++ b/Tools/CodexNetDeployer/Configuration.cs @@ -1,6 +1,5 @@ using ArgsUniform; -using DistTestCore.Codex; -using DistTestCore.Metrics; +using CodexPlugin; namespace CodexNetDeployer { @@ -51,8 +50,8 @@ namespace CodexNetDeployer [Uniform("block-mn", "bmn", "BLOCKMN", false, "Number of blocks maintained per interval. Default is 1000 blocks.")] public int BlockMN { get; set; } = 1000; - [Uniform("metrics", "m", "METRICS", false, "[None*, Record, Dashboard]. Determines if metrics will be recorded and if a dashboard service will be created.")] - public MetricsMode Metrics { get; set; } = MetricsMode.None; + [Uniform("metrics", "m", "METRICS", false, "[true, false]. Determines if metrics will be recorded. Default is false.")] + public bool Metrics { get; set; } = false; [Uniform("teststype-podlabel", "ttpl", "TESTSTYPE-PODLABEL", false, "Each kubernetes pod will be created with a label 'teststype' with value 'continuous'. " + "set this option to override the label value.")] diff --git a/Tools/CodexNetDeployer/Deployer.cs b/Tools/CodexNetDeployer/Deployer.cs index eb329fc9..94b878d9 100644 --- a/Tools/CodexNetDeployer/Deployer.cs +++ b/Tools/CodexNetDeployer/Deployer.cs @@ -1,51 +1,58 @@ -using DistTestCore; -using DistTestCore.Codex; +using CodexContractsPlugin; +using CodexPlugin; +using Core; +using GethPlugin; using KubernetesWorkflow; using Logging; -using Utils; +using MetricsPlugin; namespace CodexNetDeployer { public class Deployer { private readonly Configuration config; - private readonly DefaultTimeSet timeset; private readonly PeerConnectivityChecker peerConnectivityChecker; + private readonly EntryPoint entryPoint; public Deployer(Configuration config) { this.config = config; - timeset = new DefaultTimeSet(); peerConnectivityChecker = new PeerConnectivityChecker(); + + entryPoint = CreateEntryPoint(new NullLog()); + } + + public void AnnouncePlugins() + { + var ep = CreateEntryPoint(new ConsoleLog()); + + Log("Using plugins:" + Environment.NewLine); + ep.Announce(); + Log(""); + var metadata = ep.GetPluginMetadata(); + foreach (var entry in metadata) + { + Log($"{entry.Key} = {entry.Value}"); + } + Log(""); } public CodexDeployment Deploy() { Log("Initializing..."); - var lifecycle = CreateTestLifecycle(); + var ci = entryPoint.CreateInterface(); - Log("Preparing configuration..."); - // We trick the Geth companion node into unlocking all of its accounts, by saying we want to start 999 codex nodes. - var setup = new CodexSetup(999, config.CodexLogLevel); - setup.WithStorageQuota(config.StorageQuota!.Value.MB()).EnableMarketplace(0.TestTokens()); - setup.MetricsMode = config.Metrics; + Log("Deploying Geth instance..."); + var gethDeployment = ci.DeployGeth(s => s.IsMiner()); + var gethNode = ci.WrapGethDeployment(gethDeployment); - Log("Creating Geth instance and deploying contracts..."); - var gethStarter = new GethStarter(lifecycle); - 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."); - - // It takes a second for the geth node to unlock a single account. Let's assume 3. - // We can't start the codex nodes until their accounts are definitely unlocked. So - // We wait: - Thread.Sleep(TimeSpan.FromSeconds(3.0 * config.NumberOfCodexNodes!.Value)); + Log("Geth started. Deploying Codex contracts..."); + var contractsDeployment = ci.DeployCodexContracts(gethNode); + var contracts = ci.WrapCodexContractsDeployment(contractsDeployment); + Log("Codex contracts deployed."); Log("Starting Codex nodes..."); - - // Each node must have its own IP, so it needs it own pod. Start them 1 at a time. - var codexStarter = new CodexNodeStarter(config, lifecycle, gethResults, config.NumberOfValidators!.Value); + var codexStarter = new CodexNodeStarter(config, ci, gethNode, contracts, config.NumberOfValidators!.Value); var startResults = new List(); for (var i = 0; i < config.NumberOfCodexNodes; i++) { @@ -53,47 +60,40 @@ namespace CodexNetDeployer if (result != null) startResults.Add(result); } - var (prometheusContainer, grafanaStartInfo) = StartMetricsService(lifecycle, setup, startResults.Select(r => r.Container)); + Log("Codex nodes started."); + var metricsService = StartMetricsService(ci, startResults); CheckPeerConnectivity(startResults); CheckContainerRestarts(startResults); - return new CodexDeployment(gethResults, startResults.Select(r => r.Container).ToArray(), prometheusContainer, grafanaStartInfo, CreateMetadata()); + var codexContainers = startResults.Select(s => s.CodexNode.Container).ToArray(); + return new CodexDeployment(codexContainers, gethDeployment, metricsService, CreateMetadata()); } - private TestLifecycle CreateTestLifecycle() + private EntryPoint CreateEntryPoint(ILog log) { var kubeConfig = GetKubeConfig(config.KubeConfigFile); - var lifecycleConfig = new DistTestCore.Configuration - ( - kubeConfigFile: kubeConfig, - logPath: "null", - logDebug: false, - dataFilesPath: "notUsed", - codexLogLevel: config.CodexLogLevel, - k8sNamespacePrefix: config.KubeNamespace - ); + var configuration = new KubernetesWorkflow.Configuration( + kubeConfig, + operationTimeout: TimeSpan.FromSeconds(30), + retryDelay: TimeSpan.FromSeconds(10), + kubernetesNamespace: config.KubeNamespace); - var lifecycle = new TestLifecycle(new NullLog(), lifecycleConfig, timeset, string.Empty); - DefaultContainerRecipe.TestsType = config.TestsTypePodLabel; - DefaultContainerRecipe.ApplicationIds = lifecycle.GetApplicationIds(); - return lifecycle; + return new EntryPoint(log, configuration, string.Empty); } - private (RunningContainer?, GrafanaStartInfo?) StartMetricsService(TestLifecycle lifecycle, CodexSetup setup, IEnumerable codexContainers) + private RunningContainer? StartMetricsService(CoreInterface ci, List startResults) { - if (setup.MetricsMode == DistTestCore.Metrics.MetricsMode.None) return (null, null); + if (!config.Metrics) return null; Log("Starting metrics service..."); - var runningContainers = new[] { new RunningContainers(null!, null!, codexContainers.ToArray()) }; - var prometheusContainer = lifecycle.PrometheusStarter.CollectMetricsFor(runningContainers).Containers.Single(); - if (setup.MetricsMode == DistTestCore.Metrics.MetricsMode.Record) return (prometheusContainer, null); + var runningContainer = ci.DeployMetricsCollector(startResults.Select(r => r.CodexNode).ToArray()); - Log("Starting dashboard service..."); - var grafanaStartInfo = lifecycle.GrafanaStarter.StartDashboard(prometheusContainer, setup); - return (prometheusContainer, grafanaStartInfo); + Log("Metrics service started."); + + return runningContainer; } private string? GetKubeConfig(string kubeConfigFile) @@ -106,7 +106,7 @@ namespace CodexNetDeployer { if (!config.CheckPeerConnection) return; - Log("Starting peer-connectivity check for deployed nodes..."); + Log("Starting peer connectivity check for deployed nodes..."); peerConnectivityChecker.CheckConnectivity(codexContainers); Log("Check passed."); } @@ -114,19 +114,21 @@ namespace CodexNetDeployer private void CheckContainerRestarts(List startResults) { var crashes = new List(); + Log("Starting container crash check..."); foreach (var startResult in startResults) { - var watcher = startResult.Workflow.CreateCrashWatcher(startResult.Container); - if (watcher.HasContainerCrashed()) crashes.Add(startResult.Container); + var watcher = startResult.CodexNode.Container.CrashWatcher; + if (watcher == null) throw new Exception("Expected each CodexNode container to be created with a crash-watcher."); + if (watcher.HasContainerCrashed()) crashes.Add(startResult.CodexNode.Container); } if (!crashes.Any()) { - Log("Container restart check passed."); + Log("Check passed."); } else { - Log($"Deployment failed. The following containers have crashed: {string.Join(",", crashes.Select(c => c.Name))}"); + Log($"Check failed. The following containers have crashed: {string.Join(",", crashes.Select(c => c.Name))}"); throw new Exception("Deployment failed: One or more containers crashed."); } } diff --git a/Tools/CodexNetDeployer/PeerConnectivityChecker.cs b/Tools/CodexNetDeployer/PeerConnectivityChecker.cs index 6e7eddb7..8e20a4a2 100644 --- a/Tools/CodexNetDeployer/PeerConnectivityChecker.cs +++ b/Tools/CodexNetDeployer/PeerConnectivityChecker.cs @@ -9,9 +9,9 @@ namespace CodexNetDeployer { var log = new ConsoleLog(); var checker = new PeerConnectionTestHelpers(log); - var access = startResults.Select(r => r.Access); + var nodes = startResults.Select(r => r.CodexNode); - checker.AssertFullyConnected(access); + checker.AssertFullyConnected(nodes); } } diff --git a/Tools/CodexNetDeployer/Program.cs b/Tools/CodexNetDeployer/Program.cs index 8ddf527b..73fef7fe 100644 --- a/Tools/CodexNetDeployer/Program.cs +++ b/Tools/CodexNetDeployer/Program.cs @@ -1,8 +1,5 @@ using ArgsUniform; using CodexNetDeployer; -using DistTestCore.Codex; -using DistTestCore.Marketplace; -using DistTestCore.Metrics; using Newtonsoft.Json; using Configuration = CodexNetDeployer.Configuration; @@ -26,12 +23,8 @@ public class Program return; } - Console.WriteLine("Using images:" + nl + - $"\tCodex image: '{new CodexContainerRecipe().Image}'" + nl + - $"\tCodexContracts image: '{new CodexContractsContainerRecipe().Image}'" + nl + - $"\tPrometheus image: '{new PrometheusContainerRecipe().Image}'" + nl + - $"\tGeth image: '{new GethContainerRecipe().Image}'" + nl + - $"\tGrafana image: '{new GrafanaContainerRecipe().Image}'" + nl); + var deployer = new Deployer(config); + deployer.AnnouncePlugins(); if (!args.Any(a => a == "-y")) { @@ -40,7 +33,6 @@ public class Program Console.WriteLine("I think so too."); } - var deployer = new Deployer(config); var deployment = deployer.Deploy(); Console.WriteLine("Writing codex-deployment.json..."); diff --git a/Tools/CodexNetDeployer/deploy-continuous-testnet.sh b/Tools/CodexNetDeployer/deploy-continuous-testnet.sh index afcfc448..e4ad70a1 100644 --- a/Tools/CodexNetDeployer/deploy-continuous-testnet.sh +++ b/Tools/CodexNetDeployer/deploy-continuous-testnet.sh @@ -12,5 +12,5 @@ dotnet run \ --block-ttl=180 \ --block-mi=120 \ --block-mn=10000 \ - --metrics=Dashboard \ + --metrics=true \ --check-connect=1