Exemplo n.º 1
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services">IServiceCollection.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            services.AddSingleton(provider => Configuration);
            services.AddTransient <IResourceDomain, ResourceDomain>();
            services.AddTransient <IResourceRepository, ResourceRepository>();
            services.AddTransient <ISwaggerOptions, SwaggerOptions>();
            services.AddTransient <DbContextOptionsBuilder>();
            services.AddApplicationInsights();

            var connectionString = Configuration.GetConnectionString("Resource");

            services.AddDbContext <ResourceContext>(
                options => options.UseSqlServer(connectionString));

            services.AddSharedExceptionHandler();
            services.AddSharedAuthorizationHandler(Configuration, ApiNames.ApiCommonResourceLocator);

            const string check = "/hc/quick";
            var          hc    = new HealthCheckConfiguration();

            hc.SqlConnections.Add(new HealthCheckSqlConnection {
                ConnectionString = connectionString
            });
            hc.Urls.Add(new HealthCheckUrl {
                Url = Configuration["Security:Authority"] + check
            });
            services.AddHealthCheckServices(hc);

            services.AddSwaggerGen <Startup>();
        }
Exemplo n.º 2
0
        public void Configure(IApplicationBuilder app)
        {
            //TJOwin.HealthCheck.AppBuilderExtensions.UseHealthCheck(null);
            var config = new HealthCheckConfiguration();

            app.UseHealthCheck(config);
            app.Use(helloworldMiddleware);
        }
 private async Task <HealthCheckExecution> GetHealthCheckExecution(HealthCheckConfiguration configuration)
 {
     return(await _db.Executions
            .Include(le => le.History)
            .Include(le => le.Entries)
            .Where(le => le.Name == configuration.Name)
            .SingleOrDefaultAsync());
 }
 private async Task <HealthCheckExecution> GetHealthCheckExecution(HealthCheckConfiguration configuration)
 {
     return(await _db.Executions
            .Include(le => le.History)
            .Include(le => le.Entries)
            .Where(le => le.Name.Equals(configuration.Name, StringComparison.InvariantCultureIgnoreCase))
            .SingleOrDefaultAsync());
 }
Exemplo n.º 5
0
 public HealthCheck(
     string remoteAddress,
     ILogger logger)
 {
     _healthCheckConfiguration = new HealthCheckConfiguration();
     _remoteAddress            = remoteAddress;
     _logger = logger;
 }
