Skip to content

Comments

Add [Resource]Container class#1180

Merged
m-nash merged 38 commits intoAzure:feature/v3from
isra-fel:container
May 17, 2021
Merged

Add [Resource]Container class#1180
m-nash merged 38 commits intoAzure:feature/v3from
isra-fel:container

Conversation

@isra-fel
Copy link
Member

@isra-fel isra-fel commented Apr 20, 2021

Description

Now the mgmt track 2 generator generates meaningful [Resource]Container classes.

This will be opened as draft for some early review. At the meantime I need to resolve some todo's and refactoring.
CI is expected to fail as this is pending Azure/azure-sdk-for-net#20524

Checklist

To ensure a quick review and merge, please ensure:

  • The PR has a understandable title and description explaining the why and what.
  • The PR is opened in draft if not ready for review yet.
    • If opened in draft, please allocate sufficient time (24 hours) after moving out of draft for review
  • The branch is recent enough to not have merge conflicts upon creation.

Ready to Land?

  • Build is completely green
    • Submissions with test failures require tracking issue and approval of a CODEOWNER
  • At least one +1 review by a CODEOWNER
  • All -1 reviews are confirmed resolved by the reviewer
    • Override/Marking reviews stale must be discussed with CODEOWNERS first

@isra-fel isra-fel marked this pull request as draft April 20, 2021 16:14
@isra-fel isra-fel added the Mgmt This issue is related to a management-plane library. label Apr 20, 2021
@isra-fel
Copy link
Member Author

/azp run autorest.csharp - ci

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@isra-fel isra-fel force-pushed the container branch 2 times, most recently from d56675b to 26e0fc7 Compare May 10, 2021 10:00
private BlobContainersRestOperations _restClient => new BlobContainersRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId);

/// <summary> Typed Resource Identifier for the container. </summary>
public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier;
Copy link
Member

Choose a reason for hiding this comment

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

This new shouldn't be needed

Copy link
Member Author

Choose a reason for hiding this comment

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

Without the new, Id is just a ResourceIdentifier inherited from OperationBase. We need to cast it either here or at the level of ContainerBase

Copy link
Member Author

@isra-fel isra-fel May 12, 2021

Choose a reason for hiding this comment

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

A PR to arm.core
Though the original plan was to do the type conversion in OpeationsBase but problem is, TIdentifier has different meaning in Operation and Container.
Michael said he'll consider that later

/// <summary> Initializes a new instance of <see cref = "BlobContainerOperations"/> class. </summary>
/// <summary> Initializes a new instance of the <see cref="BlobContainerOperations"/> class. </summary>
/// <param name="genericOperations"> An instance of <see cref="GenericResourceOperations"/> that has an id for a {todo: availability set}. </param>
internal BlobContainerOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this constructor is needed

Copy link
Member Author

@isra-fel isra-fel May 11, 2021

Choose a reason for hiding this comment

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

When user lists resource with name filter, we list them as generic resource and create resource instances from the generic resources.

internal class RestClientMethod
{
public RestClientMethod(string name, string? description, CSharpType? returnType, Request request, Parameter[] parameters, Response[] responses, DataPlaneResponseHeaderGroupType? headerModel, bool bufferResponse, string accessibility)
public RestClientMethod(string name, string? description, CSharpType? returnType, Request request, Parameter[] parameters, Response[] responses, DataPlaneResponseHeaderGroupType? headerModel, bool bufferResponse, string accessibility, Operation? operation = null)
Copy link
Member Author

Choose a reason for hiding this comment

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

In order to get the Operation object in container writer, I keep a reference to it in every RestClientMethod.
This is safe because every RestClientMethod is built from an Operation.
My only concern is if I should touch LowLevelClientMethod which inherits RestClientMethod to also add Operation to its constructor. see https://github.com/Azure/autorest.csharp/blob/feature/v3/src/AutoRest.CSharp/LowLevel/Output/LowLevelClientMethod.cs#L11

@isra-fel isra-fel marked this pull request as ready for review May 14, 2021 17:05
@isra-fel isra-fel requested a review from allenjzhang as a code owner May 14, 2021 17:05
/// <param name="containerName"> The name of the blob container within the specified storage account. Blob container names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. </param>
/// <param name="blobContainer"> Properties of the blob container to create. </param>
/// <param name="cancellationToken"> A token to allow the caller to cancel the call to the service. The default value is <see cref="P:System.Threading.CancellationToken.None" />. </param>
public Operation<BlobContainer> StartCreateOrUpdate(string containerName, BlobContainerData blobContainer, CancellationToken cancellationToken = default)
Copy link
Member

Choose a reason for hiding this comment

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

need to change the reaponse type to be the LRO object

throw new ArgumentNullException(nameof(blobContainer));
}

return StartCreateOrUpdate(containerName, blobContainer, cancellationToken: cancellationToken).WaitForCompletion() as Response<BlobContainer>;
Copy link
Member

Choose a reason for hiding this comment

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

after response type change call waitforcompletion here

else if (IsStringLike(parameter.Type) && IsMandatory(parameter))
{
passThru = false;
if (string.Equals(parameter.Name, "resourceGroupName", StringComparison.InvariantCultureIgnoreCase))
Copy link
Member

Choose a reason for hiding this comment

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

Why are only checking resourceGroupName here? It could be subscriptionId, location ..etc

writer.WriteXmlDocumentationSummary($"Initializes a new instance of {resourceOperation.Type.Name} for mocking.");
using (writer.Scope($"protected {resourceOperation.Type.Name}()"))
{
var typeOfThis = resourceOperation.Type.Name;
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't use the name here. We should use the Type.

- remove outdated LRO writer
- move `IsResource` to `ResourceData`
- find Get rest method by prefix ("Get*") instead of just full match
  - this made `BlobServiceContainer` inheirt `ResourceContainerBase` corrrectly
  - and use the method name instead of hard code "Get"
- WaitForCompletionAsync
- empty lines at file end
@m-nash m-nash merged commit d3ffd61 into Azure:feature/v3 May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Mgmt This issue is related to a management-plane library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants