Skip to content

Commit

Permalink
VCI-903: CloudEnvSetParameter is waiting for env status != progressing (
Browse files Browse the repository at this point in the history
  • Loading branch information
krankenbro authored Jul 31, 2024
1 parent bed35a8 commit a54d4f2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 43 deletions.
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.

0 comments on commit a54d4f2

Please sign in to comment.