Exemplo n.º 6
0
        public void Configuration(IAppBuilder app)
        {
            var config = new HealthCheckConfiguration("/hc", new Checker());

            app.UseHealthCheck(config);
            app.Run(async context =>
            {
                await context.Response.WriteAsync("Hello");
            });
        }
        private async Task SaveExecutionHistory(HealthCheckConfiguration configuration, UIHealthReport healthReport)
        {
            _logger.LogDebug("HealthReportCollector - health report execution history saved.");

            var execution = await GetHealthCheckExecution(configuration);

            var lastExecutionTime = DateTime.UtcNow;

            if (execution != null)
            {
                execution.Entries.Clear();
                execution.Entries = healthReport.ToExecutionEntries();

                if (execution.Status == healthReport.Status)
                {
                    _logger.LogDebug("HealthReport history already exists and is in the same state, updating the values.");

                    execution.LastExecuted = lastExecutionTime;
                }
                else
                {
                    _logger.LogDebug("HealthCheckReportCollector already exists but on different state, updating the values.");

                    execution.History.Add(new HealthCheckExecutionHistory()
                    {
                        On     = lastExecutionTime,
                        Status = execution.Status
                    });

                    execution.OnStateFrom  = lastExecutionTime;
                    execution.LastExecuted = lastExecutionTime;
                    execution.Status       = healthReport.Status;
                }
            }
            else
            {
                _logger.LogDebug("Creating a new HealthReport history.");

                execution = new HealthCheckExecution()
                {
                    LastExecuted     = lastExecutionTime,
                    OnStateFrom      = lastExecutionTime,
                    Entries          = healthReport.ToExecutionEntries(),
                    Status           = healthReport.Status,
                    Name             = configuration.Name,
                    Uri              = configuration.Uri,
                    DiscoveryService = configuration.DiscoveryService
                };

                await _db.Executions
                .AddAsync(execution);
            }

            await _db.SaveChangesAsync();
        }
        private async Task <bool> HasLivenessRecoveredFromFailure(HealthCheckConfiguration configuration)
        {
            var previous = await GetHealthCheckExecution(configuration);

            if (previous != null)
            {
                return(previous.Status != UIHealthStatus.Healthy);
            }

            return(false);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Called before Configure method
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services">IServiceCollection</param>
        public void ConfigureServices(IServiceCollection services)
        {
            Mappings.Init();

            // Add framework services.
            services.AddMvc();

            services.AddSingleton(provider => Configuration);
            services.AddTransient <IBaseValueSegmentDomain, BaseValueSegmentDomain>();
            services.AddTransient <IBaseValueSegmentRepository, BaseValueSegmentRepository>();
            services.AddTransient <IAumentumDomain, AumentumDomain>();
            services.AddTransient <ICaliforniaConsumerPriceIndexRepository, CaliforniaConsumerPriceIndexRepository>();
            services.AddTransient <ISysTypeRepository, SysTypeRepository>();
            services.AddTransient <IBaseValueSegmentTransactionDomain, BaseValueSegmentTransactionDomain>();
            services.AddTransient <IBaseValueSegmentTransactionRepository, BaseValueSegmentTransactionRepository>();
            services.AddTransient <IBaseValueSegmentFlagDomain, BaseValueSegmentFlagDomain>();
            services.AddTransient <IBaseValueSegmentFlagRepository, BaseValueSegmentFlagRepository>();
            services.AddTransient <IGrmEventDomain, GrmEventDomain>();
            services.AddTransient <IGrmEventRepository, GrmEventRepository>();
            services.AddTransient <IUrlService, UrlService>();
            services.AddTransient <IHttpClientWrapper, HttpClientWrapper>();
            services.AddTransient <DbContextOptionsBuilder>();
            services.AddTransient <ISwaggerOptions, SwaggerOptions>();
            services.AddApplicationInsights();
            var connectionString = Configuration.GetConnectionString("Aumentum");

            services.AddDbContext <BaseValueSegmentQueryContext>(
                options => options.UseSqlServer(connectionString));

            services.AddDbContext <AumentumContext>(
                options => options.UseSqlServer(connectionString));

            services.AddSharedExceptionHandler();
            services.AddSharedAuthorizationHandler(Configuration, ApiNames.ApiServiceBaseValueSegment);

            const string check = "/hc/quick";
            var          hc    = new HealthCheckConfiguration();

            hc.SqlConnections.Add(new HealthCheckSqlConnection {
                ConnectionString = connectionString
            });
            hc.Urls.Add(new HealthCheckUrl {
                Url = Configuration["Security:Authority"] + check
            });
            services.AddHealthCheckServices(hc);

            services.AddHttpJwtAccessor();

            services.AddSwaggerGen <Startup>();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Called before Configure method
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services">IServiceCollection</param>
        public void ConfigureServices(IServiceCollection services)
        {
            Mappings.Init();

            // Add framework services.
            services.AddMvc();
            services.AddApiVersioning(o => o.ReportApiVersions = true);
            //Add support for common exception handling
            services.AddSharedExceptionHandler();
            services.AddSharedAuthorizationHandler(Configuration, ApiNames.ApiServiceLegalPartySearch);

            services.AddSingleton(provider => Configuration);

            services.AddTransient <IRebuildSearchLegalParty, RebuildSearchLegalParty>();
            services.AddTransient <ISearchLegalPartyDomain, SearchLegalPartyDomain>();
            services.AddTransient <IAumentumRepository, AumentumRepository>();
//			services.AddTransient<ISearchLegalPartyRepository, FreeTextSearchLegalPartyRepository>();
            services.AddTransient <ISearchLegalPartyRepository, ContainsSearchLegalPartyRepository>();
            services.AddTransient <IDefaultSearchProviderConfiguration, DefaultSearchProviderConfiguration>();
            services.AddTransient <ISearchProviderSelector, SearchProviderSelector>();
            services.AddTransient <ICommandTimeoutConfiguration, CommandTimeoutConfiguration>();
            services.AddTransient <ISearchResultsConfiguration, SearchResultsConfiguration>();
            services.AddTransient <IRebuildSearchLegalPartyIndexRepository, RebuildSearchLegalPartyIndexRepository>();
            services.AddScoped <IConfiguration>(p => Configuration);
            services.AddScoped <IPagingInfo, PagingInfo>();
            services.AddTransient <DbContextOptionsBuilder>();
            services.AddTransient(provider => provider.GetService <ILoggerFactory>().CreateLogger("LegalPartySearch"));

            var connectionString = Configuration.GetConnectionString("Aumentum");

            services.AddDbContext <SearchLegalPartyContext>(options => options.UseSqlServer(connectionString));
            services.AddDbContext <AumentumContext>(options => options.UseSqlServer(connectionString));
            services.AddTransient <ISearchOperations, SearchOperations>();

            const string check = "/hc/quick";
            var          hc    = new HealthCheckConfiguration();

            hc.SqlConnections.Add(new HealthCheckSqlConnection {
                ConnectionString = connectionString
            });
            hc.Urls.Add(new HealthCheckUrl {
                Url = Configuration["Security:Authority"] + check
            });
            services.AddHealthCheckServices(hc);

            var assembly = Assembly.GetEntryAssembly();

            services.AddSwaggerGen("Legal Party Search API", "v1.1", $"A Legal Party Search API to provide support for the retrieval of Legal Parties in Aumentum (Version: {assembly.GetName().Version}).", Configuration);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Executes all of the checks specified in the request parameter. The method
        /// performs each test asynchronously and waits for all of the checks to finish.
        /// </summary>
        /// <param name="request">The health check configuration to execute</param>
        /// <returns>A task that can be awaited for completion of all the checks</returns>
        public async Task Execute(HealthCheckConfiguration request)
        {
            if (request != null)
            {
                try
                {
                    this._LambdaContext.LogInfo($"HealthCheckConfiguration:\r\n{JsonConvert.SerializeObject(request, new HttpMethodConverter())}");

                    List <Task> Tasks = new List <Task>();

                    if (request.Http != null && request.Http.Any())
                    {
                        Tasks.AddRange(request.Http.Select(ExecuteWebRequest));
                    }

                    if (request.Https != null && request.Https.Any())
                    {
                        Tasks.AddRange(request.Https.Select(ExecuteWebRequest));
                    }

                    if (request.Tcp != null && request.Tcp.Any())
                    {
                        Tasks.AddRange(request.Tcp.Select(ExecuteTcpTest));
                    }

                    if (request.Udp != null && request.Udp.Any())
                    {
                        Tasks.AddRange(request.Udp.Select(ExecuteUdpTest));
                    }

                    if (request.Icmp != null && request.Icmp.Any())
                    {
                        Tasks.AddRange(request.Icmp.Select(ExecuteIcmpTest));
                    }

                    await Task.WhenAll(Tasks.ToArray());
                }
                catch (Exception e)
                {
                    this._LambdaContext.LogError("Problem executing the health checks.", e);
                }
            }
            else
            {
                throw new ArgumentNullException("request", "The health check configuration object cannot be null.");
            }
        }
        private async Task <UIHealthReport> GetHealthReport(HealthCheckConfiguration configuration)
        {
            var(uri, name) = configuration;

            try
            {
                var response = await _httpClient.GetAsync(uri);

                return(await response.As <UIHealthReport>());
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, $"GetHealthReport threw an exception when trying to get report from {uri} configured with name {name}.");

                return(UIHealthReport.CreateFrom(exception));
            }
        }
Exemplo n.º 13
0
        private Uri GetEndpointUri(HealthCheckConfiguration configuration)
        {
            if (endpointAddresses.ContainsKey(configuration.Id))
            {
                return(endpointAddresses[configuration.Id]);
            }

            Uri.TryCreate(configuration.Uri, UriKind.Absolute, out var absoluteUri);

            if (absoluteUri == null || !absoluteUri.IsValidHealthCheckEndpoint())
            {
                Uri.TryCreate(_serverAddressService.AbsoluteUriFromRelative(configuration.Uri), UriKind.Absolute, out absoluteUri);
            }

            endpointAddresses[configuration.Id] = absoluteUri;

            return(absoluteUri);
        }
        private async Task <UIHealthReport> GetHealthReport(HealthCheckConfiguration configuration)
        {
            var(uri, name) = configuration;

            try
            {
                var response = await PerformRequest(uri);

                return(await response.As <UIHealthReport>());
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "GetHealthReport threw an exception.");

                return(new UIHealthReport(
                           entries: new Dictionary <string, UIHealthReportEntry>(),
                           totalDuration: TimeSpan.FromSeconds(0)));
            }
        }
Exemplo n.º 15
0
        private async Task <UIHealthReport> GetHealthReport(HealthCheckConfiguration configuration)
        {
            var(uri, name) = configuration;

            try
            {
                var response = await _httpClient.GetAsync(uri);

                return(await response.As <UIHealthReport>());
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, $"GetHealthReport threw an exception when trying to get report from {uri} configured with name {name}.");

                return(new UIHealthReport(
                           entries: new Dictionary <string, UIHealthReportEntry>(),
                           totalDuration: TimeSpan.FromSeconds(0)));
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services">IServiceCollection.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            Mappings.Init();

            // Add framework services.
            services.AddMvc();
            services.AddSingleton(provider => Configuration);
            services.AddTransient <IAssessmentEventDomain, AssessmentEventDomain>();
            services.AddTransient <IAssessmentEventRepository, AssessmentEventRepository>();
            services.AddTransient <IStatutoryReferenceDomain, StatutoryReferenceDomain>();
            services.AddTransient <IStatutoryReferenceRepository, StatutoryReferenceRepository>();
            services.AddTransient <DbContextOptionsBuilder <AssessmentEventContext> >();
            services.AddTransient <DbContextOptionsBuilder <QueryOnlyAssessmentEventContext> >();
            services.AddTransient <ISwaggerOptions, SwaggerOptions>();
            services.AddApplicationInsights();
            var connectionString = Configuration.GetConnectionString("Aumentum");

            services.AddDbContext <AssessmentEventContext>(
                options => options.UseSqlServer(connectionString,
                                                sqlServerOptions => sqlServerOptions.CommandTimeout(int.Parse(Configuration["Database:AumentumCommandTimeout"]))));

            services.AddDbContext <QueryOnlyAssessmentEventContext>(
                options => options.UseSqlServer(connectionString));

            services.AddSharedExceptionHandler();
            services.AddSharedAuthorizationHandler(Configuration, ApiNames.ApiServiceAssessmentEvent);

            const string check = "/hc/quick";
            var          hc    = new HealthCheckConfiguration();

            hc.SqlConnections.Add(new HealthCheckSqlConnection {
                ConnectionString = connectionString
            });
            hc.Urls.Add(new HealthCheckUrl {
                Url = Configuration["Security:Authority"] + check
            });
            services.AddHealthCheckServices(hc);

            services.AddSwaggerGen <Startup>();
        }
Exemplo n.º 17
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services">IServiceCollection.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            Mappings.Init();

            // Add framework services.
            services.AddMvc();
            services.AddApiVersioning(o => o.ReportApiVersions = true);
            services.AddSingleton(provider => Configuration);
            services.AddTransient <ILegalPartyDomain, LegalPartyDomain>();
            services.AddTransient <ILegalPartyRepository, LegalPartyRepository>();
            services.AddTransient <ISwaggerOptions, SwaggerOptions>();
            services.AddTransient <ILegalPartyOfficialDocumentDomain, LegalPartyOfficialDocumentDomain>();
            services.AddTransient <ILegalPartyOfficialDocumentRepository, LegalPartyOfficialDocumentRepository>();
            services.AddTransient <IGrmEventRightTransferRepository, GrmEventRightTransferRepository>();
            services.AddTransient <IOfficialDocumentShortDescriptionRepository, OfficialDocumentShortDescriptionRepository>();
            services.AddTransient <DbContextOptionsBuilder>();
            services.AddApplicationInsights();
            var connectionString = Configuration.GetConnectionString("Aumentum");

            services.AddDbContext <LegalPartyContext>(
                options => options.UseSqlServer(connectionString));

            services.AddSharedExceptionHandler();
            services.AddSharedAuthorizationHandler(Configuration, ApiNames.ApiServiceLegalParty);

            const string check = "/hc/quick";
            var          hc    = new HealthCheckConfiguration();

            hc.SqlConnections.Add(new HealthCheckSqlConnection {
                ConnectionString = connectionString
            });
            hc.Urls.Add(new HealthCheckUrl {
                Url = Configuration["Security:Authority"] + check
            });
            services.AddHealthCheckServices(hc);

            services.AddSwaggerGen <Startup>();
        }
