use of org.apache.hadoop.hdfs.server.namenode.FsImageProto.SecretManagerSection in project hadoop by apache.
the class DelegationTokenSecretManager method saveSecretManagerState.
public synchronized SecretManagerState saveSecretManagerState() {
SecretManagerSection s = SecretManagerSection.newBuilder().setCurrentId(currentId).setTokenSequenceNumber(delegationTokenSequenceNumber).setNumKeys(allKeys.size()).setNumTokens(currentTokens.size()).build();
ArrayList<SecretManagerSection.DelegationKey> keys = Lists.newArrayListWithCapacity(allKeys.size());
ArrayList<SecretManagerSection.PersistToken> tokens = Lists.newArrayListWithCapacity(currentTokens.size());
for (DelegationKey v : allKeys.values()) {
SecretManagerSection.DelegationKey.Builder b = SecretManagerSection.DelegationKey.newBuilder().setId(v.getKeyId()).setExpiryDate(v.getExpiryDate());
if (v.getEncodedKey() != null) {
b.setKey(ByteString.copyFrom(v.getEncodedKey()));
}
keys.add(b.build());
}
for (Entry<DelegationTokenIdentifier, DelegationTokenInformation> e : currentTokens.entrySet()) {
DelegationTokenIdentifier id = e.getKey();
SecretManagerSection.PersistToken.Builder b = SecretManagerSection.PersistToken.newBuilder().setOwner(id.getOwner().toString()).setRenewer(id.getRenewer().toString()).setRealUser(id.getRealUser().toString()).setIssueDate(id.getIssueDate()).setMaxDate(id.getMaxDate()).setSequenceNumber(id.getSequenceNumber()).setMasterKeyId(id.getMasterKeyId()).setExpiryDate(e.getValue().getRenewDate());
tokens.add(b.build());
}
return new SecretManagerState(s, keys, tokens);
}
use of org.apache.hadoop.hdfs.server.namenode.FsImageProto.SecretManagerSection in project hadoop by apache.
the class PBImageXmlWriter method dumpSecretManagerSection.
private void dumpSecretManagerSection(InputStream is) throws IOException {
out.print("<" + SECRET_MANAGER_SECTION_NAME + ">");
SecretManagerSection s = SecretManagerSection.parseDelimitedFrom(is);
int expectedNumDelegationKeys = s.getNumKeys();
int expectedNumTokens = s.getNumTokens();
o(SECRET_MANAGER_SECTION_CURRENT_ID, s.getCurrentId()).o(SECRET_MANAGER_SECTION_TOKEN_SEQUENCE_NUMBER, s.getTokenSequenceNumber()).o(SECRET_MANAGER_SECTION_NUM_DELEGATION_KEYS, expectedNumDelegationKeys).o(SECRET_MANAGER_SECTION_NUM_TOKENS, expectedNumTokens);
for (int i = 0; i < expectedNumDelegationKeys; i++) {
SecretManagerSection.DelegationKey dkey = SecretManagerSection.DelegationKey.parseDelimitedFrom(is);
out.print("<" + SECRET_MANAGER_SECTION_DELEGATION_KEY + ">");
o(SECTION_ID, dkey.getId());
o(SECRET_MANAGER_SECTION_KEY, Hex.encodeHexString(dkey.getKey().toByteArray()));
if (dkey.hasExpiryDate()) {
dumpDate(SECRET_MANAGER_SECTION_EXPIRY, dkey.getExpiryDate());
}
out.print("</" + SECRET_MANAGER_SECTION_DELEGATION_KEY + ">");
}
for (int i = 0; i < expectedNumTokens; i++) {
SecretManagerSection.PersistToken token = SecretManagerSection.PersistToken.parseDelimitedFrom(is);
out.print("<" + SECRET_MANAGER_SECTION_TOKEN + ">");
if (token.hasVersion()) {
o(SECRET_MANAGER_SECTION_VERSION, token.getVersion());
}
if (token.hasOwner()) {
o(SECRET_MANAGER_SECTION_OWNER, token.getOwner());
}
if (token.hasRenewer()) {
o(SECRET_MANAGER_SECTION_RENEWER, token.getRenewer());
}
if (token.hasRealUser()) {
o(SECRET_MANAGER_SECTION_REAL_USER, token.getRealUser());
}
if (token.hasIssueDate()) {
dumpDate(SECRET_MANAGER_SECTION_ISSUE_DATE, token.getIssueDate());
}
if (token.hasMaxDate()) {
dumpDate(SECRET_MANAGER_SECTION_MAX_DATE, token.getMaxDate());
}
if (token.hasSequenceNumber()) {
o(SECRET_MANAGER_SECTION_SEQUENCE_NUMBER, token.getSequenceNumber());
}
if (token.hasMasterKeyId()) {
o(SECRET_MANAGER_SECTION_MASTER_KEY_ID, token.getMasterKeyId());
}
if (token.hasExpiryDate()) {
dumpDate(SECRET_MANAGER_SECTION_EXPIRY_DATE, token.getExpiryDate());
}
out.print("</" + SECRET_MANAGER_SECTION_TOKEN + ">");
}
out.print("</" + SECRET_MANAGER_SECTION_NAME + ">");
}
Aggregations