Java 类org.apache.zookeeper.client.FourLetterWordMain 实例源码

项目:ankush    文件:ZookeeperMonitor.java   
/**
 * Rest API to run fourLetterCommand Run four letter command.
 */
private void runFourLetterCommand() {
    if (!this.setEnsembleId()) {
        return;
    }
    // Getting the ip address from parameter map.
    String host = (String) parameterMap.get(Constant.Keys.HOST);

    // Getting the ip address from parameter map.
    String command = (String) parameterMap.get(Constant.Keys.COMMAND);

    int clientPort = compConf
            .getAdvanceConfIntegerProperty(ZookeeperConstant.Keys.CLIENT_PORT);

    try {
        logger.info("Zookeeper 4 Letter Command Execution ...");
        String commandOutput = FourLetterWordMain.send4LetterWord(host,
                clientPort, command);

        result.put(Constant.Keys.OUT, commandOutput);

    } catch (Exception e) {
        addErrorAndLogException(
                "Error while executing Zookeeper 4 Letter Command: ", e);
    }
}
项目:management-sdk-for-kafka    文件:ZKNodeWatcher.java   
/**
 * Try to connect to a specific zookeeper server
 * and set the new status according to the connection result
 *
 * @return the previous status
 */
private ZKNodeStatus getAndSetStatus() {
    ZKNodeStatus zkNodeStatus;
    try {
        final String zkNodeStatistics =
                FourLetterWordMain.send4LetterWord(zkNodeAddress.getHostName(),
                        zkNodeAddress.getPort(),
                        ZK_FOUR_LETTER_COMAND_STAT);
        zkNodeStatus = this.zkNodeStatus.getAndSet(new ZKNodeStatus(ZKNodeStatusName.UP, zkNodeStatistics));
    } catch (Exception ex) {
        zkNodeStatus = this.zkNodeStatus.getAndSet(new ZKNodeStatus(ZKNodeStatusName.DOWN,""));
    }
    return zkNodeStatus;
}
项目:ankush    文件:ZookeeperMonitor.java   
/**
 * Exec four letter cmd.
 * 
 * @param host
 *            the host
 * @param command
 *            the command
 * @param clientPort
 *            the client port
 * @return the string
 */
private String execFourLetterCmd(String host, String command, int clientPort) {
    try {
        String commandOutput = FourLetterWordMain.send4LetterWord(host,
                clientPort, command);

        List<String> sysoutList = new ArrayList<String>(
                Arrays.asList(commandOutput.split("\n")));
        String data = new String();

        String escapeCharacter;
        String parameterName;

        if (command
                .equalsIgnoreCase(ZookeeperConstant.Monitor_Keys.COMMAND_MNTR)) {
            escapeCharacter = "\t";
            parameterName = "zk_server_state";
        } else if (command
                .equalsIgnoreCase(ZookeeperConstant.Monitor_Keys.COMMAND_SRVR)) {
            escapeCharacter = ":";
            parameterName = "Mode";
        } else if (command
                .equalsIgnoreCase(ZookeeperConstant.Monitor_Keys.COMMAND_CONF)) {
            escapeCharacter = "=";
            parameterName = "serverId";
        } else {
            escapeCharacter = " ";
            parameterName = " ";
        }

        for (String outData : sysoutList) {

            if (outData.contains(escapeCharacter)) {
                if (outData.split(escapeCharacter)[0].trim()
                        .equalsIgnoreCase(parameterName)) {
                    data = outData.split(escapeCharacter)[1].trim();
                    logger.info("data: " + data);
                }
            }
        }

        return data;
    } catch (Exception e) {
        // addErrorAndLogException("Couldn't execute command-"+command, e);
        logger.error(e.getMessage(), e);
    }
    return "";
}