Exemplo n.º 18
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services">for adding services</param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(provider => Configuration);
            services.AddTransient <IHttpClientWrapper, HttpClientWrapper>();

            // add version 1 support
            services.AddTransient <Domain.Interfaces.V1.IApplicationSettingsHelper, Domain.Implementation.V1.ApplicationSettingsHelper>();
            services.AddTransient <Domain.Interfaces.V1.IAssessmentHeaderDomain, Domain.Implementation.V1.AssessmentHeaderDomain>();
            services.AddTransient <Domain.Interfaces.V1.IAssessmentHeaderDomain, Domain.Implementation.V1.AssessmentHeaderDomain>();
            services.AddApplicationInsights();

            const string check = "hc/quick";
            var          hc    = new HealthCheckConfiguration();

            hc.Urls.Add(new HealthCheckUrl {
                Url = Configuration["ServiceApiUrls:assessmentEventServiceApiUrl"] + check
            });
            hc.Urls.Add(new HealthCheckUrl {
                Url = Configuration["ServiceApiUrls:revenueObjectServiceApiUrl"] + check
            });
            hc.Urls.Add(new HealthCheckUrl {
                Url = Configuration["ServiceApiUrls:legalPartyServiceApiUrl"] + check
            });
            hc.Urls.Add(new HealthCheckUrl {
                Url = Configuration["ServiceApiUrls:baseValueSegmentServiceApiUrl"] + check
            });
            services.AddHealthCheckServices(hc);

            services.AddTransient <ISwaggerOptions, SwaggerOptions>();

            // Add framework services.
            services.AddMvc();
            services.AddSharedExceptionHandler();

            services.AddHttpJwtAccessor();

            services.AddSwaggerGen <Startup>();
        }
