Skip to content

Commit 38c5aac

Browse files
authored
TEZ-4564: TezClient to expose Tez AM host:port (#356). (Laszlo Bodor, reviewed by Ayush Saxena)
1 parent 30e9cdb commit 38c5aac

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

tez-api/src/main/java/org/apache/tez/client/FrameworkClient.java

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ public abstract ApplicationId submitApplication(ApplicationSubmissionContext app
9494

9595
public abstract ApplicationReport getApplicationReport(ApplicationId appId) throws YarnException, IOException;
9696

97+
public abstract String getAmHost();
98+
public abstract int getAmPort();
99+
97100
public abstract boolean isRunning() throws IOException;
98101

99102
public TezAppMasterStatus getAMStatus(Configuration conf, ApplicationId appId,

tez-api/src/main/java/org/apache/tez/client/TezClient.java

+8
Original file line numberDiff line numberDiff line change
@@ -1286,4 +1286,12 @@ public static ApplicationId appIdfromString(String appIdStr) {
12861286
+ appIdStr, n);
12871287
}
12881288
}
1289+
1290+
public String getAmHost() {
1291+
return frameworkClient == null ? null : frameworkClient.getAmHost();
1292+
}
1293+
1294+
public int getAmPort() {
1295+
return frameworkClient == null ? -1 : frameworkClient.getAmPort();
1296+
}
12891297
}

tez-api/src/main/java/org/apache/tez/client/TezYarnClient.java

+15
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public class TezYarnClient extends FrameworkClient {
4040

4141
private volatile boolean isRunning;
4242

43+
private String amHost;
44+
private int amPort;
45+
4346
protected TezYarnClient(YarnClient yarnClient) {
4447
this.yarnClient = yarnClient;
4548
}
@@ -100,11 +103,23 @@ public ApplicationReport getApplicationReport(ApplicationId appId) throws YarnEx
100103
throw new ApplicationNotFoundException("YARN reports no state for application "
101104
+ appId);
102105
}
106+
this.amHost = report.getHost();
107+
this.amPort = report.getRpcPort();
103108
return report;
104109
}
105110

106111
@Override
107112
public boolean isRunning() throws IOException {
108113
return isRunning;
109114
}
115+
116+
@Override
117+
public String getAmHost() {
118+
return amHost;
119+
}
120+
121+
@Override
122+
public int getAmPort() {
123+
return amPort;
124+
}
110125
}

tez-api/src/test/java/org/apache/tez/client/TestTezClient.java

+19
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ protected DAGClientAMProtocolBlockingPB getProxy(Configuration conf, Application
161161
}
162162
return super.getProxy(conf, sessionAppId, ugi);
163163
}
164+
165+
@Override
166+
public String getAmHost() {
167+
return "testhost";
168+
}
169+
170+
@Override
171+
public int getAmPort() {
172+
return 1234;
173+
}
164174
}
165175

166176
TezClientForTest configureAndCreateTezClient() throws YarnException, IOException, ServiceException {
@@ -1005,4 +1015,13 @@ public void testYarnZkDeprecatedConf() {
10051015
//Test that Exception is not thrown by createFinalConfProtoForApp
10061016
TezClientUtils.createFinalConfProtoForApp(conf, null);
10071017
}
1018+
1019+
@Test
1020+
public void testGetAmHostAndPort() throws Exception {
1021+
final TezClientForTest client = configureAndCreateTezClient(new TezConfiguration());
1022+
1023+
// TezClient exposes AM host and port from the FrameworkClient (now it's a TezYarnClientForTest)
1024+
assertEquals("testhost", client.getAmHost());
1025+
assertEquals(1234, client.getAmPort());
1026+
}
10081027
}

tez-dag/src/main/java/org/apache/tez/client/LocalClient.java

+15
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public class LocalClient extends FrameworkClient {
8888
private TezApiVersionInfo versionInfo = new TezApiVersionInfo();
8989
private volatile Throwable amFailException = null;
9090
private boolean isLocalWithoutNetwork;
91+
private String amHost;
92+
private int amPort;
9193

9294
private static final String localModeDAGSchedulerClassName =
9395
"org.apache.tez.dag.app.dag.impl.DAGSchedulerNaturalOrderControlled";
@@ -204,6 +206,9 @@ public ApplicationReport getApplicationReport(ApplicationId appId) {
204206
report.setProgress(dagAppMaster.getProgress());
205207
report.setAMRMToken(null);
206208

209+
this.amHost = dagAppMaster.getAppNMHost();
210+
this.amPort = dagAppMaster.getRpcPort();
211+
207212
return report;
208213
}
209214

@@ -475,4 +480,14 @@ public boolean shutdownSession(Configuration configuration, ApplicationId sessio
475480
}
476481
return super.shutdownSession(configuration, sessionAppId, ugi);
477482
}
483+
484+
@Override
485+
public String getAmHost() {
486+
return amHost;
487+
}
488+
489+
@Override
490+
public int getAmPort() {
491+
return amPort;
492+
}
478493
}

0 commit comments

Comments
 (0)