Search in sources :

Example 6 with RMDelegationTokenIdentifierData

use of org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData in project hadoop by apache.

the class ZKRMStateStore method loadRMDelegationTokenState.

private void loadRMDelegationTokenState(RMState rmState) throws Exception {
    List<String> childNodes = getChildren(delegationTokensRootPath);
    for (String childNodeName : childNodes) {
        String childNodePath = getNodePath(delegationTokensRootPath, childNodeName);
        byte[] childData = getData(childNodePath);
        if (childData == null) {
            LOG.warn("Content of " + childNodePath + " is broken.");
            continue;
        }
        ByteArrayInputStream is = new ByteArrayInputStream(childData);
        try (DataInputStream fsIn = new DataInputStream(is)) {
            if (childNodeName.startsWith(DELEGATION_TOKEN_PREFIX)) {
                RMDelegationTokenIdentifierData identifierData = new RMDelegationTokenIdentifierData();
                identifierData.readFields(fsIn);
                RMDelegationTokenIdentifier identifier = identifierData.getTokenIdentifier();
                long renewDate = identifierData.getRenewDate();
                rmState.rmSecretManagerState.delegationTokenState.put(identifier, renewDate);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Loaded RMDelegationTokenIdentifier: " + identifier + " renewDate=" + renewDate);
                }
            }
        }
    }
}
Also used : RMDelegationTokenIdentifierData(org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData) ByteArrayInputStream(java.io.ByteArrayInputStream) RMDelegationTokenIdentifier(org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier) DataInputStream(java.io.DataInputStream)

Example 7 with RMDelegationTokenIdentifierData

use of org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData in project hadoop by apache.

the class LeveldbRMStateStore method storeOrUpdateRMDT.

private void storeOrUpdateRMDT(RMDelegationTokenIdentifier tokenId, Long renewDate, boolean isUpdate) throws IOException {
    String tokenKey = getRMDTTokenNodeKey(tokenId);
    RMDelegationTokenIdentifierData tokenData = new RMDelegationTokenIdentifierData(tokenId, renewDate);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Storing token to " + tokenKey);
    }
    try {
        WriteBatch batch = db.createWriteBatch();
        try {
            batch.put(bytes(tokenKey), tokenData.toByteArray());
            if (!isUpdate) {
                ByteArrayOutputStream bs = new ByteArrayOutputStream();
                try (DataOutputStream ds = new DataOutputStream(bs)) {
                    ds.writeInt(tokenId.getSequenceNumber());
                }
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Storing " + tokenId.getSequenceNumber() + " to " + RM_DT_SEQUENCE_NUMBER_KEY);
                }
                batch.put(bytes(RM_DT_SEQUENCE_NUMBER_KEY), bs.toByteArray());
            }
            db.write(batch);
        } finally {
            batch.close();
        }
    } catch (DBException e) {
        throw new IOException(e);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) RMDelegationTokenIdentifierData(org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData) DataOutputStream(java.io.DataOutputStream) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) WriteBatch(org.iq80.leveldb.WriteBatch)

Aggregations

RMDelegationTokenIdentifierData (org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData)7 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInputStream (java.io.DataInputStream)3 IOException (java.io.IOException)3 RMDelegationTokenIdentifier (org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 Path (org.apache.hadoop.fs.Path)2 JniDBFactory.asString (org.fusesource.leveldbjni.JniDBFactory.asString)2 DBException (org.iq80.leveldb.DBException)2 FileNotFoundException (java.io.FileNotFoundException)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 DelegationKey (org.apache.hadoop.security.token.delegation.DelegationKey)1 LeveldbIterator (org.apache.hadoop.yarn.server.utils.LeveldbIterator)1 WriteBatch (org.iq80.leveldb.WriteBatch)1