HADOOP-13641. Update UGI#spawnAutoRenewalThreadForUserCreds to reduce indentation. Contributed by Huafeng Wang

This commit is contained in:
Kai Zheng 2016-10-09 15:53:36 +06:00
parent bea004eaeb
commit 3d59b18d49
1 changed files with 49 additions and 49 deletions

View File

@ -946,60 +946,60 @@ public class UserGroupInformation {
/**Spawn a thread to do periodic renewals of kerberos credentials*/ /**Spawn a thread to do periodic renewals of kerberos credentials*/
private void spawnAutoRenewalThreadForUserCreds() { private void spawnAutoRenewalThreadForUserCreds() {
if (isSecurityEnabled()) { if (!isSecurityEnabled()
//spawn thread only if we have kerb credentials || user.getAuthenticationMethod() != AuthenticationMethod.KERBEROS
if (user.getAuthenticationMethod() == AuthenticationMethod.KERBEROS && || isKeytab) {
!isKeytab) { return;
Thread t = new Thread(new Runnable() { }
@Override //spawn thread only if we have kerb credentials
public void run() { Thread t = new Thread(new Runnable() {
String cmd = conf.get("hadoop.kerberos.kinit.command",
"kinit"); @Override
KerberosTicket tgt = getTGT(); public void run() {
String cmd = conf.get("hadoop.kerberos.kinit.command", "kinit");
KerberosTicket tgt = getTGT();
if (tgt == null) {
return;
}
long nextRefresh = getRefreshTime(tgt);
while (true) {
try {
long now = Time.now();
if (LOG.isDebugEnabled()) {
LOG.debug("Current time is " + now);
LOG.debug("Next refresh is " + nextRefresh);
}
if (now < nextRefresh) {
Thread.sleep(nextRefresh - now);
}
Shell.execCommand(cmd, "-R");
if (LOG.isDebugEnabled()) {
LOG.debug("renewed ticket");
}
reloginFromTicketCache();
tgt = getTGT();
if (tgt == null) { if (tgt == null) {
LOG.warn("No TGT after renewal. Aborting renew thread for " +
getUserName());
return; return;
} }
long nextRefresh = getRefreshTime(tgt); nextRefresh = Math.max(getRefreshTime(tgt),
while (true) { now + kerberosMinSecondsBeforeRelogin);
try { } catch (InterruptedException ie) {
long now = Time.now(); LOG.warn("Terminating renewal thread");
if(LOG.isDebugEnabled()) { return;
LOG.debug("Current time is " + now); } catch (IOException ie) {
LOG.debug("Next refresh is " + nextRefresh); LOG.warn("Exception encountered while running the" +
} " renewal command. Aborting renew thread. " + ie);
if (now < nextRefresh) { return;
Thread.sleep(nextRefresh - now);
}
Shell.execCommand(cmd, "-R");
if(LOG.isDebugEnabled()) {
LOG.debug("renewed ticket");
}
reloginFromTicketCache();
tgt = getTGT();
if (tgt == null) {
LOG.warn("No TGT after renewal. Aborting renew thread for " +
getUserName());
return;
}
nextRefresh = Math.max(getRefreshTime(tgt),
now + kerberosMinSecondsBeforeRelogin);
} catch (InterruptedException ie) {
LOG.warn("Terminating renewal thread");
return;
} catch (IOException ie) {
LOG.warn("Exception encountered while running the" +
" renewal command. Aborting renew thread. " + ie);
return;
}
}
} }
}); }
t.setDaemon(true);
t.setName("TGT Renewer for " + getUserName());
t.start();
} }
} });
t.setDaemon(true);
t.setName("TGT Renewer for " + getUserName());
t.start();
} }
/** /**
* Log a user in from a keytab file. Loads a user identity from a keytab * Log a user in from a keytab file. Loads a user identity from a keytab