Skip to content

Commit

Permalink
wip #53
Browse files Browse the repository at this point in the history
* addded HttpClientUrlResponseManager to dependency injection
* added parameter to IsHealthy
  • Loading branch information
Yaroslav Husynin committed Mar 20, 2020
1 parent 963cb83 commit bf2d25c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions Elfo.Wardein.Abstractions/WebWatcher/IAmUrlResponseManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;

namespace Elfo.Firmenich.Wardein.Abstractions.WebWatcher
{
public interface IAmUrlResponseManager
{
Task<bool> IsHealthy(bool assertWithStatusCode, string assertWithRegex);
Task<bool> IsHealthy(bool assertWithStatusCode, string assertWithRegex, Uri url);
Task RestartPool(string poolName);
}
}
5 changes: 4 additions & 1 deletion Elfo.Wardein.Core/DependencyInjection/ServicesContainer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Elfo.Firmenich.Wardein.Abstractions.HeartBeat;
using Elfo.Firmenich.Wardein.Abstractions.Watchers;
using Elfo.Firmenich.Wardein.Abstractions.WebWatcher;
using Elfo.Firmenich.Wardein.Core.HeartBeat;
using Elfo.Firmenich.Wardein.Core.Persistence;
using Elfo.Firmenich.Wardein.Core.ServiceManager;
using Elfo.Wardein.Abstractions.Configuration;
using Elfo.Wardein.Abstractions.Services;
using Elfo.Wardein.Abstractions.Services.Models;
Expand Down Expand Up @@ -74,7 +76,8 @@ protected void Configure()
=> new OracleWardeinHeartBeatPersistanceService(new OracleConnectionConfiguration.Builder(connectionString).Build()) // TODO add clientinfo etc
).AddTransient<Func<string, IAmWatcherPersistenceService>>(sp => (connectionString)
=> new OracleWatcherPersistenceService(new OracleConnectionConfiguration.Builder(connectionString).Build()) // TODO add clientinfo etc
);
)
.AddTransient<Func<HttpClientUrlResponseManager, IAmUrlResponseManager>>();


serviceProvider = serviceCollection.BuildServiceProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ namespace Elfo.Firmenich.Wardein.Core.ServiceManager
public class HttpClientUrlResponseManager : IAmUrlResponseManager
{

public async Task<bool> IsHealthy(bool assertWithStatusCode, string assertWithRegex)
public async Task<bool> IsHealthy(bool assertWithStatusCode, string assertWithRegex, Uri url)
{
var endPoint = "";
using (var handler = new HttpClientHandler())
using (var client = new HttpClient(handler))
{
// TODO support authentication
client.BaseAddress = new Uri("http://google.com/");
client.BaseAddress = url;
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

Expand Down
6 changes: 3 additions & 3 deletions Elfo.Wardein.Watchers/WebWatcher/WebWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class WebWatcher : WardeinWatcher<WebWatcherConfig>
{
private readonly WebWatcherConfig configuration;
private readonly IAmWatcherPersistenceService watcherPersistenceService;
private readonly HttpClientUrlResponseManager urlResponseManager;
protected static ILogger log = LogManager.GetCurrentClassLogger();

protected WebWatcher(string name, WebWatcherConfig config, string group) : base(name, config, group)
Expand All @@ -31,6 +32,7 @@ protected WebWatcher(string name, WebWatcherConfig config, string group) : base(

configuration = config;
watcherPersistenceService = ServicesContainer.WatcherPersistenceService(configuration.ConnectionString);

}

public override async Task<IWatcherCheckResult> ExecuteWatcherActionAsync()
Expand All @@ -57,10 +59,8 @@ internal virtual async Task RunCheck()
{
log.Info($"Starting check on {GetUrlDisplayName}");

IAmUrlResponseManager urlResponseManager = new HttpClientUrlResponseManager();

var notificationService = ServicesContainer.NotificationService(NotificationType.Mail);
var isHealthy = await urlResponseManager.IsHealthy(configuration.AssertWithStatusCode, configuration.AssertWithRegex);
var isHealthy = await urlResponseManager.IsHealthy(configuration.AssertWithStatusCode, configuration.AssertWithRegex, configuration.Url);
var currentStatus = await watcherPersistenceService.UpsertCurrentStatus
(
watcherConfigurationId: configuration.WatcherConfigurationId,
Expand Down

0 comments on commit bf2d25c

Please sign in to comment.