Example usage for org.apache.hadoop.hdfs.security.token.delegation DelegationTokenIdentifier getIssueDate

List of usage examples for org.apache.hadoop.hdfs.security.token.delegation DelegationTokenIdentifier getIssueDate

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs.security.token.delegation DelegationTokenIdentifier getIssueDate.

Prototype

public long getIssueDate() 

Source Link

Usage

From source file:co.cask.cdap.app.runtime.spark.SparkCredentialsUpdater.java

License:Apache License

@VisibleForTesting
long getNextUpdateDelay(Credentials credentials) throws IOException {
    long now = System.currentTimeMillis();

    // This is almost the same logic as in SparkHadoopUtil.getTimeFromNowToRenewal
    for (Token<? extends TokenIdentifier> token : credentials.getAllTokens()) {
        if (DelegationTokenIdentifier.HDFS_DELEGATION_KIND.equals(token.getKind())) {
            DelegationTokenIdentifier identifier = new DelegationTokenIdentifier();
            try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(token.getIdentifier()))) {
                identifier.readFields(input);

                // speed up by 2 seconds to account for any time race between driver and executor
                return Math.max(0L, (long) (identifier.getIssueDate() + 0.8 * updateIntervalMs) - now - 2000);
            }/*from   ww  w  .  ja  v a2 s  . c  om*/
        }
    }
    return 0L;
}