org.apache.zookeeper.client.FourLetterWordMain Java Examples

The following examples show how to use org.apache.zookeeper.client.FourLetterWordMain. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ZookeeperMonitor.java    From ankush with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example #2
Source File: ZooKeeperState.java    From Mario with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	try {
		ret = FourLetterWordMain.send4LetterWord(host, port, cmd);
	} catch (IOException e) {
		return;
	}
}
 
Example #3
Source File: IndexController.java    From Mario with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
	try {
		ret = FourLetterWordMain.send4LetterWord(info.gethost().trim(), info.getport(), cmd);
	} catch (IOException e) {
		return;
	}
}
 
Example #4
Source File: ZookeeperMonitor.java    From ankush with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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 "";
}