/// <inheritdoc /> public async Task <ResolvedEndpoint> RetrieveAsync(ClientRegionLocale locale, string serviceType) { //TODO: Validate string so they don't sniff out private services if (!Enum.IsDefined(typeof(ClientRegionLocale), locale)) { throw new ArgumentOutOfRangeException(nameof(locale), "Value should be defined in the ClientRegionLocale enum."); } if (string.IsNullOrWhiteSpace(serviceType)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(serviceType)); } if (EntryCache.ContainsKey(ConvertLocaleServiceTypeToString(locale, serviceType))) { return(EntryCache[ConvertLocaleServiceTypeToString(locale, serviceType)]); } CatalogServiceNodeEntry[] result = await QueryConsul(locale, serviceType); if (!QueryResultIsValid(result)) { ThrowQueryException(locale, serviceType); } return(ParseQueryToEndpoint(locale, serviceType, result)); }
/// <inheritdoc /> public Task <bool> HasRegionStore(ClientRegionLocale region) { if (!Enum.IsDefined(typeof(ClientRegionLocale), region)) { throw new ArgumentOutOfRangeException(nameof(region), "Value should be defined in the ClientRegionLocale enum."); } return(Task.FromResult(File.Exists(BuildRegionEndpointFileLocation(region)))); }
private string BuildRegionEndpointFileLocation(ClientRegionLocale region) { if (!Enum.IsDefined(typeof(ClientRegionLocale), region)) { throw new ArgumentOutOfRangeException(nameof(region), "Value should be defined in the ClientRegionLocale enum."); } return($@"Endpoints/Endpoints{region.ToString()}.json"); }
/// <inheritdoc /> public Task <bool> HasDataForRegionAsync(ClientRegionLocale locale) { if (!Enum.IsDefined(typeof(ClientRegionLocale), locale)) { throw new ArgumentOutOfRangeException(nameof(locale), "Value should be defined in the ClientRegionLocale enum."); } return(EndpointsContext.Endpoints.AnyAsync(e => e.Region == locale)); }
/// <inheritdoc /> public async Task <ResolvedEndpoint> RetrieveAsync(ClientRegionLocale locale, string serviceType) { if (!await HasEntryAsync(locale, serviceType)) { throw new InvalidOperationException($"Does not contain informations for Region: {locale} Type: {serviceType}"); } NameEndpointResolutionStorageModel regionInfo = await Retrieve(locale); return(new ResolvedEndpoint(regionInfo.ServiceEndpoints[serviceType].EndpointAddress, regionInfo.ServiceEndpoints[serviceType].EndpointPort)); }
/// <inheritdoc /> public async Task <NameEndpointResolutionStorageModel> Retrieve(ClientRegionLocale region) { if (!Enum.IsDefined(typeof(ClientRegionLocale), region)) { throw new ArgumentOutOfRangeException(nameof(region), "Value should be defined in the ClientRegionLocale enum."); } using (StreamReader reader = File.OpenText(BuildRegionEndpointFileLocation(region))) { return(Newtonsoft.Json.JsonConvert.DeserializeObject <NameEndpointResolutionStorageModel>(await reader.ReadToEndAsync())); } }
public static void Test_Can_JSON_Serialize_To_NonNull_Non_Whitespace(ClientRegionLocale region, string service) { //arrange ResolveServiceEndpointRequestModel model = new ResolveServiceEndpointRequestModel(region, service); //act string serializedModel = JsonConvert.SerializeObject(model); //assert Assert.NotNull(serializedModel); Assert.IsNotEmpty(serializedModel); }
/// <inheritdoc /> public Task <bool> HasEntryAsync(ClientRegionLocale locale, string serviceType) { if (!Enum.IsDefined(typeof(ClientRegionLocale), locale)) { throw new ArgumentOutOfRangeException(nameof(locale), "Value should be defined in the ClientRegionLocale enum."); } if (string.IsNullOrWhiteSpace(serviceType)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(serviceType)); } return(EndpointsContext.Endpoints.AnyAsync(e => e.Region == locale && e.Service == serviceType)); }
/// <inheritdoc /> public async Task <bool> HasEntryAsync(ClientRegionLocale locale, NetworkServiceType serviceType) { if (!Enum.IsDefined(typeof(ClientRegionLocale), locale)) { throw new ArgumentOutOfRangeException(nameof(locale), "Value should be defined in the ClientRegionLocale enum."); } if (!Enum.IsDefined(typeof(NetworkServiceType), serviceType)) { throw new ArgumentOutOfRangeException(nameof(serviceType), "Value should be defined in the NetworkServiceType enum."); } return(await EndpointsContext.Endpoints.AnyAsync(e => e.Region == locale && e.Service == serviceType)); }
private static ResolvedEndpoint ParseQueryToEndpoint(ClientRegionLocale locale, string serviceType, CatalogServiceNodeEntry[] result) { if (!QueryResultIsValid(result)) { ThrowQueryException(locale, serviceType); } //TODO: Check health //TODO: Manual loadbalancing roadrobin? CatalogServiceNodeEntry entry = result.First(); return(ConvertConsulEntryToEndpoint(entry)); }
//We don't need a real ctor because we load a file public NameEndpointResolutionStorageModel(ClientRegionLocale region, Dictionary <string, ResolvedEndpoint> serviceEndpoints) { if (serviceEndpoints == null) { throw new ArgumentNullException(nameof(serviceEndpoints)); } if (!Enum.IsDefined(typeof(ClientRegionLocale), region)) { throw new ArgumentOutOfRangeException(nameof(region), "Value should be defined in the ClientRegionLocale enum."); } Region = region; _ServiceEndpoints = serviceEndpoints; }
public ResolveServiceEndpointRequest(ClientRegionLocale region, string serviceType) { if (!Enum.IsDefined(typeof(ClientRegionLocale), region)) { throw new ArgumentOutOfRangeException(nameof(region), "Value should be defined in the ClientRegionLocale enum."); } if (string.IsNullOrWhiteSpace(serviceType)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(serviceType)); } Region = region; ServiceType = serviceType; }
} //must have setter for EF public GameServerListEntryModel(ClientRegionLocale region, string endpointAddress, int endpointPort) { if (!Enum.IsDefined(typeof(ClientRegionLocale), region)) { throw new ArgumentOutOfRangeException(nameof(region), "Value should be defined in the ClientRegionLocale enum."); } if (string.IsNullOrWhiteSpace(endpointAddress)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(endpointAddress)); } Region = region; EndpointAddress = endpointAddress; EndpointPort = endpointPort; }
/// <inheritdoc /> public async Task <bool> HasEntryAsync(ClientRegionLocale locale, string serviceType) { if (!await HasDataForRegionAsync(locale)) { return(false); } NameEndpointResolutionStorageModel regionInfo = await Retrieve(locale); if (regionInfo.ServiceEndpoints.ContainsKey(serviceType)) { return(true); } return(false); }
public GameServerInfo(string serverName, ClientRegionLocale serverLocale, ResolvedEndpoint endpoint) { if (endpoint == null) { throw new ArgumentNullException(nameof(endpoint)); } if (string.IsNullOrWhiteSpace(serverName)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(serverName)); } if (!Enum.IsDefined(typeof(ClientRegionLocale), serverLocale)) { throw new ArgumentOutOfRangeException(nameof(serverLocale), "Value should be defined in the ClientRegionLocale enum."); } ServerName = serverName; ServerLocale = serverLocale; Endpoint = endpoint; }
/// <inheritdoc /> public async Task <bool> HasEntryAsync(ClientRegionLocale locale, string serviceType) { if (EntryCache.ContainsKey(ConvertLocaleServiceTypeToString(locale, serviceType))) { return(true); } CatalogServiceNodeEntry[] result = await QueryConsul(locale, serviceType); bool valid = QueryResultIsValid(result); if (valid) { //Add to cache so we can look up from the cache in this lifetime of the service EntryCache.Add(ConvertLocaleServiceTypeToString(locale, serviceType), ParseQueryToEndpoint(locale, serviceType, result)); } return(valid); }
public static void Test_Can_JSON_Serialize_To_NonNull_Non_Whitespace(ClientRegionLocale value) { //arrange Dictionary <string, ResolvedEndpoint> endpoints = new Dictionary <string, ResolvedEndpoint>() { { "AuthenticationService", new ResolvedEndpoint("127.0.0.1", 5555) } }; NameEndpointResolutionStorageModel model = new NameEndpointResolutionStorageModel(value, endpoints); //act string serializedModel = JsonConvert.SerializeObject(model); //assert Assert.NotNull(serializedModel); Assert.IsNotEmpty(serializedModel); Assert.True(serializedModel.Contains(endpoints.Values.First().EndpointAddress)); Assert.True(serializedModel.Contains(nameof(model.ServiceEndpoints))); Assert.True(serializedModel.Contains(endpoints.Values.First().EndpointPort.ToString())); Assert.True(serializedModel.Contains(value.ToString())); }
} //must have setter for EF public NamedResolvedEndpointEntryModel(ClientRegionLocale region, NetworkServiceType service, string endpointAddress, int endpointPort) { if (!Enum.IsDefined(typeof(ClientRegionLocale), region)) { throw new ArgumentOutOfRangeException(nameof(region), "Value should be defined in the ClientRegionLocale enum."); } if (!Enum.IsDefined(typeof(NetworkServiceType), service)) { throw new ArgumentOutOfRangeException(nameof(service), "Value should be defined in the NetworkServiceType enum."); } if (string.IsNullOrWhiteSpace(endpointAddress)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(endpointAddress)); } Region = region; Service = service; EndpointAddress = endpointAddress; EndpointPort = endpointPort; }
/// <inheritdoc /> public async Task <ResolvedEndpoint> RetrieveAsync(ClientRegionLocale locale, string serviceType) { if (!Enum.IsDefined(typeof(ClientRegionLocale), locale)) { throw new ArgumentOutOfRangeException(nameof(locale), "Value should be defined in the ClientRegionLocale enum."); } if (string.IsNullOrWhiteSpace(serviceType)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(serviceType)); } NamedResolvedEndpointEntryModel model = await EndpointsContext.Endpoints.FirstOrDefaultAsync(e => e.Region == locale && e.Service == serviceType); if (model == null) { throw new KeyNotFoundException($"Provided keypair {locale} and {serviceType} not found."); } return(new ResolvedEndpoint(model.EndpointAddress, model.EndpointPort)); }
public async Task <ResolvedEndpoint> RetrieveAsync(ClientRegionLocale locale, string serviceType) { //This is kinda hacky but I named the authentication app service before thinking about this properly //so now we have to have this ugly check if (serviceType.ToLower() == "authentication") { serviceType = "auth"; } #if AZURE_DEBUG string deploymentName = "test"; #elif AZURE_RELEASE string deploymentName = "prod"; #else string deploymentName = null; throw new NotImplementedException($"Unsupported Build Configuration detected for {nameof(AzureStaticEndpointRepository)}"); #endif //https://test-guardians-auth.azurewebsites.net return(new ResolvedEndpoint($"http://{deploymentName}-Guardians-{serviceType}.azurewebsites.net", 80)); }
private static string ConvertLocaleServiceTypeToString(ClientRegionLocale locale, string serviceType) { return($"{serviceType}:{locale}"); }
public static void Test_Throws_On_Construction_With_Invalid_Argument_Service(ClientRegionLocale region, string service) { //assert Assert.Throws <ArgumentException>(() => new ResolveServiceEndpointRequestModel(region, service)); }
private static void ThrowQueryException(ClientRegionLocale locale, string serviceType) { throw new InvalidOperationException($"Failed to query Consul for Locale:{locale} ServiceType: {serviceType}"); }
public static void Test_Can_JSON_Serialize_Then_Deserialize_With_Preserved_Values(ClientRegionLocale value) { //arrange Dictionary <string, ResolvedEndpoint> endpoints = new Dictionary <string, ResolvedEndpoint>() { { "AuthenticationService", new ResolvedEndpoint("127.0.0.1", 5555) } }; NameEndpointResolutionStorageModel model = new NameEndpointResolutionStorageModel(value, endpoints); //act NameEndpointResolutionStorageModel deserializedModel = JsonConvert.DeserializeObject <NameEndpointResolutionStorageModel>(JsonConvert.SerializeObject(model)); //assert Assert.NotNull(deserializedModel); Assert.NotNull(deserializedModel.ServiceEndpoints); Assert.IsNotEmpty(deserializedModel.ServiceEndpoints); Assert.True(Enum.IsDefined(typeof(ClientRegionLocale), deserializedModel.Region)); Assert.NotNull(deserializedModel.ServiceEndpoints.Keys.First()); Assert.AreEqual(endpoints.First().Key, deserializedModel.ServiceEndpoints.First().Key); Assert.AreEqual(endpoints.First().Value.EndpointAddress, deserializedModel.ServiceEndpoints.First().Value.EndpointAddress); }
public static void Test_Doesnt_Throw_On_Valid_Arguments(ClientRegionLocale region, string service) { //assert Assert.DoesNotThrow(() => new ResolveServiceEndpointRequestModel(region, service)); }
public static void Test_Can_JSON_Serialize_Then_Deserialize_With_Preserved_Values(ClientRegionLocale region, string service) { //arrange ResolveServiceEndpointRequestModel model = new ResolveServiceEndpointRequestModel(region, service); //act ResolveServiceEndpointRequestModel deserializedModel = JsonConvert.DeserializeObject <ResolveServiceEndpointRequestModel>(JsonConvert.SerializeObject(model)); //assert Assert.NotNull(deserializedModel); Assert.True(Enum.IsDefined(typeof(ClientRegionLocale), deserializedModel.Region)); Assert.NotNull(deserializedModel.ServiceType); }
public static void Test_Doesnt_Throw_On_Valid_Arguments(ClientRegionLocale value) { //assert Assert.DoesNotThrow(() => new NameEndpointResolutionStorageModel(value, new Dictionary <string, ResolvedEndpoint>())); }
public static void Test_Throws_On_Construction_With_Invalid_Argument_Dictionary(ClientRegionLocale value) { //assert Assert.Throws <ArgumentNullException>(() => new NameEndpointResolutionStorageModel(value, null)); }
public static void Test_Throws_On_Construction_With_Invalid_Argument_ServiceType(ClientRegionLocale value) { //assert Assert.Throws <ArgumentOutOfRangeException>(() => new NameEndpointResolutionStorageModel(value, new Dictionary <string, ResolvedEndpoint>())); }
/// <inheritdoc /> public Task <bool> HasDataForRegionAsync(ClientRegionLocale locale) { //TODO: How should we handle region stuff with consul? return(Task.FromResult(true)); }