Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCI-903: CloudEnvSetParameter is waiting for env status != progressing #140

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions src/VirtoCommerce.Build/Cloud/Build.SaaS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public string CloudAuthProvider
for (var i = 0; i < AttemptsNumber; i++)
{
Log.Information($"Attempt #{i + 1}");
var env = await cloudClient.GetEnvironment(EnvironmentName);
var env = await cloudClient.GetEnvironmentAsync(EnvironmentName);
Log.Information(
$"Actual Health Status is {env.Status} - expected is {HealthStatus ?? "Not expected"}\n Actual Sync Status is {env.SyncStatus} - expected is {SyncStatus ?? "Not expected"}");
if (CheckAppServiceStatus(HealthStatus, env.Status) &&
Expand All @@ -106,12 +106,37 @@ public string CloudAuthProvider
Assert.True(isSuccess, $"Statuses {HealthStatus} {SyncStatus} were not obtained for the number of attempts: {AttemptsNumber}");
});

private static async Task<bool> WaitForEnvironmentState(Func<Task<CloudEnvironment>> cloudEnvProvider, Func<CloudEnvironment, bool> condition, int delay, int attempts)
{
for (var i = 0; i < attempts; i++)
{
var env = await cloudEnvProvider();
Log.Information($"Attempt #{i + 1}");
Log.Information($"Health Status is {env.Status}\nSync Status is {env.SyncStatus}");
if (condition(env))
{
return true;
}

await Task.Delay(TimeSpan.FromSeconds(delay));
}

return false;
}
public Target CloudEnvSetParameter => _ => _
.Executes(async () =>
{
var cloudClient = new VirtoCloudClient(CloudUrl, await GetCloudTokenAsync());
var env = await cloudClient.GetEnvironment(EnvironmentName, SaaSOrganizationName);

var isProgressing = await WaitForEnvironmentState(async () => await cloudClient.GetEnvironmentAsync(EnvironmentName, SaaSOrganizationName),
env => env.Status != "Progressing", Delay, AttemptsNumber);

if (!isProgressing)
{
Assert.Fail("Environment is in 'Progressing' status for too long.");
}

var env = await cloudClient.GetEnvironmentAsync(EnvironmentName, SaaSOrganizationName);

var envHelmParameters = env.Helm.Parameters;
foreach (var parameter in HelmParameters)
Expand Down Expand Up @@ -259,7 +284,7 @@ private static void CopyPlatformDirectory(AbsolutePath platformDirectory, Absolu
.Executes(async () =>
{
var cloudClient = new VirtoCloudClient(CloudUrl, await GetCloudTokenAsync());
var env = await cloudClient.GetEnvironment(EnvironmentName, SaaSOrganizationName);
var env = await cloudClient.GetEnvironmentAsync(EnvironmentName, SaaSOrganizationName);

var envHelmParameters = env.Helm.Parameters;

Expand Down
5 changes: 2 additions & 3 deletions src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Cloud.Models;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Utilities;
using VirtoCloud.Client.Model;

namespace Cloud.Client;

Expand Down Expand Up @@ -52,7 +51,7 @@ public async Task UpdateEnvironmentAsync(CloudEnvironment environment)
}
}

public async Task<CloudEnvironment> GetEnvironment(string environmentName, string orgName = null)
public async Task<CloudEnvironment> GetEnvironmentAsync(string environmentName, string orgName = null)
{
var relativeUri = string.IsNullOrWhiteSpace(orgName) ? $"api/saas/environments/{environmentName}" : $"api/saas/environments/{orgName}/{environmentName}";
var response = await _client.SendAsync(new HttpRequestMessage
Expand Down
28 changes: 0 additions & 28 deletions src/VirtoCommerce.Build/Cloud/Models/CloudEnvironment.cs

This file was deleted.

9 changes: 0 additions & 9 deletions src/VirtoCommerce.Build/Cloud/Models/Helm.cs

This file was deleted.

Loading