/** * Send the 4letterword * @param host the destination host * @param port the destination port * @param cmd the 4letterword * @return server response * @throws java.io.IOException * @throws SSLContextException */ public static String send4LetterWord(String host, int port, String cmd) throws IOException, SSLContextException { return send4LetterWord(host, port, cmd, false, DEFAULT_SOCKET_TIMEOUT); }
/** * Send the 4letterword * @param host the destination host * @param port the destination port * @param cmd the 4letterword * @param secure whether to use SSL * @return server response * @throws java.io.IOException * @throws SSLContextException */ public static String send4LetterWord(String host, int port, String cmd, boolean secure) throws IOException, SSLContextException { return send4LetterWord(host, port, cmd, secure, DEFAULT_SOCKET_TIMEOUT); }
/** * Send the 4letterword * @param host the destination host * @param port the destination port * @param cmd the 4letterword * @return server response * @throws java.io.IOException */ public static String send4LetterWord(String host, int port, String cmd) throws IOException { return send4LetterWord(host, port, cmd, DEFAULT_SOCKET_TIMEOUT); } /**
public static void main(String[] args) throws IOException, SSLContextException { if (args.length == 3) { System.out.println(send4LetterWord(args[0], Integer.parseInt(args[1]), args[2])); } else if (args.length == 4) { System.out.println(send4LetterWord(args[0], Integer.parseInt(args[1]), args[2], Boolean.parseBoolean(args[3]))); } else { System.out.println("Usage: FourLetterWordMain <host> <port> <cmd> <secure(optional)>"); } } }
private String sendRequest(String cmd) throws IOException, SSLContextException { return send4LetterWord(HOST, PORT, cmd); }
public static void main(String[] args) throws IOException { if (args.length != 3) { System.out.println("Usage: FourLetterWordMain <host> <port> <cmd>"); } else { System.out.println(send4LetterWord(args[0], Integer.parseInt(args[1]), args[2])); } } }
private String sendRequest(String cmd) throws IOException, SSLContextException { HostPort hpobj = ClientBase.parseHostPortList(hostPort).get(0); return send4LetterWord(hpobj.host, hpobj.port, cmd); }
private String sendRequest(String cmd) throws IOException, SSLContextException { HostPort hpobj = ClientBase.parseHostPortList(hostPort).get(0); return send4LetterWord(hpobj.host, hpobj.port, cmd); } private String sendRequest(String cmd, int timeout) throws IOException, SSLContextException {
private String sendRequest(String cmd, int timeout) throws IOException, SSLContextException { HostPort hpobj = ClientBase.parseHostPortList(hostPort).get(0); return send4LetterWord(hpobj.host, hpobj.port, cmd, false, timeout); }
private void verify(String hp, String cmd, String expected) throws IOException, SSLContextException { for(HostPort hpobj: parseHostPortList(hp)) { String resp = send4LetterWord(hpobj.host, hpobj.port, cmd); LOG.info("cmd " + cmd + " expected " + expected + " got " + resp); if (cmd.equals("dump")) { Assert.assertTrue(resp.contains(expected) || resp.contains("Sessions with Ephemerals")); } else { Assert.assertTrue(resp.contains(expected)); } } } }
String result = send4LetterWord(hpobj.host, hpobj.port, "stat", secure); if (result.startsWith("Zookeeper version:") && !result.contains("READ-ONLY")) {
public static boolean waitForServerDown(String hp, long timeout, boolean secure) { long start = Time.currentElapsedTime(); while (true) { try { HostPort hpobj = parseHostPortList(hp).get(0); send4LetterWord(hpobj.host, hpobj.port, "stat", secure); } catch (IOException e) { return true; } catch (SSLContextException e) { return true; } if (Time.currentElapsedTime() > start + timeout) { break; } try { Thread.sleep(250); } catch (InterruptedException e) { // ignore } } return false; }
/** * Starts a single server in replicated mode, * initializes its client, and waits for it * to be connected. */ private void startServer(int id, String config) throws Exception { peers[id] = new MainThread(id, clientPorts[id], config); peers[id].start(); Assert.assertTrue("Server " + id + " is not up", ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[id], CONNECTION_TIMEOUT)); Assert.assertTrue("Error- Server started in Standalone Mode!", peers[id].isQuorumPeerRunning()); zkHandles[id] = ClientBase.createZKClient("127.0.0.1:" + clientPorts[id]); zkAdminHandles[id] = new ZooKeeperAdmin("127.0.0.1:" + clientPorts[id], CONNECTION_TIMEOUT, this); zkAdminHandles[id].addAuthInfo("digest", "super:test".getBytes()); String statCommandOut = FourLetterWordMain.send4LetterWord("127.0.0.1", clientPorts[id], "stat"); LOG.info(String.format("Started server id %d with config:\n%s\nStat output:\n%s", id, config, statCommandOut)); }