private async Task <T> GenerateUrlAndExecuteRequestAsync <T>(RestRequest request, CancellationToken cancellationToken) { IEnumerable <Uri> yarnRmUris = await _yarnRmUrlProviderUri.GetUrlAsync(); var exceptions = new List <Exception>(); foreach (var yarnRmUri in yarnRmUris) { try { return (await _restRequestExecutor.ExecuteAsync <T>(request, yarnRmUri, cancellationToken)); } catch (Exception e) { exceptions.Add(e); Logger.Log(Level.Verbose, string.Format(CultureInfo.CurrentCulture, "Possibly transient error in rest call {0}", e.Message)); } } throw new AggregateException("Failed Rest Request", exceptions); }
public void UrlProviderReadsEnvVarConfiguredConfigFileAndParsesCorrectHttpUrl() { string tempFile = Path.GetTempFileName(); string tempDir = Path.GetDirectoryName(tempFile); string yarnConfigFile = Path.Combine(tempDir, YarnConfigFileName); using (new YarnConfigurationUrlProviderTests.TempFileWriter(yarnConfigFile, YarnConfigurationXmlContent)) using (new YarnConfigurationUrlProviderTests.TemporaryOverrideEnvironmentVariable(HadoopConfDirEnvVariable, tempDir)) { IUrlProvider urlProvider = GetYarnConfigurationUrlProvider(); var url = urlProvider.GetUrlAsync().GetAwaiter().GetResult(); int i = 0; foreach (var u in url) { i++; Assert.Equal("http", u.Scheme); if (i == 1) { Assert.Equal(AnyHttpAddressConfig.Split(':')[0], u.Host); Assert.Equal(AnyHttpAddressConfig.Split(':')[1], u.Port.ToString(CultureInfo.InvariantCulture)); } else { Assert.Equal(AnyHttpAddressConfigUpdated.Split(':')[0], u.Host); Assert.Equal(AnyHttpAddressConfigUpdated.Split(':')[1], u.Port.ToString(CultureInfo.InvariantCulture)); } } } }