-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Implement mgmt resource #47944
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
Merged
Merged
Implement mgmt resource #47944
Changes from 54 commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
f041f24
wip
live1206 badf1a5
wip
live1206 69fa28a
wip
live1206 615fec1
Merge remote-tracking branch 'origin/main' into implement-mgmt-resource
live1206 d136be2
wip
live1206 a040627
wip
live1206 0296a71
Merge remote-tracking branch 'origin/main' into implement-mgmt-resource
live1206 fda752a
generate operation methods for Resource
live1206 580508a
add package back
live1206 ba12225
Merge remote-tracking branch 'origin/main' into implement-mgmt-resource
live1206 ef83882
update to latest MGC
live1206 120e164
fix test
live1206 e4bbde0
Merge branch 'main' into implement-mgmt-resource
live1206 b2842c4
Add test for ResourceProvider
live1206 5f5cee9
Merge remote-tracking branch 'origin/main' into implement-mgmt-resource
live1206 41cf53c
Add RequestPath
live1206 7bba967
remove unused property
live1206 5d3a879
address comments
live1206 2fe508f
Include custom code for convenience methods
live1206 d9fd368
add TODO
live1206 17b2a0f
merge from main
live1206 45a10a7
implement resource LRO
live1206 b06fb59
implement LRO for resource
live1206 c98e231
Implement IOperationSouce and generated MgmtTypeSpec can build now
live1206 848e6d7
update test data
live1206 0db68cb
Add test for OperationSourceProvider
live1206 2b15650
update tests
live1206 51bd7f3
cleanup
live1206 a8b2b8f
update
live1206 dc2b83d
cleanup
live1206 adbcc1c
Address comments
live1206 bb92673
Add Mgmt-TypeSpec generation to Generate.ps1
live1206 af9bd9c
Merge remote-tracking branch 'origin/main' into implement-mgmt-resource
live1206 c5ca437
Update eng/packages/http-client-csharp/generator/Azure.Generator/src/…
live1206 3ed339d
update
live1206 d800d35
Merge branch 'main' into implement-mgmt-resource
live1206 8d78f7f
fix build
live1206 8fbc8aa
update to use CanonicalView
live1206 081696d
update test
live1206 f9e8afd
Use ModelSerializationExtensions.WireOptions instead of new instance
live1206 8d7b831
update test
live1206 4dcccc7
Address comments
live1206 d00ee3a
typo
live1206 0086b11
Merge remote-tracking branch 'origin/main' into implement-mgmt-resource
live1206 e34db7b
resolve comments
live1206 417af63
fix build
live1206 965e951
update test
live1206 579dd9b
separate tests for ResourceClientProvider
live1206 682e704
Add TODO
live1206 22e08c6
fix tests
live1206 541193c
Move resource related logic to ResourceBuilder
live1206 20cdaaf
Remove clientProvider and implement client methods in Resource directly
live1206 78b5cb5
update
live1206 ff44b6b
simplify resource detection
live1206 33c30fa
Merge branch 'main' into implement-mgmt-resource
live1206 ca43fe6
replace resource detection with decorators
live1206 7ff96ba
cleanup
live1206 34478aa
Apply resourceMetadata decorator for generator to consume
live1206 f6d7776
Merge remote-tracking branch 'upstream/main' into implement-mgmt-reso…
live1206 41721a8
cleanup
live1206 949d5e1
refine
live1206 10ca791
rename
live1206 eb48437
Merge remote-tracking branch 'upstream/main' into implement-mgmt-reso…
live1206 70c212d
merge
live1206 ace3f42
address comments
live1206 4037c12
fix lint and format
live1206 79f2a3f
address comments
live1206 b2ab27a
rename
live1206 98f91a6
set update callback with options
live1206 f691c45
update MTG emitter version
live1206 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 33 additions & 60 deletions
93
eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureOutputLibrary.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,96 +1,69 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Azure.Generator.Mgmt.Models; | ||
| using Azure.Generator.Providers; | ||
| using Azure.Generator.Utilities; | ||
| using Microsoft.TypeSpec.Generator.ClientModel; | ||
| using Microsoft.TypeSpec.Generator.Input; | ||
| using Microsoft.TypeSpec.Generator.Providers; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace Azure.Generator | ||
| { | ||
| /// <inheritdoc/> | ||
| public class AzureOutputLibrary : ScmOutputLibrary | ||
| { | ||
| // TODO: categorize clients into operationSets, which contains operations sharing the same Path | ||
| private Dictionary<string, OperationSet> _pathToOperationSetMap; | ||
| private Dictionary<string, HashSet<OperationSet>> _resourceDataBySpecNameMap; | ||
| private Dictionary<string, InputModelType> _inputTypeMap; | ||
|
|
||
| /// <inheritdoc/> | ||
| public AzureOutputLibrary() | ||
| { | ||
| _pathToOperationSetMap = CategorizeClients(); | ||
| _resourceDataBySpecNameMap = EnsureResourceDataMap(); | ||
| _inputTypeMap = AzureClientPlugin.Instance.InputLibrary.InputNamespace.Models.OfType<InputModelType>().ToDictionary(model => model.Name); | ||
| } | ||
|
|
||
| private Dictionary<string, HashSet<OperationSet>> EnsureResourceDataMap() | ||
| { | ||
| var result = new Dictionary<string, HashSet<OperationSet>>(); | ||
| foreach (var operationSet in _pathToOperationSetMap.Values) | ||
| { | ||
| if (AzureClientPlugin.Instance.ResourceDetection.TryGetResourceDataSchema(operationSet, out var resourceSpecName, out var resourceSchema)) | ||
| { | ||
| // if this operation set corresponds to a SDK resource, we add it to the map | ||
| if (!result.TryGetValue(resourceSpecName!, out HashSet<OperationSet>? value)) | ||
| { | ||
| value = new HashSet<OperationSet>(); | ||
| result.Add(resourceSpecName!, value); | ||
| } | ||
| value.Add(operationSet); | ||
| } | ||
| } | ||
| private LongRunningOperationProvider? _armOperation; | ||
| internal LongRunningOperationProvider ArmOperation => _armOperation ??= new LongRunningOperationProvider(false); | ||
|
|
||
| return result; | ||
| } | ||
| private LongRunningOperationProvider? _genericArmOperation; | ||
| internal LongRunningOperationProvider GenericArmOperation => _genericArmOperation ??= new LongRunningOperationProvider(true); | ||
|
|
||
| private Dictionary<string, OperationSet> CategorizeClients() | ||
| private IReadOnlyList<TypeProvider> BuildResources() | ||
| { | ||
| var result = new Dictionary<string, OperationSet>(); | ||
| foreach (var inputClient in AzureClientPlugin.Instance.InputLibrary.InputNamespace.Clients) | ||
| var result = new List<TypeProvider>(); | ||
| foreach ((InputClient client, string requestPath, bool isSingleton, string requestType, string specName) in AzureClientPlugin.Instance.ResourceBuilder.BuildResourceClients()) | ||
| { | ||
| var requestPathList = new HashSet<string>(); | ||
| foreach (var operation in inputClient.Operations) | ||
| { | ||
| var path = operation.GetHttpPath(); | ||
| requestPathList.Add(path); | ||
| if (result.TryGetValue(path, out var operationSet)) | ||
| { | ||
| operationSet.Add(operation); | ||
| } | ||
| else | ||
| { | ||
| operationSet = new OperationSet(path, inputClient) | ||
| { | ||
| operation | ||
| }; | ||
| result.Add(path, operationSet); | ||
| } | ||
| } | ||
| var resourceData = AzureClientPlugin.Instance.TypeFactory.CreateModel(_inputTypeMap[specName])!; | ||
| var resource = CreateResourceCore(client, requestPath, specName, resourceData, requestType, isSingleton); | ||
| AzureClientPlugin.Instance.AddTypeToKeep(resource.Name); | ||
| result.Add(resource); | ||
| } | ||
|
|
||
| // TODO: add operation set for the partial resources here | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Create a resource client provider | ||
| /// </summary> | ||
| /// <param name="inputClient"></param> | ||
live1206 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// <param name="requestPath"></param> | ||
| /// <param name="schemaName"></param> | ||
| /// <param name="resourceData"></param> | ||
| /// <param name="resourceType"></param> | ||
| /// <param name="isSingleton"></param> | ||
| /// <returns></returns> | ||
| public virtual TypeProvider CreateResourceCore(InputClient inputClient, string requestPath, string schemaName, ModelProvider resourceData, string resourceType, bool isSingleton) | ||
live1206 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| => new ResourceClientProvider(inputClient, requestPath, schemaName, resourceData, resourceType, isSingleton); | ||
|
|
||
| /// <inheritdoc/> | ||
| // TODO: generate resources and collections | ||
| // TODO: generate collections | ||
| protected override TypeProvider[] BuildTypeProviders() | ||
| { | ||
| var baseProviders = base.BuildTypeProviders(); | ||
| if (AzureClientPlugin.Instance.IsAzureArm.Value == true) | ||
| { | ||
| var armOperation = new MgmtLongRunningOperationProvider(false); | ||
| var genericArmOperation = new MgmtLongRunningOperationProvider(true); | ||
|
|
||
| // TODO: remove them once they are referenced in Resource operation implementation | ||
| AzureClientPlugin.Instance.AddTypeToKeep(armOperation.Name); | ||
| AzureClientPlugin.Instance.AddTypeToKeep(genericArmOperation.Name); | ||
| return [.. base.BuildTypeProviders(), new RequestContextExtensionsDefinition(), armOperation, genericArmOperation]; | ||
| var resources = BuildResources(); | ||
| return [.. baseProviders, new RequestContextExtensionsDefinition(), ArmOperation, GenericArmOperation, .. resources, .. resources.Select(r => ((ResourceClientProvider)r).Source)]; | ||
| } | ||
| return [.. base.BuildTypeProviders(), new RequestContextExtensionsDefinition()]; | ||
| return [.. baseProviders, new RequestContextExtensionsDefinition()]; | ||
| } | ||
|
|
||
| internal bool IsResource(string name) => _resourceDataBySpecNameMap.ContainsKey(name); | ||
| } | ||
| } | ||
113 changes: 0 additions & 113 deletions
113
eng/packages/http-client-csharp/generator/Azure.Generator/src/Mgmt/Models/OperationSet.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.