fix(POSTV1-02): 修复便携包首次启动链路
Dada P0-A isolated Windows CI / validate-and-package (push) Waiting to run
Dada P0-A isolated Windows CI / validate-and-package (push) Waiting to run
This commit is contained in:
@@ -40,6 +40,7 @@ internal static class Program
|
||||
var supervisor = await TestSupervisorLifecycleAsync();
|
||||
await TestAmapProbeSecurityAsync();
|
||||
TestSecureConfigurationPersistence();
|
||||
TestRuntimeDirectoryBootstrap();
|
||||
TestStructuredLogging();
|
||||
WriteEvidence(Environment.GetEnvironmentVariable("DADA_EVIDENCE_DIR_SEC"), security);
|
||||
WriteEvidence(Environment.GetEnvironmentVariable("DADA_EVIDENCE_DIR_SUP"), supervisor);
|
||||
@@ -125,6 +126,29 @@ internal static class Program
|
||||
}
|
||||
}
|
||||
|
||||
private static void TestRuntimeDirectoryBootstrap()
|
||||
{
|
||||
var root = Path.Combine(Path.GetTempPath(), $"dada-runtime-root-{Guid.NewGuid():N}");
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(root);
|
||||
SupervisorRuntime.EnsureRuntimeDirectories(root);
|
||||
foreach (var relativePath in new[]
|
||||
{
|
||||
"db", "content/references", "content/generated", "content/exports",
|
||||
"managed-assets", "derived-assets", "staging",
|
||||
"logs/api", "logs/worker", "logs/supervisor",
|
||||
})
|
||||
{
|
||||
True(Directory.Exists(Path.Combine(root, relativePath)), $"runtime directory missing: {relativePath}");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (Directory.Exists(root)) Directory.Delete(root, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<object> TestCredentialBoundaryAsync()
|
||||
{
|
||||
var store = new TestCredentialStore();
|
||||
|
||||
@@ -50,7 +50,9 @@ internal static class CredentialProcessLauncher
|
||||
var credentials = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
foreach (var target in CredentialCatalog.RequiredFor(role))
|
||||
{
|
||||
credentials[target] = store.Read(target) ?? string.Empty;
|
||||
var value = store.Read(target);
|
||||
if (role == ChildRole.Worker && string.IsNullOrWhiteSpace(value)) throw new MissingCredentialException(target);
|
||||
credentials[target] = value ?? string.Empty;
|
||||
}
|
||||
|
||||
startInfo.UseShellExecute = false;
|
||||
@@ -98,7 +100,9 @@ internal static class CredentialProcessLauncher
|
||||
var credentials = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
foreach (var target in CredentialCatalog.RequiredFor(role))
|
||||
{
|
||||
credentials[target] = store.Read(target) ?? string.Empty;
|
||||
var value = store.Read(target);
|
||||
if (role == ChildRole.Worker && string.IsNullOrWhiteSpace(value)) throw new MissingCredentialException(target);
|
||||
credentials[target] = value ?? string.Empty;
|
||||
}
|
||||
|
||||
startInfo.UseShellExecute = false;
|
||||
|
||||
@@ -5,6 +5,19 @@ namespace Dada.Supervisor;
|
||||
|
||||
internal sealed class SupervisorRuntime : IAsyncDisposable
|
||||
{
|
||||
private static readonly string[] RequiredDataDirectories =
|
||||
[
|
||||
"db",
|
||||
Path.Combine("content", "references"),
|
||||
Path.Combine("content", "generated"),
|
||||
Path.Combine("content", "exports"),
|
||||
"managed-assets",
|
||||
"derived-assets",
|
||||
"staging",
|
||||
Path.Combine("logs", "api"),
|
||||
Path.Combine("logs", "worker"),
|
||||
Path.Combine("logs", "supervisor"),
|
||||
];
|
||||
private readonly ICredentialStore credentials;
|
||||
private ManagedComponentSupervisor? api;
|
||||
private ManagedComponentSupervisor? worker;
|
||||
@@ -26,6 +39,7 @@ internal sealed class SupervisorRuntime : IAsyncDisposable
|
||||
{
|
||||
return SupervisorState.StartupFailed;
|
||||
}
|
||||
EnsureRuntimeDirectories(configuration.LocalDataRoot);
|
||||
try
|
||||
{
|
||||
logger = new StructuredJsonlLogger(Path.Combine(configuration.LocalDataRoot, "logs", "supervisor"), "supervisor");
|
||||
@@ -42,12 +56,30 @@ internal sealed class SupervisorRuntime : IAsyncDisposable
|
||||
var workerEntry = Path.Combine(AppContext.BaseDirectory, "server", "worker.mjs");
|
||||
if (!File.Exists(node) || !File.Exists(apiEntry) || !File.Exists(workerEntry)) return SupervisorState.StartupFailed;
|
||||
|
||||
api = CreateComponent(node, apiEntry, ChildRole.Api, SupervisorState.ApiDegraded);
|
||||
await api.StartAsync(cancellationToken);
|
||||
try
|
||||
{
|
||||
api = CreateComponent(node, apiEntry, ChildRole.Api, SupervisorState.ApiDegraded);
|
||||
await api.StartAsync(cancellationToken);
|
||||
|
||||
worker = CreateComponent(node, workerEntry, ChildRole.Worker, SupervisorState.WorkerDegraded);
|
||||
await worker.StartAsync(cancellationToken);
|
||||
return TryLog(new StructuredLogEvent("ready", ErrorCategory: "none")) ? SupervisorState.Ready : SupervisorState.StorageUnavailable;
|
||||
worker = CreateComponent(node, workerEntry, ChildRole.Worker, SupervisorState.WorkerDegraded);
|
||||
await worker.StartAsync(cancellationToken);
|
||||
return TryLog(new StructuredLogEvent("ready", ErrorCategory: "none")) ? SupervisorState.Ready : SupervisorState.StorageUnavailable;
|
||||
}
|
||||
catch
|
||||
{
|
||||
await StopComponentsAsync();
|
||||
return TryLog(new StructuredLogEvent("failed", ErrorCategory: "service_unavailable"))
|
||||
? SupervisorState.StartupFailed
|
||||
: SupervisorState.StorageUnavailable;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void EnsureRuntimeDirectories(string dataRoot)
|
||||
{
|
||||
foreach (var directory in RequiredDataDirectories)
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(dataRoot, directory));
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureAdminPepper()
|
||||
@@ -102,10 +134,26 @@ internal sealed class SupervisorRuntime : IAsyncDisposable
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await StopComponentsAsync();
|
||||
}
|
||||
|
||||
private async Task StopComponentsAsync()
|
||||
{
|
||||
var stops = new List<Task>();
|
||||
if (worker is not null) stops.Add(worker.DisposeAsync().AsTask());
|
||||
if (api is not null) stops.Add(api.DisposeAsync().AsTask());
|
||||
await Task.WhenAll(stops);
|
||||
try
|
||||
{
|
||||
await Task.WhenAll(stops);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
worker = null;
|
||||
api = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user