org.apache.hadoop.hbase.security.access.ZKPermissionWatcher类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(142)

本文整理了Java中org.apache.hadoop.hbase.security.access.ZKPermissionWatcher类的一些代码示例,展示了ZKPermissionWatcher类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKPermissionWatcher类的具体详情如下:
包路径:org.apache.hadoop.hbase.security.access.ZKPermissionWatcher
类名称:ZKPermissionWatcher

ZKPermissionWatcher介绍

[英]Handles synchronization of access control list entries and updates throughout all nodes in the cluster. The AccessController instance on the acl table regions, creates a znode for each table as /hbase/acl/tablename, with the znode data containing a serialized list of the permissions granted for the table. The AccessControllerinstances on all other cluster hosts watch the znodes for updates, which trigger updates in the AuthManager permission cache.
[中]处理群集中所有节点的访问控制列表项和更新的同步。_acl_u表区域上的AccessController实例为每个表创建一个znode,即/hbase/acl/tablename,znode数据包含为该表授予的权限的序列化列表。所有其他群集主机上的AccessControllerInstance都会监视zNode的更新,从而触发AuthManager权限缓存中的更新。

代码示例

代码示例来源:origin: apache/hbase

private void initialize(RegionCoprocessorEnvironment e) throws IOException {
 final Region region = e.getRegion();
 Configuration conf = e.getConfiguration();
 Map<byte[], ListMultimap<String, UserPermission>> tables = AccessControlLists.loadAll(region);
 // For each table, write out the table's permissions to the respective
 // znode for that table.
 for (Map.Entry<byte[], ListMultimap<String, UserPermission>> t:
  tables.entrySet()) {
  byte[] entry = t.getKey();
  ListMultimap<String, UserPermission> perms = t.getValue();
  byte[] serialized = AccessControlLists.writePermissionsAsBytes(perms, conf);
  getAuthManager().getZKPermissionWatcher().writeToZookeeper(entry, serialized);
 }
 initialized = true;
}

代码示例来源:origin: apache/hbase

private AuthManager(ZKWatcher watcher, Configuration conf)
  throws IOException {
 this.conf = conf;
 // initialize global permissions based on configuration
 globalCache = initGlobal(conf);
 this.zkperms = new ZKPermissionWatcher(watcher, this, conf);
 try {
  this.zkperms.start();
 } catch (KeeperException ke) {
  LOG.error("ZooKeeper initialization failed", ke);
 }
}

代码示例来源:origin: apache/hbase

@Override
public void postDeleteNamespace(ObserverContext<MasterCoprocessorEnvironment> ctx,
  final String namespace) throws IOException {
 final Configuration conf = ctx.getEnvironment().getConfiguration();
 User.runAsLoginUser(new PrivilegedExceptionAction<Void>() {
  @Override
  public Void run() throws Exception {
   try (Table table = ctx.getEnvironment().getConnection().
     getTable(AccessControlLists.ACL_TABLE_NAME)) {
    AccessControlLists.removeNamespacePermissions(conf, namespace, table);
   }
   return null;
  }
 });
 getAuthManager().getZKPermissionWatcher().deleteNamespaceACLNode(namespace);
 LOG.info(namespace + " entry deleted in " + AccessControlLists.ACL_TABLE_NAME + " table.");
}

代码示例来源:origin: apache/hbase

@Override
public void nodeCreated(String path) {
 waitUntilStarted();
 if (path.equals(aclZNode)) {
  asyncProcessNodeUpdate(new Runnable() {
   @Override
   public void run() {
    try {
     List<ZKUtil.NodeAndData> nodes =
       ZKUtil.getChildDataAndWatchForNewChildren(watcher, aclZNode);
     refreshNodes(nodes);
    } catch (KeeperException ke) {
     LOG.error("Error reading data from zookeeper", ke);
     // only option is to abort
     watcher.abort("ZooKeeper error obtaining acl node children", ke);
    }
   }
  });
 }
}

代码示例来源:origin: apache/hbase

