@Override public void run() { if (cancelled.get()) { return; } Token<?> token = dttr.token; try { requestNewHdfsDelegationTokenIfNeeded(dttr); // if the token is not replaced by a new token, renew the token if (!dttr.isTimerCancelled()) { renewToken(dttr); setTimerForTokenRenewal(dttr);// set the next one } else { LOG.info("The token was removed already. Token = [" +dttr +"]"); } } catch (Exception e) { LOG.error("Exception renewing token" + token + ". Not rescheduled", e); removeFailedDelegationToken(dttr); } }
iter.remove(); allTokens.remove(t.token); t.cancelTimer(); LOG.info("Removed expiring token " + t);
/** * set task to renew the token */ @VisibleForTesting protected void setTimerForTokenRenewal(DelegationTokenToRenew token) throws IOException { // calculate timer time long expiresIn = token.expirationDate - System.currentTimeMillis(); if (expiresIn <= 0) { LOG.info("Will not renew token " + token); return; } long renewIn = token.expirationDate - expiresIn/10; // little bit before the expiration // need to create new task every time RenewalTimerTask tTask = new RenewalTimerTask(token); token.setTimerTask(tTask); // keep reference to the timer renewalTimer.schedule(token.timerTask, new Date(renewIn)); LOG.info("Renew " + token + " in " + expiresIn + " ms, appId = " + token.referringAppIds); }
tokenConf = getConfig(); dttr = new DelegationTokenToRenew(Arrays.asList(applicationId), token, tokenConf, now, shouldCancelAtEnd, evt.getUser()); try {
Assert.assertTrue(dttr.referringAppIds.contains(app1.getApplicationId())); Assert.assertFalse(dttr.referringAppIds.contains(app2.getApplicationId())); Assert.assertFalse(dttr.isTimerCancelled()); Assert.assertFalse(Renewer.cancelled); Assert.assertTrue(dttr.referringAppIds.contains(app1.getApplicationId())); Assert.assertTrue(dttr.referringAppIds.contains(app3.getApplicationId())); Assert.assertFalse(dttr.isTimerCancelled()); Assert.assertFalse(Renewer.cancelled); Assert.assertFalse(dttr.referringAppIds.contains(app1.getApplicationId())); Assert.assertTrue(dttr.referringAppIds.contains(app3.getApplicationId())); Assert.assertFalse(dttr.isTimerCancelled()); Assert.assertFalse(Renewer.cancelled); Assert.assertTrue(dttr.isTimerCancelled()); GenericTestUtils.waitFor(new Supplier<Boolean>() { @Override
Assert.assertTrue(dttr.referringAppIds.contains(app1.getApplicationId())); Assert.assertFalse(dttr.referringAppIds.contains(app2.getApplicationId())); Assert.assertFalse(dttr.isTimerCancelled()); Assert.assertFalse(Renewer.cancelled); Assert.assertTrue(dttr.referringAppIds.contains(app1.getApplicationId())); Assert.assertTrue(dttr.referringAppIds.contains(app3.getApplicationId())); Assert.assertFalse(dttr.isTimerCancelled()); Assert.assertFalse(Renewer.cancelled); Assert.assertFalse(dttr.referringAppIds.contains(app1.getApplicationId())); Assert.assertTrue(dttr.referringAppIds.contains(app3.getApplicationId())); Assert.assertFalse(dttr.isTimerCancelled()); Assert.assertFalse(Renewer.cancelled); Assert.assertFalse(renewer.getAllTokens().containsKey(token1)); Assert.assertTrue(dttr.referringAppIds.isEmpty()); Assert.assertTrue(dttr.isTimerCancelled()); Assert.assertTrue(Renewer.cancelled);
dttr = new DelegationTokenToRenew(Arrays.asList(applicationId), token, getConfig(), now, shouldCancelAtEnd, evt.getUser()); try {
dttr = new DelegationTokenToRenew(Arrays.asList(applicationId), token, getConfig(), now, shouldCancelAtEnd, evt.getUser()); try {
if (token.isManaged()) { DelegationTokenToRenew tokenToRenew = new DelegationTokenToRenew(referringAppIds, token, getConfig(), Time.now(), shouldCancelAtEnd, user);
if (token.isManaged()) { DelegationTokenToRenew tokenToRenew = new DelegationTokenToRenew(referringAppIds, token, getConfig(), Time.now(), shouldCancelAtEnd, user);
if (token.isManaged()) { DelegationTokenToRenew tokenToRenew = new DelegationTokenToRenew(referringAppIds, token, getConfig(), Time.now(), shouldCancelAtEnd, user);
iter.remove(); allTokens.remove(t.token); t.cancelTimer(); LOG.info("Removed expiring token " + t);
private void removeApplicationFromRenewal(ApplicationId applicationId) { rmContext.getSystemCredentialsForApps().remove(applicationId); Set<DelegationTokenToRenew> tokens = appTokens.remove(applicationId); if (tokens != null && !tokens.isEmpty()) { synchronized (tokens) { Iterator<DelegationTokenToRenew> it = tokens.iterator(); while (it.hasNext()) { DelegationTokenToRenew dttr = it.next(); if (LOG.isDebugEnabled()) { LOG.debug("Removing delegation token for appId=" + applicationId + "; token=" + dttr.token.getService()); } // continue if the app list isn't empty synchronized(dttr.referringAppIds) { dttr.referringAppIds.remove(applicationId); if (!dttr.referringAppIds.isEmpty()) { continue; } } // cancel the timer dttr.cancelTimer(); // cancel the token cancelToken(dttr); allTokens.remove(dttr.token); } } } }
private void removeApplicationFromRenewal(ApplicationId applicationId) { rmContext.getSystemCredentialsForApps().remove(applicationId); Set<DelegationTokenToRenew> tokens = appTokens.remove(applicationId); if (tokens != null && !tokens.isEmpty()) { synchronized (tokens) { Iterator<DelegationTokenToRenew> it = tokens.iterator(); while (it.hasNext()) { DelegationTokenToRenew dttr = it.next(); if (LOG.isDebugEnabled()) { LOG.debug("Removing delegation token for appId=" + applicationId + "; token=" + dttr.token.getService()); } // continue if the app list isn't empty synchronized(dttr.referringAppIds) { dttr.referringAppIds.remove(applicationId); if (!dttr.referringAppIds.isEmpty()) { continue; } } // cancel the timer dttr.cancelTimer(); // cancel the token cancelToken(dttr); allTokens.remove(dttr.token); } } } }
iter.remove(); allTokens.remove(t.token); t.cancelTimer(); LOG.info("Removed expiring token " + t);
@Override public void run() { if (cancelled.get()) { return; } Token<?> token = dttr.token; try { requestNewHdfsDelegationTokenIfNeeded(dttr); // if the token is not replaced by a new token, renew the token if (!dttr.isTimerCancelled()) { renewToken(dttr); setTimerForTokenRenewal(dttr);// set the next one } else { LOG.info("The token was removed already. Token = [" +dttr +"]"); } } catch (Exception e) { LOG.error("Exception renewing token" + token + ". Not rescheduled", e); removeFailedDelegationToken(dttr); } }
@Override public void run() { if (cancelled.get()) { return; } Token<?> token = dttr.token; try { requestNewHdfsDelegationTokenIfNeeded(dttr); // if the token is not replaced by a new token, renew the token if (!dttr.isTimerCancelled()) { renewToken(dttr); setTimerForTokenRenewal(dttr);// set the next one } else { LOG.info("The token was removed already. Token = [" +dttr +"]"); } } catch (Exception e) { LOG.error("Exception renewing token" + token + ". Not rescheduled", e); removeFailedDelegationToken(dttr); } }
/** * removing failed DT */ private void removeFailedDelegationToken(DelegationTokenToRenew t) { Collection<ApplicationId> applicationIds = t.referringAppIds; synchronized (applicationIds) { LOG.error("removing failed delegation token for appid=" + applicationIds + ";t=" + t.token.getService()); for (ApplicationId applicationId : applicationIds) { appTokens.get(applicationId).remove(t); } } allTokens.remove(t.token); // cancel the timer t.cancelTimer(); }
/** * set task to renew the token */ @VisibleForTesting protected void setTimerForTokenRenewal(DelegationTokenToRenew token) throws IOException { // calculate timer time long expiresIn = token.expirationDate - System.currentTimeMillis(); long renewIn = token.expirationDate - expiresIn/10; // little bit before the expiration // need to create new task every time RenewalTimerTask tTask = new RenewalTimerTask(token); token.setTimerTask(tTask); // keep reference to the timer renewalTimer.schedule(token.timerTask, new Date(renewIn)); LOG.info("Renew " + token + " in " + expiresIn + " ms, appId = " + token.referringAppIds); }