Exemplo n.º 19
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            HealthCheckConfiguration.ConfigureHealthChecks(app, env);

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseMiddleware <Middlewares.ExceptionMiddleware>();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });

            app.UseHangfireDashboard(); // http://localhost/hangfire
            app.UseHangfireServer();
        }
Exemplo n.º 20
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <Helpers.MailSettings>(Configuration.GetSection("MailSettings"));


            var _dbConnectionString = Configuration.GetConnectionString("DowntimeDbConnection");

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(_dbConnectionString)
                                                         );

            services.AddDefaultIdentity <IdentityUser>(options =>
            {
                options.SignIn.RequireConfirmedAccount = false;
            })
            .AddEntityFrameworkStores <ApplicationDbContext>();

            services.AddControllersWithViews();
            services.AddHttpContextAccessor();
            services.AddTransient <ApplicationDbContext>();
            services.AddScoped <ITargetAppService, TargetAppService>();
            services.AddScoped <INotifyService, MailService>();
            services.AddScoped <ILogService, LogService>();

            services.AddRazorPages();

            services.AddMvc()
            .AddJsonOptions(o =>
            {
                o.JsonSerializerOptions.PropertyNamingPolicy = new WebUI.Helpers.JsonPascalCaseNamingPolicy();
            });

            services.AddHangfire(x => x.UseSqlServerStorage(_dbConnectionString));

            HealthCheckConfiguration.RegisterHealthCheckSettings(services);
        }
