Java Code Examples for org.apache.hadoop.hbase.zookeeper.ZKUtil#NodeAndData

The following examples show how to use org.apache.hadoop.hbase.zookeeper.ZKUtil#NodeAndData . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZKSecretWatcher.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void refreshNodes(List<ZKUtil.NodeAndData> nodes) {
  for (ZKUtil.NodeAndData n : nodes) {
    String path = n.getNode();
    String keyId = ZKUtil.getNodeName(path);
    try {
      byte[] data = n.getData();
      if (data == null || data.length == 0) {
        LOG.debug("Ignoring empty node "+path);
        continue;
      }
      AuthenticationKey key = (AuthenticationKey)Writables.getWritable(
          data, new AuthenticationKey());
      secretManager.addKey(key);
    } catch (IOException ioe) {
      LOG.error(HBaseMarkers.FATAL, "Failed reading new secret key for id '" +
          keyId + "' from zk", ioe);
      watcher.abort("Error deserializing key from znode "+path, ioe);
    }
  }
}
 
Example 2
Source File: ZKPermissionWatcher.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void refreshNodes(List<ZKUtil.NodeAndData> nodes) {
  for (ZKUtil.NodeAndData n : nodes) {
    if (Thread.interrupted()) {
      // Use Thread.interrupted so that we clear interrupt status
      break;
    }
    if (n.isEmpty()) continue;
    String path = n.getNode();
    String entry = (ZKUtil.getNodeName(path));
    try {
      refreshAuthManager(entry, n.getData());
    } catch (IOException ioe) {
      LOG.error("Failed parsing permissions for table '" + entry +
          "' from zk", ioe);
    }
  }
}
 
Example 3
Source File: ZKSecretWatcher.java    From hbase with Apache License 2.0 5 votes vote down vote up
public void start() throws KeeperException {
  watcher.registerListener(this);
  // make sure the base node exists
  ZKUtil.createWithParents(watcher, keysParentZNode);

  if (ZKUtil.watchAndCheckExists(watcher, keysParentZNode)) {
    List<ZKUtil.NodeAndData> nodes =
        ZKUtil.getChildDataAndWatchForNewChildren(watcher, keysParentZNode);
    refreshNodes(nodes);
  }
}
 
Example 4
Source File: ZKSecretWatcher.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void nodeCreated(String path) {
  if (path.equals(keysParentZNode)) {
    try {
      List<ZKUtil.NodeAndData> nodes =
          ZKUtil.getChildDataAndWatchForNewChildren(watcher, keysParentZNode);
      refreshNodes(nodes);
    } catch (KeeperException ke) {
      LOG.error(HBaseMarkers.FATAL, "Error reading data from zookeeper", ke);
      watcher.abort("Error reading new key znode "+path, ke);
    }
  }
}
 
Example 5
Source File: ZKSecretWatcher.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void nodeChildrenChanged(String path) {
  if (path.equals(keysParentZNode)) {
    // keys changed
    try {
      List<ZKUtil.NodeAndData> nodes =
          ZKUtil.getChildDataAndWatchForNewChildren(watcher, keysParentZNode);
      refreshNodes(nodes);
    } catch (KeeperException ke) {
      LOG.error(HBaseMarkers.FATAL, "Error reading data from zookeeper", ke);
      watcher.abort("Error reading changed keys from zookeeper", ke);
    }
  }
}
 
Example 6
Source File: ZKSecretWatcher.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * refresh keys
 */
synchronized void refreshKeys() {
  try {
    List<ZKUtil.NodeAndData> nodes =
        ZKUtil.getChildDataAndWatchForNewChildren(watcher, keysParentZNode);
    refreshNodes(nodes);
  } catch (KeeperException ke) {
    LOG.error(HBaseMarkers.FATAL, "Error reading data from zookeeper", ke);
    watcher.abort("Error reading changed keys from zookeeper", ke);
  }
}