public async Task Start_DiscoversFunctions() { var functionRunner = new FunctionRunner(); await Container.Launch(functionRunner); var functions = functionRunner.Functions; // TODO: this is a bit of a red herring, it should nominally return 0 because no functions are added, but this asserts it doesnt' fail hard functions.Count().Should().Be(0); }
public void StoreAndRetrieve_ReturnsDataCorrectly() { var lighthouseServer = new LighthouseServer(Output.WriteLine); lighthouseServer.Start(); var warehouseServer = new WarehouseServer(); // bind the warehouserServer to the lighthouseServer lighthouseServer.Launch(warehouseServer); var key = new WarehouseKey("testData", StorageScope.Global); // get a shelf that can hold data for the duration of the session var payload = new[] { "data" }; warehouseServer.Store(key, payload, new[] { LoadingDockPolicy.Ephemeral }); var retrievedValues = warehouseServer.Retrieve <string>(key); payload.Should().BeEquivalentTo(payload); }
public int Run(IEnumerable <string> args) { LighthouseClient GetClient(Uri target) { var networkProvider = TypeFactory.Create <INetworkProvider>(); var client = new LighthouseClient(target, networkProvider); client.AddLogger(ConsoleWrite); return(client); } var result = Parser.Default.ParseArguments <RunOptions, InspectOptions, StopOptions, StoreOptions, RetrieveOptions, ConfigureOptions>(args) .MapResult( (RunOptions run) => { if (run.IsFileMode) { var fileContents = File.ReadAllText(run.File); var config = YamlUtil.ParseYaml <LighthouseRunConfig>(fileContents); // load resources first foreach (var resource in config.Resources) { } // then launch apps foreach (var app in config.Applications) { } } else { if (run.Where != null) { var client = GetClient(run.Where.ToUri()); // make a connection to the other server var response = client.MakeRequest <RemoteAppRunRequest, RemoteAppRunHandle>(new RemoteAppRunRequest(run.What)).GetAwaiter().GetResult(); ConsoleWrite($"Request {response?.Status ?? "no response"} (ID: {response?.Id ?? "no ID"})"); } else { Type appType = LighthouseFetcher.Fetch(run.What); if (appType == null) { throw new ApplicationException($"Can't find app with name: {run.What}"); } // start a lighthouse server locally, and have it run the task var server = new LighthouseServer(); server.AddLogger(ConsoleWrite); server.Launch(appType).GetAwaiter().GetResult(); } } return(0); }, (InspectOptions inspect) => { var client = GetClient(inspect.Where.ToUri()); if (inspect.Where == null) { throw new Exception("Must include Where to inspect."); } if (inspect.What == null) { var response = client.MakeRequest <StatusRequest, StatusResponse>(new StatusRequest()).GetAwaiter().GetResult(); ConsoleWrite(response.ToString()); } else { var response = client.MakeRequest <InspectRequest, InspectResponse>( new InspectRequest { What = inspect.What } ).GetAwaiter().GetResult(); ConsoleWrite(string.Join(Environment.NewLine, response.RawResponse)); } return(0); }, (StopOptions stop) => { if (stop.What == null || stop.Where == null) { throw new Exception("Stop what and where?"); } var client = GetClient(stop.Where.ToUri()); var response = client.MakeRequest <StopRequest, bool>( new StopRequest { What = stop.What } ).GetAwaiter().GetResult(); ConsoleWrite(response ? $"{stop.What} stopped on {stop.Where}" : "failed"); return(0); }, (StoreOptions store) => { if (store.What == null || store.Where == null) { throw new Exception("Stop what and where?"); } var client = GetClient(store.Where.ToUri()); var deserialize = store.What.DeserializeFromJSON <WarehouseStoreRequest>(); var response = client.MakeRequest <WarehouseStoreRequest, bool>( new WarehouseStoreRequest { Key = deserialize.Key, Value = deserialize.Value } ).GetAwaiter().GetResult(); ConsoleWrite(response ? "stored" : "failed"); return(0); }, (RetrieveOptions retrieve) => { if (retrieve.What == null || retrieve.Where == null) { throw new Exception("Stop what and where?"); } var client = GetClient(retrieve.Where.ToUri()); var deserialize = retrieve.What.DeserializeFromJSON <WarehouseRetrieveRequest>(); var response = client.MakeRequest <WarehouseRetrieveRequest, WarehouseRetrieveResponse>( new WarehouseRetrieveRequest { Key = deserialize.Key } ).GetAwaiter().GetResult(); ConsoleWrite(response.Value ?? string.Empty); return(0); }, (ConfigureOptions configure) => { if (configure.What == null || configure.Where == null || configure.How == null) { throw new Exception("Configure what,where, and how?"); } var client = GetClient(configure.Where.ToUri()); if (configure.What == "resource") { var request = configure.How.DeserializeFromJSON <ResourceRequest>(); var response = client.MakeRequest <ResourceRequest, ResourceResponse>(request).GetAwaiter().GetResult(); foreach (var val in response.ActionsTaken) { ConsoleWrite(val); } // inspect the event stream for bound events ??? return(0); } ConsoleWrite($"unsupported configure target {configure.What}"); return(-1); }, errs => { foreach (var error in errs) { ConsoleWrite(error.ToString()); } throw new Exception(string.Join(",", errs)); }); return(0); }