Exemplo n.º 21
0
 public ValueTask OnCollectExecuting(HealthCheckConfiguration healthCheck)
 {
     return(ValueTask.CompletedTask);
 }
Exemplo n.º 22
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services">IServiceCollection.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            var connectionString   = Configuration.GetConnectionString("DefaultConnection");
            var migrationsAssembly = MigrationsAssemblyReference.Name;

            var identityServer = services.AddIdentityServer()
                                 .AddOperationalStore(builder => builder.ConfigureDbContext   = ctx => ctx.UseSqlServer(connectionString, options => options.MigrationsAssembly(migrationsAssembly)))
                                 .AddConfigurationStore(builder => builder.ConfigureDbContext = ctx => ctx.UseSqlServer(connectionString, options => options.MigrationsAssembly(migrationsAssembly)));

            var certName = Configuration["Security:CertName"];

            if (string.IsNullOrEmpty(certName))
            {
                identityServer.AddDeveloperSigningCredential(true, Configuration["Security:SigningFilename"]);
            }
            else
            {
                var isCertLocationCurrentUser = Convert.ToBoolean(Configuration["Security:IsCertLocationCurrentUser"]);

                identityServer.AddSigningCredential(certName, isCertLocationCurrentUser ?
                                                    StoreLocation.CurrentUser : StoreLocation.LocalMachine);
            }
            services.AddMvc();

            services.AddSingleton(provider => Configuration);

            services.AddTransient <DbContextOptionsBuilder>();

            var permissionsConnectionString = Configuration.GetConnectionString("Permissions");

            services.AddDbContext <AumentumSecurityQueryContext>(
                options => options.UseSqlServer(permissionsConnectionString));

            services.AddDbContext <ProxyConfigurationDbContext>(
                options => options.UseSqlServer(connectionString));

            services.AddTransient <IPermissionRepository, PermissionRepository>();
            services.AddTransient <IAppFunctionForQueryRepository, AppFunctionForQueryRepository>();
            services.AddTransient <IClaimsProvider, ClaimsProvider>();
            services.AddTransient <IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
            services.AddTransient <IClaimsService, ServiceClientClaimsService>();
            services.AddTransient <IApiResourceRepository, ApiResourceRepository>();
            services.AddTransient <IClientRepository, ClientRepository>();
            services.AddTransient <IClientDomain, ClientDomain>();
            services.AddTransient <ISwaggerOptions, SwaggerOptions>();

            services.AddApplicationInsights();
            services.AddSharedExceptionHandler();
            services.AddSharedAuthorizationHandler(Configuration, ApiNames.ApiCommonSecurity);

            var hc = new HealthCheckConfiguration();

            hc.SqlConnections.Add(new HealthCheckSqlConnection {
                ConnectionString = connectionString
            });
            hc.SqlConnections.Add(new HealthCheckSqlConnection {
                ConnectionString = permissionsConnectionString
            });
            services.AddHealthCheckServices(hc);

            services.AddSwaggerGen <Startup>();
        }
