Bootstrapping waku nodes
This commit is contained in:
parent
30ba382db7
commit
12f6710a56
|
@ -5,45 +5,26 @@ namespace WakuPlugin
|
||||||
{
|
{
|
||||||
public static class CoreInterfaceExtensions
|
public static class CoreInterfaceExtensions
|
||||||
{
|
{
|
||||||
public static RunningContainers[] DeployWakuNodes(this CoreInterface ci, int number)
|
public static RunningContainers[] DeployWakuNodes(this CoreInterface ci, int number, Action<IWakuSetup> setup)
|
||||||
{
|
{
|
||||||
return Plugin(ci).DeployWakuNodes(number);
|
return Plugin(ci).DeployWakuNodes(number, setup);
|
||||||
}
|
}
|
||||||
|
|
||||||
//public static ICodexNodeGroup WrapCodexContainers(this CoreInterface ci, RunningContainer[] containers)
|
public static IWakuNode WrapWakuContainer(this CoreInterface ci, RunningContainer container)
|
||||||
//{
|
{
|
||||||
// // ew, clean this up.
|
return Plugin(ci).WrapWakuContainer(container);
|
||||||
// var rcs = new RunningContainers(null!, containers.First().Pod, containers);
|
}
|
||||||
// return WrapCodexContainers(ci, new[] { rcs });
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public static ICodexNodeGroup WrapCodexContainers(this CoreInterface ci, RunningContainers[] containers)
|
public static IWakuNode StartWakuNode(this CoreInterface ci)
|
||||||
//{
|
{
|
||||||
// return Plugin(ci).WrapCodexContainers(ci, containers);
|
return ci.StartWakuNode(s => { });
|
||||||
//}
|
}
|
||||||
|
|
||||||
//public static ICodexNode StartCodexNode(this CoreInterface ci)
|
public static IWakuNode StartWakuNode(this CoreInterface ci, Action<IWakuSetup> setup)
|
||||||
//{
|
{
|
||||||
// return ci.StartCodexNodes(1)[0];
|
var rc = ci.DeployWakuNodes(1, setup);
|
||||||
//}
|
return ci.WrapWakuContainer(rc.First().Containers.First());
|
||||||
|
}
|
||||||
//public static ICodexNode StartCodexNode(this CoreInterface ci, Action<ICodexSetup> setup)
|
|
||||||
//{
|
|
||||||
// return ci.StartCodexNodes(1, setup)[0];
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public static ICodexNodeGroup StartCodexNodes(this CoreInterface ci, int number, Action<ICodexSetup> setup)
|
|
||||||
//{
|
|
||||||
// var rc = ci.DeployCodexNodes(number, setup);
|
|
||||||
// var result = ci.WrapCodexContainers(rc);
|
|
||||||
// Plugin(ci).WireUpMarketplace(result, setup);
|
|
||||||
// return result;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public static ICodexNodeGroup StartCodexNodes(this CoreInterface ci, int number)
|
|
||||||
//{
|
|
||||||
// return ci.StartCodexNodes(number, s => { });
|
|
||||||
//}
|
|
||||||
|
|
||||||
private static WakuPlugin Plugin(CoreInterface ci)
|
private static WakuPlugin Plugin(CoreInterface ci)
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
namespace WakuPlugin
|
||||||
|
{
|
||||||
|
public class DebugInfoResponse
|
||||||
|
{
|
||||||
|
public string[] listenAddresses { get; set; }
|
||||||
|
public string enrUri { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,22 +11,28 @@ namespace WakuPlugin
|
||||||
|
|
||||||
protected override void Initialize(StartupConfig startupConfig)
|
protected override void Initialize(StartupConfig startupConfig)
|
||||||
{
|
{
|
||||||
|
var config = startupConfig.Get<WakuSetup>();
|
||||||
|
|
||||||
SetResourcesRequest(milliCPUs: 100, memory: 100.MB());
|
SetResourcesRequest(milliCPUs: 100, memory: 100.MB());
|
||||||
SetResourceLimits(milliCPUs: 4000, memory: 12.GB());
|
SetResourceLimits(milliCPUs: 4000, memory: 12.GB());
|
||||||
|
|
||||||
AddInternalPortAndVar("WAKUNODE2_TCP_PORT");
|
AddEnvVar("WAKUNODE2_LOG_LEVEL", "TRACE");
|
||||||
|
|
||||||
AddEnvVar("WAKUNODE2_RPC_ADDRESS", "0.0.0.0");
|
|
||||||
|
|
||||||
AddEnvVar("WAKUNODE2_REST", "1");
|
AddEnvVar("WAKUNODE2_REST", "1");
|
||||||
AddEnvVar("WAKUNODE2_REST_ADDRESS", "0.0.0.0");
|
|
||||||
AddExposedPortAndVar("WAKUNODE2_REST_PORT", "restport");
|
AddExposedPortAndVar("WAKUNODE2_REST_PORT", "restport");
|
||||||
|
AddEnvVar("WAKUNODE2_REST_ADDRESS", "0.0.0.0");
|
||||||
|
|
||||||
|
AddInternalPortAndVar("WAKUNODE2_TCP_PORT");
|
||||||
|
AddEnvVar("WAKUNODE2_RPC_ADDRESS", "0.0.0.0");
|
||||||
|
|
||||||
AddEnvVar("WAKUNODE2_DISCV5_DISCOVERY", "1");
|
AddEnvVar("WAKUNODE2_DISCV5_DISCOVERY", "1");
|
||||||
AddInternalPortAndVar("WAKUNODE2_DISCV5_UDP_PORT");
|
AddInternalPortAndVar("WAKUNODE2_DISCV5_UDP_PORT");
|
||||||
//AddEnvVar("WAKUNODE2_DISCV5_BOOTSTRAP_NODE", "________<---- enr here");
|
|
||||||
AddEnvVar("WAKUNODE2_DISCV5_ENR_AUTO_UPDATEY", "1");
|
AddEnvVar("WAKUNODE2_DISCV5_ENR_AUTO_UPDATEY", "1");
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(config.BootstrapEnr))
|
||||||
|
{
|
||||||
|
AddEnvVar("WAKUNODE2_DISCV5_BOOTSTRAP_NODE", config.BootstrapEnr);
|
||||||
|
}
|
||||||
|
|
||||||
AddEnvVar("WAKUNODE2_TOPICS", "test_topics_plz");
|
AddEnvVar("WAKUNODE2_TOPICS", "test_topics_plz");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
using Core;
|
||||||
|
using KubernetesWorkflow;
|
||||||
|
|
||||||
|
namespace WakuPlugin
|
||||||
|
{
|
||||||
|
public interface IWakuNode : IHasContainer
|
||||||
|
{
|
||||||
|
DebugInfoResponse DebugInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WakuNode : IWakuNode
|
||||||
|
{
|
||||||
|
private readonly IPluginTools tools;
|
||||||
|
|
||||||
|
public WakuNode(IPluginTools tools, RunningContainer container)
|
||||||
|
{
|
||||||
|
this.tools = tools;
|
||||||
|
Container = container;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RunningContainer Container { get; }
|
||||||
|
|
||||||
|
public DebugInfoResponse DebugInfo()
|
||||||
|
{
|
||||||
|
return Http().HttpGetJson<DebugInfoResponse>("debug/v1/info");
|
||||||
|
}
|
||||||
|
|
||||||
|
private IHttp Http()
|
||||||
|
{
|
||||||
|
return tools.CreateHttp(Container.Address, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,9 +30,15 @@ namespace WakuPlugin
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public RunningContainers[] DeployWakuNodes(int numberOfNodes)
|
public RunningContainers[] DeployWakuNodes(int numberOfNodes, Action<IWakuSetup> setup)
|
||||||
{
|
{
|
||||||
return starter.Start(numberOfNodes);
|
return starter.Start(numberOfNodes, setup);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IWakuNode WrapWakuContainer(RunningContainer container)
|
||||||
|
{
|
||||||
|
container = SerializeGate.Gate(container);
|
||||||
|
return starter.Wrap(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
//public ICodexNodeGroup WrapCodexContainers(CoreInterface coreInterface, RunningContainers[] containers)
|
//public ICodexNodeGroup WrapCodexContainers(CoreInterface coreInterface, RunningContainers[] containers)
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
namespace WakuPlugin
|
||||||
|
{
|
||||||
|
public interface IWakuSetup
|
||||||
|
{
|
||||||
|
IWakuSetup WithBootstrapNode(IWakuNode node);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WakuSetup : IWakuSetup
|
||||||
|
{
|
||||||
|
internal string? Name { get; private set; }
|
||||||
|
internal string? BootstrapEnr { get; private set; }
|
||||||
|
|
||||||
|
public IWakuSetup WithName(string name)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IWakuSetup WithBootstrapNode(IWakuNode node)
|
||||||
|
{
|
||||||
|
BootstrapEnr = node.DebugInfo().enrUri;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,17 +12,33 @@ namespace WakuPlugin
|
||||||
this.tools = tools;
|
this.tools = tools;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RunningContainers[] Start(int numberOfNodes)
|
public RunningContainers[] Start(int numberOfNodes, Action<IWakuSetup> setup)
|
||||||
{
|
{
|
||||||
var result = new List<RunningContainers>();
|
var result = new List<RunningContainers>();
|
||||||
var workflow = tools.CreateWorkflow();
|
var workflow = tools.CreateWorkflow();
|
||||||
|
var startupConfig = CreateStartupConfig(setup);
|
||||||
|
|
||||||
for (var i = 0; i < numberOfNodes; i++)
|
for (var i = 0; i < numberOfNodes; i++)
|
||||||
{
|
{
|
||||||
result.Add(workflow.Start(1, new WakuPluginContainerRecipe(), new StartupConfig()));
|
result.Add(workflow.Start(1, new WakuPluginContainerRecipe(), startupConfig));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.ToArray();
|
return result.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IWakuNode Wrap(RunningContainer container)
|
||||||
|
{
|
||||||
|
return new WakuNode(tools, container);
|
||||||
|
}
|
||||||
|
|
||||||
|
private StartupConfig CreateStartupConfig(Action<IWakuSetup> setup)
|
||||||
|
{
|
||||||
|
var config = new WakuSetup();
|
||||||
|
setup(config);
|
||||||
|
var startupConfig = new StartupConfig();
|
||||||
|
startupConfig.Add(config);
|
||||||
|
startupConfig.NameOverride = config.Name;
|
||||||
|
return startupConfig;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,16 @@ namespace WakuTests
|
||||||
[Test]
|
[Test]
|
||||||
public void Hi()
|
public void Hi()
|
||||||
{
|
{
|
||||||
var rc = Ci.DeployWakuNodes(1);
|
var node1 = Ci.StartWakuNode();
|
||||||
|
|
||||||
|
var info1 = node1.DebugInfo();
|
||||||
|
Assert.That(info1.enrUri, Is.Not.Empty);
|
||||||
|
|
||||||
|
var node2 = Ci.StartWakuNode(s => s.WithBootstrapNode(node1));
|
||||||
|
var info2 = node2.DebugInfo();
|
||||||
|
Assert.That(info2.enrUri, Is.Not.Empty);
|
||||||
|
|
||||||
|
|
||||||
var i = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue