Example usage for org.apache.zookeeper KeeperException getMessage

List of usage examples for org.apache.zookeeper KeeperException getMessage

Introduction

In this page you can find the example usage for org.apache.zookeeper KeeperException getMessage.

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:org.apache.accumulo.fate.AdminUtil.java

License:Apache License

public boolean checkGlobalLock(IZooReaderWriter zk, String path) {
    try {//ww  w  .  j a v  a2  s  .c  o m
        if (ZooLock.getLockData(zk.getZooKeeper(), path) != null) {
            System.err.println("ERROR: Master lock is held, not running");
            if (this.exitOnError)
                System.exit(1);
            else
                return false;
        }
    } catch (KeeperException e) {
        System.err.println("ERROR: Could not read master lock, not running " + e.getMessage());
        if (this.exitOnError)
            System.exit(1);
        else
            return false;
    } catch (InterruptedException e) {
        System.err.println("ERROR: Could not read master lock, not running" + e.getMessage());
        if (this.exitOnError)
            System.exit(1);
        else
            return false;
    }
    return true;
}

From source file:org.apache.accumulo.server.security.handler.ZKAuthenticator.java

License:Apache License

@Override
public void initializeSecurity(TCredentials credentials, String principal, byte[] token)
        throws AccumuloSecurityException {
    try {/*  ww w  .j  a  v a2s  . co m*/
        // remove old settings from zookeeper first, if any
        IZooReaderWriter zoo = ZooReaderWriter.getInstance();
        synchronized (zooCache) {
            zooCache.clear();
            if (zoo.exists(ZKUserPath)) {
                zoo.recursiveDelete(ZKUserPath, NodeMissingPolicy.SKIP);
                log.info("Removed " + ZKUserPath + "/" + " from zookeeper");
            }

            // prep parent node of users with root username
            zoo.putPersistentData(ZKUserPath, principal.getBytes(UTF_8), NodeExistsPolicy.FAIL);

            constructUser(principal, ZKSecurityTool.createPass(token));
        }
    } catch (KeeperException e) {
        log.error("{}", e.getMessage(), e);
        throw new RuntimeException(e);
    } catch (InterruptedException e) {
        log.error("{}", e.getMessage(), e);
        throw new RuntimeException(e);
    } catch (AccumuloException e) {
        log.error("{}", e.getMessage(), e);
        throw new RuntimeException(e);
    }
}

From source file:org.apache.accumulo.server.security.handler.ZKAuthenticator.java

License:Apache License

@Override
public void createUser(String principal, AuthenticationToken token) throws AccumuloSecurityException {
    try {/*from   w w  w .  ja va  2 s .c om*/
        if (!(token instanceof PasswordToken))
            throw new AccumuloSecurityException(principal, SecurityErrorCode.INVALID_TOKEN);
        PasswordToken pt = (PasswordToken) token;
        constructUser(principal, ZKSecurityTool.createPass(pt.getPassword()));
    } catch (KeeperException e) {
        if (e.code().equals(KeeperException.Code.NODEEXISTS))
            throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_EXISTS, e);
        throw new AccumuloSecurityException(principal, SecurityErrorCode.CONNECTION_ERROR, e);
    } catch (InterruptedException e) {
        log.error("{}", e.getMessage(), e);
        throw new RuntimeException(e);
    } catch (AccumuloException e) {
        log.error("{}", e.getMessage(), e);
        throw new AccumuloSecurityException(principal, SecurityErrorCode.DEFAULT_SECURITY_ERROR, e);
    }
}

From source file:org.apache.accumulo.server.security.handler.ZKAuthenticator.java

License:Apache License

@Override
public void changePassword(String principal, AuthenticationToken token) throws AccumuloSecurityException {
    if (!(token instanceof PasswordToken))
        throw new AccumuloSecurityException(principal, SecurityErrorCode.INVALID_TOKEN);
    PasswordToken pt = (PasswordToken) token;
    if (userExists(principal)) {
        try {/*  ww  w .ja  v a2s .c  om*/
            synchronized (zooCache) {
                zooCache.clear(ZKUserPath + "/" + principal);
                ZooReaderWriter.getInstance().putPrivatePersistentData(ZKUserPath + "/" + principal,
                        ZKSecurityTool.createPass(pt.getPassword()), NodeExistsPolicy.OVERWRITE);
            }
        } catch (KeeperException e) {
            log.error("{}", e.getMessage(), e);
            throw new AccumuloSecurityException(principal, SecurityErrorCode.CONNECTION_ERROR, e);
        } catch (InterruptedException e) {
            log.error("{}", e.getMessage(), e);
            throw new RuntimeException(e);
        } catch (AccumuloException e) {
            log.error("{}", e.getMessage(), e);
            throw new AccumuloSecurityException(principal, SecurityErrorCode.DEFAULT_SECURITY_ERROR, e);
        }
    } else
        throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST); // user doesn't exist
}

From source file:org.apache.accumulo.server.security.handler.ZKAuthorizor.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 w  ww . j  av  a  2  s .  com*/
    Map<String, Set<TablePermission>> tablePerms = new HashMap<>();
    // Allow the root user to flush the metadata tables
    tablePerms.put(MetadataTable.ID, Collections.singleton(TablePermission.ALTER_TABLE));
    tablePerms.put(RootTable.ID, Collections.singleton(TablePermission.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 + ZKUserAuths,
                ZKSecurityTool.convertAuthorizations(Authorizations.EMPTY), NodeExistsPolicy.FAIL);
    } 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.ZKAuthorizor.java

License:Apache License

@Override
public void initUser(String user) throws AccumuloSecurityException {
    IZooReaderWriter zoo = ZooReaderWriter.getInstance();
    try {//from   w  w w  . jav a 2s  .  com
        zoo.putPersistentData(ZKUserPath + "/" + user, 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.security.handler.ZKAuthorizor.java

License:Apache License

@Override
public void changeAuthorizations(String user, Authorizations authorizations) throws AccumuloSecurityException {
    try {/*from  w w  w .j  av  a 2  s  . c o  m*/
        synchronized (zooCache) {
            zooCache.clear();
            ZooReaderWriter.getInstance().putPersistentData(ZKUserPath + "/" + user + ZKUserAuths,
                    ZKSecurityTool.convertAuthorizations(authorizations), 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 grantSystemPermission(String user, SystemPermission permission) throws AccumuloSecurityException {
    try {/*from w  w  w  .ja  v  a  2s .c  om*/
        byte[] permBytes = zooCache.get(ZKUserPath + "/" + user + ZKUserSysPerms);
        Set<SystemPermission> perms;
        if (permBytes == null) {
            perms = new TreeSet<>();
        } else {
            perms = ZKSecurityTool.convertSystemPermissions(permBytes);
        }

        if (perms.add(permission)) {
            synchronized (zooCache) {
                zooCache.clear();
                ZooReaderWriter.getInstance().putPersistentData(ZKUserPath + "/" + user + ZKUserSysPerms,
                        ZKSecurityTool.convertSystemPermissions(perms), 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 grantTablePermission(String user, String table, TablePermission permission)
        throws AccumuloSecurityException {
    Set<TablePermission> tablePerms;
    byte[] serializedPerms = zooCache.get(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table);
    if (serializedPerms != null)
        tablePerms = ZKSecurityTool.convertTablePermissions(serializedPerms);
    else/* w  w  w  .j  a v  a 2s .  c  om*/
        tablePerms = new TreeSet<>();

    try {
        if (tablePerms.add(permission)) {
            synchronized (zooCache) {
                zooCache.clear(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table);
                ZooReaderWriter.getInstance().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 grantNamespacePermission(String user, String namespace, NamespacePermission permission)
        throws AccumuloSecurityException {
    Set<NamespacePermission> namespacePerms;
    byte[] serializedPerms = zooCache.get(ZKUserPath + "/" + user + ZKUserNamespacePerms + "/" + namespace);
    if (serializedPerms != null)
        namespacePerms = ZKSecurityTool.convertNamespacePermissions(serializedPerms);
    else//from w  ww . ja  v  a 2  s .c  o  m
        namespacePerms = new TreeSet<>();

    try {
        if (namespacePerms.add(permission)) {
            synchronized (zooCache) {
                zooCache.clear(ZKUserPath + "/" + user + ZKUserNamespacePerms + "/" + namespace);
                ZooReaderWriter.getInstance().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);
    }
}