Skip to content

Commit 852b7f1

Browse files
committed
fix ut
1 parent fe396f6 commit 852b7f1

File tree

11 files changed

+473
-65
lines changed

11 files changed

+473
-65
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,4 +609,9 @@ public boolean equals(Object obj) {
609609
protected interface Func<T, TResult> {
610610
TResult invoke(T input) throws Exception;
611611
}
612+
613+
@VisibleForTesting
614+
public FederationStateStore getStateStore() {
615+
return stateStore;
616+
}
612617
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/AppReportFetcher.java

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.hadoop.yarn.server.webproxy;
2020

2121
import java.io.IOException;
22+
import org.apache.hadoop.classification.VisibleForTesting;
2223
import org.apache.hadoop.conf.Configuration;
2324
import org.apache.hadoop.yarn.api.ApplicationHistoryProtocol;
2425
import org.apache.hadoop.yarn.api.records.ApplicationId;
@@ -29,6 +30,8 @@
2930
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
3031
import org.apache.hadoop.yarn.factories.RecordFactory;
3132
import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
33+
import org.apache.hadoop.yarn.util.StringHelper;
34+
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
3235

3336
/**
3437
* This class abstracts away how ApplicationReports are fetched.
@@ -37,21 +40,26 @@ public abstract class AppReportFetcher {
3740

3841
protected enum AppReportSource {RM, AHS}
3942

40-
protected final Configuration conf;
41-
protected ApplicationHistoryProtocol historyManager;
42-
protected final RecordFactory recordFactory = RecordFactoryProvider
43+
private final Configuration conf;
44+
private ApplicationHistoryProtocol historyManager;
45+
private String ahsAppPageUrlBase;
46+
private final RecordFactory recordFactory = RecordFactoryProvider
4347
.getRecordFactory(null);
44-
protected boolean isAHSEnabled;
48+
private boolean isAHSEnabled;
4549

4650
public AppReportFetcher(Configuration conf) {
4751
this.conf = conf;
4852
if (conf.getBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED,
4953
YarnConfiguration.DEFAULT_APPLICATION_HISTORY_ENABLED)) {
5054
isAHSEnabled = true;
5155
}
56+
this.ahsAppPageUrlBase =
57+
StringHelper.pjoin(WebAppUtils.getHttpSchemePrefix(conf)
58+
+ WebAppUtils.getAHSWebAppURLWithoutScheme(conf),
59+
"applicationhistory", "app");
5260
try {
5361
if (isAHSEnabled) {
54-
historyManager = getAHSProxy(conf);
62+
this.historyManager = getAHSProxy(conf);
5563
} else {
5664
this.historyManager = null;
5765
}
@@ -83,8 +91,34 @@ public abstract FetchedAppReport getApplicationReport(ApplicationId appId)
8391
public abstract String getRmAppPageUrlBase(ApplicationId appId)
8492
throws IOException, YarnException;
8593

94+
public String getAhsAppPageUrlBase(ApplicationId appId) {
95+
return this.ahsAppPageUrlBase;
96+
}
97+
8698
public abstract void stop();
8799

100+
protected Configuration getConf() {
101+
return this.conf;
102+
}
103+
104+
protected ApplicationHistoryProtocol getHistoryManager() {
105+
return this.historyManager;
106+
}
107+
108+
protected RecordFactory getRecordFactory() {
109+
return this.recordFactory;
110+
}
111+
112+
protected boolean isAHSEnabled() {
113+
return this.isAHSEnabled;
114+
}
115+
116+
@VisibleForTesting
117+
public void setHistoryManager(
118+
ApplicationHistoryProtocol historyManager) {
119+
this.historyManager = historyManager;
120+
}
121+
88122
/*
89123
* This class creates a bundle of the application report and the source from
90124
* where the the report was fetched. This allows the WebAppProxyServlet

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/DefaultAppReportFetcher.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public DefaultAppReportFetcher(Configuration conf,
8080
*/
8181
public FetchedAppReport getApplicationReport(ApplicationId appId)
8282
throws YarnException, IOException {
83-
GetApplicationReportRequest request = recordFactory
83+
GetApplicationReportRequest request = getRecordFactory()
8484
.newRecordInstance(GetApplicationReportRequest.class);
8585
request.setApplicationId(appId);
8686

@@ -91,12 +91,12 @@ public FetchedAppReport getApplicationReport(ApplicationId appId)
9191
getApplicationReport(request).getApplicationReport();
9292
fetchedAppReport = new FetchedAppReport(appReport, AppReportSource.RM);
9393
} catch (ApplicationNotFoundException e) {
94-
if (!isAHSEnabled) {
94+
if (!isAHSEnabled()) {
9595
// Just throw it as usual if historyService is not enabled.
9696
throw e;
9797
}
9898
//Fetch the application report from AHS
99-
appReport = historyManager.getApplicationReport(request)
99+
appReport = getHistoryManager().getApplicationReport(request)
100100
.getApplicationReport();
101101
fetchedAppReport = new FetchedAppReport(appReport, AppReportSource.AHS);
102102
}
@@ -112,8 +112,8 @@ public void stop() {
112112
if (this.applicationsManager != null) {
113113
RPC.stopProxy(this.applicationsManager);
114114
}
115-
if (this.historyManager != null) {
116-
RPC.stopProxy(this.historyManager);
115+
if (this.getHistoryManager() != null) {
116+
RPC.stopProxy(this.getHistoryManager());
117117
}
118118
}
119119
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/FedAppReportFetcher.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public FetchedAppReport getApplicationReport(ApplicationId appId)
7272
ApplicationClientProtocol applicationsManager = subClusters.get(scid)
7373
.getRight();
7474

75-
GetApplicationReportRequest request = recordFactory
75+
GetApplicationReportRequest request = getRecordFactory()
7676
.newRecordInstance(GetApplicationReportRequest.class);
7777
request.setApplicationId(appId);
7878

@@ -83,12 +83,12 @@ public FetchedAppReport getApplicationReport(ApplicationId appId)
8383
getApplicationReport(request).getApplicationReport();
8484
fetchedAppReport = new FetchedAppReport(appReport, AppReportSource.RM);
8585
} catch (ApplicationNotFoundException e) {
86-
if (!isAHSEnabled) {
86+
if (!isAHSEnabled()) {
8787
// Just throw it as usual if historyService is not enabled.
8888
throw e;
8989
}
9090
//Fetch the application report from AHS
91-
appReport = historyManager.getApplicationReport(request)
91+
appReport = getHistoryManager().getApplicationReport(request)
9292
.getApplicationReport();
9393
fetchedAppReport = new FetchedAppReport(appReport, AppReportSource.AHS);
9494
}
@@ -102,15 +102,15 @@ public String getRmAppPageUrlBase(ApplicationId appId)
102102
makeSureGetClusterInfo(scid);
103103

104104
SubClusterInfo subClusterInfo = subClusters.get(scid).getLeft();
105-
return StringHelper.pjoin(WebAppUtils.getHttpSchemePrefix(conf)
105+
return StringHelper.pjoin(WebAppUtils.getHttpSchemePrefix(getConf())
106106
+ subClusterInfo.getRMWebServiceAddress(), "cluster", "app");
107107
}
108108

109109
private void makeSureGetClusterInfo(SubClusterId scid)
110110
throws YarnException, IOException {
111111
if (subClusters.get(scid) == null) {
112112
SubClusterInfo subClusterInfo = federationFacade.getSubCluster(scid);
113-
Configuration subClusterConf = new Configuration(conf);
113+
Configuration subClusterConf = new Configuration(getConf());
114114
FederationProxyProviderUtil.updateConfForFederation(subClusterConf,
115115
subClusterInfo.getSubClusterId().toString());
116116
ApplicationClientProtocol proxy =
@@ -124,8 +124,8 @@ public void stop() {
124124
for (Pair pair : this.subClusters.values()) {
125125
RPC.stopProxy(pair.getRight());
126126
}
127-
if (this.historyManager != null) {
128-
RPC.stopProxy(this.historyManager);
127+
if (this.getHistoryManager() != null) {
128+
RPC.stopProxy(this.getHistoryManager());
129129
}
130130
}
131131

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,9 @@ public void join() {
162162
String getBindAddress() {
163163
return bindAddress + ":" + port;
164164
}
165+
166+
@VisibleForTesting
167+
public AppReportFetcher getFetcher() {
168+
return fetcher;
169+
}
165170
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxyServlet.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public class WebAppProxyServlet extends HttpServlet {
9595
public static final String PROXY_USER_COOKIE_NAME = "proxy-user";
9696

9797
private transient List<TrackingUriPlugin> trackingUriPlugins;
98-
private final String ahsAppPageUrlBase;
9998
private final String failurePageUrlBase;
10099
private transient YarnConfiguration conf;
101100

@@ -136,10 +135,6 @@ public WebAppProxyServlet() {
136135
this.failurePageUrlBase =
137136
StringHelper.pjoin(WebAppUtils.getResolvedRMWebAppURLWithScheme(conf),
138137
"cluster", "failure");
139-
this.ahsAppPageUrlBase =
140-
StringHelper.pjoin(WebAppUtils.getHttpSchemePrefix(conf)
141-
+ WebAppUtils.getAHSWebAppURLWithoutScheme(conf),
142-
"applicationhistory", "app");
143138
}
144139

145140
private String getRmAppPageUrlBase(ApplicationId id)
@@ -148,6 +143,12 @@ private String getRmAppPageUrlBase(ApplicationId id)
148143
.getAttribute(WebAppProxy.FETCHER_ATTRIBUTE)).getRmAppPageUrlBase(id);
149144
}
150145

146+
private String getAhsAppPageUrlBase(ApplicationId id)
147+
throws YarnException, IOException {
148+
return ((AppReportFetcher) getServletContext()
149+
.getAttribute(WebAppProxy.FETCHER_ATTRIBUTE)).getAhsAppPageUrlBase(id);
150+
}
151+
151152
/**
152153
* Output 404 with appropriate message.
153154
* @param resp the http response.
@@ -599,7 +600,7 @@ private URI getTrackingUri(HttpServletRequest req, HttpServletResponse resp,
599600
LOG.debug("Original tracking url is '{}'. Redirecting to AHS app page",
600601
originalUri == null ? "NULL" : originalUri);
601602
ProxyUtils.sendRedirect(req, resp,
602-
StringHelper.pjoin(ahsAppPageUrlBase, id.toString()));
603+
StringHelper.pjoin(getAhsAppPageUrlBase(id), id.toString()));
603604
}
604605
} else if (ProxyUriUtils.getSchemeFromUrl(originalUri).isEmpty()) {
605606
trackingUri =

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestAppReportFetcher.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@
3636

3737
public class TestAppReportFetcher {
3838

39-
static ApplicationHistoryProtocol history;
39+
static ApplicationHistoryProtocol historyManager;
4040
static Configuration conf = new Configuration();
4141
private static ApplicationClientProtocol appManager;
4242
private static AppReportFetcher fetcher;
4343
private final String appNotFoundExceptionMsg = "APP NOT FOUND";
4444

4545
@After
4646
public void cleanUp() {
47-
history = null;
47+
historyManager = null;
4848
appManager = null;
4949
fetcher = null;
5050
}
@@ -65,7 +65,7 @@ public void testHelper(boolean isAHSEnabled)
6565
@Test
6666
public void testFetchReportAHSEnabled() throws YarnException, IOException {
6767
testHelper(true);
68-
Mockito.verify(history, Mockito.times(1))
68+
Mockito.verify(historyManager, Mockito.times(1))
6969
.getApplicationReport(Mockito.any(GetApplicationReportRequest.class));
7070
Mockito.verify(appManager, Mockito.times(1))
7171
.getApplicationReport(Mockito.any(GetApplicationReportRequest.class));
@@ -85,7 +85,7 @@ public void testFetchReportAHSDisabled() throws YarnException, IOException {
8585
Mockito.verify(appManager, Mockito.times(1))
8686
.getApplicationReport(Mockito.any(GetApplicationReportRequest.class));
8787
Assert.assertNull("HistoryManager should be null as AHS is disabled",
88-
history);
88+
historyManager);
8989
}
9090

9191
static class AppReportFetcherForTest extends DefaultAppReportFetcher {
@@ -101,15 +101,15 @@ protected ApplicationHistoryProtocol getAHSProxy(Configuration conf)
101101
{
102102
GetApplicationReportResponse resp = Mockito.
103103
mock(GetApplicationReportResponse.class);
104-
history = Mockito.mock(ApplicationHistoryProtocol.class);
104+
historyManager = Mockito.mock(ApplicationHistoryProtocol.class);
105105
try {
106-
Mockito.when(history.getApplicationReport(Mockito
106+
Mockito.when(historyManager.getApplicationReport(Mockito
107107
.any(GetApplicationReportRequest.class))).thenReturn(resp);
108108
} catch (YarnException e) {
109109
// TODO Auto-generated catch block
110110
e.printStackTrace();
111111
}
112-
return history;
112+
return historyManager;
113113
}
114114
}
115115
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestFedAppReportFetcher.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@
4545

4646
public class TestFedAppReportFetcher {
4747

48-
Configuration conf;
49-
static ApplicationHistoryProtocol history;
48+
private Configuration conf;
49+
private static ApplicationHistoryProtocol history;
5050

5151
private SubClusterId subClusterId1 = SubClusterId.newInstance("subCluster1");
5252
private SubClusterId subClusterId2 = SubClusterId.newInstance("subCluster2");
5353
private SubClusterInfo clusterInfo1 = SubClusterInfo
5454
.newInstance(subClusterId1, "10.0.0.1:1000", "10.0.0.1:1000",
55-
"10.0.0.1:1000", "10.0.0.1:1000", SubClusterState.SC_RUNNING, 0l, "");
55+
"10.0.0.1:1000", "10.0.0.1:1000", SubClusterState.SC_RUNNING, 0L, "");
5656
private SubClusterInfo clusterInfo2 = SubClusterInfo
5757
.newInstance(subClusterId2, "10.0.0.2:1000", "10.0.0.2:1000",
58-
"10.0.0.2:1000", "10.0.0.2:1000", SubClusterState.SC_RUNNING, 0l, "");
58+
"10.0.0.2:1000", "10.0.0.2:1000", SubClusterState.SC_RUNNING, 0L, "");
5959
private ApplicationClientProtocol appManager1;
6060
private ApplicationClientProtocol appManager2;
6161
private ApplicationId appId1 = ApplicationId.newInstance(0, 1);
@@ -161,7 +161,7 @@ public void testGetRmAppPageUrlBase() throws IOException, YarnException {
161161

162162
static class FedAppReportFetcherForTest extends FedAppReportFetcher {
163163

164-
public FedAppReportFetcherForTest(Configuration conf) {
164+
FedAppReportFetcherForTest(Configuration conf) {
165165
super(conf);
166166
}
167167

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class TestWebAppProxyServer {
3434
private WebAppProxyServer webAppProxy = null;
3535
private final String port = "8888";
3636
private final String proxyAddress = "localhost:" + port;
37-
protected YarnConfiguration conf = null;
37+
private YarnConfiguration conf = null;
3838

3939
@Before
4040
public void setUp() throws Exception {

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServerFed.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)