Skip to content

Commit

Permalink
Reuse SystemCapabilityEvaluator for a server mode session
Browse files Browse the repository at this point in the history
  • Loading branch information
ashovlin committed Jul 3, 2024
1 parent 2d0b078 commit 5b1c4c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/AWS.Deploy.CLI/ServerMode/Controllers/DeploymentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,15 @@ private IServiceProvider CreateSessionServiceProvider(SessionState state)
services.AddSingleton<IAWSResourceQueryer>(state.AWSResourceQueryService);
}

if (state.SystemCapabilityEvaluator == null)
{
services.AddSingleton<ISystemCapabilityEvaluator, SystemCapabilityEvaluator>();
}
else
{
services.AddSingleton<ISystemCapabilityEvaluator>(state.SystemCapabilityEvaluator);
}

services.AddCustomServices();
var serviceProvider = services.BuildServiceProvider();

Expand All @@ -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<IAWSResourceQueryer>() as SessionAWSResourceQuery;
state.SystemCapabilityEvaluator = serviceProvider.GetRequiredService<ISystemCapabilityEvaluator>() as SystemCapabilityEvaluator;

return serviceProvider;
}
Expand Down
3 changes: 3 additions & 0 deletions src/AWS.Deploy.CLI/ServerMode/SessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -30,6 +31,8 @@ public class SessionState

public SessionAWSResourceQuery? AWSResourceQueryService { get; set; }

public SystemCapabilityEvaluator? SystemCapabilityEvaluator { get; set; }

public Task? DeploymentTask { get; set; }

public SessionState(
Expand Down

0 comments on commit 5b1c4c2

Please sign in to comment.