Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Google.Api.Generator.Tests/ProtoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void CleanUp(string path)
public void Paginated0() => ProtoTestSingle("Paginated", ignoreCsProj: true);

[Fact]
public void Lro0() => ProtoTestSingle("Lro", ignoreSnippets: true);
public void Lro0() => ProtoTestSingle("Lro", ignoreSnippets: true, serviceConfigPath: "ServiceConfig.yaml");

[Fact]
public void ServerStreaming0() => ProtoTestSingle("ServerStreaming", ignoreCsProj: true, ignoreSnippets: true);
Expand Down
9 changes: 9 additions & 0 deletions Google.Api.Generator.Tests/ProtoTests/Lro/Lro.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ service Lro {
};
option (google.api.method_signature) = "name";
}

// Test an LRO RPC with polling settings specified in the service config.
rpc ServiceConfigPollingMethod(Request) returns(google.longrunning.Operation) {
option (google.longrunning.operation_info) = {
response_type: "LroResponse"
metadata_type: "LroMetadata"
};
option (google.api.method_signature) = "name";
}
}

message Request {
Expand Down
2 changes: 2 additions & 0 deletions Google.Api.Generator.Tests/ProtoTests/Lro/LroFakes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public LroClient(CallInvoker callInvoker) { }
public virtual Operation SignatureMethod(Request request, CallOptions options) => throw new NotImplementedException();
public virtual AsyncUnaryCall<Operation> ResourcedMethodAsync(ResourceRequest request, CallOptions options) => throw new NotImplementedException();
public virtual Operation ResourcedMethod(ResourceRequest request, CallOptions options) => throw new NotImplementedException();
public virtual AsyncUnaryCall<Operation> ServiceConfigPollingMethodAsync(Request request, CallOptions options) => throw new NotImplementedException();
public virtual Operation ServiceConfigPollingMethod(Request request, CallOptions options) => throw new NotImplementedException();
}
}

Expand Down
16 changes: 16 additions & 0 deletions Google.Api.Generator.Tests/ProtoTests/Lro/ServiceConfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type: google.api.Service
config_version: 3
name: test.googleapis.com
title: Client Libraries Showcase API

apis:
- name: testing.lro.Lro

publishing:
method_settings:
- selector: testing.lro.Lro.ServiceConfigPollingMethod
long_running:
initial_poll_delay: 60s
poll_delay_multiplier: 2
max_poll_delay: 360s
total_poll_timeout: 54000s
151 changes: 151 additions & 0 deletions Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro/LroClient.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ private LroSettings(LroSettings existing) : base(existing)
SignatureMethodOperationsSettings = existing.SignatureMethodOperationsSettings.Clone();
ResourcedMethodSettings = existing.ResourcedMethodSettings;
ResourcedMethodOperationsSettings = existing.ResourcedMethodOperationsSettings.Clone();
ServiceConfigPollingMethodSettings = existing.ServiceConfigPollingMethodSettings;
ServiceConfigPollingMethodOperationsSettings = existing.ServiceConfigPollingMethodOperationsSettings.Clone();
OnCopy(existing);
}

Expand Down Expand Up @@ -114,6 +116,36 @@ private LroSettings(LroSettings existing) : base(existing)
DefaultPollSettings = new gax::PollSettings(gax::Expiration.FromTimeout(sys::TimeSpan.FromHours(24)), sys::TimeSpan.FromSeconds(20), 1.5, sys::TimeSpan.FromSeconds(45)),
};

/// <summary>
/// <see cref="gaxgrpc::CallSettings"/> for synchronous and asynchronous calls to
/// <c>LroClient.ServiceConfigPollingMethod</c> and <c>LroClient.ServiceConfigPollingMethodAsync</c>.
/// </summary>
/// <remarks>
/// <list type="bullet">
/// <item><description>This call will not be retried.</description></item>
/// <item><description>No timeout is applied.</description></item>
/// </list>
/// </remarks>
public gaxgrpc::CallSettings ServiceConfigPollingMethodSettings { get; set; } = gaxgrpc::CallSettings.FromExpiration(gax::Expiration.None);

