Example usage for org.apache.zookeeper.client FourLetterWordMain send4LetterWord

List of usage examples for org.apache.zookeeper.client FourLetterWordMain send4LetterWord

Introduction

In this page you can find the example usage for org.apache.zookeeper.client FourLetterWordMain send4LetterWord.

Prototype

public static String send4LetterWord(String host, int port, String cmd)
        throws IOException, SSLContextException 

Source Link

Document

Send the 4letterword

Usage

From source file:com.impetus.ankush2.zookeeper.ZookeeperMonitor.java

License:Open Source License

/**
 * Rest API to run fourLetterCommand Run four letter command.
 *//*from w w  w  .ja va  2  s .  c om*/
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);
    }
}

From source file:com.impetus.ankush2.zookeeper.ZookeeperMonitor.java

License:Open Source License

/**
 * Exec four letter cmd./*from   w w w  .j  a  va2 s .c o m*/
 * 
 * @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 "";
}

From source file:io.confluent.admin.utils.EmbeddedZookeeperEnsemble.java

License:Apache License

public String send4LW(String hp, long timeout, String FourLW) throws TimeoutException {
    long start = System.currentTimeMillis();

    while (true) {
        try {// ww w .  j av a 2s.  co  m
            HostPort e = (HostPort) parseHostPortList(hp).get(0);
            String result = FourLetterWordMain.send4LetterWord(e.host, e.port, FourLW);
            return result;
        } catch (IOException var7) {
            log.info("server " + hp + " not up " + var7);
        }

        if (System.currentTimeMillis() > start + timeout) {
            throw new TimeoutException();
        }

        try {
            Thread.sleep(250L);
        } catch (InterruptedException e) {
            //Ignore
        }
    }
}