Skip to content

Commit

Permalink
Release 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
itzikYeret authored and actions-user committed Nov 28, 2021
1 parent 425f7bf commit 5fc9862
Show file tree
Hide file tree
Showing 38 changed files with 1,249 additions and 472 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using Amazon.CloudFormation;
using System;
using System.Collections.Generic;
using System.Text;

namespace Dome9.CloudGuardOnboarding.Orchestrator
{
public static class ChangeSetStatusExtensions
{
public static bool IsFinal(this ChangeSetStatus changeSetStatus)
{
switch (changeSetStatus)
{
case "FAILED":
case "DELETE_COMPLETE":
case "CREATE_COMPLETE":
case "DELETE_FAILED":
return true;

default:
return false;
}
}

public static bool IsSuccess(this ChangeSetStatus changeSetStatus)
{
switch (changeSetStatus)
{
case "CREATE_COMPLETE":
return true;

default:
return false;
}
}

public static bool IsFinal(this ExecutionStatus executionStatus)
{
switch (executionStatus)
{
case "UNAVAILABLE":
case "AVAILABLE":
case "EXECUTE_COMPLETE":
case "EXECUTE_FAILED":
case "OBSOLETE":
return true;

default:
return false;
}
}

public static bool IsSuccess(this ExecutionStatus executionStatus)
{
switch (executionStatus)
{
case "EXECUTE_COMPLETE":
return true;

default:
return false;
}
}

public static bool IsReady(this ExecutionStatus executionStatus)
{
switch (executionStatus)
{
case "AVAILABLE":
return true;

default:
return false;
}
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Amazon.CloudFormation;

namespace Dome9.CloudGuardOnboarding.Orchestrator
{
public class CloudGuardChangeSetStatus
{
public bool? HasChanges { get; set; }
public ExecutionStatus ExecutionStatus { get; set; }
public ChangeSetStatus ChangeSetStatus { get; set; }
public string StatusReason { get; set; }

public override string ToString()
{
return $"{nameof(HasChanges)}='{HasChanges}', {nameof(ExecutionStatus)}='{ExecutionStatus}', {nameof(ChangeSetStatus)}='{ChangeSetStatus}', {nameof(StatusReason)}='{StatusReason}'";
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ Task<string> CreateStackAsync(
Action<string> statusUpdate,
int executionTimeoutMinutes);

Task<string> UpdateStackAsync(
Task UpdateStackAsync(
Enums.Feature feature,
string stackTemplateS3Url,
string stackName,
List<string> capabilities,
Dictionary<string, string> parameters);
Dictionary<string, string> parameters,
int executionTimeoutMinutes);

Task<string> GetStackTemplateAsync(Enums.Feature feature, string stackName);

Task<StackSummary> GetStackSummaryAsync(Enums.Feature feature, string stackName);
Task<Stack> GetStackDescriptionAsync(Enums.Feature feature, string stackName, bool filterDeleted = true);

Task DeleteStackAsync(Enums.Feature feature, string stackName, int executionTimeoutMinutes);
Task<bool> IsStackExist(Enums.Feature feature, string stackName);

Task<ApiCredentials> GetCredentialsFromSecretsManager(string key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static bool IsFinal(this StackStatus status)
return info.IsFinal;
}
throw new ArgumentOutOfRangeException(status);
}
}

public static bool IsError(this StackStatus status)
{
Expand All @@ -68,9 +68,14 @@ public static bool IsError(this StackStatus status)
throw new ArgumentOutOfRangeException(status);
}

public static string ToDetailedString(this Stack stack)
{
return $"StackName:'{stack.StackName}' Status:'{stack.StackStatus}', Reason:'{stack.StackStatusReason}', LastUpdated:{stack.LastUpdatedTime}";
}

public static string ToDetailedString(this StackSummary stackSummary)
{
return $"StackName:'{stackSummary.StackName}' Status:'{stackSummary.StackStatus}', Reason:'{stackSummary.StackStatusReason}', LastUpdated:{stackSummary.LastUpdatedTime}";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

namespace Dome9.CloudGuardOnboarding.Orchestrator
{
public abstract class StackWrapperBase : IDisposable
public enum StackOperation
{
protected enum StackOperation
{
None,
Create,
Update,
}
None,
Create,
Update,
}

public abstract class StackWrapperBase : IDisposable
{
protected readonly ICloudFormationWrapper _cfnWrapper;
protected readonly ICloudGuardApiWrapper _apiProvider;
protected readonly IRetryAndBackoffService _retryAndBackoffService;
Expand All @@ -38,11 +38,10 @@ public StackWrapperBase(ICloudGuardApiWrapper apiProvider, IRetryAndBackoffServi
/// </summary>
/// <param name="stackConfig"></param>
/// <returns></returns>
public async Task RunStackAsync(OnboardingStackConfig stackConfig)
public async Task RunStackAsync(OnboardingStackConfig stackConfig, StackOperation stackOperation)
{
Dictionary<string, string> parameters = GetParameters(stackConfig);

var stackOperation = await GetStackOperation(stackConfig.StackName);
switch (stackOperation)
{
case StackOperation.Create:
Expand All @@ -52,9 +51,8 @@ public async Task RunStackAsync(OnboardingStackConfig stackConfig)
break;

case StackOperation.Update:
throw new NotImplementedException("Need to check diff before can update.");
await _retryAndBackoffService.RunAsync(() => _apiProvider.UpdateOnboardingStatus(StatusModel.CreateActiveStatusModel(stackConfig.OnboardingId, Enums.Status.PENDING, "Updating existing stack", Feature)));
await _cfnWrapper.UpdateStackAsync(Feature, stackConfig.TemplateS3Url, stackConfig.StackName, stackConfig.Capabilities, parameters);
await _cfnWrapper.UpdateStackAsync(Feature, stackConfig.TemplateS3Url, stackConfig.StackName, stackConfig.Capabilities, parameters, stackConfig.ExecutionTimeoutMinutes);
await _retryAndBackoffService.RunAsync(() => _apiProvider.UpdateOnboardingStatus(StatusModel.CreateActiveStatusModel(stackConfig.OnboardingId, Enums.Status.ACTIVE, "Updated existing stack successfully", Feature)));
break;

Expand Down Expand Up @@ -115,43 +113,6 @@ private async Task TryUpdateStackStatus(string onboaringId, string stackStatus,
}
}

/// <summary>
/// TODO: update action will fail if there is nothing to update, so checking the name has one of _readyStatus values is not enough.
/// </summary>
/// <param name="stackName"></param>
/// <param name="iteration"></param>
/// <returns></returns>
protected async Task<StackOperation> GetStackOperation(string stackName, int iteration = 0)
{
// for now disabling this recursive method, as we only support Create anyway.
return StackOperation.Create;


var existingStack = await _cfnWrapper.GetStackSummaryAsync(Feature, stackName);
if (existingStack == null || _nonExistingStatus.Contains(existingStack.StackStatus))
{
return StackOperation.Create;
}

if (_inProgressStatus.Contains(existingStack.StackStatus))
{
if (iteration >= 12)
{
return StackOperation.None;
}

await Task.Delay(TimeSpan.FromSeconds(5));
return await GetStackOperation(stackName, ++iteration);
}

if (_readyStatus.Contains(existingStack.StackStatus))
{
return StackOperation.Update;
}

return StackOperation.None;
}

protected virtual void Dispose(bool disposing)
{
if (!_disposed)
Expand Down
Loading

0 comments on commit 5fc9862

Please sign in to comment.