Пример #1
0
        public async Task <IActionResult> Get()
        {
            var healthReport = await _healthCheckService.CheckHealthAsync();

            var applications = await _applicationManagementService.GetApplications();

            if (applications != null)
            {
                foreach (var entry in healthReport.Entries)
                {
                    var app = applications.FirstOrDefault(x => x.Name == entry.Key);
                    if (app != null)
                    {
                        if (entry.Value.Status == HealthStatus.Unhealthy)
                        {
                            app.IsHealthy = false;
                        }
                        else if (entry.Value.Status == HealthStatus.Healthy)
                        {
                            app.IsHealthy = true;
                        }
                    }
                }
                _memoryCache.Remove(CacheKey.Applications);
                _memoryCache.Set(CacheKey.Applications, applications);
            }

            return(Ok(healthReport));
        }
        private void ConfigureRouting(IApplicationBuilder app, ApplicationManagementService applicationManagementService)
        {
            // This isnt ideal...
            var applications = applicationManagementService.GetApplications().Result;

            app.UseMvc(routes =>
            {
                // map any incoming routes for each application
                foreach (var application in applications.Where(w => !string.IsNullOrEmpty(w.MainMenuText)))
                {
                    if (application.RequiresAuthorization)
                    {
                        routes.MapRoute(
                            name: $"application-{application.RouteName}-Index",
                            template: application.RouteName,
                            defaults: new { controller = "Authorized", action = "Index", application.RouteName }
                            );
                    }
                    else
                    {
                        routes.MapRoute(
                            name: $"application-{application.RouteName}-Index",
                            template: application.RouteName,
                            defaults: new { controller = "Application", action = "Index", application.RouteName }
                            );
                    }
                }

                // add the default route
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
        private void AddHealthChecks(IServiceCollection services, ApplicationManagementService applicationManagementService)
        {
            services.AddHealthChecksUI();
            var healthChecks = services.AddHealthChecks().AddCheck("self", () => HealthCheckResult.Healthy());
            var applications = applicationManagementService.GetApplications().Result;

            var canCheck = applications.Where(w => !string.IsNullOrEmpty(w.HealthCheckUrl)).ToList();

            canCheck.ForEach(f => healthChecks.AddUrlGroup(new Uri(f.HealthCheckUrl), name: f.Name, tags: new string[] { $"{f.RouteName}-api" }));

            services.Configure <HealthCheckPublisherOptions>(options =>
            {
                options.Period  = new TimeSpan(0, 0, 4);
                options.Delay   = TimeSpan.FromSeconds(2);
                options.Timeout = new TimeSpan(0, 0, 10);
                //    options.Predicate = (check) => check.Tags.Contains("ready");
            });

            const string HealthCheckServiceAssembly = "Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckPublisherHostedService";

            services.TryAddEnumerable(
                ServiceDescriptor.Singleton(typeof(IHostedService),
                                            typeof(HealthCheckPublisherOptions).Assembly
                                            .GetType(HealthCheckServiceAssembly)));

            services.AddSingleton <IHealthCheckPublisher, ReadinessPublisher>();
        }
Пример #4
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var vm           = new ApplicationNavigationMenuViewModel();
            var applications = await _applicationManagementService.GetApplications();

            vm.Applications = applications.Where(x => x.IsOnline && x.IsRegistered && x.IsHealthy).ToList();
            return(View(vm));
        }
        private async Task SetApplicationContextAsync(string applicationName)
        {
            var applications = await _applicationManagementService.GetApplications();

            _applicationService.Application = applications.FirstOrDefault(f => string.Compare(f.Name, applicationName, true) == 0);

            ViewData["CorrelationId"] = _correlationContextAccessor.CorrelationContext.CorrelationId;

            _logger.LogInformation($"Loaded application for name: {applicationName}: {_applicationService.Application.MainMenuText}: {_correlationContextAccessor.CorrelationContext.CorrelationId}");

            _pageViewModel = MapApplicationToPageViewModel(_applicationService.Application);

            _applicationService.BearerToken    = (User.Identity.IsAuthenticated ? await HttpContext.GetTokenAsync("id_token") : null);
            _applicationService.User           = User;
            _applicationService.RequestBaseUrl = string.Format("{0}://{1}{2}", Request.Scheme, Request.Host, Url.Content("~"));

            if (_applicationService.Application == null)
            {
                ModelState.AddModelError(string.Empty, "Internal error: Missing Application definition");
            }
            else
            {
                if (string.IsNullOrEmpty(_applicationService.Application.RootUrl))
                {
                    ModelState.AddModelError(string.Empty, $"Application context error: ({_applicationService.Application.Title}) Missing RootUrl definition");
                }

                if (string.IsNullOrEmpty(_applicationService.Application.HealthCheckUrl))
                {
                    ModelState.AddModelError(string.Empty, $"Application context error: ({_applicationService.Application.Title}) Missing HealthCheckUrl definition");
                }

                if (string.IsNullOrEmpty(_applicationService.Application.EntrypointUrl))
                {
                    ModelState.AddModelError(string.Empty, $"Application context error: ({_applicationService.Application.Title}) Missing EntrypointUrl definition");
                }

                if (_applicationService.Application.ShowSideBar && string.IsNullOrEmpty(_applicationService.Application.SidebarUrl))
                {
                    ModelState.AddModelError(string.Empty, $"Application context error: ({_applicationService.Application.Title}) Missing SidebarUrl definition");
                }
            }

            if (ModelState.IsValid && !string.IsNullOrEmpty(_applicationService.Application.HealthCheckUrl))
            {
                await _applicationService.HeathCheckAsync();

                if (!_applicationService.Health.IsHealthy)
                {
                    ModelState.AddModelError(string.Empty, $"{_applicationService.Health.UnHealthyClue}: ({_applicationService.Application.Title})");
                }
            }
        }