Skip to content

Commit

Permalink
remove resources dependency (#22293)
Browse files Browse the repository at this point in the history
* wip

* remove remaining references to azure.resourcemanager.resources

* update tests to handle new changes

* update summary for gets or sets
  • Loading branch information
m-nash authored Jun 29, 2021
1 parent ddf31a6 commit 2529732
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 128 deletions.
1 change: 0 additions & 1 deletion eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
<PackageReference Update="Azure.Security.KeyVault.Keys" Version="4.0.2" />
<PackageReference Update="Azure.Security.KeyVault.Certificates" Version="4.0.2" />
<PackageReference Update="Azure.Storage.Blobs" Version="12.8.0" />
<PackageReference Update="Azure.ResourceManager.Resources" Version="1.0.0-preview.2" />

<!-- Other approved packages -->
<PackageReference Update="Microsoft.Azure.Amqp" Version="2.4.13" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
<IncludeGeneratorSharedCode>true</IncludeGeneratorSharedCode>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.ResourceManager.Resources" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(AzureCoreSharedSources)ForwardsClientCallsAttribute.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
</ItemGroup>
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.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using Azure.Core;
using Azure.Core.Pipeline;
using Azure.ResourceManager.Resources;

namespace Azure.ResourceManager.Core
{
Expand All @@ -13,6 +12,8 @@ namespace Azure.ResourceManager.Core
/// </summary>
public abstract class OperationsBase
{
private ProviderContainer _providerContainer;

/// <summary>
/// Initializes a new instance of the <see cref="OperationsBase"/> class for mocking.
/// </summary>
Expand Down Expand Up @@ -47,6 +48,16 @@ internal OperationsBase(ClientContext clientContext, ResourceIdentifier id)
Validate(id);
}

/// <summary>
/// Gets the provider operations.
/// </summary>
protected ProviderContainer ProviderContainer => _providerContainer ??= GetProviderContainer();

private ProviderContainer GetProviderContainer()
{
return new ProviderContainer(this);
}

internal ClientDiagnostics Diagnostics { get; }

/// <summary>
Expand Down Expand Up @@ -80,23 +91,6 @@ internal OperationsBase(ClientContext clientContext, ResourceIdentifier id)
/// <returns> A valid Azure resource type. </returns>
protected abstract ResourceType ValidResourceType { get; }

/// <summary>
/// Gets the resource client.
/// </summary>
protected ResourcesManagementClient ResourcesClient
{
get
{
string subscription;
if (!Id.TryGetSubscriptionId(out subscription))
{
subscription = Guid.Empty.ToString();
}

return new ResourcesManagementClient(BaseUri, subscription, Credential, ClientOptions.Convert<ResourcesManagementClientOptions>());
}
}

/// <summary>
/// Validate the resource identifier against current operations.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ protected virtual async Task<TOperations> GetResourceAsync(CancellationToken can
/// <returns> A collection of location that may take multiple service requests to iterate over. </returns>
protected IEnumerable<LocationData> ListAvailableLocations(ResourceType resourceType, CancellationToken cancellationToken = default)
{
var pageableProvider = ResourcesClient.Providers.List(expand: "metadata", cancellationToken: cancellationToken);
var resourcePageableProvider = pageableProvider.FirstOrDefault(p => string.Equals(p.Namespace, resourceType?.Namespace, StringComparison.InvariantCultureIgnoreCase));
var pageableProvider = ProviderContainer.List(expand: "metadata", cancellationToken: cancellationToken);
var resourcePageableProvider = pageableProvider.FirstOrDefault(p => string.Equals(p.Data.Namespace, resourceType?.Namespace, StringComparison.InvariantCultureIgnoreCase));
if (resourcePageableProvider is null)
throw new InvalidOperationException($"{resourceType.Type} not found for {resourceType.Namespace}");
var theResource = resourcePageableProvider.ResourceTypes.FirstOrDefault(r => resourceType.Type.Equals(r.ResourceType));
var theResource = resourcePageableProvider.Data.ResourceTypes.FirstOrDefault(r => resourceType.Type.Equals(r.ResourceType));
if (theResource is null)
throw new InvalidOperationException($"{resourceType.Type} not found for {resourceType.Type}");
return theResource.Locations.Select(l => (LocationData)l);
Expand All @@ -137,13 +137,13 @@ protected IEnumerable<LocationData> ListAvailableLocations(ResourceType resource
/// <returns> A collection of location that may take multiple service requests to iterate over. </returns>
protected async Task<IEnumerable<LocationData>> ListAvailableLocationsAsync(ResourceType resourceType, CancellationToken cancellationToken = default)
{
var pageableProvider = ResourcesClient.Providers.ListAsync(expand: "metadata", cancellationToken: cancellationToken);
var pageableProvider = ProviderContainer.ListAsync(expand: "metadata", cancellationToken: cancellationToken);
var resourcePageableProvider = await pageableProvider.FirstOrDefaultAsync(
p => string.Equals(p.Namespace, resourceType?.Namespace, StringComparison.InvariantCultureIgnoreCase),
p => string.Equals(p.Data.Namespace, resourceType?.Namespace, StringComparison.InvariantCultureIgnoreCase),
cancellationToken).ConfigureAwait(false);
if (resourcePageableProvider is null)
throw new InvalidOperationException($"{resourceType.Type} not found for {resourceType.Namespace}");
var theResource = resourcePageableProvider.ResourceTypes.FirstOrDefault(r => resourceType.Type.Equals(r.ResourceType));
var theResource = resourcePageableProvider.Data.ResourceTypes.FirstOrDefault(r => resourceType.Type.Equals(r.ResourceType));
if (theResource is null)
throw new InvalidOperationException($"{resourceType.Type} not found for {resourceType.Type}");
return theResource.Locations.Select(l => (LocationData)l);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ protected static GenericResourceData ConstructGenericAvailabilitySet()
{
var data = new GenericResourceData();
data.Location = LocationData.WestUS2;
data.Sku = new Sku("Aligned");
data.Sku = new Sku();
data.Sku.Name = "Aligned";
var propertyBag = new Dictionary<string, object>();
propertyBag.Add("platformUpdateDomainCount", 5);
propertyBag.Add("platformFaultDomainCount", 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void SerializationTestType1()
string expected = File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "Unit", "TestAssets", "GenericResourceData", "SerializationTestType1.json"));
ResourceGroupResourceIdentifier id = Id;
Plan plan = new Plan("NameForPlan", "PublisherForPlan", "ProductForPlan", "PromotionCodeForPlan", "VersionForPlan");
Sku sku = new Sku("NameForSku", "TierForSku", "FamilyForSku", "SizeForSku", 15464547);
Sku sku = new Sku("NameForSku", "TierForSku", "SizeForSku", "FamilyForSku", "ModelForSku", 15464547);
GenericResourceData data = new GenericResourceData(id, id.Name, id.ResourceType, LocationData.EastUS, null, plan, null, "KindForResource", "ManagedByForResource", sku, null);

var json = JsonHelper.SerializePropertiesToString(data, indented: true) + Environment.NewLine;
Expand All @@ -34,7 +34,7 @@ public void SerializationTestType2()
var plan = new Plan("NameForPlan", "PublisherForPlan", "ProductForPlan", "PromotionCodeForPlan", "VersionForPlan");
var kind = "KindForResource";
var managedBy = "ManagedByForResource";
var sku = new Sku("NameForSku", "TierForSku", "FamilyForSku", "SizeForSku", 15464547);
var sku = new Sku("NameForSku", "TierForSku", "SizeForSku", "FamilyForSku", "ModelForSku", 15464547);
GenericResourceData genericResource = new GenericResourceData(id, id.Name, id.ResourceType, LocationData.EastUS, null, plan, null, kind, managedBy, sku, null);
genericResource.Tags.Add("key1", "value1");
genericResource.Tags.Add("key2", "value2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private static Plan GetPlan()

private static Sku GetSku()
{
return new Sku("name", "tier", "family", "size", 10);
return new Sku("name", "tier", "family", "size", "model", 10);
}

private static GenericResourceData GetGenericResource()
Expand Down
Loading

0 comments on commit 2529732

Please sign in to comment.