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
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).ToList();
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