List of usage examples for org.apache.hadoop.hdfs.security.token.block BlockKey setExpiryDate
public void setExpiryDate(long expiryDate)
From source file:io.hops.metadata.security.token.block.NameNodeBlockTokenSecretManager.java
License:Apache License
private boolean updateBlockKeys() throws IOException { return (Boolean) new HopsTransactionalRequestHandler(HDFSOperationType.UPDATE_BLOCK_KEYS) { @Override//w ww.ja v a 2 s .c o m public void acquireLock(TransactionLocks locks) throws IOException { LockFactory lf = LockFactory.getInstance(); locks.add(lf.getVariableLock(Variable.Finder.BlockTokenKeys, LockType.WRITE)); } @Override public Object performTask() throws StorageException, IOException { Map<Integer, BlockKey> keys = HdfsVariables.getAllBlockTokenKeysByType(); if (keys.isEmpty()) { log.debug("keys is not generated yet to be updated"); return false; } // set final expiry date of retiring currentKey // also modifying this key to mark it as 'simple key' instead of 'current key' BlockKey currentKeyFromDB = keys.get(BlockKey.KeyType.CurrKey.ordinal()); currentKeyFromDB.setExpiryDate(Time.now() + keyUpdateInterval + tokenLifetime); currentKeyFromDB.setKeyType(BlockKey.KeyType.SimpleKey); // after above update, we only have a key marked as 'next key' // the 'next key' becomes the 'current key' // update the estimated expiry date of new currentKey BlockKey nextKeyFromDB = keys.get(BlockKey.KeyType.NextKey.ordinal()); currentKey = new BlockKey(nextKeyFromDB.getKeyId(), Time.now() + 2 * keyUpdateInterval + tokenLifetime, nextKeyFromDB.getKey()); currentKey.setKeyType(BlockKey.KeyType.CurrKey); // generate a new nextKey setSerialNo(serialNo + 1); nextKey = new BlockKey(serialNo, Time.now() + 3 * keyUpdateInterval + tokenLifetime, generateSecret()); nextKey.setKeyType(BlockKey.KeyType.NextKey); HdfsVariables.updateBlockTokenKeys(currentKey, nextKey, currentKeyFromDB); return true; } }.handle(); }