Skip to content

Commit

Permalink
fix(adf): DataFactoryResource.GetPipelineRuns cannot do pagination (#…
Browse files Browse the repository at this point in the history
…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) <[email protected]>
  • Loading branch information
archerzz and Mingzhe Huang (from Dev Box) authored Feb 29, 2024
1 parent 7bf9877 commit ac91637
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Query pipeline runs in the factory based on input filter conditions.
/// <list type="bullet">
/// <item>
/// <term>Request Path</term>
/// <description>/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/queryPipelineRuns</description>
/// </item>
/// <item>
/// <term>Operation Id</term>
/// <description>PipelineRuns_QueryByFactory</description>
/// </item>
/// <item>
/// <term>Default Api Version</term>
/// <description>2018-06-01</description>
/// </item>
/// </list>
/// </summary>
/// <param name="content"> Parameters to filter the pipeline run. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception>
/// <returns> An async collection of <see cref="DataFactoryPipelineRunInfo"/> that may take multiple service requests to iterate over. </returns>
public virtual AsyncPageable<DataFactoryPipelineRunInfo> 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);
}

/// <summary>
/// Query pipeline runs in the factory based on input filter conditions.
/// <list type="bullet">
/// <item>
/// <term>Request Path</term>
/// <description>/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/queryPipelineRuns</description>
/// </item>
/// <item>
/// <term>Operation Id</term>
/// <description>PipelineRuns_QueryByFactory</description>
/// </item>
/// <item>
/// <term>Default Api Version</term>
/// <description>2018-06-01</description>
/// </item>
/// </list>
/// </summary>
/// <param name="content"> Parameters to filter the pipeline run. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception>
/// <returns> A collection of <see cref="DataFactoryPipelineRunInfo"/> that may take multiple service requests to iterate over. </returns>
public virtual Pageable<DataFactoryPipelineRunInfo> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

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
@@ -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}");
}
}
}

0 comments on commit ac91637

Please sign in to comment.