// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IBaseRepository <TestState> repository, IRaftService raftService, IDataService dataService, ITaskService taskService, ILogger <Startup> logger, IClusterRequestHandler clusterRequestHandler) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } // node.MetricGenerated += metricGenerated; clusterRequestHandler.MetricGenerated += metricGenerated; app.Use(async(context, next) => { if (context.Request.Path == "/api/kill" && context.Request.Method == "POST") { Killed = true; logger.LogInformation("Killing node"); raftService.SetNodeRole(Domain.Enums.NodeState.Disabled); } if (context.Request.Path == "/api/revive" && context.Request.Method == "POST") { Killed = false; logger.LogInformation("Restoring node"); raftService.SetNodeRole(Domain.Enums.NodeState.Follower); } if (Killed == false) { await next(); } else { context.Abort(); } }); app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); app.UseHttpsRedirection(); app.UseMvc(); }
public ClusterRequestHandler( IOptions <ClusterOptions> clusterOptions, ILogger <ClusterRequestHandler <State> > logger, IRaftService raftService, NodeStateService nodeStateService, ClusterClient clusterClient, IDataService dataService) { _clusterClient = clusterClient; _clusterOptions = clusterOptions.Value; _nodeStateService = nodeStateService; _logger = logger; _raftService = raftService; _dataService = dataService; }
public AppendEntriesRPC_Test() { var sp = TestUtility.GetFullNodeProvider(); Node = sp.GetService <IRaftService>(); NodeStorage = sp.GetService <INodeStorage <TestState> >(); NodeStorage.AddLogs(new System.Collections.Generic.List <LogEntry>() { new LogEntry() { Commands = new List <BaseCommand>(), Index = 2, Term = 5 } }); NodeStorage.SetCurrentTerm(5); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IClusterStateService service, ILogger <Startup> logger, IRaftService raftService, IDataService dataService, ITaskService taskService, IStateMachine <CindiClusterState> stateMachine, NodeStateService node, IDatabaseMetricsCollector collector, ClusterMonitorService monitor, IMediator mediator, IServiceProvider serviceProvider, MetricManagementService metricManagementService, InternalBotManager internalBotManager ) { BootstrapThread = new Task(() => { while (node.Status != ConsensusCore.Domain.Models.NodeStatus.Yellow && node.Status != ConsensusCore.Domain.Models.NodeStatus.Green ) { logger.LogInformation("Waiting for cluster to establish a quorum"); Thread.Sleep(1000); } var med = (IMediator)app.ApplicationServices.CreateScope().ServiceProvider.GetService(typeof(IMediator)); ClusterStateService.Initialized = stateMachine.CurrentState.Initialized; var key = Configuration.GetValue <string>("EncryptionKey"); if (key != null) { if (ClusterStateService.Initialized) { logger.LogWarning("Loading key in configuration file, this is not recommended for production."); try { service.SetEncryptionKey(key); logger.LogInformation("Successfully applied encryption key."); } catch (InvalidPrivateKeyException e) { logger.LogError("Failed to apply stored key. Key does not match registered encryption hash."); } } } if (!ClusterStateService.Initialized) { if (key != null) { logger.LogWarning("Initializing new node with key in configuration file, this is not recommended for production."); service.SetEncryptionKey(key); } else { logger.LogWarning("No default key detected, post key to /api/cluster/encryption-key."); } var setPassword = Configuration.GetValue <string>("DefaultPassword"); if (node.Role == ConsensusCore.Domain.Enums.NodeState.Leader) { // Thread.Sleep(5000); med.Send(new InitializeClusterCommand() { DefaultPassword = setPassword == null ? "PleaseChangeMe" : setPassword, Name = Configuration.GetValue <string>("ClusterName") }).GetAwaiter().GetResult(); } } if (node.Role == ConsensusCore.Domain.Enums.NodeState.Leader) { metricManagementService.InitializeMetricStore(); if (service.GetSettings == null) { logger.LogWarning("No setting detected, resetting settings to default."); med.Send(new UpdateClusterStateCommand() { DefaultIfNull = true }).GetAwaiter().GetResult();; } } foreach (var template in InternalStepLibrary.All) { med.Send(new CreateStepTemplateCommand() { Name = template.Name, InputDefinitions = template.InputDefinitions, OutputDefinitions = template.OutputDefinitions, CreatedBy = SystemUsers.SYSTEM_TEMPLATES_MANAGER, Version = template.Version, Description = template.Description }).GetAwaiter().GetResult(); } //internalBotManager.AddAdditionalBot(); }); BootstrapThread.Start(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); //c.OAuthUseBasicAuthenticationWithAccessCodeGrant(); }); app.UseCindiClusterPipeline(); app.UseAuthentication(); app.UseCors("AllowAll"); app.UseMvc(); if (EnableUI) { OverrideUISettings(); app.UseSpaStaticFiles(); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); } }