/// <summary>
/// Long Running Operation settings for calls to <c>LroClient.ServiceConfigPollingMethod</c> and
/// <c>LroClient.ServiceConfigPollingMethodAsync</c>.
/// </summary>
/// <remarks>
/// Uses default <see cref="gax::PollSettings"/> of:
/// <list type="bullet">
/// <item><description>Initial delay: 60 seconds.</description></item>
/// <item><description>Delay multiplier: 2</description></item>
/// <item><description>Maximum delay: 360 seconds.</description></item>
/// <item><description>Total timeout: 15 hours.</description></item>
/// </list>
/// </remarks>
public lro::OperationsSettings ServiceConfigPollingMethodOperationsSettings { get; set; } = new lro::OperationsSettings
{
DefaultPollSettings = new gax::PollSettings(gax::Expiration.FromTimeout(sys::TimeSpan.FromHours(15)), sys::TimeSpan.FromSeconds(60), 2, sys::TimeSpan.FromSeconds(360)),
};

/// <summary>Creates a deep clone of this object, with all the same property values.</summary>
/// <returns>A deep clone of this <see cref="LroSettings"/> object.</returns>
public LroSettings Clone() => new LroSettings(this);
Expand Down Expand Up @@ -440,6 +472,90 @@ internal static LroClient Create(grpccore::CallInvoker callInvoker, LroSettings
/// <returns>A Task containing the RPC response.</returns>
public virtual stt::Task<lro::Operation<LroResponse.Types.Nested, LroMetadata.Types.Nested>> ResourcedMethodAsync(ResourceName name, st::CancellationToken cancellationToken) =>
ResourcedMethodAsync(name, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken));

/// <summary>
/// Test an LRO RPC with polling settings specified in the service config.
/// </summary>
/// <param name="request">The request object containing all of the parameters for the API call.</param>
/// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
/// <returns>The RPC response.</returns>
public virtual lro::Operation<LroResponse, LroMetadata> ServiceConfigPollingMethod(Request request, gaxgrpc::CallSettings callSettings = null) =>
throw new sys::NotImplementedException();

/// <summary>
/// Test an LRO RPC with polling settings specified in the service config.
/// </summary>
/// <param name="request">The request object containing all of the parameters for the API call.</param>
/// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
/// <returns>A Task containing the RPC response.</returns>
public virtual stt::Task<lro::Operation<LroResponse, LroMetadata>> ServiceConfigPollingMethodAsync(Request request, gaxgrpc::CallSettings callSettings = null) =>
throw new sys::NotImplementedException();

/// <summary>
/// Test an LRO RPC with polling settings specified in the service config.
/// </summary>
/// <param name="request">The request object containing all of the parameters for the API call.</param>
/// <param name="cancellationToken">A <see cref="st::CancellationToken"/> to use for this RPC.</param>
/// <returns>A Task containing the RPC response.</returns>
public virtual stt::Task<lro::Operation<LroResponse, LroMetadata>> ServiceConfigPollingMethodAsync(Request request, st::CancellationToken cancellationToken) =>
ServiceConfigPollingMethodAsync(request, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken));

/// <summary>The long-running operations client for <c>ServiceConfigPollingMethod</c>.</summary>
public virtual lro::OperationsClient ServiceConfigPollingMethodOperationsClient => throw new sys::NotImplementedException();

/// <summary>
/// Poll an operation once, using an <c>operationName</c> from a previous invocation of
/// <c>ServiceConfigPollingMethod</c>.
/// </summary>
/// <param name="operationName">
/// The name of a previously invoked operation. Must not be <c>null</c> or empty.
/// </param>
/// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
/// <returns>The result of polling the operation.</returns>
public virtual lro::Operation<LroResponse, LroMetadata> PollOnceServiceConfigPollingMethod(string operationName, gaxgrpc::CallSettings callSettings = null) =>
lro::Operation<LroResponse, LroMetadata>.PollOnceFromName(gax::GaxPreconditions.CheckNotNullOrEmpty(operationName, nameof(operationName)), ServiceConfigPollingMethodOperationsClient, callSettings);

/// <summary>
/// Asynchronously poll an operation once, using an <c>operationName</c> from a previous invocation of
/// <c>ServiceConfigPollingMethod</c>.
/// </summary>
/// <param name="operationName">
/// The name of a previously invoked operation. Must not be <c>null</c> or empty.
/// </param>
/// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
/// <returns>A task representing the result of polling the operation.</returns>
public virtual stt::Task<lro::Operation<LroResponse, LroMetadata>> PollOnceServiceConfigPollingMethodAsync(string operationName, gaxgrpc::CallSettings callSettings = null) =>
lro::Operation<LroResponse, LroMetadata>.PollOnceFromNameAsync(gax::GaxPreconditions.CheckNotNullOrEmpty(operationName, nameof(operationName)), ServiceConfigPollingMethodOperationsClient, callSettings);

