public override void InitFilter(FilterContainer container, Configuration conf) { IDictionary <string, string> @params = new Dictionary <string, string>(); IList <string> proxies = WebAppUtils.GetProxyHostsAndPortsForAmFilter(conf); StringBuilder sb = new StringBuilder(); foreach (string proxy in proxies) { sb.Append(proxy.Split(":")[0]).Append(AmIpFilter.ProxyHostsDelimiter); } sb.Length = sb.Length - 1; @params[AmIpFilter.ProxyHosts] = sb.ToString(); string prefix = WebAppUtils.GetHttpSchemePrefix(conf); string proxyBase = GetApplicationWebProxyBase(); sb = new StringBuilder(); foreach (string proxy_1 in proxies) { sb.Append(prefix).Append(proxy_1).Append(proxyBase).Append(AmIpFilter.ProxyHostsDelimiter ); } sb.Length = sb.Length - 1; @params[AmIpFilter.ProxyUriBases] = sb.ToString(); container.AddFilter(FilterName, FilterClass, @params); }
public virtual void TestGetProxyHostsAndPortsForAmFilter() { // Check no configs given Configuration conf = new Configuration(false); IList <string> proxyHosts = WebAppUtils.GetProxyHostsAndPortsForAmFilter(conf); NUnit.Framework.Assert.AreEqual(1, proxyHosts.Count); NUnit.Framework.Assert.AreEqual(WebAppUtils.GetResolvedRMWebAppURLWithoutScheme(conf ), proxyHosts[0]); // Check PROXY_ADDRESS has priority conf = new Configuration(false); conf.Set(YarnConfiguration.ProxyAddress, "host1:1000"); conf.SetBoolean(YarnConfiguration.RmHaEnabled, true); conf.Set(YarnConfiguration.RmHaIds, "rm1,rm2,rm3"); conf.Set(YarnConfiguration.RmWebappAddress + ".rm1", "host2:2000"); conf.Set(YarnConfiguration.RmWebappAddress + ".rm2", "host3:3000"); conf.Set(YarnConfiguration.RmWebappAddress + ".rm3", "host4:4000"); proxyHosts = WebAppUtils.GetProxyHostsAndPortsForAmFilter(conf); NUnit.Framework.Assert.AreEqual(1, proxyHosts.Count); NUnit.Framework.Assert.AreEqual("host1:1000", proxyHosts[0]); // Check getting a single RM_WEBAPP_ADDRESS conf = new Configuration(false); conf.Set(YarnConfiguration.RmWebappAddress, "host2:2000"); proxyHosts = WebAppUtils.GetProxyHostsAndPortsForAmFilter(conf); NUnit.Framework.Assert.AreEqual(1, proxyHosts.Count); proxyHosts.Sort(); NUnit.Framework.Assert.AreEqual("host2:2000", proxyHosts[0]); // Check getting multiple RM_WEBAPP_ADDRESSes (RM HA) conf = new Configuration(false); conf.SetBoolean(YarnConfiguration.RmHaEnabled, true); conf.Set(YarnConfiguration.RmHaIds, "rm1,rm2,rm3"); conf.Set(YarnConfiguration.RmWebappAddress + ".rm1", "host2:2000"); conf.Set(YarnConfiguration.RmWebappAddress + ".rm2", "host3:3000"); conf.Set(YarnConfiguration.RmWebappAddress + ".rm3", "host4:4000"); conf.Set(YarnConfiguration.RmWebappAddress + ".rm4", "dummy"); conf.Set(YarnConfiguration.RmWebappHttpsAddress + ".rm1", "host5:5000"); conf.Set(YarnConfiguration.RmWebappHttpsAddress + ".rm2", "host6:6000"); proxyHosts = WebAppUtils.GetProxyHostsAndPortsForAmFilter(conf); NUnit.Framework.Assert.AreEqual(3, proxyHosts.Count); proxyHosts.Sort(); NUnit.Framework.Assert.AreEqual("host2:2000", proxyHosts[0]); NUnit.Framework.Assert.AreEqual("host3:3000", proxyHosts[1]); NUnit.Framework.Assert.AreEqual("host4:4000", proxyHosts[2]); // Check getting multiple RM_WEBAPP_ADDRESSes (RM HA) with HTTPS conf = new Configuration(false); conf.Set(YarnConfiguration.YarnHttpPolicyKey, HttpConfig.Policy.HttpsOnly.ToString ()); conf.SetBoolean(YarnConfiguration.RmHaEnabled, true); conf.Set(YarnConfiguration.RmHaIds, "rm1,rm2,rm3,dummy"); conf.Set(YarnConfiguration.RmWebappAddress + ".rm1", "host2:2000"); conf.Set(YarnConfiguration.RmWebappAddress + ".rm2", "host3:3000"); conf.Set(YarnConfiguration.RmWebappAddress + ".rm3", "host4:4000"); conf.Set(YarnConfiguration.RmWebappHttpsAddress + ".rm1", "host5:5000"); conf.Set(YarnConfiguration.RmWebappHttpsAddress + ".rm2", "host6:6000"); proxyHosts = WebAppUtils.GetProxyHostsAndPortsForAmFilter(conf); NUnit.Framework.Assert.AreEqual(2, proxyHosts.Count); proxyHosts.Sort(); NUnit.Framework.Assert.AreEqual("host5:5000", proxyHosts[0]); NUnit.Framework.Assert.AreEqual("host6:6000", proxyHosts[1]); }