List of usage examples for org.apache.zookeeper KeeperException getMessage
@Override
public String getMessage()
From source file:org.apache.accumulo.server.security.handler.ZKPermHandler.java
License:Apache License
@Override public void revokeSystemPermission(String user, SystemPermission permission) throws AccumuloSecurityException { byte[] sysPermBytes = zooCache.get(ZKUserPath + "/" + user + ZKUserSysPerms); // User had no system permission, nothing to revoke. if (sysPermBytes == null) return;//from w w w . j a v a 2 s. com Set<SystemPermission> sysPerms = ZKSecurityTool.convertSystemPermissions(sysPermBytes); try { if (sysPerms.remove(permission)) { synchronized (zooCache) { zooCache.clear(); ZooReaderWriter.getInstance().putPersistentData(ZKUserPath + "/" + user + ZKUserSysPerms, ZKSecurityTool.convertSystemPermissions(sysPerms), NodeExistsPolicy.OVERWRITE); } } } catch (KeeperException e) { log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } }
From source file:org.apache.accumulo.server.security.handler.ZKPermHandler.java
License:Apache License
@Override public void revokeTablePermission(String user, String table, TablePermission permission) throws AccumuloSecurityException { byte[] serializedPerms = zooCache.get(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table); // User had no table permission, nothing to revoke. if (serializedPerms == null) return;//from w w w . j a v a2 s. com Set<TablePermission> tablePerms = ZKSecurityTool.convertTablePermissions(serializedPerms); try { if (tablePerms.remove(permission)) { zooCache.clear(); IZooReaderWriter zoo = ZooReaderWriter.getInstance(); if (tablePerms.size() == 0) zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table, NodeMissingPolicy.SKIP); else zoo.putPersistentData(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table, ZKSecurityTool.convertTablePermissions(tablePerms), NodeExistsPolicy.OVERWRITE); } } catch (KeeperException e) { log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } }
From source file:org.apache.accumulo.server.security.handler.ZKPermHandler.java
License:Apache License
@Override public void revokeNamespacePermission(String user, String namespace, NamespacePermission permission) throws AccumuloSecurityException { byte[] serializedPerms = zooCache.get(ZKUserPath + "/" + user + ZKUserNamespacePerms + "/" + namespace); // User had no namespace permission, nothing to revoke. if (serializedPerms == null) return;//from w ww .j av a2 s .c o m Set<NamespacePermission> namespacePerms = ZKSecurityTool.convertNamespacePermissions(serializedPerms); try { if (namespacePerms.remove(permission)) { zooCache.clear(); IZooReaderWriter zoo = ZooReaderWriter.getInstance(); if (namespacePerms.size() == 0) zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserNamespacePerms + "/" + namespace, NodeMissingPolicy.SKIP); else zoo.putPersistentData(ZKUserPath + "/" + user + ZKUserNamespacePerms + "/" + namespace, ZKSecurityTool.convertNamespacePermissions(namespacePerms), NodeExistsPolicy.OVERWRITE); } } catch (KeeperException e) { log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } }
From source file:org.apache.accumulo.server.security.handler.ZKPermHandler.java
License:Apache License
@Override public void cleanTablePermissions(String table) throws AccumuloSecurityException { try {//from w w w . j a v a 2 s.com synchronized (zooCache) { zooCache.clear(); IZooReaderWriter zoo = ZooReaderWriter.getInstance(); for (String user : zooCache.getChildren(ZKUserPath)) zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table, NodeMissingPolicy.SKIP); } } catch (KeeperException e) { log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException("unknownUser", SecurityErrorCode.CONNECTION_ERROR, e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } }
From source file:org.apache.accumulo.server.security.handler.ZKPermHandler.java
License:Apache License
@Override public void cleanNamespacePermissions(String namespace) throws AccumuloSecurityException { try {// w ww .j a va2s. c o m synchronized (zooCache) { zooCache.clear(); IZooReaderWriter zoo = ZooReaderWriter.getInstance(); for (String user : zooCache.getChildren(ZKUserPath)) zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserNamespacePerms + "/" + namespace, NodeMissingPolicy.SKIP); } } catch (KeeperException e) { log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException("unknownUser", SecurityErrorCode.CONNECTION_ERROR, e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } }
From source file:org.apache.accumulo.server.security.handler.ZKPermHandler.java
License:Apache License
@Override public void initializeSecurity(TCredentials itw, String rootuser) throws AccumuloSecurityException { IZooReaderWriter zoo = ZooReaderWriter.getInstance(); // create the root user with all system privileges, no table privileges, and no record-level authorizations Set<SystemPermission> rootPerms = new TreeSet<>(); for (SystemPermission p : SystemPermission.values()) rootPerms.add(p);/*from www . java2s .c o m*/ Map<String, Set<TablePermission>> tablePerms = new HashMap<>(); // Allow the root user to flush the system tables tablePerms.put(RootTable.ID, Collections.singleton(TablePermission.ALTER_TABLE)); tablePerms.put(MetadataTable.ID, Collections.singleton(TablePermission.ALTER_TABLE)); // essentially the same but on the system namespace, the ALTER_TABLE permission is now redundant Map<String, Set<NamespacePermission>> namespacePerms = new HashMap<>(); namespacePerms.put(Namespaces.ACCUMULO_NAMESPACE_ID, Collections.singleton(NamespacePermission.ALTER_NAMESPACE)); namespacePerms.put(Namespaces.ACCUMULO_NAMESPACE_ID, Collections.singleton(NamespacePermission.ALTER_TABLE)); try { // prep parent node of users with root username if (!zoo.exists(ZKUserPath)) zoo.putPersistentData(ZKUserPath, rootuser.getBytes(UTF_8), NodeExistsPolicy.FAIL); initUser(rootuser); zoo.putPersistentData(ZKUserPath + "/" + rootuser + ZKUserSysPerms, ZKSecurityTool.convertSystemPermissions(rootPerms), NodeExistsPolicy.FAIL); for (Entry<String, Set<TablePermission>> entry : tablePerms.entrySet()) createTablePerm(rootuser, entry.getKey(), entry.getValue()); for (Entry<String, Set<NamespacePermission>> entry : namespacePerms.entrySet()) createNamespacePerm(rootuser, entry.getKey(), entry.getValue()); } catch (KeeperException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } }
From source file:org.apache.accumulo.server.security.handler.ZKPermHandler.java
License:Apache License
@Override public void initUser(String user) throws AccumuloSecurityException { IZooReaderWriter zoo = ZooReaderWriter.getInstance(); try {/*from w w w . j av a 2s . c om*/ zoo.putPersistentData(ZKUserPath + "/" + user, new byte[0], NodeExistsPolicy.SKIP); zoo.putPersistentData(ZKUserPath + "/" + user + ZKUserTablePerms, new byte[0], NodeExistsPolicy.SKIP); zoo.putPersistentData(ZKUserPath + "/" + user + ZKUserNamespacePerms, new byte[0], NodeExistsPolicy.SKIP); } catch (KeeperException e) { log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } }
From source file:org.apache.accumulo.server.util.MasterMetadataUtil.java
License:Apache License
private static TServerInstance getTServerInstance(String address, ZooLock zooLock) { while (true) { try {/* ww w . ja va 2s . co m*/ return new TServerInstance(address, zooLock.getSessionId()); } catch (KeeperException e) { log.error("{}", e.getMessage(), e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); } sleepUninterruptibly(1, TimeUnit.SECONDS); } }
From source file:org.apache.accumulo.server.util.MasterMetadataUtil.java
License:Apache License
/** * Update the data file for the root tablet *//* www.ja va 2s .c om*/ private static void updateRootTabletDataFile(KeyExtent extent, FileRef path, FileRef mergeFile, DataFileValue dfv, String time, Set<FileRef> filesInUseByScans, String address, ZooLock zooLock, Set<String> unusedWalLogs, TServerInstance lastLocation, long flushId) { IZooReaderWriter zk = ZooReaderWriter.getInstance(); String root = MetadataTableUtil.getZookeeperLogLocation(); for (String entry : unusedWalLogs) { String[] parts = entry.split("/"); String zpath = root + "/" + parts[parts.length - 1]; while (true) { try { if (zk.exists(zpath)) { log.debug("Removing WAL reference for root table " + zpath); zk.recursiveDelete(zpath, NodeMissingPolicy.SKIP); } break; } catch (KeeperException e) { log.error("{}", e.getMessage(), e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); } sleepUninterruptibly(1, TimeUnit.SECONDS); } } }
From source file:org.apache.blur.zookeeper.WatchChildren.java
License:Apache License
public WatchChildren watch(final OnChange onChange, long fireAnywayTime, TimeUnit timeUnit) { if (_debug) { StringWriter writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); new Throwable().printStackTrace(printWriter); printWriter.close();//w ww. ja va 2 s . co m _debugStackTrace = writer.toString(); } final long timeToFireAnywayTime = TimeUnit.MILLISECONDS.convert(fireAnywayTime, timeUnit); _watchThread = new Thread(new Runnable() { @Override public void run() { Watcher watcher = new Watcher() { @Override public void process(WatchedEvent event) { synchronized (_lock) { _lock.notify(); } } }; startDoubleCheckThread(); while (_running.get()) { synchronized (_lock) { try { List<String> children = _zooKeeper.getChildren(_path, watcher); try { onChange.action(children); _children = children; } catch (Throwable t) { LOG.error("Unknown error during onchange action [" + this + "].", t); } _lock.wait(timeToFireAnywayTime); } catch (KeeperException e) { if (!_running.get()) { LOG.info("Error [{0}]", e.getMessage()); return; } if (e.code() == Code.NONODE) { if (_debug) { LOG.debug("Path for watching not found [{0}], no longer watching, debug [{1}].", _path, _debugStackTrace); } else { LOG.debug("Path for watching not found [{0}], no longer watching.", _path); } close(); return; } if (_debug) { LOG.error("Unknown error [{0}]", e, _debugStackTrace); } else { LOG.error("Unknown error", e); } throw new RuntimeException(e); } catch (InterruptedException e) { return; } } } _running.set(false); } }); _watchThread.setName("Watch Children [" + _path + "][" + instance + "]"); _watchThread.setDaemon(true); _watchThread.start(); return this; }