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

Add lookup mechanism for ID to apiversion #19437

Merged
merged 48 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
bd06bf1
WIP: updates
bquantump Mar 8, 2021
a11a769
WIP: updates
bquantump Mar 10, 2021
71dabee
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
bquantump Mar 10, 2021
b72173b
Update test
bquantump Mar 10, 2021
79cb491
Update ResourceListOperationsTest.cs
bquantump Mar 11, 2021
f4162e3
Update CreateSingleVmExample.cs
bquantump Mar 11, 2021
ff8d333
Update CreateSingleVmExample.cs
bquantump Mar 11, 2021
9fa1e0c
Update CreateSingleVmExample.cs
bquantump Mar 11, 2021
a9da33b
Update CreateSingleVmExample.cs
bquantump Mar 11, 2021
e35f07c
WIP: Updates
bquantump Mar 11, 2021
d884f56
Add extra line
bquantump Mar 11, 2021
fcc2aab
Update
bquantump Mar 11, 2021
4f2dae5
WIP:
bquantump Mar 11, 2021
aee7547
WIP: updates
bquantump Mar 15, 2021
6b7ba0f
Merge branch 'mgmt-track2' of https://github.com/AME-Redmond/azure-sd…
bquantump Mar 15, 2021
db3b7f4
WIp: updates
bquantump Mar 15, 2021
e5fd067
Remove API version extensions
bquantump Mar 16, 2021
93da13a
WIP: updates
bquantump Mar 16, 2021
baacd99
Updates
bquantump Mar 16, 2021
c398fb8
Update test
bquantump Mar 16, 2021
8e5f11d
WIP updates
bquantump Mar 16, 2021
2f47da4
Merge branch 'feature/mgmt-track2' into stevens_5117
bquantump Mar 16, 2021
757015c
Updates
bquantump Mar 17, 2021
2bc016e
WIP
bquantump Mar 17, 2021
6bdf327
Remove blank lines
bquantump Mar 17, 2021
45c23e7
Update filtering
bquantump Mar 17, 2021
af3d5e6
Updates
bquantump Mar 17, 2021
5ec195c
Update
bquantump Mar 18, 2021
847e593
WIP: updates
bquantump Mar 18, 2021
d76be3f
WIP: updates
bquantump Mar 18, 2021
f267bf3
Add space
bquantump Mar 18, 2021
26f4385
Remove debug
bquantump Mar 18, 2021
9e26522
Updates
bquantump Mar 18, 2021
fcba084
WIP: updates
bquantump Mar 22, 2021
3dc030d
WIP
bquantump Mar 22, 2021
10f6ad0
Change the accessbility to virtual for Resource.Id
YalinLi0312 Mar 24, 2021
b8291aa
WIP: updates
bquantump Mar 25, 2021
db74f22
WIP Updates
bquantump Mar 25, 2021
ff09cb4
Merge branch 'mgmt-track2' of https://github.com/AME-Redmond/azure-sd…
bquantump Mar 25, 2021
428f6bc
WIP updates
bquantump Mar 26, 2021
2013b78
WIP
bquantump Mar 26, 2021
6a2dec1
WIP
bquantump Mar 26, 2021
9ea1997
WIP:
bquantump Mar 26, 2021
00b5d31
revert
bquantump Mar 26, 2021
431479a
WIP: updates
bquantump Mar 26, 2021
69a6f6b
WIP: updates
bquantump Mar 26, 2021
804515d
WIP: updated
bquantump Mar 26, 2021
b01050c
WIP
bquantump Mar 26, 2021
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
39 changes: 30 additions & 9 deletions sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ where method.GetParameters()[0].ParameterType == typeof(AzureResourceManagerClie
return results;
}

