Restores CodexNetDeployer

This commit is contained in:
benbierens 2023-09-20 12:55:09 +02:00
parent 75369d68f7
commit 3b6fdaa3bc
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
12 changed files with 32 additions and 28 deletions

View File

@ -41,9 +41,6 @@ namespace KubernetesWorkflow
public Address ClusterExternalAddress { get; }
public Address ClusterInternalAddress { get; }
[JsonIgnore]
public CrashWatcher? CrashWatcher { get; set; }
[JsonIgnore]
public Address Address
{

View File

@ -5,7 +5,6 @@
private readonly List<object> configs = new List<object>();
public string? NameOverride { get; set; }
public bool CreateCrashWatcher { get; set; }
public void Add(object config)
{

View File

@ -6,6 +6,7 @@ namespace KubernetesWorkflow
public interface IStartupWorkflow
{
RunningContainers Start(int numberOfContainers, Location location, ContainerRecipeFactory recipeFactory, StartupConfig startupConfig);
CrashWatcher CreateCrashWatcher(RunningContainer container);
void Stop(RunningContainers runningContainers);
void DownloadContainerLog(RunningContainer container, ILogHandler logHandler, int? tailLines = null);
string ExecuteCommand(RunningContainer container, string command, params string[] args);
@ -39,14 +40,17 @@ namespace KubernetesWorkflow
var runningPod = controller.BringOnline(recipes, location);
var containers = CreateContainers(runningPod, recipes, startupConfig);
if (startupConfig.CreateCrashWatcher) CreateCrashWatchers(controller, containers);
var rc = new RunningContainers(startupConfig, runningPod, containers);
cluster.Configuration.Hooks.OnContainersStarted(rc);
return rc;
});
}
public CrashWatcher CreateCrashWatcher(RunningContainer container)
{
return K8s(c => c.CreateCrashWatcher(container));
}
public void Stop(RunningContainers runningContainers)
{
K8s(controller =>
@ -88,14 +92,6 @@ namespace KubernetesWorkflow
});
}
private void CreateCrashWatchers(K8sController controller, RunningContainer[] runningContainers)
{
foreach (var container in runningContainers)
{
container.CrashWatcher = controller.CreateCrashWatcher(container);
}
}
private RunningContainer[] CreateContainers(RunningPod runningPod, ContainerRecipe[] recipes, StartupConfig startupConfig)
{
log.Debug();

View File

@ -8,16 +8,18 @@ namespace CodexPlugin
private readonly IPluginTools tools;
private bool hasContainerCrashed;
public CodexAccess(IPluginTools tools, RunningContainer container)
public CodexAccess(IPluginTools tools, RunningContainer container, CrashWatcher crashWatcher)
{
this.tools = tools;
Container = container;
CrashWatcher = crashWatcher;
hasContainerCrashed = false;
if (container.CrashWatcher != null) container.CrashWatcher.Start(this);
CrashWatcher.Start(this);
}
public RunningContainer Container { get; }
public CrashWatcher CrashWatcher { get; }
public CodexDebugResponse GetDebugInfo()
{

View File

@ -18,6 +18,7 @@ namespace CodexPlugin
void ConnectToPeer(ICodexNode node);
CodexDebugVersionResponse Version { get; }
IMarketplaceAccess Marketplace { get; }
CrashWatcher CrashWatcher { get; }
void Stop();
}
@ -40,6 +41,7 @@ namespace CodexPlugin
public RunningContainer Container { get { return CodexAccess.Container; } }
public CodexAccess CodexAccess { get; }
public CrashWatcher CrashWatcher { get => CodexAccess.CrashWatcher; }
public CodexNodeGroup Group { get; }
public IMarketplaceAccess Marketplace { get; }
public CodexDebugVersionResponse Version { get; private set; }

View File

@ -1,11 +1,13 @@
using Core;
using GethPlugin;
using KubernetesWorkflow;
namespace CodexPlugin
{
public interface ICodexNodeFactory
{
CodexNode CreateOnlineCodexNode(CodexAccess access, CodexNodeGroup group);
CrashWatcher CreateCrashWatcher(RunningContainer c);
}
public class CodexNodeFactory : ICodexNodeFactory
@ -36,5 +38,10 @@ namespace CodexPlugin
if (mStart == null) return null;
return mStart.EthAddress;
}
public CrashWatcher CreateCrashWatcher(RunningContainer c)
{
return tools.CreateWorkflow().CreateCrashWatcher(c);
}
}
}

View File

@ -76,7 +76,8 @@ namespace CodexPlugin
private CodexNode CreateOnlineCodexNode(RunningContainer c, IPluginTools tools, ICodexNodeFactory factory)
{
var access = new CodexAccess(tools, c);
var watcher = factory.CreateCrashWatcher(c);
var access = new CodexAccess(tools, c, watcher);
return factory.CreateOnlineCodexNode(access, this);
}
}

View File

@ -46,10 +46,10 @@ namespace CodexPlugin
public void BringOffline(CodexNodeGroup group)
{
Log($"Stopping {group.Describe()}...");
StopCrashWatcher(group);
var workflow = pluginTools.CreateWorkflow();
foreach (var c in group.Containers)
{
StopCrashWatcher(c);
workflow.Stop(c);
}
Log("Stopped.");
@ -65,7 +65,6 @@ namespace CodexPlugin
{
var startupConfig = new StartupConfig();
startupConfig.NameOverride = codexSetup.NameOverride;
startupConfig.CreateCrashWatcher = true;
startupConfig.Add(codexSetup);
return startupConfig;
}
@ -114,11 +113,11 @@ namespace CodexPlugin
pluginTools.GetLog().Log(message);
}
private void StopCrashWatcher(RunningContainers containers)
private void StopCrashWatcher(CodexNodeGroup group)
{
foreach (var c in containers.Containers)
foreach (var node in group)
{
c.CrashWatcher?.Stop();
node.CrashWatcher.Stop();
}
}
}

View File

@ -12,7 +12,7 @@ namespace CodexNetDeployer
private readonly CoreInterface ci;
private readonly IGethNode gethNode;
private readonly ICodexContracts contracts;
private string bootstrapSpr = "";
private ICodexNode? bootstrapNode = null;
private int validatorsLeft;
public CodexNodeStarter(Configuration config, CoreInterface ci, IGethNode gethNode, ICodexContracts contracts, int numberOfValidators)
@ -27,7 +27,7 @@ namespace CodexNetDeployer
public CodexNodeStartResult? Start(int i)
{
var name = GetCodexContainerName(i);
Console.Write($" - {i} ({name}) = ");
Console.Write($" - {i} ({name}) \t= ");
ICodexNode? codexNode = null;
try
@ -40,6 +40,7 @@ namespace CodexNetDeployer
s.EnableMarketplace(gethNode, contracts, 100.Eth(), config.InitialTestTokens.TestTokens(), validatorsLeft > 0);
s.EnableMetrics();
if (bootstrapNode != null) s.WithBootstrapNode(bootstrapNode);
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);
@ -60,8 +61,8 @@ namespace CodexNetDeployer
{
Console.Write("Storage available\tOK" + Environment.NewLine);
if (string.IsNullOrEmpty(bootstrapSpr)) bootstrapSpr = debugInfo.spr;
validatorsLeft--;
if (bootstrapNode == null) bootstrapNode = codexNode;
return new CodexNodeStartResult(codexNode);
}
}

View File

@ -57,7 +57,7 @@ namespace CodexNetDeployer
"set this option to override the label value.")]
public string TestsTypePodLabel { get; set; } = "continuous-tests";
[Uniform("check-connect", "cc", "CHECKCONNECT", false, "If true, deployer check ensure peer-connectivity between all deployed nodes after deployment.")]
[Uniform("check-connect", "cc", "CHECKCONNECT", false, "If true, deployer check ensure peer-connectivity between all deployed nodes after deployment. Default is false.")]
public bool CheckPeerConnection { get; set; } = false;
public List<string> Validate()

View File

@ -117,7 +117,7 @@ namespace CodexNetDeployer
Log("Starting container crash check...");
foreach (var startResult in startResults)
{
var watcher = startResult.CodexNode.Container.CrashWatcher;
var watcher = startResult.CodexNode.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);
}

View File

@ -12,5 +12,5 @@ dotnet run \
--block-ttl=180 \
--block-mi=120 \
--block-mn=10000 \
--metrics=true \
--metrics=1 \
--check-connect=1