/// <summary>
/// Test an LRO RPC with polling settings specified in the service config.
/// </summary>
/// <param name="name">
/// </param>
/// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
/// <returns>The RPC response.</returns>
public virtual lro::Operation<LroResponse, LroMetadata> ServiceConfigPollingMethod(string name, gaxgrpc::CallSettings callSettings = null) =>
ServiceConfigPollingMethod(new Request { Name = name ?? "", }, callSettings);

/// <summary>
/// Test an LRO RPC with polling settings specified in the service config.
/// </summary>
/// <param name="name">
/// </param>
/// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
/// <returns>A Task containing the RPC response.</returns>
public virtual stt::Task<lro::Operation<LroResponse, LroMetadata>> ServiceConfigPollingMethodAsync(string name, gaxgrpc::CallSettings callSettings = null) =>
ServiceConfigPollingMethodAsync(new Request { Name = name ?? "", }, callSettings);

/// <summary>
/// Test an LRO RPC with polling settings specified in the service config.
/// </summary>
/// <param name="name">
/// </param>
/// <param name="cancellationToken">A <see cref="st::CancellationToken"/> to use for this RPC.</param>
/// <returns>A Task containing the RPC response.</returns>
public virtual stt::Task<lro::Operation<LroResponse, LroMetadata>> ServiceConfigPollingMethodAsync(string name, st::CancellationToken cancellationToken) =>
ServiceConfigPollingMethodAsync(name, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken));
}

/// <summary>Lro client wrapper implementation, for convenient use.</summary>
Expand All @@ -452,6 +568,8 @@ public sealed partial class LroClientImpl : LroClient

private readonly gaxgrpc::ApiCall<ResourceRequest, lro::Operation> _callResourcedMethod;

private readonly gaxgrpc::ApiCall<Request, lro::Operation> _callServiceConfigPollingMethod;

/// <summary>
/// Constructs a client wrapper for the Lro service, with the specified gRPC client and settings.
/// </summary>
Expand All @@ -469,12 +587,16 @@ public LroClientImpl(Lro.LroClient grpcClient, LroSettings settings, mel::ILogge
});
SignatureMethodOperationsClient = new lro::OperationsClientImpl(grpcClient.CreateOperationsClient(), effectiveSettings.SignatureMethodOperationsSettings, logger);
ResourcedMethodOperationsClient = new lro::OperationsClientImpl(grpcClient.CreateOperationsClient(), effectiveSettings.ResourcedMethodOperationsSettings, logger);
ServiceConfigPollingMethodOperationsClient = new lro::OperationsClientImpl(grpcClient.CreateOperationsClient(), effectiveSettings.ServiceConfigPollingMethodOperationsSettings, logger);
_callSignatureMethod = clientHelper.BuildApiCall<Request, lro::Operation>("SignatureMethod", grpcClient.SignatureMethodAsync, grpcClient.SignatureMethod, effectiveSettings.SignatureMethodSettings);
Modify_ApiCall(ref _callSignatureMethod);
Modify_SignatureMethodApiCall(ref _callSignatureMethod);
_callResourcedMethod = clientHelper.BuildApiCall<ResourceRequest, lro::Operation>("ResourcedMethod", grpcClient.ResourcedMethodAsync, grpcClient.ResourcedMethod, effectiveSettings.ResourcedMethodSettings);
Modify_ApiCall(ref _callResourcedMethod);
Modify_ResourcedMethodApiCall(ref _callResourcedMethod);
_callServiceConfigPollingMethod = clientHelper.BuildApiCall<Request, lro::Operation>("ServiceConfigPollingMethod", grpcClient.ServiceConfigPollingMethodAsync, grpcClient.ServiceConfigPollingMethod, effectiveSettings.ServiceConfigPollingMethodSettings);
Modify_ApiCall(ref _callServiceConfigPollingMethod);
Modify_ServiceConfigPollingMethodApiCall(ref _callServiceConfigPollingMethod);
OnConstruction(grpcClient, effectiveSettings, clientHelper);
}