internal string LoadApiVersion(ProvidersOperations providers, ResourceIdentifier id, CancellationToken cancellationToken)
private string LoadApiVersion(ProvidersOperations providers, ResourceIdentifier id, CancellationToken cancellationToken)
{
var results = providers.Get(id.Type.Namespace, null, cancellationToken);
bquantump marked this conversation as resolved.
Show resolved Hide resolved
foreach (var type in results.Value.ResourceTypes)
Expand All @@ -75,10 +75,10 @@ internal string LoadApiVersion(ProvidersOperations providers, ResourceIdentifier
return type.ApiVersions[0];
}
}
return string.Empty;
return null;
}

internal async Task<string> LoadApiVersionAsync(ProvidersOperations providers, ResourceIdentifier id, CancellationToken cancellationToken)
private async Task<string> LoadApiVersionAsync(ProvidersOperations providers, ResourceIdentifier id, CancellationToken cancellationToken)
{
var results = await providers.GetAsync(id.Type.Namespace, null, cancellationToken).ConfigureAwait(false);
foreach (var type in results.Value.ResourceTypes)
Expand All @@ -89,27 +89,48 @@ internal async Task<string> LoadApiVersionAsync(ProvidersOperations providers, R
return type.ApiVersions[0];
}
}
return string.Empty;
return null;
}

internal string TyrGetApiVersion(ProvidersOperations providers, ResourceIdentifier resourceId, CancellationToken cancellationToken)
bquantump marked this conversation as resolved.
Show resolved Hide resolved
{
string val;
if (TryGetApiVersion(resourceId, out val))
{
return val;
}
return LoadApiVersion(providers, resourceId, cancellationToken);
}

