Skip to content

Commit

Permalink
wip #52
Browse files Browse the repository at this point in the history
* added watcher persistence interface
* added watcher persistence oracle implementation (wip)
* added watcher persistence interface to the DI
* added watcher persistence interface to the webwatcher
  • Loading branch information
mrksoftware committed Mar 20, 2020
1 parent 83fc6d9 commit e3670cf
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
12 changes: 12 additions & 0 deletions Elfo.Wardein.Abstractions/Watchers/IAmWatcherPersistenceService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Elfo.Firmenich.Wardein.Abstractions.Watchers
{
public interface IAmWatcherPersistenceService
{
Task<WatcherStatusResult> UpsertCurrentStatus(int watcherConfigurationId, int applicationId, int applicationHostname, bool isHealthy, Exception failureException = null);
}
}
12 changes: 12 additions & 0 deletions Elfo.Wardein.Abstractions/Watchers/Models/WatcherStatusResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Elfo.Firmenich.Wardein.Abstractions.Watchers
{
public class WatcherStatusResult
{
public bool PreviousStatus { get; set; }
public int FailureCount { get; set; }
}
}
10 changes: 10 additions & 0 deletions Elfo.Wardein.Core/DependencyInjection/ServicesContainer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Elfo.Firmenich.Wardein.Abstractions.HeartBeat;
using Elfo.Firmenich.Wardein.Abstractions.Watchers;
using Elfo.Firmenich.Wardein.Core.HeartBeat;
using Elfo.Firmenich.Wardein.Core.Persistence;
using Elfo.Wardein.Abstractions.Configuration;
using Elfo.Wardein.Abstractions.Services;
using Elfo.Wardein.Abstractions.Services.Models;
Expand Down Expand Up @@ -70,6 +72,8 @@ protected void Configure()
.AddTransient<Func<string, OracleConnectionConfiguration>>(sp => (connectionString) => new OracleConnectionConfiguration(connectionString))
.AddTransient<Func<string, IAmWardeinHeartBeatPersistanceService>>(sp => (connectionString)
=> 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
);


Expand Down Expand Up @@ -109,6 +113,12 @@ public static IAmPersistenceService<WindowsServiceStats> PersistenceService(stri
return instanceResolver(filePath);
}

public static IAmWatcherPersistenceService WatcherPersistenceService(string connectionString)
{
var instanceResolver = Current.serviceProvider.GetService<Func<string, IAmWatcherPersistenceService>>();
return instanceResolver(connectionString);
}

public static IAmWardeinHeartBeatPersistanceService WardeinHeartBeatPersistenceService(string connectionString)
{
var instanceResolver = Current.serviceProvider.GetService<Func<string, IAmWardeinHeartBeatPersistanceService>>();
Expand Down
24 changes: 24 additions & 0 deletions Elfo.Wardein.Core/Persistence/OracleWatcherPersistenceService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Elfo.Firmenich.Wardein.Abstractions.Watchers;
using Elfo.Wardein.Core.Helpers;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Elfo.Firmenich.Wardein.Core.Persistence
{
public class OracleWatcherPersistenceService : IAmWatcherPersistenceService
{
private readonly OracleConnectionConfiguration oracleConnectionConfiguration;

public OracleWatcherPersistenceService(OracleConnectionConfiguration oracleConnectionConfiguration)
{
this.oracleConnectionConfiguration = oracleConnectionConfiguration;
}

public Task<WatcherStatusResult> UpsertCurrentStatus(int watcherConfigurationId, int applicationId, int applicationHostname, bool isHealthy, Exception failureException = null)
{
throw new NotImplementedException();
}
}
}
3 changes: 3 additions & 0 deletions Elfo.Wardein.Watchers/WebWatcher/Config/WebWatcherConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ public class WebWatcherConfig : IWatcherConfig

[JsonProperty(PropertyName = "restoredMessage")]
public string RestoredMessage { get; protected set; }

[JsonProperty(PropertyName = "connectionString")]
public string ConnectionString { get; protected set; }
}
}
12 changes: 6 additions & 6 deletions Elfo.Wardein.Watchers/WebWatcher/WebWatcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Elfo.Wardein.Abstractions.Services;
using Elfo.Firmenich.Wardein.Abstractions.Watchers;
using Elfo.Wardein.Abstractions.Services;
using Elfo.Wardein.Core;
using Elfo.Wardein.Core.Helpers;
using Elfo.Wardein.Core.NotificationService;
Expand All @@ -17,15 +18,14 @@ namespace Elfo.Wardein.Watchers.WebWatcher
{
public class WebWatcher : IWatcher
{
private readonly WebWatcherConfiguration configuration;
private readonly WebWatcherConfig configuration;
private readonly IAmWatcherPersistenceService watcherPersistenceService;
protected static ILogger log = LogManager.GetCurrentClassLogger();
private readonly IHttpService httpService;
public WebWatcherConfig Config { get; protected set; }
public string Name { get; }
public string Group { get; }
public const string DefaultName = "Web Watcher";

protected WebWatcher(string name, WebWatcherConfiguration config, string group)
protected WebWatcher(string name, WebWatcherConfig config, string group)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentException("Watcher name can not be empty.");
Expand All @@ -39,7 +39,7 @@ protected WebWatcher(string name, WebWatcherConfiguration config, string group)
Name = name;
this.configuration = config;
Group = group;
httpService = configuration.HttpServiceProvider();
watcherPersistenceService = ServicesContainer.WatcherPersistenceService(configuration.ConnectionString);
}

public async Task<IWatcherCheckResult> ExecuteAsync()
Expand Down

0 comments on commit e3670cf

Please sign in to comment.