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

Fix the handling of long-running operation statuses for New-AzManagedApplication and Set-AzManagedApplication #13679

Merged
merged 2 commits into from
Dec 9, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
using System.Collections.Generic;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Application;
using Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Operations;

/// <summary>
/// Base class for policy assignment cmdlets.
Expand Down Expand Up @@ -146,5 +147,33 @@ protected JToken GetObjectFromParameter(string parameter)
? JToken.FromObject(FileUtilities.DataStore.ReadFileAsText(path))
: JToken.FromObject(parameter);
}

/// <summary>
/// Processes and outputs the result of the operation.
/// </summary>
protected void ProcessResult(string result, string resourceId, string apiVersion)
{
if (result.TryConvertTo<AzureAsyncOperationResource>(out var operationResource) && operationResource != null)
{
if (String.Equals(operationResource.Status, "Succeeded", StringComparison.OrdinalIgnoreCase))
{
var getResult = this.GetResourcesClient()
.GetResource<JObject>(
resourceId: resourceId,
apiVersion: apiVersion,
cancellationToken: this.CancellationToken.Value)
.Result;
this.WriteObject(this.GetOutputObjects("ManagedApplicationId", getResult), enumerateCollection: true);
}
else
{
this.WriteObject(operationResource.Error.ToJToken());
}
}
else
{
throw new InvalidOperationException("The operation failed because the operation status could not be de-serialized.");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
using Common.ArgumentCompleters;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Application;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Operations;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Resources;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
Expand Down Expand Up @@ -127,7 +128,8 @@ protected override void OnProcessRecord()
var activity = string.Format("PUT {0}", managementUri.PathAndQuery);
var result = this.GetLongRunningOperationTracker(activityName: activity, isResourceCreateOrUpdate: true)
.WaitOnOperation(operationResult: operationResult);
this.WriteObject(this.GetOutputObjects("ManagedApplicationId", JObject.Parse(result)), enumerateCollection: true);

this.ProcessResult(result, resourceId, apiVersion);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
using Common.ArgumentCompleters;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Application;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Operations;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Resources;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
Expand Down Expand Up @@ -150,7 +151,8 @@ protected override void OnProcessRecord()
var activity = string.Format("PUT {0}", managementUri.PathAndQuery);
var result = this.GetLongRunningOperationTracker(activityName: activity, isResourceCreateOrUpdate: true)
.WaitOnOperation(operationResult: operationResult);
this.WriteObject(this.GetOutputObjects("ManagedApplicationId", JObject.Parse(result)), enumerateCollection: true);

this.ProcessResult(result, resourceId, apiVersion);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ function Test-ManagedApplicationCRUD
# Test
New-AzResourceGroup -Name $rgname -Location $rglocation

$appDef = New-AzManagedApplicationDefinition -Name $appDefName -ResourceGroupName $rgname -DisplayName $display -Description "Test" -Location $rglocation -LockLevel ReadOnly -PackageFileUri https://testclinew.blob.core.windows.net/files/vivekMAD.zip -Authorization 5e91139a-c94b-462e-a6ff-1ee95e8aac07:8e3af657-a8ff-443c-a75c-2fe8c4bcb635
$actual = New-AzManagedApplication -Name $appName -ResourceGroupName $rgname -ManagedResourceGroupName $managedrgname -ManagedApplicationDefinitionId $appDef.ResourceId -Location $rglocation -Kind ServiceCatalog -Parameter "$TestOutputRoot\SampleManagedApplicationParameters.json"
$appDef = New-AzManagedApplicationDefinition -Name $appDefName -ResourceGroupName $rgname -DisplayName $display -Description "Test" -Location $rglocation -LockLevel ReadOnly -PackageFileUri https://ilshat.blob.core.windows.net/packages/blank_working.zip -Authorization 6fd8564d-425b-4017-9121-ba334bab0be4:8e3af657-a8ff-443c-a75c-2fe8c4bcb635
$actual = New-AzManagedApplication -Name $appName -ResourceGroupName $rgname -ManagedResourceGroupName $managedrgname -ManagedApplicationDefinitionId $appDef.ResourceId -Location $rglocation -Kind ServiceCatalog
$expected = Get-AzManagedApplication -Name $appName -ResourceGroupName $rgname
Assert-AreEqual $expected.Name $actual.Name
Assert-AreEqual $expected.ManagedApplicationId $actual.ManagedApplicationId
Expand Down
Loading