-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add type hints on child settings
- Loading branch information
Showing
20 changed files
with
261 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/AWS.Deploy.CLI/Commands/TypeHints/InstanceTypeCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Amazon.EC2.Model; | ||
using AWS.Deploy.Common; | ||
using AWS.Deploy.Common.Recipes; | ||
using AWS.Deploy.Common.TypeHintData; | ||
using AWS.Deploy.Orchestration.Data; | ||
|
||
namespace AWS.Deploy.CLI.Commands.TypeHints | ||
{ | ||
public class InstanceTypeCommand : ITypeHintCommand | ||
{ | ||
private readonly IAWSResourceQueryer _awsResourceQueryer; | ||
private readonly IConsoleUtilities _consoleUtilities; | ||
|
||
public InstanceTypeCommand(IAWSResourceQueryer awsResourceQueryer, IConsoleUtilities consoleUtilities) | ||
{ | ||
_awsResourceQueryer = awsResourceQueryer; | ||
_consoleUtilities = consoleUtilities; | ||
} | ||
|
||
private async Task<List<InstanceTypeInfo>?> GetData(Recommendation recommendation, OptionSettingItem optionSetting) | ||
{ | ||
return await _awsResourceQueryer.ListOfAvailableInstanceTypes(); | ||
} | ||
|
||
public async Task<List<TypeHintResource>?> GetResources(Recommendation recommendation, OptionSettingItem optionSetting) | ||
{ | ||
var instanceType = await GetData(recommendation, optionSetting); | ||
return instanceType? | ||
.Select(x => new TypeHintResource(x.InstanceType.Value, x.InstanceType.Value)) | ||
.Distinct() | ||
.OrderBy(x => x) | ||
.ToList(); | ||
} | ||
|
||
public async Task<object> Execute(Recommendation recommendation, OptionSettingItem optionSetting) | ||
{ | ||
var instanceTypes = await GetData(recommendation, optionSetting); | ||
var instanceTypeDefaultValue = recommendation.GetOptionSettingDefaultValue<string>(optionSetting); | ||
if (instanceTypes == null) | ||
{ | ||
return _consoleUtilities.AskUserForValue("Select EC2 Instance Type:", instanceTypeDefaultValue ?? string.Empty, true); | ||
} | ||
|
||
var freeTierEligibleAnswer = _consoleUtilities.AskYesNoQuestion("Do you want the EC2 instance to be free tier eligible?", "true"); | ||
var freeTierEligible = freeTierEligibleAnswer == YesNo.Yes; | ||
|
||
var architectureAllowedValues = new List<string> { "x86_64", "arm64"}; | ||
|
||
var architecture = _consoleUtilities.AskUserToChoose(architectureAllowedValues, "The architecture of the EC2 instances created for the environment.", "x86_64"); | ||
|
||
var cpuCores = instanceTypes | ||
.Where(x => x.FreeTierEligible.Equals(freeTierEligible)) | ||
.Where(x => x.ProcessorInfo.SupportedArchitectures.Contains(architecture)) | ||
.Select(x => x.VCpuInfo.DefaultCores).Distinct().OrderBy(x => x).ToList(); | ||
|
||
if (cpuCores.Count == 0) | ||
return _consoleUtilities.AskUserForValue("Select EC2 Instance Type:", instanceTypeDefaultValue ?? string.Empty, true); | ||
|
||
var cpuCoreCount = int.Parse(_consoleUtilities.AskUserToChoose(cpuCores.Select(x => x.ToString()).ToList(), "Select EC2 Instance CPU Cores:", "1")); | ||
|
||
var memory = instanceTypes | ||
.Where(x => x.FreeTierEligible.Equals(freeTierEligible)) | ||
.Where(x => x.ProcessorInfo.SupportedArchitectures.Contains(architecture)) | ||
.Where(x => x.VCpuInfo.DefaultCores.Equals(cpuCoreCount)) | ||
.Select(x => x.MemoryInfo.SizeInMiB).Distinct().OrderBy(x => x).ToList(); | ||
|
||
if (memory.Count == 0) | ||
return _consoleUtilities.AskUserForValue("Select EC2 Instance Type:", instanceTypeDefaultValue ?? string.Empty, true); | ||
|
||
var memoryCount = _consoleUtilities.AskUserToChoose(memory.Select(x => x.ToString()).ToList(), "Select EC2 Instance Memory:", "1024"); | ||
|
||
var availableInstanceTypes = instanceTypes | ||
.Where(x => x.FreeTierEligible.Equals(freeTierEligible)) | ||
.Where(x => x.ProcessorInfo.SupportedArchitectures.Contains(architecture)) | ||
.Where(x => x.VCpuInfo.DefaultCores.Equals(cpuCoreCount)) | ||
.Where(x => x.MemoryInfo.SizeInMiB.Equals(long.Parse(memoryCount))) | ||
.Select(x => x.InstanceType.Value).Distinct().OrderBy(x => x).ToList(); | ||
|
||
if (availableInstanceTypes.Count == 0) | ||
return _consoleUtilities.AskUserForValue("Select EC2 Instance Type:", instanceTypeDefaultValue ?? string.Empty, true); | ||
|
||
var userResponse = _consoleUtilities.AskUserToChoose(availableInstanceTypes, "Select EC2 Instance Type:", availableInstanceTypes.First()); | ||
|
||
return userResponse; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/AWS.Deploy.Common/TypeHintData/DynamoDBTableTypeHintData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\r | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using AWS.Deploy.Common.Recipes; | ||
|
||
namespace AWS.Deploy.Common.TypeHintData | ||
{ | ||
/// <summary> | ||
/// Holds additional data for <see cref="OptionSettingTypeHint.DynamoDBTableName"/> processing. | ||
/// </summary> | ||
public class DynamoDBTableTypeHintData | ||
{ | ||
/// <summary> | ||
/// Determines whether to allow no value or not. | ||
/// </summary> | ||
public bool AllowNoValue { get; set; } | ||
|
||
public DynamoDBTableTypeHintData(bool allowNoValue) | ||
{ | ||
AllowNoValue = allowNoValue; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/AWS.Deploy.Common/TypeHintData/S3BucketNameTypeHintData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\r | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using AWS.Deploy.Common.Recipes; | ||
|
||
namespace AWS.Deploy.Common.TypeHintData | ||
{ | ||
/// <summary> | ||
/// Holds additional data for <see cref="OptionSettingTypeHint.S3BucketName"/> processing. | ||
/// </summary> | ||
public class S3BucketNameTypeHintData | ||
{ | ||
/// <summary> | ||
/// Determines whether to allow no value or not. | ||
/// </summary> | ||
public bool AllowNoValue { get; set; } | ||
|
||
public S3BucketNameTypeHintData(bool allowNoValue) | ||
{ | ||
AllowNoValue = allowNoValue; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/AWS.Deploy.Common/TypeHintData/SNSTopicArnsTypeHintData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\r | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using AWS.Deploy.Common.Recipes; | ||
|
||
namespace AWS.Deploy.Common.TypeHintData | ||
{ | ||
/// <summary> | ||
/// Holds additional data for <see cref="OptionSettingTypeHint.SNSTopicArn"/> processing. | ||
/// </summary> | ||
public class SNSTopicArnsTypeHintData | ||
{ | ||
/// <summary> | ||
/// Determines whether to allow no value or not. | ||
/// </summary> | ||
public bool AllowNoValue { get; set; } | ||
|
||
public SNSTopicArnsTypeHintData(bool allowNoValue) | ||
{ | ||
AllowNoValue = allowNoValue; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/AWS.Deploy.Common/TypeHintData/SQSQueueUrlTypeHintData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\r | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using AWS.Deploy.Common.Recipes; | ||
|
||
namespace AWS.Deploy.Common.TypeHintData | ||
{ | ||
/// <summary> | ||
/// Holds additional data for <see cref="OptionSettingTypeHint.SQSQueueUrl"/> processing. | ||
/// </summary> | ||
public class SQSQueueUrlTypeHintData | ||
{ | ||
/// <summary> | ||
/// Determines whether to allow no value or not. | ||
/// </summary> | ||
public bool AllowNoValue { get; set; } | ||
|
||
public SQSQueueUrlTypeHintData(bool allowNoValue) | ||
{ | ||
AllowNoValue = allowNoValue; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.