@Override
public void nodeChildrenChanged(final String path) {
 waitUntilStarted();
 if (path.equals(aclZNode)) {
  try {
   final List<ZKUtil.NodeAndData> nodeList =
     ZKUtil.getChildDataAndWatchForNewChildren(watcher, aclZNode);
   // preempt any existing nodeChildrenChanged event processing
   if (childrenChangedFuture != null && !childrenChangedFuture.isDone()) {
    boolean cancelled = childrenChangedFuture.cancel(true);
    if (!cancelled) {
     // task may have finished between our check and attempted cancel, this is fine.
     if (! childrenChangedFuture.isDone()) {
      LOG.warn("Could not cancel processing node children changed event, " +
        "please file a JIRA and attach logs if possible.");
     }
    }
   }
   childrenChangedFuture = asyncProcessNodeUpdate(() -> refreshNodes(nodeList));
  } catch (KeeperException ke) {
   LOG.error("Error reading data from zookeeper for path "+path, ke);
   watcher.abort("ZooKeeper error get node children for path "+path, ke);
  }
 }
}

代码示例来源:origin: harbby/presto-connectors

@Override
public void nodeCreated(String path) {
 waitUntilStarted();
 if (path.equals(aclZNode)) {
  try {
   List<ZKUtil.NodeAndData> nodes =
     ZKUtil.getChildDataAndWatchForNewChildren(watcher, aclZNode);
   refreshNodes(nodes);
  } catch (KeeperException ke) {
   LOG.error("Error reading data from zookeeper", ke);
   // only option is to abort
   watcher.abort("Zookeeper error obtaining acl node children", ke);
  }
 }
}

代码示例来源:origin: harbby/presto-connectors

@Override
public void nodeDataChanged(String path) {
 waitUntilStarted();
 if (aclZNode.equals(ZKUtil.getParent(path))) {
  // update cache on an existing table node
  String entry = ZKUtil.getNodeName(path);
  try {
   byte[] data = ZKUtil.getDataAndWatch(watcher, path);
   refreshAuthManager(entry, data);
  } catch (KeeperException ke) {
   LOG.error("Error reading data from zookeeper for node " + entry, ke);
   // only option is to abort
   watcher.abort("Zookeeper error getting data for node " + entry, ke);
  } catch (IOException ioe) {
   LOG.error("Error reading permissions writables", ioe);
  }
 }
}

代码示例来源:origin: apache/hbase

@Override
public void postDeleteTable(ObserverContext<MasterCoprocessorEnvironment> c,
  final TableName tableName) throws IOException {
 final Configuration conf = c.getEnvironment().getConfiguration();
 User.runAsLoginUser(new PrivilegedExceptionAction<Void>() {
  @Override
  public Void run() throws Exception {
   try (Table table = c.getEnvironment().getConnection().
     getTable(AccessControlLists.ACL_TABLE_NAME)) {
    AccessControlLists.removeTablePermissions(conf, tableName, table);
   }
   return null;
  }
 });
 getAuthManager().getZKPermissionWatcher().deleteTableACLNode(tableName);
}

代码示例来源:origin: apache/hbase

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);
  }
 }
}

代码示例来源:origin: harbby/presto-connectors

@Override
public void nodeDeleted(String path) {
 waitUntilStarted();
 if (aclZNode.equals(ZKUtil.getParent(path))) {
  String table = ZKUtil.getNodeName(path);
  if(AccessControlLists.isNamespaceEntry(table)) {
   authManager.removeNamespace(Bytes.toBytes(table));
  } else {
   authManager.removeTable(TableName.valueOf(table));
  }
 }
}

代码示例来源:origin: harbby/presto-connectors

public void start() throws KeeperException {
 try {
  watcher.registerListener(this);
  if (ZKUtil.watchAndCheckExists(watcher, aclZNode)) {
   List<ZKUtil.NodeAndData> existing =
     ZKUtil.getChildDataAndWatchForNewChildren(watcher, aclZNode);
   if (existing != null) {
    refreshNodes(existing);
   }
  }
 } finally {
  initialized.countDown();
 }
}

代码示例来源:origin: harbby/presto-connectors

@Override
public void nodeChildrenChanged(String path) {
 waitUntilStarted();
 if (path.equals(aclZNode)) {
  // table permissions changed
  try {
   List<ZKUtil.NodeAndData> nodes =
     ZKUtil.getChildDataAndWatchForNewChildren(watcher, aclZNode);
   refreshNodes(nodes);
  } catch (KeeperException ke) {
   LOG.error("Error reading data from zookeeper for path "+path, ke);
   watcher.abort("Zookeeper error get node children for path "+path, ke);
  }
 }
}

