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

Move Providers and ProviderOperations from Azure.ResourceManager.Resources into Azure.ResourceManager.Core-nibhati-5862 #21337

Merged
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
10f6ad0
Change the accessbility to virtual for Resource.Id
Mar 24, 2021
1db5501
merge
nisha-bhatia Apr 1, 2021
e98ceff
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
nisha-bhatia Apr 12, 2021
2846fa4
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
nisha-bhatia Apr 14, 2021
99fa023
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
nisha-bhatia Apr 23, 2021
1937e2a
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
nisha-bhatia May 10, 2021
488c905
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
nisha-bhatia May 18, 2021
150dc73
WIP
nisha-bhatia May 19, 2021
ab64c01
WIP
nisha-bhatia May 20, 2021
16955bf
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
nisha-bhatia May 20, 2021
6fa6c95
WIP
nisha-bhatia May 20, 2021
c5cec5d
wip
nisha-bhatia May 25, 2021
79c4c69
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
nisha-bhatia May 25, 2021
996eaef
Update TenantOperations.cs
nisha-bhatia May 25, 2021
f1c5360
wip
nisha-bhatia May 26, 2021
c3c4890
WIP
nisha-bhatia May 26, 2021
f228390
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
nisha-bhatia Jun 10, 2021
523cb0b
wip
nisha-bhatia Jun 15, 2021
7e050a7
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
nisha-bhatia Jun 15, 2021
d977438
wip
nisha-bhatia Jun 15, 2021
f47937d
wip
nisha-bhatia Jun 16, 2021
b0f057c
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
nisha-bhatia Jun 16, 2021
2d38b31
wip
nisha-bhatia Jun 18, 2021
eccf749
merge
nisha-bhatia Jun 18, 2021
2c1da14
fix formatting
nisha-bhatia Jun 18, 2021
3cef95d
merge
nisha-bhatia Jun 18, 2021
127b0bf
wip
nisha-bhatia Jun 23, 2021
31377e4
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
nisha-bhatia Jun 23, 2021
3b36cc2
Update ProviderContainer.cs
nisha-bhatia Jun 23, 2021
e8d14fe
Update ProviderContainer.cs
nisha-bhatia Jun 23, 2021
ce6f7d9
wip
nisha-bhatia Jun 23, 2021
3d31c95
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
nisha-bhatia Jun 23, 2021
11c7b95
wip
nisha-bhatia Jun 24, 2021
cd7caac
Update ProviderContainerTests.cs
nisha-bhatia Jun 24, 2021
d6c8247
wip
nisha-bhatia Jun 25, 2021
8beab8c
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
nisha-bhatia Jun 25, 2021
c785fe3
wip
nisha-bhatia Jun 25, 2021
2cabad7
update to interceptor to handle targetinvocation on a failed task
m-nash Jun 25, 2021
8c3e7ac
remove expand parameter from LoadApiVersion methods
nisha-bhatia Jun 28, 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Castle.DynamicProxy;
Expand Down Expand Up @@ -39,11 +40,25 @@ public void Intercept(IInvocation invocation)
var taskResultType = type.GetGenericArguments()[0];
if (taskResultType.Name.StartsWith("Response"))
{
var taskResult = result.GetType().GetProperty("Result").GetValue(result);
var instrumentedResult = _testBase.InstrumentClient(taskResultType, taskResult, new IInterceptor[] { new ManagementInterceptor(_testBase) });
invocation.ReturnValue = type.Name.StartsWith("ValueTask")
? GetValueFromValueTask(taskResultType, instrumentedResult)
: GetValueFromOther(taskResultType, instrumentedResult);
try
{
var taskResult = result.GetType().GetProperty("Result").GetValue(result);
var instrumentedResult = _testBase.InstrumentClient(taskResultType, taskResult, new IInterceptor[] { new ManagementInterceptor(_testBase) });
invocation.ReturnValue = type.Name.StartsWith("ValueTask")
? GetValueFromValueTask(taskResultType, instrumentedResult)
: GetValueFromOther(taskResultType, instrumentedResult);
}
catch (TargetInvocationException e)
{
if (e.InnerException is AggregateException aggException)
{
throw aggException.InnerExceptions.First();
}
else
{
throw e.InnerException;
}
}
}
}
else if (invocation.Method.Name.EndsWith("Value") && type.BaseType.Name.EndsWith("Operations"))
Expand Down
32 changes: 13 additions & 19 deletions sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;

