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

This commit is contained in:
Jason Lowe 2015-02-06 20:55:00 +00:00
parent 4c484320b4
commit 6f10434a5a
5 changed files with 80 additions and 14 deletions

View File

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

View File

@ -1385,6 +1385,13 @@ public class YarnConfiguration extends Configuration {
public static final long public static final long
DEFAULT_TIMELINE_SERVICE_CLIENT_RETRY_INTERVAL_MS = 1000; 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 */ /** Flag to enable recovery of timeline service */
public static final String TIMELINE_SERVICE_RECOVERY_ENABLED = public static final String TIMELINE_SERVICE_RECOVERY_ENABLED =
TIMELINE_SERVICE_PREFIX + "recovery.enabled"; TIMELINE_SERVICE_PREFIX + "recovery.enabled";

View File

@ -129,6 +129,7 @@ public class YarnClientImpl extends YarnClient {
@VisibleForTesting @VisibleForTesting
String timelineDTRenewer; String timelineDTRenewer;
protected boolean timelineServiceEnabled; protected boolean timelineServiceEnabled;
protected boolean timelineServiceBestEffort;
private static final String ROOT = "root"; private static final String ROOT = "root";
@ -163,14 +164,22 @@ public class YarnClientImpl extends YarnClient {
if (conf.getBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, if (conf.getBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED,
YarnConfiguration.DEFAULT_TIMELINE_SERVICE_ENABLED)) { YarnConfiguration.DEFAULT_TIMELINE_SERVICE_ENABLED)) {
timelineServiceEnabled = true; timelineServiceEnabled = true;
timelineClient = TimelineClient.createTimelineClient(); timelineClient = createTimelineClient();
timelineClient.init(conf); timelineClient.init(conf);
timelineDTRenewer = getTimelineDelegationTokenRenewer(conf); timelineDTRenewer = getTimelineDelegationTokenRenewer(conf);
timelineService = TimelineUtils.buildTimelineTokenService(conf); timelineService = TimelineUtils.buildTimelineTokenService(conf);
} }
timelineServiceBestEffort = conf.getBoolean(
YarnConfiguration.TIMELINE_SERVICE_CLIENT_BEST_EFFORT,
YarnConfiguration.DEFAULT_TIMELINE_SERVICE_CLIENT_BEST_EFFORT);
super.serviceInit(conf); super.serviceInit(conf);
} }
TimelineClient createTimelineClient() throws IOException, YarnException {
return TimelineClient.createTimelineClient();
}
@Override @Override
protected void serviceStart() throws Exception { protected void serviceStart() throws Exception {
try { try {
@ -325,7 +334,16 @@ public class YarnClientImpl extends YarnClient {
@VisibleForTesting @VisibleForTesting
org.apache.hadoop.security.token.Token<TimelineDelegationTokenIdentifier> org.apache.hadoop.security.token.Token<TimelineDelegationTokenIdentifier>
getTimelineDelegationToken() throws IOException, YarnException { getTimelineDelegationToken() throws IOException, YarnException {
return timelineClient.getDelegationToken(timelineDTRenewer); 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) 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 @Test
public void testAutomaticTimelineDelegationTokenLoading() public void testAutomaticTimelineDelegationTokenLoading()
throws Exception { throws Exception {
@ -864,22 +900,18 @@ public class TestYarnClient {
final Token<TimelineDelegationTokenIdentifier> dToken = final Token<TimelineDelegationTokenIdentifier> dToken =
new Token<TimelineDelegationTokenIdentifier>( new Token<TimelineDelegationTokenIdentifier>(
timelineDT.getBytes(), new byte[0], timelineDT.getKind(), new Text()); timelineDT.getBytes(), new byte[0], timelineDT.getKind(), new Text());
// crate a mock client // create a mock client
YarnClientImpl client = spy(new YarnClientImpl() { YarnClientImpl client = spy(new YarnClientImpl() {
@Override @Override
protected void serviceInit(Configuration conf) throws Exception { TimelineClient createTimelineClient() throws IOException, YarnException {
if (getConfig().getBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, timelineClient = mock(TimelineClient.class);
YarnConfiguration.DEFAULT_TIMELINE_SERVICE_ENABLED)) { when(timelineClient.getDelegationToken(any(String.class)))
timelineServiceEnabled = true; .thenReturn(dToken);
timelineClient = mock(TimelineClient.class); return timelineClient;
when(timelineClient.getDelegationToken(any(String.class)))
.thenReturn(dToken);
timelineClient.init(getConfig());
timelineService = TimelineUtils.buildTimelineTokenService(getConfig());
}
this.setConfig(conf);
} }
@Override @Override
protected void serviceStart() throws Exception { protected void serviceStart() throws Exception {
rmClient = mock(ApplicationClientProtocol.class); rmClient = mock(ApplicationClientProtocol.class);

View File

@ -1370,6 +1370,12 @@
<value>30</value> <value>30</value>
</property> </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> <property>
<description> <description>
Default retry time interval for timeline servive client. Default retry time interval for timeline servive client.