private async Task<EndpointResponseModel> GetEndpointModel(string fabricAddress) { var endpoints = await GetInstanceEndpoints(fabricAddress); var endpointResult = new EndpointResponseModel { FabricAddress = fabricAddress, IsSuccess = true, AllInternalEndpoints = endpoints, InternalEndpointRandom = endpoints.OrderBy(x => Guid.NewGuid()).First(), //Todo: optimize this, endure even distribution IsRoutableByGateway = endpoints.Any(x => x.ToLower().Contains("http")), //Todo: get the port from config. RoutedEndpoint = fabricAddress.ToString().Replace("fabric:/", "http://blankycluster.westus.cloudapp.azure.com/route/") }; return endpointResult; }
public async Task<List<EndpointResponseModel>> ListServiceEndpoints() { var servicesWithEndpoints = new List<EndpointResponseModel>(); foreach (var service in await DiscoverClusterServices()) { EndpointResponseModel endpointResult; if (service.IsStatefulService) { endpointResult = new EndpointResponseModel { FabricAddress = service.FabricAddress.ToString(), IsSuccess = false, ErrorDetails = "StatefulService - Need Partition To Determine Endpoint" }; } else { try { endpointResult = await GetEndpointModel(service.FabricAddress.ToString()); } catch (Exception ex) { logger.LogWarning("Failed to get endpoint for stateless service", ex); endpointResult = new EndpointResponseModel { IsSuccess = false, ErrorDetails = ex.Message }; } } servicesWithEndpoints.Add(endpointResult); } return servicesWithEndpoints; }