namespace Azure.ResourceManager.Core
{
Expand All @@ -20,7 +18,7 @@ namespace Azure.ResourceManager.Core
/// </summary>
public class ApiVersions
{
private ProvidersOperations ProviderOperations;
private ArmClient _armClient;
private ArmClientOptions _clientOptions;

/// <summary>
Expand All @@ -30,19 +28,15 @@ internal ApiVersions(ArmClientOptions clientOptions)
{
BuildApiTable(clientOptions);
_clientOptions = clientOptions;
ProviderOperations = null;
_armClient = null;
}

/// <summary>
/// Make a provider resource client class.
/// </summary>
internal void SetProviderClient(TokenCredential credential, Uri baseUri, string subscription)
internal void SetProviderClient(ArmClient armClient)
{
ProviderOperations = new ResourcesManagementClient(
baseUri,
subscription,
credential,
_clientOptions.Convert<ResourcesManagementClientOptions>()).Providers;
_armClient = armClient; ;
}

private ConcurrentDictionary<string, PropertyWrapper> _loadedResourceToApiVersions = new ConcurrentDictionary<string, PropertyWrapper>();
Expand Down Expand Up @@ -84,18 +78,18 @@ where method.GetParameters()[0].ParameterType == typeof(ArmClientOptions)
return results;
}

private string LoadApiVersion(ResourceType resourceType, CancellationToken cancellationToken)
private string LoadApiVersion(ResourceType resourceType, CancellationToken cancellationToken, string expand = null)
{
Response<Provider> results;
try
{
results = ProviderOperations.Get(resourceType.Namespace, null, cancellationToken);
results = _armClient.DefaultSubscription.GetProviders().Get(resourceType.Namespace, expand, cancellationToken);
}
catch (RequestFailedException ex) when (ex.Status == 404)
{
return null;
}
foreach (var type in results.Value.ResourceTypes)
foreach (var type in results.Value.Data.ResourceTypes)
{
if (type.ResourceType.Equals(resourceType.Type))
{
Expand All @@ -106,18 +100,18 @@ private string LoadApiVersion(ResourceType resourceType, CancellationToken cance
return null;
}

private async Task<string> LoadApiVersionAsync(ResourceType resourceType, CancellationToken cancellationToken)
private async Task<string> LoadApiVersionAsync(ResourceType resourceType, CancellationToken cancellationToken, string expand = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need of exposing expand for List/LoadApiVersion.

{
Response<Provider> results;
try
{
results = await ProviderOperations.GetAsync(resourceType.Namespace, null, cancellationToken).ConfigureAwait(false);
results = await _armClient.DefaultSubscription.GetProviders().GetAsync(resourceType.Namespace, expand, cancellationToken).ConfigureAwait(false);
}
catch (RequestFailedException ex) when (ex.Status == 404)
{
return null;
}
foreach (var type in results.Value.ResourceTypes)
foreach (var type in results.Value.Data.ResourceTypes)
{
if (type.ResourceType.Equals(resourceType.Type))
{
Expand All @@ -138,7 +132,7 @@ public string TryGetApiVersion(ResourceType resourceType, CancellationToken canc
{
return val;
}
return ProviderOperations == null ? null : LoadApiVersion(resourceType.ToString(), cancellationToken);
return _armClient == null ? null : LoadApiVersion(resourceType.ToString(), cancellationToken);
}

/// <summary>
Expand All @@ -151,7 +145,7 @@ public async Task<string> TryGetApiVersionAsync(ResourceType resourceType, Cance
{
return val;
}
return ProviderOperations == null ? null : await LoadApiVersionAsync(resourceType.ToString(), cancellationToken).ConfigureAwait(false);
return _armClient == null ? null : await LoadApiVersionAsync(resourceType.ToString(), cancellationToken).ConfigureAwait(false);
}

private bool TryGetApiVersion(string resourceType, out string val)
Expand Down Expand Up @@ -190,7 +184,7 @@ public void SetApiVersion(ResourceType resourceType, string apiVersion)
internal ApiVersions Clone()
{
ApiVersions copy = new ApiVersions(_clientOptions);
copy.ProviderOperations = ProviderOperations;
copy._armClient = _armClient;
copy._loadedResourceToApiVersions = new ConcurrentDictionary<string, PropertyWrapper>(_loadedResourceToApiVersions);
copy._nonLoadedResourceToApiVersion = new ConcurrentDictionary<string, string>(_nonLoadedResourceToApiVersion);
return copy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private ArmClient(
DefaultSubscription = string.IsNullOrWhiteSpace(defaultSubscriptionId)
? GetDefaultSubscription()
: GetSubscriptions().TryGet(defaultSubscriptionId);
ClientOptions.ApiVersions.SetProviderClient(credential, baseUri, defaultSubscriptionId ?? DefaultSubscription.Id.SubscriptionId);
ClientOptions.ApiVersions.SetProviderClient(this);
}

/// <summary>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading