2023-04-12 14:12:04 +00:00
|
|
|
|
using DistTestCore.Codex;
|
|
|
|
|
using KubernetesWorkflow;
|
2023-04-12 14:06:04 +00:00
|
|
|
|
|
|
|
|
|
namespace DistTestCore
|
|
|
|
|
{
|
|
|
|
|
public class CodexStarter
|
|
|
|
|
{
|
2023-04-13 07:33:10 +00:00
|
|
|
|
private readonly TestLifecycle lifecycle;
|
2023-04-13 12:36:17 +00:00
|
|
|
|
private readonly WorkflowCreator workflowCreator;
|
2023-04-12 14:06:04 +00:00
|
|
|
|
|
2023-04-13 12:36:17 +00:00
|
|
|
|
public CodexStarter(TestLifecycle lifecycle, WorkflowCreator workflowCreator)
|
2023-04-12 14:06:04 +00:00
|
|
|
|
{
|
2023-04-13 07:33:10 +00:00
|
|
|
|
this.lifecycle = lifecycle;
|
2023-04-13 12:36:17 +00:00
|
|
|
|
this.workflowCreator = workflowCreator;
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 09:53:54 +00:00
|
|
|
|
public List<CodexNodeGroup> RunningGroups { get; } = new List<CodexNodeGroup>();
|
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
public ICodexNodeGroup BringOnline(CodexSetup codexSetup)
|
2023-04-12 14:06:04 +00:00
|
|
|
|
{
|
2023-04-14 07:54:07 +00:00
|
|
|
|
var something = lifecycle.GethStarter.BringOnlineMarketplaceFor(codexSetup);
|
|
|
|
|
|
2023-04-13 12:36:17 +00:00
|
|
|
|
var containers = StartCodexContainers(codexSetup);
|
2023-04-13 09:53:54 +00:00
|
|
|
|
|
2023-04-13 12:36:17 +00:00
|
|
|
|
var metricAccessFactory = lifecycle.PrometheusStarter.CollectMetricsFor(codexSetup, containers);
|
2023-04-12 14:06:04 +00:00
|
|
|
|
|
2023-04-13 12:36:17 +00:00
|
|
|
|
var codexNodeFactory = new CodexNodeFactory(lifecycle, metricAccessFactory);
|
2023-04-12 14:12:04 +00:00
|
|
|
|
|
2023-04-13 12:36:17 +00:00
|
|
|
|
var group = CreateCodexGroup(codexSetup, containers, codexNodeFactory);
|
2023-04-13 09:53:54 +00:00
|
|
|
|
|
|
|
|
|
return group;
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 09:53:54 +00:00
|
|
|
|
public void BringOffline(CodexNodeGroup group)
|
2023-04-13 09:07:36 +00:00
|
|
|
|
{
|
2023-04-13 09:53:54 +00:00
|
|
|
|
Log($"Stopping {group.Describe()}...");
|
2023-04-13 09:07:36 +00:00
|
|
|
|
var workflow = CreateWorkflow();
|
2023-04-13 09:53:54 +00:00
|
|
|
|
workflow.Stop(group.Containers);
|
|
|
|
|
RunningGroups.Remove(group);
|
|
|
|
|
Log("Stopped.");
|
2023-04-13 09:07:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 14:06:04 +00:00
|
|
|
|
public void DeleteAllResources()
|
|
|
|
|
{
|
2023-04-13 09:07:36 +00:00
|
|
|
|
var workflow = CreateWorkflow();
|
2023-04-12 14:06:04 +00:00
|
|
|
|
workflow.DeleteAllResources();
|
2023-04-13 09:53:54 +00:00
|
|
|
|
|
|
|
|
|
RunningGroups.Clear();
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
2023-04-13 09:07:36 +00:00
|
|
|
|
|
2023-04-13 09:30:19 +00:00
|
|
|
|
public void DownloadLog(RunningContainer container, ILogHandler logHandler)
|
|
|
|
|
{
|
|
|
|
|
var workflow = CreateWorkflow();
|
|
|
|
|
workflow.DownloadContainerLog(container, logHandler);
|
|
|
|
|
}
|
2023-04-13 12:36:17 +00:00
|
|
|
|
|
|
|
|
|
private RunningContainers StartCodexContainers(CodexSetup codexSetup)
|
|
|
|
|
{
|
|
|
|
|
Log($"Starting {codexSetup.Describe()}...");
|
|
|
|
|
|
|
|
|
|
var workflow = CreateWorkflow();
|
|
|
|
|
var startupConfig = new StartupConfig();
|
|
|
|
|
startupConfig.Add(codexSetup);
|
|
|
|
|
|
|
|
|
|
return workflow.Start(codexSetup.NumberOfNodes, codexSetup.Location, new CodexContainerRecipe(), startupConfig);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CodexNodeGroup CreateCodexGroup(CodexSetup codexSetup, RunningContainers runningContainers, CodexNodeFactory codexNodeFactory)
|
|
|
|
|
{
|
|
|
|
|
var group = new CodexNodeGroup(lifecycle, codexSetup, runningContainers, codexNodeFactory);
|
|
|
|
|
RunningGroups.Add(group);
|
|
|
|
|
|
|
|
|
|
Log($"Started at '{group.Containers.RunningPod.Ip}'");
|
|
|
|
|
return group;
|
|
|
|
|
}
|
2023-04-13 09:30:19 +00:00
|
|
|
|
|
2023-04-13 09:07:36 +00:00
|
|
|
|
private StartupWorkflow CreateWorkflow()
|
|
|
|
|
{
|
|
|
|
|
return workflowCreator.CreateWorkflow();
|
|
|
|
|
}
|
2023-04-13 09:53:54 +00:00
|
|
|
|
|
|
|
|
|
private void Log(string msg)
|
|
|
|
|
{
|
|
|
|
|
lifecycle.Log.Log(msg);
|
|
|
|
|
}
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|