From 2d10bd075e0c09587ea3fe699b3012e6777373f9 Mon Sep 17 00:00:00 2001 From: Benjamin Petit Date: Fri, 13 Apr 2018 10:08:43 -0700 Subject: [PATCH 1/2] Add serviceId parameters to helper methods that were configuring the clusterId --- .../Configuration/Options/ClusterOptions.cs | 5 ++++ .../Core/ClientBuilderExtensions.cs | 10 +++++-- .../Hosting/CoreHostingExtensions.cs | 30 +++++++++++++++---- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/Orleans.Core/Configuration/Options/ClusterOptions.cs b/src/Orleans.Core/Configuration/Options/ClusterOptions.cs index f832e7a619..4c928c3b9d 100644 --- a/src/Orleans.Core/Configuration/Options/ClusterOptions.cs +++ b/src/Orleans.Core/Configuration/Options/ClusterOptions.cs @@ -12,6 +12,11 @@ public class ClusterOptions /// internal const string DevelopmentClusterId = "dev"; + /// + /// Default service id for development clusters. + /// + internal const string DevelopmentServiceId = "dev-service"; + /// /// Gets or sets the cluster identity. This used to be called DeploymentId before Orleans 2.0 name. /// diff --git a/src/Orleans.Core/Core/ClientBuilderExtensions.cs b/src/Orleans.Core/Core/ClientBuilderExtensions.cs index 7602d9b414..7e3b00a68a 100644 --- a/src/Orleans.Core/Core/ClientBuilderExtensions.cs +++ b/src/Orleans.Core/Core/ClientBuilderExtensions.cs @@ -166,15 +166,18 @@ public static IClientBuilder ConfigureLogging(this IClientBuilder builder, Actio /// /// The local silo's gateway port. /// Cluster ID to use + /// Service ID to use 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(options => { - if (!string.IsNullOrWhiteSpace(clusterId)) options.ClusterId = clusterId; + if (!string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId; + if (!string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId; }); } @@ -188,7 +191,8 @@ public static IClientBuilder UseLocalhostClustering(this IClientBuilder builder, return builder.UseStaticClustering(gatewayPorts.Select(p => new IPEndPoint(IPAddress.Loopback, p)).ToArray()) .Configure(options => { - options.ClusterId = ClusterOptions.DevelopmentClusterId; + if (!string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = ClusterOptions.DevelopmentClusterId; + if (!string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = ClusterOptions.DevelopmentServiceId; }); } diff --git a/src/Orleans.Runtime/Hosting/CoreHostingExtensions.cs b/src/Orleans.Runtime/Hosting/CoreHostingExtensions.cs index 22a0e52a7d..f283629ab0 100644 --- a/src/Orleans.Runtime/Hosting/CoreHostingExtensions.cs +++ b/src/Orleans.Runtime/Hosting/CoreHostingExtensions.cs @@ -48,13 +48,15 @@ public static ISiloHostBuilder ConfigureDefaults(this ISiloHostBuilder builder) /// The endpoint of the primary silo, or to use this silo as the primary. /// /// Cluster ID + /// Service ID /// The silo builder. 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(options => { @@ -64,7 +66,11 @@ public static ISiloHostBuilder ConfigureDefaults(this ISiloHostBuilder builder) }); builder.UseDevelopmentClustering(primarySiloEndpoint ?? new IPEndPoint(IPAddress.Loopback, siloPort)); - builder.Configure(options => options.ClusterId = clusterId); + builder.Configure(options => + { + if (!string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId; + if (!string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId; + }); builder.Configure(options => options.ExpectedClusterSize = 1); return builder; @@ -89,10 +95,15 @@ public static ISiloHostBuilder UseDevelopmentClustering(this ISiloHostBuilder bu public static ISiloHostBuilder UseDevelopmentClustering( this ISiloHostBuilder builder, Action configureOptions, - string clusterId = ClusterOptions.DevelopmentClusterId) + string clusterId = ClusterOptions.DevelopmentClusterId, + string serviceId = ClusterOptions.DevelopmentServiceId) { return builder - .Configure(options => options.ClusterId = clusterId) + .Configure(options => + { + if (!string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId; + if (!string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId; + }) .ConfigureServices( services => { @@ -114,9 +125,16 @@ public static ISiloHostBuilder UseDevelopmentClustering(this ISiloHostBuilder bu public static ISiloHostBuilder UseDevelopmentClustering( this ISiloHostBuilder builder, Action> configureOptions, - string clusterId = ClusterOptions.DevelopmentClusterId) + string clusterId = ClusterOptions.DevelopmentClusterId, + string serviceId = ClusterOptions.DevelopmentServiceId) { - return builder.ConfigureServices( + return builder + .Configure(options => + { + if (!string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId; + if (!string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId; + }) + .ConfigureServices( services => { configureOptions?.Invoke(services.AddOptions()); From 177bea2054dc1e6c95fe54b712c578379539050d Mon Sep 17 00:00:00 2001 From: Benjamin Petit Date: Fri, 13 Apr 2018 13:22:16 -0700 Subject: [PATCH 2/2] Fix logic --- src/Orleans.Core/Core/ClientBuilderExtensions.cs | 8 ++++---- src/Orleans.Runtime/Hosting/CoreHostingExtensions.cs | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Orleans.Core/Core/ClientBuilderExtensions.cs b/src/Orleans.Core/Core/ClientBuilderExtensions.cs index 7e3b00a68a..b82d36f31a 100644 --- a/src/Orleans.Core/Core/ClientBuilderExtensions.cs +++ b/src/Orleans.Core/Core/ClientBuilderExtensions.cs @@ -176,8 +176,8 @@ public static IClientBuilder ConfigureLogging(this IClientBuilder builder, Actio return builder.UseStaticClustering(new IPEndPoint(IPAddress.Loopback, gatewayPort)) .Configure(options => { - if (!string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId; - if (!string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId; + if (string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId; + if (string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId; }); } @@ -191,8 +191,8 @@ public static IClientBuilder UseLocalhostClustering(this IClientBuilder builder, return builder.UseStaticClustering(gatewayPorts.Select(p => new IPEndPoint(IPAddress.Loopback, p)).ToArray()) .Configure(options => { - if (!string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = ClusterOptions.DevelopmentClusterId; - if (!string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = ClusterOptions.DevelopmentServiceId; + if (string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = ClusterOptions.DevelopmentClusterId; + if (string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = ClusterOptions.DevelopmentServiceId; }); } diff --git a/src/Orleans.Runtime/Hosting/CoreHostingExtensions.cs b/src/Orleans.Runtime/Hosting/CoreHostingExtensions.cs index f283629ab0..da781e9db7 100644 --- a/src/Orleans.Runtime/Hosting/CoreHostingExtensions.cs +++ b/src/Orleans.Runtime/Hosting/CoreHostingExtensions.cs @@ -68,8 +68,8 @@ public static ISiloHostBuilder ConfigureDefaults(this ISiloHostBuilder builder) builder.UseDevelopmentClustering(primarySiloEndpoint ?? new IPEndPoint(IPAddress.Loopback, siloPort)); builder.Configure(options => { - if (!string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId; - if (!string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId; + if (string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId; + if (string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId; }); builder.Configure(options => options.ExpectedClusterSize = 1); @@ -101,8 +101,8 @@ public static ISiloHostBuilder UseDevelopmentClustering(this ISiloHostBuilder bu return builder .Configure(options => { - if (!string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId; - if (!string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId; + if (string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId; + if (string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId; }) .ConfigureServices( services => @@ -131,8 +131,8 @@ public static ISiloHostBuilder UseDevelopmentClustering(this ISiloHostBuilder bu return builder .Configure(options => { - if (!string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId; - if (!string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId; + if (string.IsNullOrWhiteSpace(options.ClusterId)) options.ClusterId = clusterId; + if (string.IsNullOrWhiteSpace(options.ServiceId)) options.ServiceId = serviceId; }) .ConfigureServices( services =>