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

[Part3.4][Live-scale] Implement add endpoint. #841

Merged
merged 11 commits into from
Mar 17, 2020
2 changes: 1 addition & 1 deletion src/Microsoft.Azure.SignalR.AspNet/ServiceOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ServiceOptions : IServiceEndpointOptions
/// Gets or sets the lifetime of auto-generated access token, which will be used to authenticate with Azure SignalR Service.
/// Default value is one hour.
/// </summary>
public TimeSpan AccessTokenLifetime { get; set; } = Constants.DefaultAccessTokenLifetime;
public TimeSpan AccessTokenLifetime { get; set; } = Constants.Periods.DefaultAccessTokenLifetime;

/// <summary>
/// Customize the multiple endpoints used
Expand Down
15 changes: 10 additions & 5 deletions src/Microsoft.Azure.SignalR.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ internal static class Constants
public const string ConnectionStringDefaultKey = "Azure:SignalR:ConnectionString";
public const string ApplicationNameDefaultKey = "Azure:SignalR:ApplicationName";

public const int DefaultShutdownTimeoutInSeconds = 30;
public const int DefaultScaleTimeoutInSeconds = 300;

public const string AsrsMigrateFrom = "Asrs-Migrate-From";
public const string AsrsMigrateTo = "Asrs-Migrate-To";

Expand All @@ -31,8 +28,16 @@ internal static class Constants

public static readonly string ConnectionStringSecondaryKeyPrefix = $"{ConnectionStringSecondaryKey}:";

// Default access token lifetime
public static readonly TimeSpan DefaultAccessTokenLifetime = TimeSpan.FromHours(1);
public static class Periods
{
public static readonly TimeSpan DefaultAccessTokenLifetime = TimeSpan.FromHours(1);
public static readonly TimeSpan DefaultScaleTimeout = TimeSpan.FromMinutes(5);
public static readonly TimeSpan DefaultShutdownTimeout = TimeSpan.FromSeconds(30);
public static readonly TimeSpan RemoveFromServiceTimeout = TimeSpan.FromSeconds(5);

public static readonly TimeSpan DefaultStatusPingInterval = TimeSpan.FromSeconds(10);
public static readonly TimeSpan DefaultServersPingInterval = TimeSpan.FromSeconds(5);
}

public static class ClaimType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace Microsoft.Azure.SignalR
internal enum ScaleOperation
{
Add,
Remove,
Rename
Remove
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private async Task AddServiceEndpointsAsync(IEnumerable<ServiceEndpoint> endpoin

await Task.WhenAll(hubEndpoints.Select(e => AddHubServiceEndpointAsync(e, cancellationToken)));

// TODO: update local store for negotiation
UpdateNegotiationEndpointsStore(hubEndpoints, ScaleOperation.Add);
}
catch (Exception ex)
{
Expand All @@ -155,6 +155,25 @@ private async Task AddServiceEndpointsAsync(IEnumerable<ServiceEndpoint> endpoin
}
}

private void UpdateNegotiationEndpointsStore(IReadOnlyList<HubServiceEndpoint> endpoints, ScaleOperation scaleOperation)
{
foreach (var hubEndpoint in _endpointsPerHub)
{
var updatedEndpoints = endpoints.Where(e => e.Hub == hubEndpoint.Key);
var oldEndpoints = hubEndpoint.Value;
var newEndpoints = oldEndpoints.ToList();
switch (scaleOperation)
{
case ScaleOperation.Add:
newEndpoints.AddRange(updatedEndpoints);
break;
default:
break;
}
_endpointsPerHub.TryUpdate(hubEndpoint.Key, newEndpoints, oldEndpoints);
}
}

private async Task RemoveServiceEndpointsAsync(IEnumerable<ServiceEndpoint> endpoints, CancellationToken cancellationToken)
{
if (endpoints.Count() > 0)
Expand Down
Loading