代码示例来源:origin: apache/hbase

@Override
public void nodeDeleted(final String path) {
 waitUntilStarted();
 if (aclZNode.equals(ZKUtil.getParent(path))) {
  asyncProcessNodeUpdate(new Runnable() {
   @Override
   public void run() {
    String table = ZKUtil.getNodeName(path);
    if(AccessControlLists.isNamespaceEntry(table)) {
     authManager.removeNamespace(Bytes.toBytes(table));
    } else {
     authManager.removeTable(TableName.valueOf(table));
    }
   }
  });
 }
}

代码示例来源:origin: harbby/presto-connectors

@Override
public void postDeleteTable(ObserverContext<MasterCoprocessorEnvironment> c,
  final TableName tableName) throws IOException {
 final Configuration conf = c.getEnvironment().getConfiguration();
 User.runAsLoginUser(new PrivilegedExceptionAction<Void>() {
  @Override
  public Void run() throws Exception {
   AccessControlLists.removeTablePermissions(conf, tableName);
   return null;
  }
 });
 this.authManager.getZKPermissionWatcher().deleteTableACLNode(tableName);
}

代码示例来源:origin: harbby/presto-connectors

private void refreshNodes(List<ZKUtil.NodeAndData> nodes) {
 for (ZKUtil.NodeAndData n : nodes) {
  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);
  }
 }
}

代码示例来源:origin: apache/hbase

AccessControlLists.getPermissions(conf, entry, t, null, null, null, false);
byte[] serialized = AccessControlLists.writePermissionsAsBytes(perms, conf);
zkw.writeToZookeeper(entry, serialized);

代码示例来源:origin: harbby/presto-connectors

private TableAuthManager(ZooKeeperWatcher watcher, Configuration conf)
  throws IOException {
 this.conf = conf;
 // initialize global permissions based on configuration
 globalCache = initGlobal(conf);
 this.zkperms = new ZKPermissionWatcher(watcher, this, conf);
 try {
  this.zkperms.start();
 } catch (KeeperException ke) {
  LOG.error("ZooKeeper initialization failed", ke);
 }
}

代码示例来源:origin: apache/hbase

@Override
public void nodeDataChanged(final String path) {
 waitUntilStarted();
 if (aclZNode.equals(ZKUtil.getParent(path))) {
  asyncProcessNodeUpdate(new Runnable() {
   @Override
   public void run() {
    // update cache on an existing table node
    String entry = ZKUtil.getNodeName(path);
    try {
     byte[] data = ZKUtil.getDataAndWatch(watcher, path);
     refreshAuthManager(entry, data);
    } catch (KeeperException ke) {
     LOG.error("Error reading data from zookeeper for node " + entry, ke);
     // only option is to abort
     watcher.abort("ZooKeeper error getting data for node " + entry, ke);
    } catch (IOException ioe) {
     LOG.error("Error reading permissions writables", ioe);
    }
   }
  });
 }
}

代码示例来源:origin: harbby/presto-connectors

@Override
public void postDeleteNamespace(ObserverContext<MasterCoprocessorEnvironment> ctx,
  final String namespace) throws IOException {
 final Configuration conf = ctx.getEnvironment().getConfiguration();
 User.runAsLoginUser(new PrivilegedExceptionAction<Void>() {
  @Override
  public Void run() throws Exception {
   AccessControlLists.removeNamespacePermissions(conf, namespace);
   return null;
  }
 });
 this.authManager.getZKPermissionWatcher().deleteNamespaceACLNode(namespace);
 LOG.info(namespace + " entry deleted in "+AccessControlLists.ACL_TABLE_NAME+" table.");
}

代码示例来源:origin: apache/hbase

multimap.putAll(george.getShortName(), acl);
byte[] serialized = AccessControlLists.writePermissionsAsBytes(multimap, conf);
AUTH_A.getZKPermissionWatcher().writeToZookeeper(TEST_TABLE.getName(), serialized);
final long mtimeB = AUTH_B.getMTime();
multimap.putAll(hubert.getShortName(), acl2);
byte[] serialized2 = AccessControlLists.writePermissionsAsBytes(multimap, conf);
AUTH_B.getZKPermissionWatcher().writeToZookeeper(TEST_TABLE.getName(), serialized2);

相关文章