Exemplo n.º 23
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services">for adding services</param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(provider => Configuration);

            services.AddTransient <IHttpClientWrapper, HttpClientWrapper>();

            // add version 1.1 support
            services.AddTransient <IApplicationSettingsHelper, ApplicationSettingsHelper>();
            services.AddTransient <IBaseValueSegmentRepository, BaseValueSegmentRepository>();
            services.AddTransient <IRevenueObjectRepository, RevenueObjectRepository>();
            services.AddTransient <IAssessmentEventRepository, AssessmentEventRepository>();
            services.AddTransient <IGrmEventRepository, GrmEventRepository>();
            services.AddTransient <ILegalPartyRepository, LegalPartyRepository>();
            services.AddTransient <ILegalPartyDomain, LegalPartyDomain>();
            services.AddTransient <IGrmEventDomain, GrmEventDomain>();
            services.AddTransient <IRevenueObjectDomain, RevenueObjectDomain>();
            services.AddTransient <IBeneificialInterestBaseValueSegmentDomain, BeneificialInterestBaseValueSegmentDomain>();
            services.AddTransient <IBeneificialInterestDetailBaseValueSegmentDomain, BeneificialInterestDetailBaseValueSegmentDomain>();
            services.AddTransient <ISubComponentBaseValueSegmentDomain, SubComponentBaseValueSegmentDomain>();
            services.AddTransient <IBaseValueSegmentDomain, BaseValueSegmentDomain>();
            services.AddTransient <IBaseValueSegmentProvider, BaseValueSegmentProvider>();
            services.AddTransient <IBaseValueSegmentHistoryDomain, BaseValueSegmentHistoryDomain>();
            services.AddTransient(
                provider => provider.GetService <ILoggerFactory>().CreateLogger("FacadeBaseValueSegment"));
            services.AddApplicationInsights();
            services.AddSharedCaching();
            services.AddSharedExceptionHandler();

            // Add framework services.
            services.AddMvc(options =>
            {
                // for all controllers, tell client browser not to cache
                options.Filters.Add(new ResponseCacheAttribute {
                    NoStore = true, Location = ResponseCacheLocation.None
                });
            });

            services.AddHttpJwtAccessor();

            const string check = "hc/quick";
            var          hc    = new HealthCheckConfiguration();

            hc.Urls.Add(new HealthCheckUrl {
                Url = Configuration["ServiceApiUrls:assessmentEventServiceApiUrl"] + check
            });
            hc.Urls.Add(new HealthCheckUrl {
                Url = Configuration["ServiceApiUrls:revenueObjectServiceApiUrl"] + check
            });
            hc.Urls.Add(new HealthCheckUrl {
                Url = Configuration["ServiceApiUrls:legalPartyServiceApiUrl"] + check
            });
            hc.Urls.Add(new HealthCheckUrl {
                Url = Configuration["ServiceApiUrls:baseValueSegmentServiceApiUrl"] + check
            });
            hc.Urls.Add(new HealthCheckUrl {
                Url = Configuration["ServiceApiUrls:grmEventServiceApiUrl"] + check
            });
            services.AddHealthCheckServices(hc);
            services.AddTransient <ISwaggerOptions, SwaggerOptions>();
            services.AddSwaggerGen <Startup>();
        }
 public ValueTask OnCollectExecuting(HealthCheckConfiguration healthCheck)
 {
     return(new ValueTask());
 }
        private async Task SaveExecutionHistory(HealthCheckConfiguration configuration, UIHealthReport healthReport)
        {
            _logger.LogDebug("HealthReportCollector - health report execution history saved.");

            var execution = await GetHealthCheckExecution(configuration);

            var lastExecutionTime = DateTime.UtcNow;

            if (execution != null)
            {
                //update existing entries from new health report

                foreach (var item in healthReport.ToExecutionEntries())
                {
                    var existing = execution.Entries
                                   .Where(e => e.Name == item.Name)
                                   .SingleOrDefault();

                    if (existing != null)
                    {
                        existing.Status      = item.Status;
                        existing.Description = item.Description;
                        existing.Duration    = item.Duration;
                    }
                    else
                    {
                        execution.Entries.Add(item);
                    }
                }

                //remove old entries in existing execution not present in new health report

                foreach (var item in execution.Entries)
                {
                    var existing = healthReport.Entries
                                   .ContainsKey(item.Name);

                    if (!existing)
                    {
                        var oldEntry = execution.Entries
                                       .Where(t => t.Name == item.Name)
                                       .SingleOrDefault();

                        _db.HealthCheckExecutionEntries
                        .Remove(oldEntry);
                    }
                }

                if (execution.Status == healthReport.Status)
                {
                    _logger.LogDebug("HealthReport history already exists and is in the same state, updating the values.");

                    execution.LastExecuted = lastExecutionTime;
                }
                else
                {
                    _logger.LogDebug("HealthCheckReportCollector already exists but on different state, updating the values.");

                    execution.History.Add(new HealthCheckExecutionHistory()
                    {
                        On     = lastExecutionTime,
                        Status = execution.Status
                    });

                    execution.OnStateFrom  = lastExecutionTime;
                    execution.LastExecuted = lastExecutionTime;
                    execution.Status       = healthReport.Status;
                }
            }
            else
            {
                _logger.LogDebug("Creating a new HealthReport history.");

                execution = new HealthCheckExecution()
                {
                    LastExecuted     = lastExecutionTime,
                    OnStateFrom      = lastExecutionTime,
                    Entries          = healthReport.ToExecutionEntries(),
                    Status           = healthReport.Status,
                    Name             = configuration.Name,
                    Uri              = configuration.Uri,
                    DiscoveryService = configuration.DiscoveryService
                };

                await _db.Executions
                .AddAsync(execution);
            }

            await _db.SaveChangesAsync();
        }
Exemplo n.º 26
0
 private void UpdateUris(HealthCheckExecution execution, HealthCheckConfiguration configuration)
 {
     execution.Uri = configuration.Uri;
     endpointAddresses.Remove(configuration.Id);
 }
Exemplo n.º 27
0
 /// <summary>
 /// Sets the health check configuration the client will use
 /// </summary>
 /// <param name="config">The health check configuration</param>
 public void SetHealthCheckConfiguration(HealthCheckConfiguration config)
 {
     this.HealthChecks = config ?? throw new ArgumentNullException("config", "The health check configuration cannot be null.");
 }