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:com.github.mosuka.zookeeper.nicli.command.LsCommand.java

License:Apache License

@Override
public void run(Map<String, Object> parameters) {
    Map<String, Object> statMap = new LinkedHashMap<String, Object>();

    try {//  ww  w. j  a  v a  2s  . c  o  m
        String path = (String) parameters.get("path");
        boolean watch = parameters.containsKey("watch") ? (Boolean) parameters.get("watch") : DEFAULT_WATCH;
        boolean withStat = parameters.containsKey("with_stat") ? (Boolean) parameters.get("with_stat")
                : DEFAULT_WITH_STAT;

        ZooKeeper zk = getZookeeperConnection().getZooKeeper();

        Stat stat = new Stat();
        List<String> children = null;
        if (withStat) {
            children = zk.getChildren(path, watch, stat);
        } else {
            children = zk.getChildren(path, watch);
        }

        putResponse("children", children);
        if (stat != null && withStat) {
            putResponse("stat", StatUtil.stat2Map(stat));
        }

        setStatus(Command.STATUS_SUCCESS);
        setMessage(Command.SUCCESS_MESSAGE);
    } catch (KeeperException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (InterruptedException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (ClassCastException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (NullPointerException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    }
}

From source file:com.github.mosuka.zookeeper.nicli.command.SetAclCommand.java

License:Apache License

@Override
public void run(Map<String, Object> parameters) {
    try {//from  w ww.  ja va2s .c  om
        String path = (String) parameters.get("path");
        String acl = (String) parameters.get("acl");
        int version = parameters.containsKey("version") ? (Integer) parameters.get("version") : DEFAULT_VERSION;
        boolean withStat = parameters.containsKey("with_stat") ? (Boolean) parameters.get("with_stat")
                : DEFAULT_WITH_STAT;

        ZooKeeper zk = getZookeeperConnection().getZooKeeper();

        List<ACL> aclObj = acl.length() > 0 ? ACLUtil.parseACLs(acl) : Ids.OPEN_ACL_UNSAFE;
        Stat stat = zk.setACL(path, aclObj, version);

        if (stat != null && withStat) {
            putResponse("stat", StatUtil.stat2Map(stat));
        }

        setStatus(Command.STATUS_SUCCESS);
        setMessage(Command.SUCCESS_MESSAGE);
    } catch (KeeperException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (InterruptedException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (ClassCastException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (NullPointerException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    }
}

From source file:com.github.mosuka.zookeeper.nicli.command.SetCommand.java

License:Apache License

@Override
public void run(Map<String, Object> parameters) {
    try {//from  w  w  w .  j ava  2s.c om
        String path = (String) parameters.get("path");
        String data = (String) parameters.get("data");
        int version = parameters.containsKey("version") ? (Integer) parameters.get("version") : DEFAULT_VERSION;
        boolean withStat = parameters.containsKey("with_stat") ? (Boolean) parameters.get("with_stat")
                : DEFAULT_WITH_STAT;

        ZooKeeper zk = getZookeeperConnection().getZooKeeper();

        byte[] dataByte = data.getBytes();

        Stat stat = zk.setData(path, dataByte, version);

        if (stat != null && withStat) {
            putResponse("stat", StatUtil.stat2Map(stat));
        }

        setStatus(Command.STATUS_SUCCESS);
        setMessage(Command.SUCCESS_MESSAGE);
    } catch (KeeperException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (InterruptedException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (ClassCastException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (NullPointerException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    }
}

From source file:com.github.mosuka.zookeeper.nicli.command.SetQuotaCommand.java

License:Apache License

@Override
public void run(Map<String, Object> parameters) {
    try {//from w  w  w.jav a  2 s . c o  m
        String path = (String) parameters.get("path");
        long bytes = parameters.containsKey("bytes") ? (Long) parameters.get("bytes") : DEFAULT_BYTES;
        int numNodes = parameters.containsKey("num_nodes") ? (Integer) parameters.get("num_nodes")
                : DEFAULT_NUM_NODES;

        ZooKeeper zk = getZookeeperConnection().getZooKeeper();

        if (parameters.containsKey("bytes")) {
            QuotaUtil.createQuota(zk, path, bytes, -1);
        } else if (parameters.containsKey("num_nodes")) {
            QuotaUtil.createQuota(zk, path, -1L, numNodes);
        } else {
            setStatus(Command.STATUS_ERROR);
            setMessage("too few arguments");
            return;
        }

        setStatus(Command.STATUS_SUCCESS);
        setMessage(Command.SUCCESS_MESSAGE);
    } catch (KeeperException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (InterruptedException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (IOException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (ClassCastException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (NullPointerException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    }
}

From source file:com.github.mosuka.zookeeper.nicli.command.StatCommand.java

License:Apache License

@Override
public void run(Map<String, Object> parameters) {
    try {/* w  w w. j a v  a  2s. com*/
        String path = (String) parameters.get("path");
        boolean watch = parameters.containsKey("watch") ? (Boolean) parameters.get("watch") : DEFAULT_WATCH;

        ZooKeeper zk = getZookeeperConnection().getZooKeeper();

        Stat stat = zk.exists(path, watch);
        if (stat != null) {
            putResponse("stat", StatUtil.stat2Map(stat));
        } else {
            throw KeeperException.NoNodeException.create(Code.NONODE, path);
        }

        setStatus(Command.STATUS_SUCCESS);
        setMessage(Command.SUCCESS_MESSAGE);
    } catch (KeeperException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (InterruptedException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (ClassCastException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    } catch (NullPointerException e) {
        setStatus(Command.STATUS_ERROR);
        setMessage(e.getMessage());
    }
}

From source file:com.jbrisbin.vpc.jobsched.mapred.MapReduceClosure.java

License:Apache License

@Override
public Object call(Object[] args) {
    if (args.length != 5) {
        throw new IllegalArgumentException(
                "mapreduce() takes 5 parameters: Job id <String|byte[]>, replyTo <String>, Groovy src <String>, key <String>, value <Object>)");
    }/* w  ww.  jav a2s  . co m*/
    final String id = args[0].toString();
    final String replyTo = (null != args[1] ? args[1].toString() : null);
    final String src = args[2].toString();
    final String key = args[3].toString();
    final Object value = args[4];

    try {
        Stat s = zookeeper.exists(String.format("/vpc/mapred/jobs/%s", id));
        if (log.isDebugEnabled()) {
            log.debug("Job node stat: " + s);
        }
    } catch (KeeperException e) {
        log.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        log.error(e.getMessage(), e);
    }
    /*
    rabbitTemplate.send(mapreduceExchange, mapRoutingKey, new MessageCreator() {
      public Message createMessage() {
        MessageProperties props = new RabbitMessageProperties();
        props.setContentType("application/json");
        if (null != replyTo) {
          props.setReplyTo(new Address(replyTo));
        }
        props.getHeaders().put(SecureMessageConverter.SECURITY_KEY_HDR, mapreduceSecurityKey);
        props.getHeaders().put("mapreduce.key", key);
        props.getHeaders().put("mapreduce.src", src);
        props.setCorrelationId(id.getBytes());
            
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
          mapper.writeValue(out, value);
        } catch (IOException e) {
          log.error(e.getMessage(), e);
        }
        Message msg = new Message(out.toByteArray(), props);
        log.debug("outgoing map: " + msg);
        return msg;
      }
    });
    */
    return null;
}

From source file:com.jxt.web.cluster.zookeeper.ZookeeperClient.java

License:Apache License

private void handleException(KeeperException keeperException) throws PinpointZookeeperException {
    switch (keeperException.code()) {
    case CONNECTIONLOSS:
    case SESSIONEXPIRED:
        throw new ConnectionException(keeperException.getMessage(), keeperException);
    case AUTHFAILED:
    case INVALIDACL:
    case NOAUTH:/*from  www .ja  v  a2  s . c om*/
        throw new AuthException(keeperException.getMessage(), keeperException);
    case BADARGUMENTS:
    case BADVERSION:
    case NOCHILDRENFOREPHEMERALS:
    case NOTEMPTY:
    case NODEEXISTS:
        throw new BadOperationException(keeperException.getMessage(), keeperException);
    case NONODE:
        throw new NoNodeException(keeperException.getMessage(), keeperException);
    case OPERATIONTIMEOUT:
        throw new TimeoutException(keeperException.getMessage(), keeperException);
    default:
        throw new UnknownException(keeperException.getMessage(), keeperException);
    }
}

From source file:com.navercorp.client.Client.java

License:Apache License

private static Result keeperExceptionResult(KeeperException e) {
    switch (e.code()) {
    case NONODE:/*from  w ww .ja v  a2 s .c o m*/
        return new Result("", e.getMessage(), ZK_NO_NODE);
    case NODEEXISTS:
        return new Result("", e.getMessage(), ZK_NODE_EXISTS);
    case NOTEMPTY:
        return new Result("", e.getMessage(), ZK_NOT_EMPTY_NODE);
    case NOCHILDRENFOREPHEMERALS:
        return new Result("", e.getMessage(), ZK_NO_CHILDREN_FOR_EPHEMERALS);
    case BADVERSION:
        return new Result("", e.getMessage(), ZK_BAD_NODE_VERSION);
    default:
        return new Result("", e.getMessage(), ZK_UNEXPECTED_ERROR);
    }
}

From source file:com.navercorp.pinpoint.common.server.cluster.zookeeper.ZookeeperExceptionResolver.java

License:Apache License

static PinpointZookeeperException resolve(Exception exception) {
    if (exception instanceof KeeperException) {
        KeeperException keeperException = (KeeperException) exception;
        switch (keeperException.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
            return new ConnectionException(keeperException.getMessage(), keeperException);
        case AUTHFAILED:
        case INVALIDACL:
        case NOAUTH:
            return new AuthException(keeperException.getMessage(), keeperException);
        case BADARGUMENTS:
        case BADVERSION:
        case NOCHILDRENFOREPHEMERALS:
        case NOTEMPTY:
        case NODEEXISTS:
            return new BadOperationException(keeperException.getMessage(), keeperException);
        case NONODE:
            return new NoNodeException(keeperException.getMessage(), keeperException);
        case OPERATIONTIMEOUT:
            return new TimeoutException(keeperException.getMessage(), keeperException);
        default:/*from  ww  w  . j ava  2 s  .c  o m*/
            return new UnknownException(keeperException.getMessage(), keeperException);
        }
    } else {
        return new UnknownException(exception.getMessage(), exception);
    }
}

From source file:com.oneapm.base.tools.ZookeeperClient.java

/**
 * //from   w w  w .j a v a  2 s. c  o m
 *
 * @param path
 * @return
 */
public boolean deleteNode(String path) {
    try {
        this.zk.delete(path, -1);
        LOG.info("?, Path: " + path);
        return true;
    } catch (KeeperException e) {
        LOG.error(", ?KeeperException! path: " + path + ", errMsg:" + e.getMessage(), e);
    } catch (InterruptedException e) {
        LOG.error(
                ", ? InterruptedException! path: " + path + ", errMsg:" + e.getMessage(),
                e);
    }
    return false;
}