private DelegationKey getKeyFromZK(int keyId) throws IOException { String nodePath = getNodePath(ZK_DTSM_MASTER_KEY_ROOT, DELEGATION_KEY_PREFIX + keyId); try { byte[] data = zkClient.getData().forPath(nodePath); if ((data == null) || (data.length == 0)) { return null; } ByteArrayInputStream bin = new ByteArrayInputStream(data); DataInputStream din = new DataInputStream(bin); DelegationKey key = new DelegationKey(); key.readFields(din); return key; } catch (KeeperException.NoNodeException e) { LOG.error("No node in path [" + nodePath + "]"); } catch (Exception ex) { throw new IOException(ex); } return null; }
@Override protected void updateToken(TokenIdent ident, DelegationTokenInformation tokenInfo) throws IOException { String nodeRemovePath = getNodePath(ZK_DTSM_TOKENS_ROOT, DELEGATION_TOKEN_PREFIX + ident.getSequenceNumber()); try { if (zkClient.checkExists().forPath(nodeRemovePath) != null) { addOrUpdateToken(ident, tokenInfo, true); } else { addOrUpdateToken(ident, tokenInfo, false); LOG.debug("Attempted to update a non-existing znode " + nodeRemovePath); } } catch (Exception e) { throw new RuntimeException("Could not update Stored Token ZKDTSMDelegationToken_" + ident.getSequenceNumber(), e); } }
@Override protected void removeStoredMasterKey(DelegationKey key) { String nodeRemovePath = getNodePath(ZK_DTSM_MASTER_KEY_ROOT, DELEGATION_KEY_PREFIX + key.getKeyId()); if (LOG.isDebugEnabled()) { LOG.debug("Removing ZKDTSMDelegationKey_" + key.getKeyId()); } try { if (zkClient.checkExists().forPath(nodeRemovePath) != null) { while(zkClient.checkExists().forPath(nodeRemovePath) != null){ try { zkClient.delete().guaranteed().forPath(nodeRemovePath); } catch (NoNodeException nne) { // It is possible that the node might be deleted between the // check and the actual delete.. which might lead to an // exception that can bring down the daemon running this // SecretManager LOG.debug("Node already deleted by peer " + nodeRemovePath); } } } else { LOG.debug("Attempted to delete a non-existing znode " + nodeRemovePath); } } catch (Exception e) { LOG.debug(nodeRemovePath + " znode could not be removed!!"); } }
private DelegationTokenInformation getTokenInfoFromZK(TokenIdent ident, boolean quiet) throws IOException { String nodePath = getNodePath(ZK_DTSM_TOKENS_ROOT, DELEGATION_TOKEN_PREFIX + ident.getSequenceNumber()); try {
private void addOrUpdateDelegationKey(DelegationKey key, boolean isUpdate) throws IOException { String nodeCreatePath = getNodePath(ZK_DTSM_MASTER_KEY_ROOT, DELEGATION_KEY_PREFIX + key.getKeyId()); ByteArrayOutputStream os = new ByteArrayOutputStream();
throws IOException { String nodeRemovePath = getNodePath(ZK_DTSM_TOKENS_ROOT, DELEGATION_TOKEN_PREFIX + ident.getSequenceNumber()); if (LOG.isDebugEnabled()) {
private void addOrUpdateToken(TokenIdent ident, DelegationTokenInformation info, boolean isUpdate) throws Exception { String nodeCreatePath = getNodePath(ZK_DTSM_TOKENS_ROOT, DELEGATION_TOKEN_PREFIX + ident.getSequenceNumber()); try (ByteArrayOutputStream tokenOs = new ByteArrayOutputStream(); DataOutputStream tokenOut = new DataOutputStream(tokenOs)) { ident.write(tokenOut); tokenOut.writeLong(info.getRenewDate()); tokenOut.writeInt(info.getPassword().length); tokenOut.write(info.getPassword()); if (LOG.isDebugEnabled()) { LOG.debug((isUpdate ? "Updating " : "Storing ") + "ZKDTSMDelegationToken_" + ident.getSequenceNumber()); } if (isUpdate) { zkClient.setData().forPath(nodeCreatePath, tokenOs.toByteArray()) .setVersion(-1); } else { zkClient.create().withMode(CreateMode.PERSISTENT) .forPath(nodeCreatePath, tokenOs.toByteArray()); } } }
private DelegationKey getKeyFromZK(int keyId) throws IOException { String nodePath = getNodePath(ZK_DTSM_MASTER_KEY_ROOT, DELEGATION_KEY_PREFIX + keyId); try { byte[] data = zkClient.getData().forPath(nodePath); if ((data == null) || (data.length == 0)) { return null; } ByteArrayInputStream bin = new ByteArrayInputStream(data); DataInputStream din = new DataInputStream(bin); DelegationKey key = new DelegationKey(); key.readFields(din); return key; } catch (KeeperException.NoNodeException e) { LOG.error("No node in path [" + nodePath + "]"); } catch (Exception ex) { throw new IOException(ex); } return null; }
private DelegationKey getKeyFromZK(int keyId) throws IOException { String nodePath = getNodePath(ZK_DTSM_MASTER_KEY_ROOT, DELEGATION_KEY_PREFIX + keyId); try { byte[] data = zkClient.getData().forPath(nodePath); if ((data == null) || (data.length == 0)) { return null; } ByteArrayInputStream bin = new ByteArrayInputStream(data); DataInputStream din = new DataInputStream(bin); DelegationKey key = new DelegationKey(); key.readFields(din); return key; } catch (KeeperException.NoNodeException e) { LOG.error("No node in path [" + nodePath + "]"); } catch (Exception ex) { throw new IOException(ex); } return null; }
private DelegationKey getKeyFromZK(int keyId) throws IOException { String nodePath = getNodePath(ZK_DTSM_MASTER_KEY_ROOT, DELEGATION_KEY_PREFIX + keyId); try { byte[] data = zkClient.getData().forPath(nodePath); if ((data == null) || (data.length == 0)) { return null; } ByteArrayInputStream bin = new ByteArrayInputStream(data); DataInputStream din = new DataInputStream(bin); DelegationKey key = new DelegationKey(); key.readFields(din); return key; } catch (KeeperException.NoNodeException e) { LOG.error("No node in path [" + nodePath + "]"); } catch (Exception ex) { throw new IOException(ex); } return null; }
private DelegationKey getKeyFromZK(int keyId) throws IOException { String nodePath = getNodePath(ZK_DTSM_MASTER_KEY_ROOT, DELEGATION_KEY_PREFIX + keyId); try { byte[] data = zkClient.getData().forPath(nodePath); if ((data == null) || (data.length == 0)) { return null; } ByteArrayInputStream bin = new ByteArrayInputStream(data); DataInputStream din = new DataInputStream(bin); DelegationKey key = new DelegationKey(); key.readFields(din); return key; } catch (KeeperException.NoNodeException e) { LOG.error("No node in path [" + nodePath + "]"); } catch (Exception ex) { throw new IOException(ex); } return null; }
@Override protected void removeStoredMasterKey(DelegationKey key) { String nodeRemovePath = getNodePath(ZK_DTSM_MASTER_KEY_ROOT, DELEGATION_KEY_PREFIX + key.getKeyId()); if (LOG.isDebugEnabled()) { LOG.debug("Removing ZKDTSMDelegationKey_" + key.getKeyId()); } try { if (zkClient.checkExists().forPath(nodeRemovePath) != null) { while(zkClient.checkExists().forPath(nodeRemovePath) != null){ zkClient.delete().guaranteed().forPath(nodeRemovePath); } } else { LOG.debug("Attempted to delete a non-existing znode " + nodeRemovePath); } } catch (Exception e) { LOG.debug(nodeRemovePath + " znode could not be removed!!"); } }
@Override protected void removeStoredMasterKey(DelegationKey key) { String nodeRemovePath = getNodePath(ZK_DTSM_MASTER_KEY_ROOT, DELEGATION_KEY_PREFIX + key.getKeyId()); if (LOG.isDebugEnabled()) { LOG.debug("Removing ZKDTSMDelegationKey_" + key.getKeyId()); } try { if (zkClient.checkExists().forPath(nodeRemovePath) != null) { while(zkClient.checkExists().forPath(nodeRemovePath) != null){ zkClient.delete().guaranteed().forPath(nodeRemovePath); } } else { LOG.debug("Attempted to delete a non-existing znode " + nodeRemovePath); } } catch (Exception e) { LOG.debug(nodeRemovePath + " znode could not be removed!!"); } }
@Override protected void updateToken(TokenIdent ident, DelegationTokenInformation tokenInfo) throws IOException { String nodeRemovePath = getNodePath(ZK_DTSM_TOKENS_ROOT, DELEGATION_TOKEN_PREFIX + ident.getSequenceNumber()); try { if (zkClient.checkExists().forPath(nodeRemovePath) != null) { addOrUpdateToken(ident, tokenInfo, true); } else { addOrUpdateToken(ident, tokenInfo, false); LOG.debug("Attempted to update a non-existing znode " + nodeRemovePath); } } catch (Exception e) { throw new RuntimeException("Could not update Stored Token ZKDTSMDelegationToken_" + ident.getSequenceNumber(), e); } }
@Override protected void updateToken(TokenIdent ident, DelegationTokenInformation tokenInfo) throws IOException { String nodeRemovePath = getNodePath(ZK_DTSM_TOKENS_ROOT, DELEGATION_TOKEN_PREFIX + ident.getSequenceNumber()); try { if (zkClient.checkExists().forPath(nodeRemovePath) != null) { addOrUpdateToken(ident, tokenInfo, true); } else { addOrUpdateToken(ident, tokenInfo, false); LOG.debug("Attempted to update a non-existing znode " + nodeRemovePath); } } catch (Exception e) { throw new RuntimeException("Could not update Stored Token ZKDTSMDelegationToken_" + ident.getSequenceNumber(), e); } }
@Override protected void updateToken(TokenIdent ident, DelegationTokenInformation tokenInfo) throws IOException { String nodeRemovePath = getNodePath(ZK_DTSM_TOKENS_ROOT, DELEGATION_TOKEN_PREFIX + ident.getSequenceNumber()); try { if (zkClient.checkExists().forPath(nodeRemovePath) != null) { addOrUpdateToken(ident, tokenInfo, true); } else { addOrUpdateToken(ident, tokenInfo, false); LOG.debug("Attempted to update a non-existing znode " + nodeRemovePath); } } catch (Exception e) { throw new RuntimeException("Could not update Stored Token ZKDTSMDelegationToken_" + ident.getSequenceNumber(), e); } }
@Override protected void removeStoredToken(TokenIdent ident) throws IOException { String nodeRemovePath = getNodePath(ZK_DTSM_TOKENS_ROOT, DELEGATION_TOKEN_PREFIX + ident.getSequenceNumber()); if (LOG.isDebugEnabled()) { LOG.debug("Removing ZKDTSMDelegationToken_" + ident.getSequenceNumber()); } try { if (zkClient.checkExists().forPath(nodeRemovePath) != null) { while(zkClient.checkExists().forPath(nodeRemovePath) != null){ zkClient.delete().guaranteed().forPath(nodeRemovePath); } } else { LOG.debug("Attempted to remove a non-existing znode " + nodeRemovePath); } } catch (Exception e) { throw new RuntimeException( "Could not remove Stored Token ZKDTSMDelegationToken_" + ident.getSequenceNumber(), e); } }
@Override protected void updateToken(TokenIdent ident, DelegationTokenInformation tokenInfo) throws IOException { String nodeRemovePath = getNodePath(ZK_DTSM_TOKENS_ROOT, DELEGATION_TOKEN_PREFIX + ident.getSequenceNumber()); try { if (zkClient.checkExists().forPath(nodeRemovePath) != null) { addOrUpdateToken(ident, tokenInfo, true); } else { addOrUpdateToken(ident, tokenInfo, false); LOG.debug("Attempted to update a non-existing znode " + nodeRemovePath); } } catch (Exception e) { throw new RuntimeException("Could not update Stored Token ZKDTSMDelegationToken_" + ident.getSequenceNumber(), e); } }
@Override protected void removeStoredToken(TokenIdent ident) throws IOException { String nodeRemovePath = getNodePath(ZK_DTSM_TOKENS_ROOT, DELEGATION_TOKEN_PREFIX + ident.getSequenceNumber()); if (LOG.isDebugEnabled()) { LOG.debug("Removing ZKDTSMDelegationToken_" + ident.getSequenceNumber()); } try { if (zkClient.checkExists().forPath(nodeRemovePath) != null) { while(zkClient.checkExists().forPath(nodeRemovePath) != null){ zkClient.delete().guaranteed().forPath(nodeRemovePath); } } else { LOG.debug("Attempted to remove a non-existing znode " + nodeRemovePath); } } catch (Exception e) { throw new RuntimeException( "Could not remove Stored Token ZKDTSMDelegationToken_" + ident.getSequenceNumber(), e); } }
@Override protected void removeStoredMasterKey(DelegationKey key) { String nodeRemovePath = getNodePath(ZK_DTSM_MASTER_KEY_ROOT, DELEGATION_KEY_PREFIX + key.getKeyId()); if (LOG.isDebugEnabled()) { LOG.debug("Removing ZKDTSMDelegationKey_" + key.getKeyId()); } try { if (zkClient.checkExists().forPath(nodeRemovePath) != null) { while(zkClient.checkExists().forPath(nodeRemovePath) != null){ zkClient.delete().guaranteed().forPath(nodeRemovePath); } } else { LOG.debug("Attempted to delete a non-existing znode " + nodeRemovePath); } } catch (Exception e) { LOG.debug(nodeRemovePath + " znode could not be removed!!"); } }