initialize plugins with constructor
This commit is contained in:
parent
d900416d7c
commit
3c724f6206
|
@ -1,26 +1,27 @@
|
|||
using Core;
|
||||
using KubernetesWorkflow;
|
||||
using Logging;
|
||||
|
||||
namespace CodexPlugin
|
||||
{
|
||||
public class CodexPlugin : IProjectPlugin
|
||||
{
|
||||
private CodexStarter codexStarter = null!;
|
||||
private readonly CodexStarter codexStarter;
|
||||
private readonly IPluginTools tools;
|
||||
|
||||
public CodexPlugin(IPluginTools tools)
|
||||
{
|
||||
codexStarter = new CodexStarter(tools);
|
||||
this.tools = tools;
|
||||
}
|
||||
|
||||
#region IProjectPlugin Implementation
|
||||
|
||||
public void Announce(ILog log)
|
||||
public void Announce()
|
||||
{
|
||||
log.Log("hello from codex plugin. codex container info here.");
|
||||
tools.GetLog().Log("hello from codex plugin. codex container info here.");
|
||||
}
|
||||
|
||||
public void Initialize(IPluginTools tools)
|
||||
{
|
||||
codexStarter = new CodexStarter(tools);
|
||||
}
|
||||
|
||||
public void Finalize(ILog log)
|
||||
public void Decommission()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -6,16 +6,6 @@
|
|||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Metrics\dashboard.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Metrics\dashboard.json">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -83,7 +83,7 @@ namespace CodexPlugin
|
|||
{
|
||||
var logMessage = $"Downloading for contentId: '{contentId.Id}'...";
|
||||
Log(logMessage);
|
||||
var file = tools.GetFileManager().CreateEmptyTestFile(fileLabel);
|
||||
var file = tools.GetFileManager().CreateEmptyFile(fileLabel);
|
||||
Stopwatch.Measure(tools.GetLog(), logMessage, () => DownloadToFile(contentId.Id, file));
|
||||
Log($"Downloaded file {file.Describe()} to '{file.Filename}'.");
|
||||
return file;
|
||||
|
|
|
@ -1,26 +1,16 @@
|
|||
using FileUtils;
|
||||
using KubernetesWorkflow;
|
||||
using KubernetesWorkflow;
|
||||
using Logging;
|
||||
using Utils;
|
||||
|
||||
namespace Core
|
||||
{
|
||||
public class EntryPoint : IPluginTools
|
||||
public class EntryPoint
|
||||
{
|
||||
private readonly PluginManager manager = new PluginManager();
|
||||
private readonly ILog log;
|
||||
private readonly ITimeSet timeSet;
|
||||
private readonly FileManager fileManager;
|
||||
private readonly WorkflowCreator workflowCreator;
|
||||
|
||||
public EntryPoint(ILog log, Configuration configuration, string fileManagerRootFolder, ITimeSet timeSet)
|
||||
{
|
||||
this.log = log;
|
||||
this.timeSet = timeSet;
|
||||
fileManager = new FileManager(log, fileManagerRootFolder);
|
||||
workflowCreator = new WorkflowCreator(log, configuration);
|
||||
|
||||
manager.InstantiatePlugins(PluginFinder.GetPluginTypes());
|
||||
Tools = new ToolsProvider(log, configuration, fileManagerRootFolder, timeSet);
|
||||
manager.InstantiatePlugins(PluginFinder.GetPluginTypes(), Tools);
|
||||
}
|
||||
|
||||
public EntryPoint(ILog log, Configuration configuration, string fileManagerRootFolder)
|
||||
|
@ -28,14 +18,11 @@ namespace Core
|
|||
{
|
||||
}
|
||||
|
||||
public IPluginTools Tools { get; }
|
||||
|
||||
public void Announce()
|
||||
{
|
||||
manager.AnnouncePlugins(log);
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
manager.InitializePlugins(this);
|
||||
manager.AnnouncePlugins();
|
||||
}
|
||||
|
||||
public CoreInterface CreateInterface()
|
||||
|
@ -45,38 +32,12 @@ namespace Core
|
|||
|
||||
public void Decommission()
|
||||
{
|
||||
manager.FinalizePlugins(log);
|
||||
manager.DecommissionPlugins();
|
||||
}
|
||||
|
||||
internal T GetPlugin<T>() where T : IProjectPlugin
|
||||
{
|
||||
return manager.GetPlugin<T>();
|
||||
}
|
||||
|
||||
public Http CreateHttp(Address address, string baseUrl, Action<HttpClient> onClientCreated, string? logAlias = null)
|
||||
{
|
||||
return new Http(log, timeSet, address, baseUrl, onClientCreated, logAlias);
|
||||
}
|
||||
|
||||
public Http CreateHttp(Address address, string baseUrl, string? logAlias = null)
|
||||
{
|
||||
return new Http(log, timeSet, address, baseUrl, logAlias);
|
||||
}
|
||||
|
||||
public IStartupWorkflow CreateWorkflow(string? namespaceOverride = null)
|
||||
{
|
||||
if (namespaceOverride != null) throw new Exception("Namespace override is not supported in the DistTest environment. (It would mess up automatic resource cleanup.)");
|
||||
return workflowCreator.CreateWorkflow();
|
||||
}
|
||||
|
||||
public IFileManager GetFileManager()
|
||||
{
|
||||
return fileManager;
|
||||
}
|
||||
|
||||
public ILog GetLog()
|
||||
{
|
||||
return log;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using FileUtils;
|
||||
using KubernetesWorkflow;
|
||||
using Logging;
|
||||
using System.Reflection;
|
||||
using Utils;
|
||||
|
||||
namespace Core
|
||||
|
@ -10,29 +9,24 @@ namespace Core
|
|||
{
|
||||
private readonly List<IProjectPlugin> projectPlugins = new List<IProjectPlugin>();
|
||||
|
||||
public void InstantiatePlugins(Type[] pluginTypes)
|
||||
public void InstantiatePlugins(Type[] pluginTypes, IPluginTools tools)
|
||||
{
|
||||
projectPlugins.Clear();
|
||||
foreach (var pluginType in pluginTypes)
|
||||
{
|
||||
var plugin = (IProjectPlugin)Activator.CreateInstance(pluginType)!;
|
||||
var plugin = (IProjectPlugin)Activator.CreateInstance(pluginType, args: tools)!;
|
||||
projectPlugins.Add(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
public void AnnouncePlugins(ILog log)
|
||||
public void AnnouncePlugins()
|
||||
{
|
||||
foreach (var plugin in projectPlugins) plugin.Announce(log);
|
||||
foreach (var plugin in projectPlugins) plugin.Announce();
|
||||
}
|
||||
|
||||
public void InitializePlugins(IPluginTools tools)
|
||||
public void DecommissionPlugins()
|
||||
{
|
||||
foreach (var plugin in projectPlugins) plugin.Initialize(tools);
|
||||
}
|
||||
|
||||
public void FinalizePlugins(ILog log)
|
||||
{
|
||||
foreach (var plugin in projectPlugins) plugin.Finalize(log);
|
||||
foreach (var plugin in projectPlugins) plugin.Decommission();
|
||||
}
|
||||
|
||||
public T GetPlugin<T>() where T : IProjectPlugin
|
||||
|
@ -43,9 +37,8 @@ namespace Core
|
|||
|
||||
public interface IProjectPlugin
|
||||
{
|
||||
void Announce(ILog log);
|
||||
void Initialize(IPluginTools tools);
|
||||
void Finalize(ILog log);
|
||||
void Announce();
|
||||
void Decommission();
|
||||
}
|
||||
|
||||
public interface IPluginTools : IWorkflowTool, ILogTool, IHttpFactoryTool, IFileTool
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
using FileUtils;
|
||||
using KubernetesWorkflow;
|
||||
using Logging;
|
||||
using Utils;
|
||||
|
||||
namespace Core
|
||||
{
|
||||
public class ToolsProvider : IPluginTools
|
||||
{
|
||||
private readonly ILog log;
|
||||
private readonly ITimeSet timeSet;
|
||||
private readonly WorkflowCreator workflowCreator;
|
||||
private readonly IFileManager fileManager;
|
||||
|
||||
public ToolsProvider(ILog log, Configuration configuration, string fileManagerRootFolder, ITimeSet timeSet)
|
||||
{
|
||||
this.log = log;
|
||||
this.timeSet = timeSet;
|
||||
fileManager = new FileManager(log, fileManagerRootFolder);
|
||||
workflowCreator = new WorkflowCreator(log, configuration);
|
||||
}
|
||||
|
||||
public Http CreateHttp(Address address, string baseUrl, Action<HttpClient> onClientCreated, string? logAlias = null)
|
||||
{
|
||||
return new Http(log, timeSet, address, baseUrl, onClientCreated, logAlias);
|
||||
}
|
||||
|
||||
public Http CreateHttp(Address address, string baseUrl, string? logAlias = null)
|
||||
{
|
||||
return new Http(log, timeSet, address, baseUrl, logAlias);
|
||||
}
|
||||
|
||||
public IStartupWorkflow CreateWorkflow(string? namespaceOverride = null)
|
||||
{
|
||||
if (namespaceOverride != null) throw new Exception("Namespace override is not supported in the DistTest environment. (It would mess up automatic resource cleanup.)");
|
||||
return workflowCreator.CreateWorkflow();
|
||||
}
|
||||
|
||||
public IFileManager GetFileManager()
|
||||
{
|
||||
return fileManager;
|
||||
}
|
||||
|
||||
public ILog GetLog()
|
||||
{
|
||||
return log;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -45,7 +45,7 @@ namespace DistTestCore
|
|||
{
|
||||
Stopwatch.Measure(fixtureLog, "Global setup", () =>
|
||||
{
|
||||
globalEntryPoint.CreateWorkflow().DeleteNamespacesStartingWith(TestNamespacePrefix);
|
||||
globalEntryPoint.Tools.CreateWorkflow().DeleteNamespacesStartingWith(TestNamespacePrefix);
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -101,7 +101,7 @@ namespace DistTestCore
|
|||
|
||||
public TrackedFile GenerateTestFile(ByteSize size, string label = "")
|
||||
{
|
||||
return Get().EntryPoint.GetFileManager().GenerateTestFile(size, label);
|
||||
return Get().GenerateTestFile(size, label);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -110,7 +110,7 @@ namespace DistTestCore
|
|||
/// </summary>
|
||||
public void ScopedTestFiles(Action action)
|
||||
{
|
||||
Get().EntryPoint.GetFileManager().ScopedFiles(action);
|
||||
Get().ScopedTestFiles(action);
|
||||
}
|
||||
|
||||
//public IOnlineCodexNode SetupCodexBootstrapNode()
|
||||
|
@ -240,7 +240,6 @@ namespace DistTestCore
|
|||
WriteEndTestLog(lifecycle.Log);
|
||||
|
||||
IncludeLogsAndMetricsOnTestFailure(lifecycle);
|
||||
lifecycle.EntryPoint.Decommission();
|
||||
lifecycle.DeleteAllResources();
|
||||
lifecycle = null!;
|
||||
});
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Core;
|
||||
using FileUtils;
|
||||
using Logging;
|
||||
using Utils;
|
||||
|
||||
|
@ -7,6 +8,7 @@ namespace DistTestCore
|
|||
public class TestLifecycle
|
||||
{
|
||||
private readonly DateTime testStart;
|
||||
private readonly EntryPoint entryPoint;
|
||||
|
||||
public TestLifecycle(TestLog log, Configuration configuration, ITimeSet timeSet, string testNamespace)
|
||||
{
|
||||
|
@ -15,9 +17,8 @@ namespace DistTestCore
|
|||
TimeSet = timeSet;
|
||||
testStart = DateTime.UtcNow;
|
||||
|
||||
EntryPoint = new EntryPoint(log, configuration.GetK8sConfiguration(timeSet, testNamespace), configuration.GetFileManagerFolder(), timeSet);
|
||||
EntryPoint.Initialize();
|
||||
CoreInterface = EntryPoint.CreateInterface();
|
||||
entryPoint = new EntryPoint(log, configuration.GetK8sConfiguration(timeSet, testNamespace), configuration.GetFileManagerFolder(), timeSet);
|
||||
CoreInterface = entryPoint.CreateInterface();
|
||||
|
||||
log.WriteLogTag();
|
||||
}
|
||||
|
@ -25,13 +26,23 @@ namespace DistTestCore
|
|||
public TestLog Log { get; }
|
||||
public Configuration Configuration { get; }
|
||||
public ITimeSet TimeSet { get; }
|
||||
public EntryPoint EntryPoint { get; }
|
||||
public CoreInterface CoreInterface { get; }
|
||||
|
||||
public void DeleteAllResources()
|
||||
{
|
||||
EntryPoint.CreateWorkflow().DeleteNamespace();
|
||||
EntryPoint.GetFileManager().DeleteAllTestFiles();
|
||||
entryPoint.Tools.CreateWorkflow().DeleteNamespace();
|
||||
entryPoint.Tools.GetFileManager().DeleteAllFiles();
|
||||
entryPoint.Decommission();
|
||||
}
|
||||
|
||||
public TrackedFile GenerateTestFile(ByteSize size, string label = "")
|
||||
{
|
||||
return entryPoint.Tools.GetFileManager().GenerateFile(size, label);
|
||||
}
|
||||
|
||||
public void ScopedTestFiles(Action action)
|
||||
{
|
||||
entryPoint.Tools.GetFileManager().ScopedFiles(action);
|
||||
}
|
||||
|
||||
//public IDownloadedLog DownloadLog(RunningContainer container, int? tailLines = null)
|
||||
|
|
|
@ -6,9 +6,9 @@ namespace FileUtils
|
|||
{
|
||||
public interface IFileManager
|
||||
{
|
||||
TrackedFile CreateEmptyTestFile(string label = "");
|
||||
TrackedFile GenerateTestFile(ByteSize size, string label = "");
|
||||
void DeleteAllTestFiles();
|
||||
TrackedFile CreateEmptyFile(string label = "");
|
||||
TrackedFile GenerateFile(ByteSize size, string label = "");
|
||||
void DeleteAllFiles();
|
||||
void ScopedFiles(Action action);
|
||||
T ScopedFiles<T>(Func<T> action);
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace FileUtils
|
|||
this.log = log;
|
||||
}
|
||||
|
||||
public TrackedFile CreateEmptyTestFile(string label = "")
|
||||
public TrackedFile CreateEmptyFile(string label = "")
|
||||
{
|
||||
var path = Path.Combine(folder, Guid.NewGuid().ToString() + "_test.bin");
|
||||
var result = new TrackedFile(log, path, label);
|
||||
|
@ -39,15 +39,15 @@ namespace FileUtils
|
|||
return result;
|
||||
}
|
||||
|
||||
public TrackedFile GenerateTestFile(ByteSize size, string label)
|
||||
public TrackedFile GenerateFile(ByteSize size, string label)
|
||||
{
|
||||
var sw = Stopwatch.Begin(log);
|
||||
var result = GenerateFile(size, label);
|
||||
var result = GenerateRandomFile(size, label);
|
||||
sw.End($"Generated file '{result.Describe()}'.");
|
||||
return result;
|
||||
}
|
||||
|
||||
public void DeleteAllTestFiles()
|
||||
public void DeleteAllFiles()
|
||||
{
|
||||
DeleteDirectory();
|
||||
}
|
||||
|
@ -88,9 +88,9 @@ namespace FileUtils
|
|||
}
|
||||
}
|
||||
|
||||
private TrackedFile GenerateFile(ByteSize size, string label)
|
||||
private TrackedFile GenerateRandomFile(ByteSize size, string label)
|
||||
{
|
||||
var result = CreateEmptyTestFile(label);
|
||||
var result = CreateEmptyFile(label);
|
||||
CheckSpaceAvailable(result, size);
|
||||
|
||||
GenerateFileBytes(result, size);
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
|
||||
namespace MetricsPlugin
|
||||
{
|
||||
public class GrafanaStarter : BaseStarter
|
||||
public class GrafanaStarter
|
||||
{
|
||||
private const string StorageQuotaThresholdReplaceToken = "\"<CODEX_STORAGEQUOTA>\"";
|
||||
private const string BytesUsedGraphAxisSoftMaxReplaceToken = "\"<CODEX_BYTESUSED_SOFTMAX>\"";
|
||||
|
||||
public GrafanaStarter(TestLifecycle lifecycle)
|
||||
: base(lifecycle)
|
||||
public GrafanaStarter()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using Core;
|
||||
using KubernetesWorkflow;
|
||||
using Logging;
|
||||
|
||||
namespace MetricsPlugin
|
||||
{
|
||||
|
@ -9,16 +8,12 @@ namespace MetricsPlugin
|
|||
|
||||
#region IProjectPlugin Implementation
|
||||
|
||||
public void Announce(ILog log)
|
||||
public void Announce()
|
||||
{
|
||||
log.Log("Hi from the metrics plugin.");
|
||||
//log.Log("Hi from the metrics plugin.");
|
||||
}
|
||||
|
||||
public void Initialize(IPluginTools tools)
|
||||
{
|
||||
}
|
||||
|
||||
public void Finalize(ILog log)
|
||||
public void Decommission()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -6,4 +6,18 @@
|
|||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="dashboard.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="dashboard.json">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core\Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -27,7 +27,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileUtils", "FileUtils\File
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodexPlugin", "CodexPlugin\CodexPlugin.csproj", "{DE4E802C-288C-45C4-84B6-8A5A6A96EF49}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{F2BF34B3-C660-43EF-BD42-BC5C60237FC4}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{F2BF34B3-C660-43EF-BD42-BC5C60237FC4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MetricsPlugin", "MetricsPlugin\MetricsPlugin.csproj", "{FCC74AF1-463D-4E5A-9FE7-B4A13F7C8820}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -87,6 +89,10 @@ Global
|
|||
{F2BF34B3-C660-43EF-BD42-BC5C60237FC4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F2BF34B3-C660-43EF-BD42-BC5C60237FC4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F2BF34B3-C660-43EF-BD42-BC5C60237FC4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FCC74AF1-463D-4E5A-9FE7-B4A13F7C8820}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FCC74AF1-463D-4E5A-9FE7-B4A13F7C8820}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FCC74AF1-463D-4E5A-9FE7-B4A13F7C8820}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FCC74AF1-463D-4E5A-9FE7-B4A13F7C8820}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
Loading…
Reference in New Issue