From ac9163797f3f702ec28d7d88b310d8b8da2f0aac Mon Sep 17 00:00:00 2001 From: Mingzhe Huang Date: Thu, 29 Feb 2024 12:20:56 +0900 Subject: [PATCH] fix(adf): `DataFactoryResource.GetPipelineRuns` cannot do pagination (#42247) - add customization codes to implement the non-standard pagination logic of `DataFactoryResource.GetPipelineRuns` - add test fix #39438 --------- Co-authored-by: Mingzhe Huang (from Dev Box) --- .../src/Customized/DataFactoryResource.cs | 80 +++++++++++++++++++ .../PipelineRunsRestOperations.cs | 37 +++++++++ .../src/Generated/DataFactoryResource.cs | 64 --------------- .../Scenario/DataFactoryPipelineRunTests.cs | 40 ++++++++++ 4 files changed, 157 insertions(+), 64 deletions(-) create mode 100644 sdk/datafactory/Azure.ResourceManager.DataFactory/src/Customized/DataFactoryResource.cs create mode 100644 sdk/datafactory/Azure.ResourceManager.DataFactory/src/Customized/RestOperations/PipelineRunsRestOperations.cs create mode 100644 sdk/datafactory/Azure.ResourceManager.DataFactory/tests/Scenario/DataFactoryPipelineRunTests.cs diff --git a/sdk/datafactory/Azure.ResourceManager.DataFactory/src/Customized/DataFactoryResource.cs b/sdk/datafactory/Azure.ResourceManager.DataFactory/src/Customized/DataFactoryResource.cs new file mode 100644 index 0000000000000..640aae3626a2b --- /dev/null +++ b/sdk/datafactory/Azure.ResourceManager.DataFactory/src/Customized/DataFactoryResource.cs @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading; +using Autorest.CSharp.Core; +using Azure.Core; +using Azure.ResourceManager.DataFactory.Models; + +namespace Azure.ResourceManager.DataFactory +{ + public partial class DataFactoryResource : ArmResource + { + /// + /// Query pipeline runs in the factory based on input filter conditions. + /// + /// + /// Request Path + /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/queryPipelineRuns + /// + /// + /// Operation Id + /// PipelineRuns_QueryByFactory + /// + /// + /// Default Api Version + /// 2018-06-01 + /// + /// + /// + /// Parameters to filter the pipeline run. + /// The cancellation token to use. + /// is null. + /// An async collection of that may take multiple service requests to iterate over. + public virtual AsyncPageable GetPipelineRunsAsync(RunFilterContent content, CancellationToken cancellationToken = default) + { + if (content == null) + { + throw new ArgumentNullException(nameof(content)); + } + + HttpMessage FirstPageRequest(int? pageSizeHint) => _pipelineRunsRestClient.CreateQueryByFactoryRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, content); + HttpMessage NextPageRequest(int? pageSizeHint, string continuationToken) => _pipelineRunsRestClient.CreateQueryByFactoryNextPageRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, content, continuationToken); + return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => DataFactoryPipelineRunInfo.DeserializeDataFactoryPipelineRunInfo(e), _pipelineRunsClientDiagnostics, Pipeline, "DataFactoryResource.GetPipelineRuns", "value", "continuationToken", cancellationToken); + } + + /// + /// Query pipeline runs in the factory based on input filter conditions. + /// + /// + /// Request Path + /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/queryPipelineRuns + /// + /// + /// Operation Id + /// PipelineRuns_QueryByFactory + /// + /// + /// Default Api Version + /// 2018-06-01 + /// + /// + /// + /// Parameters to filter the pipeline run. + /// The cancellation token to use. + /// is null. + /// A collection of that may take multiple service requests to iterate over. + public virtual Pageable GetPipelineRuns(RunFilterContent content, CancellationToken cancellationToken = default) + { + if (content == null) + { + throw new ArgumentNullException(nameof(content)); + } + + HttpMessage FirstPageRequest(int? pageSizeHint) => _pipelineRunsRestClient.CreateQueryByFactoryRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, content); + HttpMessage NextPageRequest(int? pageSizeHint, string continuationToken) => _pipelineRunsRestClient.CreateQueryByFactoryNextPageRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, content, continuationToken); + return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => DataFactoryPipelineRunInfo.DeserializeDataFactoryPipelineRunInfo(e), _pipelineRunsClientDiagnostics, Pipeline, "DataFactoryResource.GetPipelineRuns", "value", "continuationToken", cancellationToken); + } + } +} diff --git a/sdk/datafactory/Azure.ResourceManager.DataFactory/src/Customized/RestOperations/PipelineRunsRestOperations.cs b/sdk/datafactory/Azure.ResourceManager.DataFactory/src/Customized/RestOperations/PipelineRunsRestOperations.cs new file mode 100644 index 0000000000000..ddfc0cc8dfc1d --- /dev/null +++ b/sdk/datafactory/Azure.ResourceManager.DataFactory/src/Customized/RestOperations/PipelineRunsRestOperations.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; +using Azure.ResourceManager.DataFactory.Models; + +namespace Azure.ResourceManager.DataFactory +{ + internal partial class PipelineRunsRestOperations + { + internal HttpMessage CreateQueryByFactoryNextPageRequest(string subscriptionId, string resourceGroupName, string factoryName, RunFilterContent content, string continuationToken) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId, true); + uri.AppendPath("/resourceGroups/", false); + uri.AppendPath(resourceGroupName, true); + uri.AppendPath("/providers/Microsoft.DataFactory/factories/", false); + uri.AppendPath(factoryName, true); + uri.AppendPath("/queryPipelineRuns", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + var content0 = new Utf8JsonRequestContent(); + // copy filter parameters, and set continuation token + content0.JsonWriter.WriteObjectValue(new RunFilterContent(continuationToken, content.LastUpdatedAfter, content.LastUpdatedBefore, content.Filters, content.OrderBy, null)); + request.Content = content0; + _userAgent.Apply(message); + return message; + } + } +} diff --git a/sdk/datafactory/Azure.ResourceManager.DataFactory/src/Generated/DataFactoryResource.cs b/sdk/datafactory/Azure.ResourceManager.DataFactory/src/Generated/DataFactoryResource.cs index d8c95f606693f..5f90d10984967 100644 --- a/sdk/datafactory/Azure.ResourceManager.DataFactory/src/Generated/DataFactoryResource.cs +++ b/sdk/datafactory/Azure.ResourceManager.DataFactory/src/Generated/DataFactoryResource.cs @@ -1501,70 +1501,6 @@ public virtual Response GetExposureControlFeatures(E } } - /// - /// Query pipeline runs in the factory based on input filter conditions. - /// - /// - /// Request Path - /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/queryPipelineRuns - /// - /// - /// Operation Id - /// PipelineRuns_QueryByFactory - /// - /// - /// Default Api Version - /// 2018-06-01 - /// - /// - /// - /// Parameters to filter the pipeline run. - /// The cancellation token to use. - /// is null. - /// An async collection of that may take multiple service requests to iterate over. - public virtual AsyncPageable GetPipelineRunsAsync(RunFilterContent content, CancellationToken cancellationToken = default) - { - if (content == null) - { - throw new ArgumentNullException(nameof(content)); - } - - HttpMessage FirstPageRequest(int? pageSizeHint) => _pipelineRunsRestClient.CreateQueryByFactoryRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, content); - return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, e => DataFactoryPipelineRunInfo.DeserializeDataFactoryPipelineRunInfo(e), _pipelineRunsClientDiagnostics, Pipeline, "DataFactoryResource.GetPipelineRuns", "value", null, cancellationToken); - } - - /// - /// Query pipeline runs in the factory based on input filter conditions. - /// - /// - /// Request Path - /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/queryPipelineRuns - /// - /// - /// Operation Id - /// PipelineRuns_QueryByFactory - /// - /// - /// Default Api Version - /// 2018-06-01 - /// - /// - /// - /// Parameters to filter the pipeline run. - /// The cancellation token to use. - /// is null. - /// A collection of that may take multiple service requests to iterate over. - public virtual Pageable GetPipelineRuns(RunFilterContent content, CancellationToken cancellationToken = default) - { - if (content == null) - { - throw new ArgumentNullException(nameof(content)); - } - - HttpMessage FirstPageRequest(int? pageSizeHint) => _pipelineRunsRestClient.CreateQueryByFactoryRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, content); - return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, e => DataFactoryPipelineRunInfo.DeserializeDataFactoryPipelineRunInfo(e), _pipelineRunsClientDiagnostics, Pipeline, "DataFactoryResource.GetPipelineRuns", "value", null, cancellationToken); - } - /// /// Get a pipeline run by its run ID. /// diff --git a/sdk/datafactory/Azure.ResourceManager.DataFactory/tests/Scenario/DataFactoryPipelineRunTests.cs b/sdk/datafactory/Azure.ResourceManager.DataFactory/tests/Scenario/DataFactoryPipelineRunTests.cs new file mode 100644 index 0000000000000..614842122b8a9 --- /dev/null +++ b/sdk/datafactory/Azure.ResourceManager.DataFactory/tests/Scenario/DataFactoryPipelineRunTests.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.TestFramework; +using Azure.ResourceManager.DataFactory.Models; +using NUnit.Framework; + +namespace Azure.ResourceManager.DataFactory.Tests.Scenario +{ + internal class DataFactoryPipelineRunTests : DataFactoryManagementTestBase + { + public DataFactoryPipelineRunTests(bool isAsync) : base(isAsync) + { + } + + [Test] + [RecordedTest] + [Ignore("Pending recording")] + public async Task GetPipelineRuns() + { + string subscriptionId = "xxx"; + string resourceGroupName = "test"; + string factoryName = "test"; + ResourceIdentifier dataFactoryResourceId = DataFactoryResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, factoryName); + DataFactoryResource dataFactory = GetArmClient().GetDataFactoryResource(dataFactoryResourceId); + + RunFilterContent content = new RunFilterContent(DateTimeOffset.Parse("2024-02-27T00:36:44.3345758Z"), DateTimeOffset.Parse("2024-06-16T00:49:48.3686473Z")); + int count = 0; + await foreach (DataFactoryPipelineRunInfo item in dataFactory.GetPipelineRunsAsync(content)) + { + count++; + } + + Console.WriteLine($"Total count: {count}"); + } + } +}