diff --git a/ProjectPlugins/WakuPlugin/CoreInterfaceExtensions.cs b/ProjectPlugins/WakuPlugin/CoreInterfaceExtensions.cs index 6890b0b..25cf24f 100644 --- a/ProjectPlugins/WakuPlugin/CoreInterfaceExtensions.cs +++ b/ProjectPlugins/WakuPlugin/CoreInterfaceExtensions.cs @@ -5,45 +5,26 @@ namespace WakuPlugin { public static class CoreInterfaceExtensions { - public static RunningContainers[] DeployWakuNodes(this CoreInterface ci, int number) + public static RunningContainers[] DeployWakuNodes(this CoreInterface ci, int number, Action setup) { - return Plugin(ci).DeployWakuNodes(number); + return Plugin(ci).DeployWakuNodes(number, setup); } - //public static ICodexNodeGroup WrapCodexContainers(this CoreInterface ci, RunningContainer[] containers) - //{ - // // ew, clean this up. - // var rcs = new RunningContainers(null!, containers.First().Pod, containers); - // return WrapCodexContainers(ci, new[] { rcs }); - //} + public static IWakuNode WrapWakuContainer(this CoreInterface ci, RunningContainer container) + { + return Plugin(ci).WrapWakuContainer(container); + } - //public static ICodexNodeGroup WrapCodexContainers(this CoreInterface ci, RunningContainers[] containers) - //{ - // return Plugin(ci).WrapCodexContainers(ci, containers); - //} + public static IWakuNode StartWakuNode(this CoreInterface ci) + { + return ci.StartWakuNode(s => { }); + } - //public static ICodexNode StartCodexNode(this CoreInterface ci) - //{ - // return ci.StartCodexNodes(1)[0]; - //} - - //public static ICodexNode StartCodexNode(this CoreInterface ci, Action setup) - //{ - // return ci.StartCodexNodes(1, setup)[0]; - //} - - //public static ICodexNodeGroup StartCodexNodes(this CoreInterface ci, int number, Action 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 => { }); - //} + public static IWakuNode StartWakuNode(this CoreInterface ci, Action setup) + { + var rc = ci.DeployWakuNodes(1, setup); + return ci.WrapWakuContainer(rc.First().Containers.First()); + } private static WakuPlugin Plugin(CoreInterface ci) { diff --git a/ProjectPlugins/WakuPlugin/WakuApiTypes.cs b/ProjectPlugins/WakuPlugin/WakuApiTypes.cs new file mode 100644 index 0000000..603cda6 --- /dev/null +++ b/ProjectPlugins/WakuPlugin/WakuApiTypes.cs @@ -0,0 +1,8 @@ +namespace WakuPlugin +{ + public class DebugInfoResponse + { + public string[] listenAddresses { get; set; } + public string enrUri { get; set; } + } +} diff --git a/ProjectPlugins/WakuPlugin/WakuContainerRecipe.cs b/ProjectPlugins/WakuPlugin/WakuContainerRecipe.cs index f810a18..71b574a 100644 --- a/ProjectPlugins/WakuPlugin/WakuContainerRecipe.cs +++ b/ProjectPlugins/WakuPlugin/WakuContainerRecipe.cs @@ -11,22 +11,28 @@ namespace WakuPlugin protected override void Initialize(StartupConfig startupConfig) { + var config = startupConfig.Get(); + SetResourcesRequest(milliCPUs: 100, memory: 100.MB()); SetResourceLimits(milliCPUs: 4000, memory: 12.GB()); - AddInternalPortAndVar("WAKUNODE2_TCP_PORT"); - - AddEnvVar("WAKUNODE2_RPC_ADDRESS", "0.0.0.0"); - + AddEnvVar("WAKUNODE2_LOG_LEVEL", "TRACE"); AddEnvVar("WAKUNODE2_REST", "1"); - AddEnvVar("WAKUNODE2_REST_ADDRESS", "0.0.0.0"); 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"); AddInternalPortAndVar("WAKUNODE2_DISCV5_UDP_PORT"); - //AddEnvVar("WAKUNODE2_DISCV5_BOOTSTRAP_NODE", "________<---- enr here"); 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"); } } diff --git a/ProjectPlugins/WakuPlugin/WakuNode.cs b/ProjectPlugins/WakuPlugin/WakuNode.cs new file mode 100644 index 0000000..b3b6ccf --- /dev/null +++ b/ProjectPlugins/WakuPlugin/WakuNode.cs @@ -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("debug/v1/info"); + } + + private IHttp Http() + { + return tools.CreateHttp(Container.Address, ""); + } + } +} diff --git a/ProjectPlugins/WakuPlugin/WakuPlugin.cs b/ProjectPlugins/WakuPlugin/WakuPlugin.cs index 303b461..8565d83 100644 --- a/ProjectPlugins/WakuPlugin/WakuPlugin.cs +++ b/ProjectPlugins/WakuPlugin/WakuPlugin.cs @@ -30,9 +30,15 @@ namespace WakuPlugin { } - public RunningContainers[] DeployWakuNodes(int numberOfNodes) + public RunningContainers[] DeployWakuNodes(int numberOfNodes, Action 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) diff --git a/ProjectPlugins/WakuPlugin/WakuSetup.cs b/ProjectPlugins/WakuPlugin/WakuSetup.cs new file mode 100644 index 0000000..10be689 --- /dev/null +++ b/ProjectPlugins/WakuPlugin/WakuSetup.cs @@ -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; + } + } +} diff --git a/ProjectPlugins/WakuPlugin/WakuStarter.cs b/ProjectPlugins/WakuPlugin/WakuStarter.cs index 6e8b34d..107a3f8 100644 --- a/ProjectPlugins/WakuPlugin/WakuStarter.cs +++ b/ProjectPlugins/WakuPlugin/WakuStarter.cs @@ -12,17 +12,33 @@ namespace WakuPlugin this.tools = tools; } - public RunningContainers[] Start(int numberOfNodes) + public RunningContainers[] Start(int numberOfNodes, Action setup) { var result = new List(); var workflow = tools.CreateWorkflow(); + var startupConfig = CreateStartupConfig(setup); 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(); } + + public IWakuNode Wrap(RunningContainer container) + { + return new WakuNode(tools, container); + } + + private StartupConfig CreateStartupConfig(Action setup) + { + var config = new WakuSetup(); + setup(config); + var startupConfig = new StartupConfig(); + startupConfig.Add(config); + startupConfig.NameOverride = config.Name; + return startupConfig; + } } } diff --git a/Tests/WakuTests/BasicTests.cs b/Tests/WakuTests/BasicTests.cs index 6a0a2e6..9c43b8f 100644 --- a/Tests/WakuTests/BasicTests.cs +++ b/Tests/WakuTests/BasicTests.cs @@ -8,9 +8,16 @@ namespace WakuTests [Test] 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; } } } \ No newline at end of file