2023-09-13 08:03:11 +00:00
|
|
|
|
using FileUtils;
|
|
|
|
|
using KubernetesWorkflow;
|
|
|
|
|
using Logging;
|
|
|
|
|
|
|
|
|
|
namespace Core
|
|
|
|
|
{
|
2023-09-13 08:23:05 +00:00
|
|
|
|
public interface IPluginTools : IWorkflowTool, ILogTool, IHttpFactoryTool, IFileTool
|
|
|
|
|
{
|
2024-06-05 07:20:00 +00:00
|
|
|
|
ITimeSet TimeSet { get; }
|
2024-06-06 13:09:52 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes kubernetes and tracked file resources.
|
|
|
|
|
/// when `waitTillDone` is true, this function will block until resources are deleted.
|
|
|
|
|
/// </summary>
|
|
|
|
|
void Decommission(bool deleteKubernetesResources, bool deleteTrackedFiles, bool waitTillDone);
|
2023-09-13 08:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface IWorkflowTool
|
|
|
|
|
{
|
|
|
|
|
IStartupWorkflow CreateWorkflow(string? namespaceOverride = null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface ILogTool
|
|
|
|
|
{
|
|
|
|
|
ILog GetLog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface IHttpFactoryTool
|
|
|
|
|
{
|
2024-03-26 09:03:52 +00:00
|
|
|
|
IHttp CreateHttp(Action<HttpClient> onClientCreated);
|
|
|
|
|
IHttp CreateHttp(Action<HttpClient> onClientCreated, ITimeSet timeSet);
|
|
|
|
|
IHttp CreateHttp();
|
2023-09-13 08:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface IFileTool
|
|
|
|
|
{
|
|
|
|
|
IFileManager GetFileManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class PluginTools : IPluginTools
|
2023-09-13 08:03:11 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly WorkflowCreator workflowCreator;
|
|
|
|
|
private readonly IFileManager fileManager;
|
2024-03-27 07:41:18 +00:00
|
|
|
|
private readonly LogPrefixer log;
|
2023-09-13 08:03:11 +00:00
|
|
|
|
|
2023-09-14 13:40:15 +00:00
|
|
|
|
internal PluginTools(ILog log, WorkflowCreator workflowCreator, string fileManagerRootFolder, ITimeSet timeSet)
|
2023-09-13 08:03:11 +00:00
|
|
|
|
{
|
2024-03-27 07:41:18 +00:00
|
|
|
|
this.log = new LogPrefixer(log);
|
2023-09-13 09:59:21 +00:00
|
|
|
|
this.workflowCreator = workflowCreator;
|
2024-06-05 07:20:00 +00:00
|
|
|
|
TimeSet = timeSet;
|
2023-09-13 08:03:11 +00:00
|
|
|
|
fileManager = new FileManager(log, fileManagerRootFolder);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-05 07:20:00 +00:00
|
|
|
|
public ITimeSet TimeSet { get; }
|
|
|
|
|
|
2023-09-13 08:23:05 +00:00
|
|
|
|
public void ApplyLogPrefix(string prefix)
|
|
|
|
|
{
|
2024-03-27 07:41:18 +00:00
|
|
|
|
log.Prefix = prefix;
|
2023-09-13 08:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-26 09:03:52 +00:00
|
|
|
|
public IHttp CreateHttp(Action<HttpClient> onClientCreated)
|
2023-09-13 08:03:11 +00:00
|
|
|
|
{
|
2024-06-05 07:20:00 +00:00
|
|
|
|
return CreateHttp(onClientCreated, TimeSet);
|
2023-10-10 16:08:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-26 09:03:52 +00:00
|
|
|
|
public IHttp CreateHttp(Action<HttpClient> onClientCreated, ITimeSet ts)
|
2023-10-10 16:08:21 +00:00
|
|
|
|
{
|
2024-03-26 09:03:52 +00:00
|
|
|
|
return new Http(log, ts, onClientCreated);
|
2023-09-13 08:03:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-26 09:03:52 +00:00
|
|
|
|
public IHttp CreateHttp()
|
2023-09-13 08:03:11 +00:00
|
|
|
|
{
|
2024-06-05 07:20:00 +00:00
|
|
|
|
return new Http(log, TimeSet);
|
2023-09-13 08:03:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IStartupWorkflow CreateWorkflow(string? namespaceOverride = null)
|
|
|
|
|
{
|
2023-09-13 12:37:53 +00:00
|
|
|
|
return workflowCreator.CreateWorkflow(namespaceOverride);
|
2023-09-13 08:03:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-06 13:09:52 +00:00
|
|
|
|
public void Decommission(bool deleteKubernetesResources, bool deleteTrackedFiles, bool waitTillDone)
|
2023-09-21 08:33:09 +00:00
|
|
|
|
{
|
2024-06-06 13:09:52 +00:00
|
|
|
|
if (deleteKubernetesResources) CreateWorkflow().DeleteNamespace(waitTillDone);
|
2023-09-21 08:33:09 +00:00
|
|
|
|
if (deleteTrackedFiles) fileManager.DeleteAllFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 08:03:11 +00:00
|
|
|
|
public IFileManager GetFileManager()
|
|
|
|
|
{
|
|
|
|
|
return fileManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ILog GetLog()
|
|
|
|
|
{
|
|
|
|
|
return log;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|