Skip to content
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

Add serviceId parameters to ClientBuilder/ServiceHostBuilder helper methods #4469

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Orleans.Core/Configuration/Options/ClusterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public class ClusterOptions
/// </summary>
internal const string DevelopmentClusterId = "dev";

/// <summary>
/// Default service id for development clusters.
/// </summary>
internal const string DevelopmentServiceId = "dev-service";

/// <summary>
/// Gets or sets the cluster identity. This used to be called DeploymentId before Orleans 2.0 name.
/// </summary>
Expand Down
10 changes: 7 additions & 3 deletions src/Orleans.Core/Core/ClientBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,18 @@ public static IClientBuilder ConfigureLogging(this IClientBuilder builder, Actio
/// <param name="builder"></param>
/// <param name="gatewayPort">The local silo's gateway port.</param>
/// <param name="clusterId">Cluster ID to use</param>
/// <param name="serviceId">Service ID to use</param>
public static IClientBuilder UseLocalhostClustering(
this IClientBuilder builder,
int gatewayPort = 30000,
string clusterId = ClusterOptions.DevelopmentClusterId)
string clusterId = ClusterOptions.DevelopmentClusterId,
string serviceId = ClusterOptions.DevelopmentServiceId)
{
return builder.UseStaticClustering(new IPEndPoint(IPAddress.Loopback, gatewayPort))
.Configure<ClusterOptions>(options =>
{
if (!string.IsNullOrWhiteSpace(clusterId)) options.ClusterId = clusterId;
if (string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId;
Copy link
Member

Choose a reason for hiding this comment

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

You should use PostConfigure instead of Configure for this kind of fallback configuration

if (string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId;
});
}

Expand All @@ -188,7 +191,8 @@ public static IClientBuilder UseLocalhostClustering(this IClientBuilder builder,
return builder.UseStaticClustering(gatewayPorts.Select(p => new IPEndPoint(IPAddress.Loopback, p)).ToArray())
.Configure<ClusterOptions>(options =>
{
options.ClusterId = ClusterOptions.DevelopmentClusterId;
if (string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = ClusterOptions.DevelopmentClusterId;
if (string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = ClusterOptions.DevelopmentServiceId;
});
}

Expand Down
30 changes: 24 additions & 6 deletions src/Orleans.Runtime/Hosting/CoreHostingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ public static ISiloHostBuilder ConfigureDefaults(this ISiloHostBuilder builder)
/// The endpoint of the primary silo, or <see langword="null"/> to use this silo as the primary.
/// </param>
/// <param name="clusterId">Cluster ID</param>
/// <param name="serviceId">Service ID</param>
/// <returns>The silo builder.</returns>
public static ISiloHostBuilder UseLocalhostClustering(
this ISiloHostBuilder builder,
int siloPort = EndpointOptions.DEFAULT_SILO_PORT,
int gatewayPort = EndpointOptions.DEFAULT_GATEWAY_PORT,
IPEndPoint primarySiloEndpoint = null,
string clusterId = ClusterOptions.DevelopmentClusterId)
string clusterId = ClusterOptions.DevelopmentClusterId,
string serviceId = ClusterOptions.DevelopmentServiceId)
{
builder.Configure<EndpointOptions>(options =>
{
Expand All @@ -64,7 +66,11 @@ public static ISiloHostBuilder ConfigureDefaults(this ISiloHostBuilder builder)
});

builder.UseDevelopmentClustering(primarySiloEndpoint ?? new IPEndPoint(IPAddress.Loopback, siloPort));
builder.Configure<ClusterOptions>(options => options.ClusterId = clusterId);
builder.Configure<ClusterOptions>(options =>
{
if (string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId;
if (string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId;
});
builder.Configure<ClusterMembershipOptions>(options => options.ExpectedClusterSize = 1);

return builder;
Expand All @@ -89,10 +95,15 @@ public static ISiloHostBuilder UseDevelopmentClustering(this ISiloHostBuilder bu
public static ISiloHostBuilder UseDevelopmentClustering(
this ISiloHostBuilder builder,
Action<DevelopmentClusterMembershipOptions> configureOptions,
string clusterId = ClusterOptions.DevelopmentClusterId)
string clusterId = ClusterOptions.DevelopmentClusterId,
string serviceId = ClusterOptions.DevelopmentServiceId)
{
return builder
.Configure<ClusterOptions>(options => options.ClusterId = clusterId)
.Configure<ClusterOptions>(options =>
{
if (string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId;
if (string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId;
})
.ConfigureServices(
services =>
{
Expand All @@ -114,9 +125,16 @@ public static ISiloHostBuilder UseDevelopmentClustering(this ISiloHostBuilder bu
public static ISiloHostBuilder UseDevelopmentClustering(
this ISiloHostBuilder builder,
Action<OptionsBuilder<DevelopmentClusterMembershipOptions>> configureOptions,
string clusterId = ClusterOptions.DevelopmentClusterId)
string clusterId = ClusterOptions.DevelopmentClusterId,
string serviceId = ClusterOptions.DevelopmentServiceId)
{
return builder.ConfigureServices(
return builder
.Configure<ClusterOptions>(options =>
{
if (string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId;
if (string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId;
})
.ConfigureServices(
services =>
{
configureOptions?.Invoke(services.AddOptions<DevelopmentClusterMembershipOptions>());
Expand Down