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

combine resource and resource operations classes #23205

Merged
merged 14 commits into from
Aug 11, 2021
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected void CleanupResourceGroups()
{
try
{
_cleanupClient.GetManagementGroupOperations(mgmtGroupId).StartDelete();
_cleanupClient.GetManagementGroup(mgmtGroupId).StartDelete();
}
catch (RequestFailedException e) when (e.Status == 404 || e.Status == 403)
{
Expand Down Expand Up @@ -206,7 +206,7 @@ public void OneTimeCleanupResourceGroups()
});
Parallel.ForEach(OneTimeManagementGroupCleanupPolicy.ManagementGroupsCreated, mgmtGroupId =>
{
_cleanupClient.GetManagementGroupOperations(mgmtGroupId).StartDelete();
_cleanupClient.GetManagementGroup(mgmtGroupId).StartDelete();
});
}

Expand Down
54 changes: 32 additions & 22 deletions sdk/resourcemanager/Azure.ResourceManager/src/ArmClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ArmClient
/// The base URI of the service.
/// </summary>
internal const string DefaultUri = "https://management.azure.com";
private TenantOperations _tenant;
private Tenant _tenant;

/// <summary>
/// Initializes a new instance of the <see cref="ArmClient"/> class for mocking.
Expand Down Expand Up @@ -106,7 +106,7 @@ public ArmClient(
ClientOptions = options?.Clone() ?? new ArmClientOptions();
Pipeline = ManagementPipelineBuilder.Build(Credential, options.Scope, options ?? ClientOptions);

_tenant = new TenantOperations(ClientOptions, Credential, BaseUri, Pipeline);
_tenant = new Tenant(ClientOptions, Credential, BaseUri, Pipeline);
DefaultSubscription = string.IsNullOrWhiteSpace(defaultSubscriptionId)
? GetDefaultSubscription()
: GetSubscriptions().GetIfExists(defaultSubscriptionId);
m-nash marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -157,40 +157,50 @@ public virtual TenantContainer GetTenants()
/// Gets a resource group operations object.
/// </summary>
/// <param name="id"> The id of the resourcegroup. </param>
/// <returns> Resource operations of the resource. </returns>
public virtual ResourceGroupOperations GetResourceGroupOperations(string id)
/// <returns> Resource operations of the resourcegroup. </returns>
public virtual ResourceGroup GetResourceGroup(string id)
{
return new ResourceGroupOperations(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), id);
return new ResourceGroup(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), id);
}

/// <summary>
/// Gets a subscription operations object.
/// </summary>
/// <param name="id"> The id of the subscription. </param>
/// <returns> Resource operations of the subscription. </returns>
public virtual SubscriptionOperations GetSubscriptionOperations(string id)
public virtual Subscription GetSubscription(string id)
m-nash marked this conversation as resolved.
Show resolved Hide resolved
{
return new SubscriptionOperations(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), id);
return new Subscription(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), id);
}

/// <summary>
/// Gets a feature operations object.
/// </summary>
/// <param name="id"> The id of the feature. </param>
/// <returns> Resource operations of the feature. </returns>
public virtual FeatureOperations GetFeatureOperations(string id)
public virtual Feature GetFeature(string id)
{
return new FeatureOperations(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), id);
return new Feature(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), id);
}

/// <summary>
/// Gets a feature operations object.
/// Gets a Provider operations object.
/// </summary>
/// <param name="id"> The id of the feature. </param>
/// <returns> Resource operations of the feature. </returns>
public virtual ProviderOperations GetProviderOperations(string id)
/// <param name="id"> The id of the Provider. </param>
/// <returns> Resource operations of the Provider. </returns>
public virtual Provider GetProvider(string id)
{
return new Provider(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), id);
}

/// <summary>
/// Gets a PredefinedTag operations object.
/// </summary>
/// <param name="id"> The id of the PredefinedTag. </param>
/// <returns> Resource operations of the PredefinedTag. </returns>
public virtual PredefinedTag GetPreDefinedTag(string id)
{
return new ProviderOperations(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), id);
return new PredefinedTag(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), id);
}

