Search in sources :

Example 1 with RMDelegationTokenIdentifierData

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

the class LeveldbRMStateStore method loadRMDTSecretManagerTokens.

private int loadRMDTSecretManagerTokens(RMState state) throws IOException {
    int numTokens = 0;
    LeveldbIterator iter = null;
    try {
        iter = new LeveldbIterator(db);
        iter.seek(bytes(RM_DT_TOKEN_KEY_PREFIX));
        while (iter.hasNext()) {
            Entry<byte[], byte[]> entry = iter.next();
            String key = asString(entry.getKey());
            if (!key.startsWith(RM_DT_TOKEN_KEY_PREFIX)) {
                break;
            }
            RMDelegationTokenIdentifierData tokenData = loadDelegationToken(entry.getValue());
            RMDelegationTokenIdentifier tokenId = tokenData.getTokenIdentifier();
            long renewDate = tokenData.getRenewDate();
            state.rmSecretManagerState.delegationTokenState.put(tokenId, renewDate);
            ++numTokens;
            if (LOG.isDebugEnabled()) {
                LOG.debug("Loaded RM delegation token from " + key + ": tokenId=" + tokenId + ", renewDate=" + renewDate);
            }
        }
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        if (iter != null) {
            iter.close();
        }
    }
    return numTokens;
}
Also used : DBException(org.iq80.leveldb.DBException) RMDelegationTokenIdentifierData(org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) RMDelegationTokenIdentifier(org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier) IOException(java.io.IOException)

Example 2 with RMDelegationTokenIdentifierData

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

the class LeveldbRMStateStore method loadDelegationToken.

private RMDelegationTokenIdentifierData loadDelegationToken(byte[] data) throws IOException {
    RMDelegationTokenIdentifierData tokenData = new RMDelegationTokenIdentifierData();
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));
    try {
        tokenData.readFields(in);
    } finally {
        IOUtils.cleanup(LOG, in);
    }
    return tokenData;
}
Also used : RMDelegationTokenIdentifierData(org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream)

Example 3 with RMDelegationTokenIdentifierData

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

the class ZKRMStateStore method addStoreOrUpdateOps.

private void addStoreOrUpdateOps(SafeTransaction trx, RMDelegationTokenIdentifier rmDTIdentifier, Long renewDate, boolean isUpdate) throws Exception {
    // store RM delegation token
    String nodeCreatePath = getNodePath(delegationTokensRootPath, DELEGATION_TOKEN_PREFIX + rmDTIdentifier.getSequenceNumber());
    RMDelegationTokenIdentifierData identifierData = new RMDelegationTokenIdentifierData(rmDTIdentifier, renewDate);
    ByteArrayOutputStream seqOs = new ByteArrayOutputStream();
    try (DataOutputStream seqOut = new DataOutputStream(seqOs)) {
        if (isUpdate) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Updating RMDelegationToken_" + rmDTIdentifier.getSequenceNumber());
            }
            trx.setData(nodeCreatePath, identifierData.toByteArray(), -1);
        } else {
            trx.create(nodeCreatePath, identifierData.toByteArray(), zkAcl, CreateMode.PERSISTENT);
            // Update Sequence number only while storing DT
            seqOut.writeInt(rmDTIdentifier.getSequenceNumber());
            if (LOG.isDebugEnabled()) {
                LOG.debug("Storing " + dtSequenceNumberPath + ". SequenceNumber: " + rmDTIdentifier.getSequenceNumber());
            }
            trx.setData(dtSequenceNumberPath, seqOs.toByteArray(), -1);
        }
    }
}
Also used : RMDelegationTokenIdentifierData(org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 4 with RMDelegationTokenIdentifierData

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

the class FileSystemRMStateStore method storeOrUpdateRMDelegationTokenState.

private void storeOrUpdateRMDelegationTokenState(RMDelegationTokenIdentifier identifier, Long renewDate, boolean isUpdate) throws Exception {
    Path nodeCreatePath = getNodePath(rmDTSecretManagerRoot, DELEGATION_TOKEN_PREFIX + identifier.getSequenceNumber());
    RMDelegationTokenIdentifierData identifierData = new RMDelegationTokenIdentifierData(identifier, renewDate);
    if (isUpdate) {
        LOG.info("Updating RMDelegationToken_" + identifier.getSequenceNumber());
        updateFile(nodeCreatePath, identifierData.toByteArray(), true);
    } else {
        LOG.info("Storing RMDelegationToken_" + identifier.getSequenceNumber());
        writeFileWithRetries(nodeCreatePath, identifierData.toByteArray(), true);
        // store sequence number
        Path latestSequenceNumberPath = getNodePath(rmDTSecretManagerRoot, DELEGATION_TOKEN_SEQUENCE_NUMBER_PREFIX + identifier.getSequenceNumber());
        LOG.info("Storing " + DELEGATION_TOKEN_SEQUENCE_NUMBER_PREFIX + identifier.getSequenceNumber());
        if (dtSequenceNumberPath == null) {
            if (!createFileWithRetries(latestSequenceNumberPath)) {
                throw new Exception("Failed to create " + latestSequenceNumberPath);
            }
        } else {
            if (!renameFileWithRetries(dtSequenceNumberPath, latestSequenceNumberPath)) {
                throw new Exception("Failed to rename " + dtSequenceNumberPath);
            }
        }
        dtSequenceNumberPath = latestSequenceNumberPath;
    }
}
Also used : Path(org.apache.hadoop.fs.Path) RMDelegationTokenIdentifierData(org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 5 with RMDelegationTokenIdentifierData

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

the class FileSystemRMStateStore method loadRMDTSecretManagerState.

private void loadRMDTSecretManagerState(RMState rmState) throws Exception {
    checkAndResumeUpdateOperation(rmDTSecretManagerRoot);
    FileStatus[] childNodes = listStatusWithRetries(rmDTSecretManagerRoot);
    for (FileStatus childNodeStatus : childNodes) {
        assert childNodeStatus.isFile();
        String childNodeName = childNodeStatus.getPath().getName();
        if (checkAndRemovePartialRecordWithRetries(childNodeStatus.getPath())) {
            continue;
        }
        if (childNodeName.startsWith(DELEGATION_TOKEN_SEQUENCE_NUMBER_PREFIX)) {
            rmState.rmSecretManagerState.dtSequenceNumber = Integer.parseInt(childNodeName.split("_")[1]);
            continue;
        }
        Path childNodePath = getNodePath(rmDTSecretManagerRoot, childNodeName);
        byte[] childData = readFileWithRetries(childNodePath, childNodeStatus.getLen());
        ByteArrayInputStream is = new ByteArrayInputStream(childData);
        try (DataInputStream fsIn = new DataInputStream(is)) {
            if (childNodeName.startsWith(DELEGATION_KEY_PREFIX)) {
                DelegationKey key = new DelegationKey();
                key.readFields(fsIn);
                rmState.rmSecretManagerState.masterKeyState.add(key);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Loaded delegation key: keyId=" + key.getKeyId() + ", expirationDate=" + key.getExpiryDate());
                }
            } else 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);
                }
            } else {
                LOG.warn("Unknown file for recovering RMDelegationTokenSecretManager");
            }
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) RMDelegationTokenIdentifierData(org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData) FileStatus(org.apache.hadoop.fs.FileStatus) ByteArrayInputStream(java.io.ByteArrayInputStream) DelegationKey(org.apache.hadoop.security.token.delegation.DelegationKey) RMDelegationTokenIdentifier(org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier) DataInputStream(java.io.DataInputStream) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream)

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