internal async Task<string> TyrGetApiVersionAsync(ProvidersOperations providers, ResourceIdentifier resourceId, CancellationToken cancellationToken)
bquantump marked this conversation as resolved.
Show resolved Hide resolved
{
string val;
if (TryGetApiVersion(resourceId, out val))
{
return val;
}
return await LoadApiVersionAsync(providers, resourceId, cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Gets the API version give a resource ID if it exist, else will return null.
/// </summary>
/// <returns> API version string. </returns>
bquantump marked this conversation as resolved.
Show resolved Hide resolved
public string TryGetApiVersion(string resourceId)
public bool TryGetApiVersion(string resourceId, out string val)
{
PropertyWrapper propertyWrapper;
if (_loadedResourceToApiVersions.TryGetValue(resourceId, out propertyWrapper))
{
return propertyWrapper.Info.GetValue(propertyWrapper.PropertyObject).ToString();
val = propertyWrapper.Info.GetValue(propertyWrapper.PropertyObject).ToString();
bquantump marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

string val;
if (_nonLoadedResourceToApiVersion.TryGetValue(resourceId, out val))
{
return val;
return true;
}
return null;
val = null;
return false;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class GenericResourceOperations : ResourceOperationsBase<GenericResource>
internal GenericResourceOperations(ResourceOperationsBase operations, ResourceIdentifier id)
: base(operations, id)
{
_apiVersion = ClientOptions.ApiVersions.TryGetApiVersion(id.Type.ToString());
string val;
bquantump marked this conversation as resolved.
Show resolved Hide resolved
ClientOptions.ApiVersions.TryGetApiVersion(id.Type.ToString(), out val);
_apiVersion = val;
}

/// <inheritdoc/>
Expand Down Expand Up @@ -59,7 +61,7 @@ public ArmResponse<Response> Delete(CancellationToken cancellationToken = defaul
/// <returns> A <see cref="Task"/> that on completion returns the status of the delete operation. </returns>
public async Task<ArmResponse<Response>> DeleteAsync(CancellationToken cancellationToken = default)
{
_apiVersion ??= await ClientOptions.ApiVersions.LoadApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
_apiVersion = await ClientOptions.ApiVersions.TyrGetApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
var operation = await Operations.StartDeleteByIdAsync(Id, _apiVersion, cancellationToken).ConfigureAwait(false);
var result = await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
return new ArmResponse(result);
Expand All @@ -76,7 +78,7 @@ public async Task<ArmResponse<Response>> DeleteAsync(CancellationToken cancellat
/// </remarks>
public ArmOperation<Response> StartDelete(CancellationToken cancellationToken = default)
{
_apiVersion ??= ClientOptions.ApiVersions.LoadApiVersion(ProviderOperations, Id, cancellationToken);
_apiVersion = ClientOptions.ApiVersions.TyrGetApiVersion(ProviderOperations, Id, cancellationToken);
bquantump marked this conversation as resolved.
Show resolved Hide resolved
return new ArmVoidOperation(Operations.StartDeleteById(Id, _apiVersion, cancellationToken));
}

Expand All @@ -93,7 +95,7 @@ public ArmOperation<Response> StartDelete(CancellationToken cancellationToken =
/// </remarks>
public async Task<ArmOperation<Response>> StartDeleteAsync(CancellationToken cancellationToken = default)
{
_apiVersion ??= await ClientOptions.ApiVersions.LoadApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
_apiVersion = await ClientOptions.ApiVersions.TyrGetApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
var operation = await Operations.StartDeleteByIdAsync(Id, _apiVersion, cancellationToken).ConfigureAwait(false);
return new ArmVoidOperation(operation);
}
Expand All @@ -102,7 +104,7 @@ public async Task<ArmOperation<Response>> StartDeleteAsync(CancellationToken can
public ArmResponse<GenericResource> AddTag(string key, string value, CancellationToken cancellationToken = default)
{
GenericResource resource = GetResource();
_apiVersion ??= ClientOptions.ApiVersions.LoadApiVersion(ProviderOperations, Id, cancellationToken);
_apiVersion = ClientOptions.ApiVersions.TyrGetApiVersion(ProviderOperations, Id, cancellationToken);
// Potential optimization on tags set, remove NOOP to bypass the call.
resource.Data.Tags[key] = value;
return new PhArmResponse<GenericResource, ResourceManager.Resources.Models.GenericResource>(
Expand All @@ -113,7 +115,7 @@ public ArmResponse<GenericResource> AddTag(string key, string value, Cancellatio
/// <inheritdoc/>
public async Task<ArmResponse<GenericResource>> AddTagAsync(string key, string value, CancellationToken cancellationToken = default)
{
_apiVersion ??= await ClientOptions.ApiVersions.LoadApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
_apiVersion = await ClientOptions.ApiVersions.TyrGetApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
GenericResource resource = await GetResourceAsync(cancellationToken).ConfigureAwait(false);
resource.Data.Tags[key] = value;
var op = await Operations.StartUpdateByIdAsync(Id, _apiVersion, resource.Data, cancellationToken).ConfigureAwait(false);
Expand All @@ -127,7 +129,7 @@ public ArmOperation<GenericResource> StartAddTag(string key, string value, Cance
{
GenericResource resource = GetResource();
resource.Data.Tags[key] = value;
_apiVersion ??= ClientOptions.ApiVersions.LoadApiVersion(ProviderOperations, Id, cancellationToken);
_apiVersion = ClientOptions.ApiVersions.TyrGetApiVersion(ProviderOperations, Id, cancellationToken);
return new PhArmOperation<GenericResource, ResourceManager.Resources.Models.GenericResource>(
Operations.StartUpdateById(Id, _apiVersion, resource.Data, cancellationToken).WaitForCompletionAsync(cancellationToken).EnsureCompleted(),
v => new GenericResource(this, new GenericResourceData(v)));
Expand All @@ -136,7 +138,7 @@ public ArmOperation<GenericResource> StartAddTag(string key, string value, Cance
/// <inheritdoc/>
public async Task<ArmOperation<GenericResource>> StartAddTagAsync(string key, string value, CancellationToken cancellationToken = default)
{
_apiVersion ??= await ClientOptions.ApiVersions.LoadApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
_apiVersion = await ClientOptions.ApiVersions.TyrGetApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
GenericResource resource = await GetResourceAsync(cancellationToken).ConfigureAwait(false);
resource.Data.Tags[key] = value;
var op = await Operations.StartUpdateByIdAsync(Id, _apiVersion, resource.Data, cancellationToken).ConfigureAwait(false);
Expand All @@ -148,7 +150,7 @@ await op.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false),
/// <inheritdoc/>
public override ArmResponse<GenericResource> Get(CancellationToken cancellationToken = default)
{
_apiVersion ??= ClientOptions.ApiVersions.LoadApiVersion(ProviderOperations, Id, cancellationToken);
_apiVersion = ClientOptions.ApiVersions.TyrGetApiVersion(ProviderOperations, Id, cancellationToken);
return new PhArmResponse<GenericResource, ResourceManager.Resources.Models.GenericResource>(
Operations.GetById(Id, _apiVersion, cancellationToken),
v => new GenericResource(this, new GenericResourceData(v)));
Expand All @@ -157,7 +159,7 @@ public override ArmResponse<GenericResource> Get(CancellationToken cancellationT
/// <inheritdoc/>
public override async Task<ArmResponse<GenericResource>> GetAsync(CancellationToken cancellationToken = default)
{
_apiVersion ??= await ClientOptions.ApiVersions.LoadApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
_apiVersion = await ClientOptions.ApiVersions.TyrGetApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
return new PhArmResponse<GenericResource, ResourceManager.Resources.Models.GenericResource>(
await Operations.GetByIdAsync(Id, _apiVersion, cancellationToken).ConfigureAwait(false),
v => new GenericResource(this, new GenericResourceData(v)));
Expand All @@ -177,7 +179,7 @@ protected override void Validate(ResourceIdentifier identifier)
public ArmResponse<GenericResource> SetTags(IDictionary<string, string> tags, CancellationToken cancellationToken = default)
{
GenericResource resource = GetResource();
_apiVersion ??= ClientOptions.ApiVersions.LoadApiVersion(ProviderOperations, Id, cancellationToken);
_apiVersion = ClientOptions.ApiVersions.TyrGetApiVersion(ProviderOperations, Id, cancellationToken);
resource.Data.Tags.ReplaceWith(tags);
return new PhArmResponse<GenericResource, ResourceManager.Resources.Models.GenericResource>(
Operations.StartUpdateById(Id, _apiVersion, resource.Data, cancellationToken).WaitForCompletionAsync(cancellationToken).EnsureCompleted(),
Expand All @@ -187,7 +189,7 @@ public ArmResponse<GenericResource> SetTags(IDictionary<string, string> tags, Ca
/// <inheritdoc/>
public async Task<ArmResponse<GenericResource>> SetTagsAsync(IDictionary<string, string> tags, CancellationToken cancellationToken = default)
{
_apiVersion ??= await ClientOptions.ApiVersions.LoadApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
_apiVersion = await ClientOptions.ApiVersions.TyrGetApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
GenericResource resource = await GetResourceAsync(cancellationToken).ConfigureAwait(false);
resource.Data.Tags.ReplaceWith(tags);
var op = await Operations.StartUpdateByIdAsync(Id, _apiVersion, resource.Data, cancellationToken).ConfigureAwait(false);
Expand All @@ -200,7 +202,7 @@ await op.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false),
public ArmOperation<GenericResource> StartSetTags(IDictionary<string, string> tags, CancellationToken cancellationToken = default)
{
GenericResource resource = GetResource();
_apiVersion ??= ClientOptions.ApiVersions.LoadApiVersion(ProviderOperations, Id, cancellationToken);
_apiVersion = ClientOptions.ApiVersions.TyrGetApiVersion(ProviderOperations, Id, cancellationToken);
resource.Data.Tags.ReplaceWith(tags);
return new PhArmOperation<GenericResource, ResourceManager.Resources.Models.GenericResource>(
Operations.StartUpdateById(Id, _apiVersion, resource.Data, cancellationToken).WaitForCompletionAsync(cancellationToken).EnsureCompleted(),
Expand All @@ -210,7 +212,7 @@ public ArmOperation<GenericResource> StartSetTags(IDictionary<string, string> ta
/// <inheritdoc/>
public async Task<ArmOperation<GenericResource>> StartSetTagsAsync(IDictionary<string, string> tags, CancellationToken cancellationToken = default)
{
_apiVersion ??= await ClientOptions.ApiVersions.LoadApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
_apiVersion = await ClientOptions.ApiVersions.TyrGetApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
GenericResource resource = await GetResourceAsync(cancellationToken).ConfigureAwait(false);
resource.Data.Tags.ReplaceWith(tags);
var op = await Operations.StartUpdateByIdAsync(Id, _apiVersion, resource.Data, cancellationToken).ConfigureAwait(false);
Expand All @@ -223,7 +225,7 @@ await op.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false),
public ArmResponse<GenericResource> RemoveTag(string key, CancellationToken cancellationToken = default)
{
GenericResource resource = GetResource();
_apiVersion ??= ClientOptions.ApiVersions.LoadApiVersion(ProviderOperations, Id, cancellationToken);
_apiVersion = ClientOptions.ApiVersions.TyrGetApiVersion(ProviderOperations, Id, cancellationToken);
resource.Data.Tags.Remove(key);
return new PhArmResponse<GenericResource, ResourceManager.Resources.Models.GenericResource>(
Operations.StartUpdateById(Id, _apiVersion, resource.Data, cancellationToken).WaitForCompletionAsync(cancellationToken).EnsureCompleted(),
Expand All @@ -233,7 +235,7 @@ public ArmResponse<GenericResource> RemoveTag(string key, CancellationToken canc
/// <inheritdoc/>
public async Task<ArmResponse<GenericResource>> RemoveTagAsync(string key, CancellationToken cancellationToken = default)
{
_apiVersion ??= await ClientOptions.ApiVersions.LoadApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
_apiVersion = await ClientOptions.ApiVersions.TyrGetApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
GenericResource resource = await GetResourceAsync(cancellationToken).ConfigureAwait(false);
resource.Data.Tags.Remove(key);
var op = await Operations.StartUpdateByIdAsync(Id, _apiVersion, resource.Data, cancellationToken).ConfigureAwait(false);
Expand All @@ -246,7 +248,7 @@ await op.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false),
public ArmOperation<GenericResource> StartRemoveTag(string key, CancellationToken cancellationToken = default)
{
GenericResource resource = GetResource();
_apiVersion ??= ClientOptions.ApiVersions.LoadApiVersion(ProviderOperations, Id, cancellationToken);
_apiVersion = ClientOptions.ApiVersions.TyrGetApiVersion(ProviderOperations, Id, cancellationToken);
resource.Data.Tags.Remove(key);
return new PhArmOperation<GenericResource, ResourceManager.Resources.Models.GenericResource>(
Operations.StartUpdateById(Id, _apiVersion, resource.Data, cancellationToken).WaitForCompletionAsync(cancellationToken).EnsureCompleted(),
Expand All @@ -256,7 +258,7 @@ public ArmOperation<GenericResource> StartRemoveTag(string key, CancellationToke
/// <inheritdoc/>
public async Task<ArmOperation<GenericResource>> StartRemoveTagAsync(string key, CancellationToken cancellationToken = default)
{
_apiVersion ??= await ClientOptions.ApiVersions.LoadApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
_apiVersion = await ClientOptions.ApiVersions.TyrGetApiVersionAsync(ProviderOperations, Id, cancellationToken).ConfigureAwait(false);
GenericResource resource = await GetResourceAsync(cancellationToken).ConfigureAwait(false);
resource.Data.Tags.Remove(key);
var op = await Operations.StartUpdateByIdAsync(Id, _apiVersion, resource.Data, cancellationToken).ConfigureAwait(false);
Expand Down
Loading