private Subscription GetDefaultSubscription()
Expand Down Expand Up @@ -219,7 +229,7 @@ public virtual T UseClientContext<T>(Func<Uri, TokenCredential, ArmClientOptions
/// </summary>
/// <param name="ids"> A list of the IDs of the resources to retrieve. </param>
/// <returns> The list of operations that can be performed over the GenericResources. </returns>
public virtual IReadOnlyList<GenericResourceOperations> GetGenericResourceOperations(params string[] ids)
public virtual IReadOnlyList<GenericResource> GetGenericResource(params string[] ids)
{
return GetGenericResourceOperationsInternal(ids);
}
Expand All @@ -229,22 +239,22 @@ public virtual IReadOnlyList<GenericResourceOperations> GetGenericResourceOperat
/// </summary>
/// <param name="ids"> A list of the IDs of the resources to retrieve. </param>
/// <returns> The list of operations that can be performed over the GenericResources. </returns>
public virtual IReadOnlyList<GenericResourceOperations> GetGenericResourceOperations(IEnumerable<string> ids)
public virtual IReadOnlyList<GenericResource> GetGenericResource(IEnumerable<string> ids)
{
return GetGenericResourceOperationsInternal(ids);
}

private IReadOnlyList<GenericResourceOperations> GetGenericResourceOperationsInternal(IEnumerable<string> ids)
private IReadOnlyList<GenericResource> GetGenericResourceOperationsInternal(IEnumerable<string> ids)
{
if (ids == null)
{
throw new ArgumentNullException(nameof(ids));
}

var genericRespirceOperations = new ChangeTrackingList<GenericResourceOperations>();
var genericRespirceOperations = new ChangeTrackingList<GenericResource>();
foreach (string id in ids)
{
genericRespirceOperations.Add(new GenericResourceOperations(DefaultSubscription, id));
genericRespirceOperations.Add(new GenericResource(DefaultSubscription, id));
}
return genericRespirceOperations;
}
Expand All @@ -254,14 +264,14 @@ private IReadOnlyList<GenericResourceOperations> GetGenericResourceOperationsInt
/// </summary>
/// <param name="id"> The id of the resource to retrieve. </param>
/// <returns> The operations that can be performed over a specific GenericResource. </returns>
public virtual GenericResourceOperations GetGenericResourceOperations(string id)
public virtual GenericResource GetGenericResource(string id)
{
if (id == null)
{
throw new ArgumentNullException(nameof(id));
}

return new GenericResourceOperations(DefaultSubscription, id);
return new GenericResource(DefaultSubscription, id);
}

/// <summary>
Expand Down Expand Up @@ -315,6 +325,6 @@ public virtual RestApiContainer GetRestApis(string azureNamespace)
/// </summary>
/// <param name="id"> The id of the management group operations. </param>
/// <returns> A client to perform operations on the management group. </returns>
public virtual ManagementGroupOperations GetManagementGroupOperations(string id) => _tenant.GetManagementGroupOperations(id);
public virtual ManagementGroup GetManagementGroup(string id) => _tenant.GetManagementGroup(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,51 @@ namespace Azure.ResourceManager.Core
/// <summary>
/// Base class representing collection of resources.
/// </summary>
public abstract class ResourceContainer : ResourceOperations
public abstract class ArmContainer : ArmResource
{
/// <summary>
/// Initializes a new instance of the <see cref="ResourceContainer"/> class for mocking.
/// Initializes a new instance of the <see cref="ArmContainer"/> class for mocking.
/// </summary>
protected ResourceContainer()
protected ArmContainer()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ResourceContainer"/> class.
/// Initializes a new instance of the <see cref="ArmContainer"/> class.
/// </summary>
/// <param name="clientContext"></param>
internal ResourceContainer(ClientContext clientContext)
internal ArmContainer(ClientContext clientContext)
: base(clientContext, ResourceIdentifier.RootResourceIdentifier)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ResourceContainer"/> class.
/// Initializes a new instance of the <see cref="ArmContainer"/> class.
/// </summary>
/// <param name="clientContext"></param>
/// <param name="id"> The identifier of the resource that is the target of operations. </param>
internal ResourceContainer(ClientContext clientContext, ResourceIdentifier id)
internal ArmContainer(ClientContext clientContext, ResourceIdentifier id)
: base(clientContext, id)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ResourceContainer"/> class.
/// Initializes a new instance of the <see cref="ArmContainer"/> class.
/// </summary>
/// <param name="options"> The options to use. </param>
/// <param name="credential"> The credential to use. </param>
/// <param name="baseUri"> The base uri to use. </param>
/// <param name="pipeline"> The http pipeline policy to use. </param>
protected ResourceContainer(ArmClientOptions options, TokenCredential credential, Uri baseUri, HttpPipeline pipeline)
protected ArmContainer(ArmClientOptions options, TokenCredential credential, Uri baseUri, HttpPipeline pipeline)
: this(new ClientContext(options, credential, baseUri, pipeline))
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ResourceContainer"/> class.
/// Initializes a new instance of the <see cref="ArmContainer"/> class.
/// </summary>
/// <param name="parent"> The resource representing the parent resource. </param>
protected ResourceContainer(ResourceOperations parent)
protected ArmContainer(ArmResource parent)
: base(new ClientContext(parent.ClientOptions, parent.Credential, parent.BaseUri, parent.Pipeline), parent.Id)
{
Parent = parent;
Expand All @@ -63,6 +63,6 @@ protected ResourceContainer(ResourceOperations parent)
/// <summary>
/// Gets the parent resource of this resource.
/// </summary>
protected ResourceOperations Parent { get; }
protected ArmResource Parent { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,45 @@ namespace Azure.ResourceManager.Core
/// <summary>
/// A class representing the operations that can be performed over a specific resource.
/// </summary>
public abstract class ResourceOperations
public abstract class ArmResource
{
private TagResourceContainer _tagContainer;
private TagResourceOperations _tagResourceOperations;
private TenantOperations _tenant;
private TagResource _tagResourceOperations;
private Tenant _tenant;

/// <summary>
/// Initializes a new instance of the <see cref="ResourceOperations"/> class for mocking.
/// Initializes a new instance of the <see cref="ArmResource"/> class for mocking.
/// </summary>
protected ResourceOperations()
protected ArmResource()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ResourceOperations"/> class.
/// Initializes a new instance of the <see cref="ArmResource"/> class.
/// </summary>
/// <param name="parentOperations"> The resource representing the parent resource. </param>
/// <param name="id"> The identifier of the resource that is the target of operations. </param>
protected ResourceOperations(ResourceOperations parentOperations, ResourceIdentifier id)
protected ArmResource(ArmResource parentOperations, ResourceIdentifier id)
: this(new ClientContext(parentOperations.ClientOptions, parentOperations.Credential, parentOperations.BaseUri, parentOperations.Pipeline), id)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ResourceOperations"/> class.
/// Initializes a new instance of the <see cref="ArmResource"/> class.
/// </summary>
/// <param name="clientContext"></param>
/// <param name="id"> The identifier of the resource that is the target of operations. </param>
internal ResourceOperations(ClientContext clientContext, ResourceIdentifier id)
internal ArmResource(ClientContext clientContext, ResourceIdentifier id)
{
ClientOptions = clientContext.ClientOptions;
Id = id;
Credential = clientContext.Credential;
BaseUri = clientContext.BaseUri;
Pipeline = clientContext.Pipeline;
Diagnostics = new ClientDiagnostics(ClientOptions);
ValidateResourceType(id);
}

internal ClientDiagnostics Diagnostics { get; }

private TenantOperations Tenant => _tenant ??= new TenantOperations(ClientOptions, Credential, BaseUri, Pipeline);
private Tenant Tenant => _tenant ??= new Tenant(ClientOptions, Credential, BaseUri, Pipeline);

/// <summary>
/// Gets the resource identifier.
Expand Down Expand Up @@ -94,7 +91,7 @@ internal ResourceOperations(ClientContext clientContext, ResourceIdentifier id)
/// Gets the TagResourceOperations.
/// </summary>
/// <returns> A TagResourceOperations. </returns>
protected internal TagResourceOperations TagResourceOperations => _tagResourceOperations ??= new TagResourceOperations(this, Id);
protected internal TagResource TagResourceOperations => _tagResourceOperations ??= new TagResource(this, Id);
Copy link
Member

Choose a reason for hiding this comment

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

Can we update TagResourceOperations property name to TagResource?


/// <summary>
/// Gets the TagsOperations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected PredefinedTagCreateOrUpdateOperation()
{
}

internal PredefinedTagCreateOrUpdateOperation(ResourceOperations parentOperation, Response<PredefinedTagData> response)
internal PredefinedTagCreateOrUpdateOperation(ArmResource parentOperation, Response<PredefinedTagData> response)
{
_operation = new OperationOrResponseInternals<PredefinedTag>(Response.FromValue(new PredefinedTag(parentOperation, response.Value), response.GetRawResponse()));
}
Expand Down
Loading