Clean up core accessibility

This commit is contained in:
ThatBen 2023-09-14 15:40:15 +02:00
parent ae7ab3d84b
commit fb7488769d
11 changed files with 38 additions and 35 deletions

View File

@ -1,6 +1,5 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow;
using Utils;
namespace CodexPlugin namespace CodexPlugin
{ {
@ -83,7 +82,7 @@ namespace CodexPlugin
return Container.Name; return Container.Name;
} }
private Http Http() private IHttp Http()
{ {
return tools.CreateHttp(Container.Address, baseUrl: "/api/codex/v1", CheckContainerCrashed, Container.Name); return tools.CreateHttp(Container.Address, baseUrl: "/api/codex/v1", CheckContainerCrashed, Container.Name);
} }

View File

@ -25,6 +25,7 @@ namespace Core
{ {
var workflow = entryPoint.Tools.CreateWorkflow(); var workflow = entryPoint.Tools.CreateWorkflow();
var file = entryPoint.Tools.GetLog().CreateSubfile(); var file = entryPoint.Tools.GetLog().CreateSubfile();
entryPoint.Tools.GetLog().Log($"Downloading container log for '{container.Name}' to file '{file.FullFilename}'...");
var logHandler = new LogDownloadHandler(container.Name, file); var logHandler = new LogDownloadHandler(container.Name, file);
workflow.DownloadContainerLog(container, logHandler, tailLines); workflow.DownloadContainerLog(container, logHandler, tailLines);
return logHandler.DownloadLog(); return logHandler.DownloadLog();

View File

@ -9,11 +9,11 @@ namespace Core
void DeleteFile(); void DeleteFile();
} }
public class DownloadedLog : IDownloadedLog internal class DownloadedLog : IDownloadedLog
{ {
private readonly LogFile logFile; private readonly LogFile logFile;
public DownloadedLog(LogFile logFile) internal DownloadedLog(LogFile logFile)
{ {
this.logFile = logFile; this.logFile = logFile;
} }

View File

@ -7,7 +7,19 @@ using Utils;
namespace Core namespace Core
{ {
public class Http public interface IHttp
{
string HttpGetString(string route);
T HttpGetJson<T>(string route);
TResponse HttpPostJson<TRequest, TResponse>(string route, TRequest body);
string HttpPostJson<TRequest>(string route, TRequest body);
string HttpPostString(string route, string body);
string HttpPostStream(string route, Stream stream);
Stream HttpGetStream(string route);
T TryJsonDeserialize<T>(string json);
}
internal class Http : IHttp
{ {
private readonly ILog log; private readonly ILog log;
private readonly ITimeSet timeSet; private readonly ITimeSet timeSet;
@ -16,12 +28,12 @@ namespace Core
private readonly Action<HttpClient> onClientCreated; private readonly Action<HttpClient> onClientCreated;
private readonly string? logAlias; private readonly string? logAlias;
public Http(ILog log, ITimeSet timeSet, Address address, string baseUrl, string? logAlias = null) internal Http(ILog log, ITimeSet timeSet, Address address, string baseUrl, string? logAlias = null)
: this(log, timeSet, address, baseUrl, DoNothing, logAlias) : this(log, timeSet, address, baseUrl, DoNothing, logAlias)
{ {
} }
public Http(ILog log, ITimeSet timeSet, Address address, string baseUrl, Action<HttpClient> onClientCreated, string? logAlias = null) internal Http(ILog log, ITimeSet timeSet, Address address, string baseUrl, Action<HttpClient> onClientCreated, string? logAlias = null)
{ {
this.log = log; this.log = log;
this.timeSet = timeSet; this.timeSet = timeSet;

View File

@ -3,11 +3,11 @@ using Logging;
namespace Core namespace Core
{ {
public class LogDownloadHandler : LogHandler, ILogHandler internal class LogDownloadHandler : LogHandler, ILogHandler
{ {
private readonly LogFile log; private readonly LogFile log;
public LogDownloadHandler(string description, LogFile log) internal LogDownloadHandler(string description, LogFile log)
{ {
this.log = log; this.log = log;
@ -15,7 +15,7 @@ namespace Core
log.WriteRaw(description); log.WriteRaw(description);
} }
public IDownloadedLog DownloadLog() internal IDownloadedLog DownloadLog()
{ {
return new DownloadedLog(log); return new DownloadedLog(log);
} }

View File

@ -2,11 +2,11 @@
namespace Core namespace Core
{ {
public static class PluginFinder internal static class PluginFinder
{ {
private static Type[]? pluginTypes = null; private static Type[]? pluginTypes = null;
public static Type[] GetPluginTypes() internal static Type[] GetPluginTypes()
{ {
if (pluginTypes != null) return pluginTypes; if (pluginTypes != null) return pluginTypes;

View File

@ -1,6 +1,6 @@
namespace Core namespace Core
{ {
public class PluginManager internal class PluginManager
{ {
private readonly List<IProjectPlugin> projectPlugins = new List<IProjectPlugin>(); private readonly List<IProjectPlugin> projectPlugins = new List<IProjectPlugin>();
@ -16,12 +16,12 @@
} }
} }
public void AnnouncePlugins() internal void AnnouncePlugins()
{ {
foreach (var plugin in projectPlugins) plugin.Announce(); foreach (var plugin in projectPlugins) plugin.Announce();
} }
public PluginMetadata GatherPluginMetadata() internal PluginMetadata GatherPluginMetadata()
{ {
var metadata = new PluginMetadata(); var metadata = new PluginMetadata();
foreach (var plugin in projectPlugins) foreach (var plugin in projectPlugins)
@ -34,12 +34,12 @@
return metadata; return metadata;
} }
public void DecommissionPlugins() internal void DecommissionPlugins()
{ {
foreach (var plugin in projectPlugins) plugin.Decommission(); foreach (var plugin in projectPlugins) plugin.Decommission();
} }
public T GetPlugin<T>() where T : IProjectPlugin internal T GetPlugin<T>() where T : IProjectPlugin
{ {
return (T)projectPlugins.Single(p => p.GetType() == typeof(T)); return (T)projectPlugins.Single(p => p.GetType() == typeof(T));
} }

View File

@ -1,6 +1,6 @@
namespace Core namespace Core
{ {
public interface IPluginMetadata internal interface IPluginMetadata
{ {
Dictionary<string, string> Get(); Dictionary<string, string> Get();
} }
@ -10,7 +10,7 @@
void Add(string key, string value); void Add(string key, string value);
} }
public class PluginMetadata : IPluginMetadata, IAddMetadata internal class PluginMetadata : IPluginMetadata, IAddMetadata
{ {
private readonly Dictionary<string, string> metadata = new Dictionary<string, string>(); private readonly Dictionary<string, string> metadata = new Dictionary<string, string>();

View File

@ -21,8 +21,8 @@ namespace Core
public interface IHttpFactoryTool public interface IHttpFactoryTool
{ {
Http CreateHttp(Address address, string baseUrl, Action<HttpClient> onClientCreated, string? logAlias = null); IHttp CreateHttp(Address address, string baseUrl, Action<HttpClient> onClientCreated, string? logAlias = null);
Http CreateHttp(Address address, string baseUrl, string? logAlias = null); IHttp CreateHttp(Address address, string baseUrl, string? logAlias = null);
} }
public interface IFileTool public interface IFileTool
@ -37,7 +37,7 @@ namespace Core
private readonly IFileManager fileManager; private readonly IFileManager fileManager;
private ILog log; private ILog log;
public PluginTools(ILog log, WorkflowCreator workflowCreator, string fileManagerRootFolder, ITimeSet timeSet) internal PluginTools(ILog log, WorkflowCreator workflowCreator, string fileManagerRootFolder, ITimeSet timeSet)
{ {
this.log = log; this.log = log;
this.workflowCreator = workflowCreator; this.workflowCreator = workflowCreator;
@ -50,12 +50,12 @@ namespace Core
log = new LogPrefixer(log, prefix); log = new LogPrefixer(log, prefix);
} }
public Http CreateHttp(Address address, string baseUrl, Action<HttpClient> onClientCreated, string? logAlias = null) public IHttp CreateHttp(Address address, string baseUrl, Action<HttpClient> onClientCreated, string? logAlias = null)
{ {
return new Http(log, timeSet, address, baseUrl, onClientCreated, logAlias); return new Http(log, timeSet, address, baseUrl, onClientCreated, logAlias);
} }
public Http CreateHttp(Address address, string baseUrl, string? logAlias = null) public IHttp CreateHttp(Address address, string baseUrl, string? logAlias = null)
{ {
return new Http(log, timeSet, address, baseUrl, logAlias); return new Http(log, timeSet, address, baseUrl, logAlias);
} }

View File

@ -81,22 +81,13 @@ namespace DistTestCore
public void DownloadAllLogs() public void DownloadAllLogs()
{ {
var workflow = entryPoint.Tools.CreateWorkflow();
foreach (var rc in runningContainers) foreach (var rc in runningContainers)
{ {
foreach (var c in rc.Containers) foreach (var c in rc.Containers)
{ {
DownloadContainerLog(workflow, c); CoreInterface.DownloadLog(c);
} }
} }
} }
private void DownloadContainerLog(IStartupWorkflow workflow, RunningContainer c)
{
var file = Log.CreateSubfile();
Log.Log($"Downloading container log for '{c.Name}' to file '{file.FullFilename}'...");
var handler = new LogDownloadHandler(c.Name, file);
workflow.DownloadContainerLog(c, handler);
}
} }
} }

View File

@ -6,7 +6,7 @@ namespace MetricsPlugin
{ {
public class MetricsQuery public class MetricsQuery
{ {
private readonly Http http; private readonly IHttp http;
public MetricsQuery(IPluginTools tools, RunningContainer runningContainer) public MetricsQuery(IPluginTools tools, RunningContainer runningContainer)
{ {