YARN-3601. Fix UT TestRMFailover.testRMWebAppRedirect. Contributed by Weiwei Yang
(cherry picked from commit 5009ad4a7f
)
This commit is contained in:
parent
9e656bfa94
commit
d39039d54d
|
@ -467,6 +467,8 @@ Release 2.7.1 - UNRELEASED
|
||||||
YARN-3526. ApplicationMaster tracking URL is incorrectly redirected
|
YARN-3526. ApplicationMaster tracking URL is incorrectly redirected
|
||||||
on a QJM cluster. (Weiwei Yang via xgong)
|
on a QJM cluster. (Weiwei Yang via xgong)
|
||||||
|
|
||||||
|
YARN-3601. Fix UT TestRMFailover.testRMWebAppRedirect. (Weiwei Yang via xgong)
|
||||||
|
|
||||||
Release 2.7.0 - 2015-04-20
|
Release 2.7.0 - 2015-04-20
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -21,13 +21,13 @@ package org.apache.hadoop.yarn.client;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -48,7 +48,6 @@ import org.apache.hadoop.yarn.server.webproxy.WebAppProxyServer;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TestRMFailover extends ClientBaseWithFixes {
|
public class TestRMFailover extends ClientBaseWithFixes {
|
||||||
|
@ -275,10 +274,6 @@ public class TestRMFailover extends ClientBaseWithFixes {
|
||||||
assertEquals(404, response.getResponseCode());
|
assertEquals(404, response.getResponseCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore this testcase, Always gets "too many redirect loops" exception
|
|
||||||
// Probably because of the limitation of MiniYARNCluster.
|
|
||||||
// Verified the behavior in a single node cluster.
|
|
||||||
@Ignore
|
|
||||||
@Test
|
@Test
|
||||||
public void testRMWebAppRedirect() throws YarnException,
|
public void testRMWebAppRedirect() throws YarnException,
|
||||||
InterruptedException, IOException {
|
InterruptedException, IOException {
|
||||||
|
@ -290,59 +285,62 @@ public class TestRMFailover extends ClientBaseWithFixes {
|
||||||
getAdminService(0).transitionToActive(req);
|
getAdminService(0).transitionToActive(req);
|
||||||
String rm1Url = "http://0.0.0.0:18088";
|
String rm1Url = "http://0.0.0.0:18088";
|
||||||
String rm2Url = "http://0.0.0.0:28088";
|
String rm2Url = "http://0.0.0.0:28088";
|
||||||
String header = getHeader("Refresh", rm2Url);
|
String redirectURL = getRedirectURL(rm2Url);
|
||||||
assertTrue(header.contains("; url=" + rm1Url));
|
// if uri is null, RMWebAppFilter will append a slash at the trail of the redirection url
|
||||||
|
assertEquals(redirectURL,rm1Url+"/");
|
||||||
|
|
||||||
header = getHeader("Refresh", rm2Url + "/metrics");
|
redirectURL = getRedirectURL(rm2Url + "/metrics");
|
||||||
assertTrue(header.contains("; url=" + rm1Url));
|
assertEquals(redirectURL,rm1Url + "/metrics");
|
||||||
|
|
||||||
header = getHeader("Refresh", rm2Url + "/jmx");
|
redirectURL = getRedirectURL(rm2Url + "/jmx");
|
||||||
assertTrue(header.contains("; url=" + rm1Url));
|
assertEquals(redirectURL,rm1Url + "/jmx");
|
||||||
|
|
||||||
// standby RM links /conf, /stacks, /logLevel, /static, /logs,
|
// standby RM links /conf, /stacks, /logLevel, /static, /logs,
|
||||||
// /cluster/cluster as well as webService
|
// /cluster/cluster as well as webService
|
||||||
// /ws/v1/cluster/info should not be redirected to active RM
|
// /ws/v1/cluster/info should not be redirected to active RM
|
||||||
header = getHeader("Refresh", rm2Url + "/cluster/cluster");
|
redirectURL = getRedirectURL(rm2Url + "/cluster/cluster");
|
||||||
assertEquals(null, header);
|
assertNull(redirectURL);
|
||||||
|
|
||||||
header = getHeader("Refresh", rm2Url + "/conf");
|
redirectURL = getRedirectURL(rm2Url + "/conf");
|
||||||
assertEquals(null, header);
|
assertNull(redirectURL);
|
||||||
|
|
||||||
header = getHeader("Refresh", rm2Url + "/stacks");
|
redirectURL = getRedirectURL(rm2Url + "/stacks");
|
||||||
assertEquals(null, header);
|
assertNull(redirectURL);
|
||||||
|
|
||||||
header = getHeader("Refresh", rm2Url + "/logLevel");
|
redirectURL = getRedirectURL(rm2Url + "/logLevel");
|
||||||
assertEquals(null, header);
|
assertNull(redirectURL);
|
||||||
|
|
||||||
header = getHeader("Refresh", rm2Url + "/static");
|
redirectURL = getRedirectURL(rm2Url + "/static");
|
||||||
assertEquals(null, header);
|
assertNull(redirectURL);
|
||||||
|
|
||||||
header = getHeader("Refresh", rm2Url + "/logs");
|
redirectURL = getRedirectURL(rm2Url + "/logs");
|
||||||
assertEquals(null, header);
|
assertNull(redirectURL);
|
||||||
|
|
||||||
header = getHeader("Refresh", rm2Url + "/ws/v1/cluster/info");
|
redirectURL = getRedirectURL(rm2Url + "/ws/v1/cluster/info");
|
||||||
assertEquals(null, header);
|
assertNull(redirectURL);
|
||||||
|
|
||||||
header = getHeader("Refresh", rm2Url + "/ws/v1/cluster/apps");
|
redirectURL = getRedirectURL(rm2Url + "/ws/v1/cluster/apps");
|
||||||
assertTrue(header.contains("; url=" + rm1Url));
|
assertEquals(redirectURL, rm1Url + "/ws/v1/cluster/apps");
|
||||||
|
|
||||||
header = getHeader("Refresh", rm2Url + "/proxy/" + fakeAppId);
|
redirectURL = getRedirectURL(rm2Url + "/proxy/" + fakeAppId);
|
||||||
assertEquals(null, header);
|
assertNull(redirectURL);
|
||||||
|
|
||||||
// Due to the limitation of MiniYARNCluster and dispatcher is a singleton,
|
|
||||||
// we couldn't add the test case after explicitFailover();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getHeader(String field, String url) {
|
// set up http connection with the given url and get the redirection url from the response
|
||||||
String fieldHeader = null;
|
// return null if the url is not redirected
|
||||||
|
static String getRedirectURL(String url) {
|
||||||
|
String redirectUrl = null;
|
||||||
try {
|
try {
|
||||||
Map<String, List<String>> map =
|
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
|
||||||
new URL(url).openConnection().getHeaderFields();
|
// do not automatically follow the redirection
|
||||||
fieldHeader = map.get(field).get(0);
|
// otherwise we get too many redirections exception
|
||||||
|
conn.setInstanceFollowRedirects(false);
|
||||||
|
if(conn.getResponseCode() == HttpServletResponse.SC_TEMPORARY_REDIRECT)
|
||||||
|
redirectUrl = conn.getHeaderField("Location");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return fieldHeader;
|
return redirectUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue