YARN-3144. Configuration for making delegation token failures to timeline server not-fatal. Contributed by Jonathan Eagles

(cherry picked from commit 6f10434a5a)
This commit is contained in:
Jason Lowe 2015-02-06 20:55:00 +00:00
parent 83449a4e4d
commit 9361fc8f70
5 changed files with 80 additions and 14 deletions

View File

@ -218,6 +218,9 @@ Release 2.7.0 - UNRELEASED
ApplicationHistoryClientService are uniform when application-attempt is
not found. (zjshen via acmurthy)
YARN-3144. Configuration for making delegation token failures to timeline
server not-fatal (Jonathan Eagles via jlowe)
OPTIMIZATIONS
BUG FIXES

View File

@ -1385,6 +1385,13 @@ public class YarnConfiguration extends Configuration {
public static final long
DEFAULT_TIMELINE_SERVICE_CLIENT_RETRY_INTERVAL_MS = 1000;
/** Timeline client policy for whether connections are fatal */
public static final String TIMELINE_SERVICE_CLIENT_BEST_EFFORT =
TIMELINE_SERVICE_CLIENT_PREFIX + "best-effort";
public static final boolean
DEFAULT_TIMELINE_SERVICE_CLIENT_BEST_EFFORT = false;
/** Flag to enable recovery of timeline service */
public static final String TIMELINE_SERVICE_RECOVERY_ENABLED =
TIMELINE_SERVICE_PREFIX + "recovery.enabled";

View File

@ -129,6 +129,7 @@ public class YarnClientImpl extends YarnClient {
@VisibleForTesting
String timelineDTRenewer;
protected boolean timelineServiceEnabled;
protected boolean timelineServiceBestEffort;
private static final String ROOT = "root";
@ -163,14 +164,22 @@ public class YarnClientImpl extends YarnClient {
if (conf.getBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED,
YarnConfiguration.DEFAULT_TIMELINE_SERVICE_ENABLED)) {
timelineServiceEnabled = true;
timelineClient = TimelineClient.createTimelineClient();
timelineClient = createTimelineClient();
timelineClient.init(conf);
timelineDTRenewer = getTimelineDelegationTokenRenewer(conf);
timelineService = TimelineUtils.buildTimelineTokenService(conf);
}
timelineServiceBestEffort = conf.getBoolean(
YarnConfiguration.TIMELINE_SERVICE_CLIENT_BEST_EFFORT,
YarnConfiguration.DEFAULT_TIMELINE_SERVICE_CLIENT_BEST_EFFORT);
super.serviceInit(conf);
}
TimelineClient createTimelineClient() throws IOException, YarnException {
return TimelineClient.createTimelineClient();
}
@Override
protected void serviceStart() throws Exception {
try {
@ -325,7 +334,16 @@ public class YarnClientImpl extends YarnClient {
@VisibleForTesting
org.apache.hadoop.security.token.Token<TimelineDelegationTokenIdentifier>
getTimelineDelegationToken() throws IOException, YarnException {
try {
return timelineClient.getDelegationToken(timelineDTRenewer);
} catch (Exception e ) {
if (timelineServiceBestEffort) {
LOG.warn("Failed to get delegation token from the timeline server: "
+ e.getMessage());
return null;
}
throw e;
}
}
private static String getTimelineDelegationTokenRenewer(Configuration conf)

View File

@ -853,6 +853,42 @@ public class TestYarnClient {
}
}
@Test
public void testBestEffortTimelineDelegationToken()
throws Exception {
Configuration conf = new YarnConfiguration();
conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true);
SecurityUtil.setAuthenticationMethod(AuthenticationMethod.KERBEROS, conf);
YarnClientImpl client = spy(new YarnClientImpl() {
@Override
TimelineClient createTimelineClient() throws IOException, YarnException {
timelineClient = mock(TimelineClient.class);
when(timelineClient.getDelegationToken(any(String.class)))
.thenThrow(new IOException("Best effort test exception"));
return timelineClient;
}
});
client.init(conf);
try {
conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_CLIENT_BEST_EFFORT, true);
client.serviceInit(conf);
client.getTimelineDelegationToken();
} catch (Exception e) {
Assert.fail("Should not have thrown an exception");
}
try {
conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_CLIENT_BEST_EFFORT, false);
client.serviceInit(conf);
client.getTimelineDelegationToken();
Assert.fail("Get delegation token should have thrown an exception");
} catch (Exception e) {
// Success
}
}
@Test
public void testAutomaticTimelineDelegationTokenLoading()
throws Exception {
@ -864,22 +900,18 @@ public class TestYarnClient {
final Token<TimelineDelegationTokenIdentifier> dToken =
new Token<TimelineDelegationTokenIdentifier>(
timelineDT.getBytes(), new byte[0], timelineDT.getKind(), new Text());
// crate a mock client
// create a mock client
YarnClientImpl client = spy(new YarnClientImpl() {
@Override
protected void serviceInit(Configuration conf) throws Exception {
if (getConfig().getBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED,
YarnConfiguration.DEFAULT_TIMELINE_SERVICE_ENABLED)) {
timelineServiceEnabled = true;
TimelineClient createTimelineClient() throws IOException, YarnException {
timelineClient = mock(TimelineClient.class);
when(timelineClient.getDelegationToken(any(String.class)))
.thenReturn(dToken);
timelineClient.init(getConfig());
timelineService = TimelineUtils.buildTimelineTokenService(getConfig());
}
this.setConfig(conf);
return timelineClient;
}
@Override
protected void serviceStart() throws Exception {
rmClient = mock(ApplicationClientProtocol.class);

View File

@ -1369,6 +1369,12 @@
<value>30</value>
</property>
<property>
<description>Client policy for whether timeline operations are non-fatal</description>
<name>yarn.timeline-service.client.best-effort</name>
<value>false</value>
</property>
<property>
<description>
Default retry time interval for timeline servive client.