Expand All @@ -484,6 +606,8 @@ public LroClientImpl(Lro.LroClient grpcClient, LroSettings settings, mel::ILogge

partial void Modify_ResourcedMethodApiCall(ref gaxgrpc::ApiCall<ResourceRequest, lro::Operation> call);

partial void Modify_ServiceConfigPollingMethodApiCall(ref gaxgrpc::ApiCall<Request, lro::Operation> call);

partial void OnConstruction(Lro.LroClient grpcClient, LroSettings effectiveSettings, gaxgrpc::ClientHelper clientHelper);

/// <summary>The underlying gRPC Lro client</summary>
Expand Down Expand Up @@ -546,6 +670,33 @@ public LroClientImpl(Lro.LroClient grpcClient, LroSettings settings, mel::ILogge
Modify_ResourceRequest(ref request, ref callSettings);
return new lro::Operation<LroResponse.Types.Nested, LroMetadata.Types.Nested>(await _callResourcedMethod.Async(request, callSettings).ConfigureAwait(false), ResourcedMethodOperationsClient);
}

/// <summary>The long-running operations client for <c>ServiceConfigPollingMethod</c>.</summary>
public override lro::OperationsClient ServiceConfigPollingMethodOperationsClient { get; }

/// <summary>
/// Test an LRO RPC with polling settings specified in the service config.
/// </summary>
/// <param name="request">The request object containing all of the parameters for the API call.</param>
/// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
/// <returns>The RPC response.</returns>
public override lro::Operation<LroResponse, LroMetadata> ServiceConfigPollingMethod(Request request, gaxgrpc::CallSettings callSettings = null)
{
Modify_Request(ref request, ref callSettings);
return new lro::Operation<LroResponse, LroMetadata>(_callServiceConfigPollingMethod.Sync(request, callSettings), ServiceConfigPollingMethodOperationsClient);
}

/// <summary>
/// Test an LRO RPC with polling settings specified in the service config.
/// </summary>
/// <param name="request">The request object containing all of the parameters for the API call.</param>
/// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
/// <returns>A Task containing the RPC response.</returns>
public override async stt::Task<lro::Operation<LroResponse, LroMetadata>> ServiceConfigPollingMethodAsync(Request request, gaxgrpc::CallSettings callSettings = null)
{
Modify_Request(ref request, ref callSettings);
return new lro::Operation<LroResponse, LroMetadata>(await _callServiceConfigPollingMethod.Async(request, callSettings).ConfigureAwait(false), ServiceConfigPollingMethodOperationsClient);
}
}

public static partial class Lro
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>

Expand Down Expand Up @@ -45,4 +45,4 @@
<PackageReference Include="Google.LongRunning" Version="[3.3.0, 4.0.0)" />
</ItemGroup>

</Project>
</Project>
14 changes: 14 additions & 0 deletions Google.Api.Generator/Generation/MethodDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,29 @@ public Paginated(ServiceDetails svc, MethodDescriptor desc,
/// </summary>
public abstract class Lro : MethodDetails
{
private static readonly PollSettings s_lroDefaultPollSettings = new PollSettings(
expiration: Expiration.FromTimeout(TimeSpan.FromHours(24)),
delay: TimeSpan.FromSeconds(20),
delayMultiplier: 1.5,
maxDelay: TimeSpan.FromSeconds(45));

protected Lro(ServiceDetails svc, MethodDescriptor desc)
: base(svc, desc)
{
LroSettingsName = $"{desc.Name}OperationsSettings";
LroClientName = $"{desc.Name}OperationsClient";
SyncPollMethodName = $"PollOnce{SyncMethodName}";
AsyncPollMethodName = $"PollOnce{AsyncMethodName}";
PollSettings = ServiceConfigMethodSettings?.LongRunning is MethodSettings.Types.LongRunning lro
? new PollSettings(
expiration: Expiration.FromTimeout(lro.TotalPollTimeout.ToTimeSpan()),
delay: lro.InitialPollDelay.ToTimeSpan(),
delayMultiplier: lro.PollDelayMultiplier,
maxDelay: lro.MaxPollDelay.ToTimeSpan())
: s_lroDefaultPollSettings;
}

public PollSettings PollSettings { get; }
public abstract override Typ ApiCallTyp { get; }
public abstract override Typ SyncReturnTyp { get; }
public string LroSettingsName { get; }
Expand Down
Loading