From 5b1c4c24e3e50833ed4bb3579e6e8210be66e327 Mon Sep 17 00:00:00 2001 From: Alex Shovlin Date: Tue, 2 Jul 2024 10:41:05 -0400 Subject: [PATCH] Reuse SystemCapabilityEvaluator for a server mode session --- .../Controllers/DeploymentController.cs | 15 +++++++++++++-- src/AWS.Deploy.CLI/ServerMode/SessionState.cs | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/AWS.Deploy.CLI/ServerMode/Controllers/DeploymentController.cs b/src/AWS.Deploy.CLI/ServerMode/Controllers/DeploymentController.cs index da87716a..303524e9 100644 --- a/src/AWS.Deploy.CLI/ServerMode/Controllers/DeploymentController.cs +++ b/src/AWS.Deploy.CLI/ServerMode/Controllers/DeploymentController.cs @@ -699,6 +699,15 @@ private IServiceProvider CreateSessionServiceProvider(SessionState state) services.AddSingleton(state.AWSResourceQueryService); } + if (state.SystemCapabilityEvaluator == null) + { + services.AddSingleton(); + } + else + { + services.AddSingleton(state.SystemCapabilityEvaluator); + } + services.AddCustomServices(); var serviceProvider = services.BuildServiceProvider(); @@ -710,9 +719,11 @@ private IServiceProvider CreateSessionServiceProvider(SessionState state) awsOptions.Region = RegionEndpoint.GetBySystemName(state.AWSRegion); }); - // Cache the SessionAWSResourceQuery with the session state so it can be reused in future - // ServerMode API calls with the same session id. + // Cache the SessionAWSResourceQuery and SystemCapabilityEvaluator with the session state + // so they can be reused in future ServerMode API calls with the same session id. This avoids reloading + // existing resources from AWS and running the Docker/Node checks when they're not expected to change. state.AWSResourceQueryService = serviceProvider.GetRequiredService() as SessionAWSResourceQuery; + state.SystemCapabilityEvaluator = serviceProvider.GetRequiredService() as SystemCapabilityEvaluator; return serviceProvider; } diff --git a/src/AWS.Deploy.CLI/ServerMode/SessionState.cs b/src/AWS.Deploy.CLI/ServerMode/SessionState.cs index bbac2086..19d9a3d3 100644 --- a/src/AWS.Deploy.CLI/ServerMode/SessionState.cs +++ b/src/AWS.Deploy.CLI/ServerMode/SessionState.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using AWS.Deploy.CLI.ServerMode.Services; using AWS.Deploy.Common; +using AWS.Deploy.Orchestration; namespace AWS.Deploy.CLI.ServerMode { @@ -30,6 +31,8 @@ public class SessionState public SessionAWSResourceQuery? AWSResourceQueryService { get; set; } + public SystemCapabilityEvaluator? SystemCapabilityEvaluator { get; set; } + public Task? DeploymentTask { get; set; } public SessionState(