ml.shifu.guagua.coordinator.zk.ZooKeeperUtils类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中ml.shifu.guagua.coordinator.zk.ZooKeeperUtils类的一些代码示例,展示了ZooKeeperUtils类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeperUtils类的具体详情如下:
包路径:ml.shifu.guagua.coordinator.zk.ZooKeeperUtils
类名称:ZooKeeperUtils

ZooKeeperUtils介绍

[英]ZooKeeperUtils is a helper used to start embed zookeeper server in CLI host.

For big data guagua application, independent zookeeper instance is recommended, embed server is for user easy to use guagua if there is no zookeeper server in hand.
[中]ZooKeeperUtils是用于在CLI主机中启动嵌入zookeeper服务器的助手。
对于大数据guagua应用,建议使用独立的zookeeper实例,如果手头没有zookeeper服务器,则嵌入式服务器便于用户使用guagua。

代码示例

代码示例来源:origin: ml.shifu/guagua-mapreduce

/**
 * Start zookeeper server in thread of master node.
 */
private String startZookeeperServer(String localHostName) {
  int embedZkClientPort = 0;
  try {
    embedZkClientPort = ZooKeeperUtils.startEmbedZooKeeper();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  // 2. check if it is started.
  ZooKeeperUtils.checkIfEmbedZooKeeperStarted(embedZkClientPort);
  return localHostName + ":" + embedZkClientPort;
}

代码示例来源:origin: ShifuML/guagua

String zooKeeperWorkingDir = getZooKeeperWorkingDir();
boolean isSuccessful = createFolder(zooKeeperWorkingDir);
  zooKeeperWorkingDir = getZooKeeperWorkingDir("zookeeper_" + System.currentTimeMillis());
  createFolder(zooKeeperWorkingDir);
int validZkPort = getValidZooKeeperPort();
prepZooKeeperConf(zooKeeperWorkingDir, confName, validZkPort + "");

代码示例来源:origin: ShifuML/guagua

/**
 * Retrieve zookeeper working folder.
 */
private static String getZooKeeperWorkingDir() {
  return getUserDir() + File.separator + "zookeeper";
}

代码示例来源:origin: ShifuML/guagua

embedZkClientPort = ZooKeeperUtils.startEmbedZooKeeper();
      } catch (IOException e) {
        throw new RuntimeException(e);
      ZooKeeperUtils.checkIfEmbedZooKeeperStarted(embedZkClientPort);
      try {
        embededZooKeeperServer = InetAddress.getLocalHost().getHostName() + ":" + embedZkClientPort;
      "Zookeeper servers should be provided by '-z' parameter with non-empty value.");
if(ZooKeeperUtils.checkServers(zkServers)) {
  conf.set(GuaguaConstants.GUAGUA_ZK_SERVERS, zkServers.trim());
} else {

代码示例来源:origin: ShifuML/guagua

String zooKeeperWorkingDir = getZooKeeperWorkingDir();
boolean isSuccessful = createFolder(zooKeeperWorkingDir);
  zooKeeperWorkingDir = getZooKeeperWorkingDir("zookeeper_" + System.currentTimeMillis());
  createFolder(zooKeeperWorkingDir);
int validZkPort = getValidZooKeeperPort();
prepZooKeeperConf(zooKeeperWorkingDir, confName, validZkPort + "");
commandList.add(findContainingJar(Log4jLoggerAdapter.class) + ":" + findContainingJar(Logger.class) + ":"
    + findContainingJar(org.apache.log4j.Logger.class) + ":" + findContainingJar(ZooKeeperUtils.class)
    + ":" + findContainingJar(QuorumPeerMain.class));
commandList.add(ZooKeeperMain.class.getName());
commandList.add(confName);
String hostname = getLocalHostName();
if(isServerAlive(hostname, validZkPort)) {
  return hostname + ":" + validZkPort;
} else {

代码示例来源:origin: ShifuML/guagua

@Override
public void preApplication(MasterContext<MASTER_RESULT, WORKER_RESULT> context) {
  String zkServers = context.getProps().getProperty(GuaguaConstants.GUAGUA_ZK_SERVERS);
  if(zkServers == null || zkServers.length() == 0 || !ZooKeeperUtils.checkServers(zkServers)) {
    this.isNeedStartZookeeper = true;
    if(fileSystem == null) {
    String zookeeperServer;
    try {
      zookeeperServer = ZooKeeperUtils.startChildZooKeeperProcess(zkJavaOpts);
    } catch (IOException e) {
      LOG.error("Error in start child zookeeper process.", e);

代码示例来源:origin: ml.shifu/guagua-mapreduce

@Override
public void preApplication(WorkerContext<MASTER_RESULT, WORKER_RESULT> context) {
  String zkServers = context.getProps().getProperty(GuaguaConstants.GUAGUA_ZK_SERVERS);
  if(zkServers == null || zkServers.length() == 0 || !ZooKeeperUtils.checkServers(zkServers)) {
    this.sleepTime = NumberFormatUtils.getLong(
        context.getProps().getProperty(GuaguaConstants.GUAGUA_COORDINATOR_SLEEP_UNIT), WAIT_SLOT_MILLS);

代码示例来源:origin: ShifuML/guagua

/**
 * Create zookeeper file with specified name and client port setting.
 */
public static void prepZooKeeperConf(String zkFolder, String fileName, String clientPort) throws IOException {
  Map<String, String> props = new HashMap<String, String>();
  String dataDir = zkFolder + File.separator + "zkdata";
  createFolder(dataDir);
  String dataLogDir = zkFolder + File.separator + "zklog";
  createFolder(dataLogDir);
  props.put("tickTime", "2000");
  props.put("initLimit", "10");
  props.put("syncLimit", "5");
  props.put("dataDir", dataDir);
  props.put("dataLogDir", dataLogDir);
  props.put("clientPort", clientPort);
  props.put("minSessionTimeout", "10000");
  props.put("maxSessionTimeout", "30000000");
  // The number of snapshots to retain in dataDir
  props.put("autopurge.snapRetainCount", "3");
  // Purge task interval in hours set to "0" to disable auto purge feature
  props.put("autopurge.purgeInterval", "1");
  populateZooKeeperConfFile(fileName, props);
}

代码示例来源:origin: ml.shifu/guagua-yarn

embedZkClientPort = ZooKeeperUtils.startEmbedZooKeeper();
      } catch (IOException e) {
        throw new RuntimeException(e);
      ZooKeeperUtils.checkIfEmbedZooKeeperStarted(embedZkClientPort);
      try {
        embededZooKeeperServer = InetAddress.getLocalHost().getHostName() + ":" + embedZkClientPort;
      "Zookeeper servers should be provided by '-z' parameter with non-empty value.");
if(ZooKeeperUtils.checkServers(zkServers)) {
  conf.set(GuaguaConstants.GUAGUA_ZK_SERVERS, zkServers.trim());
} else {

代码示例来源:origin: ml.shifu/guagua-yarn

@Override
public void preApplication(MasterContext<MASTER_RESULT, WORKER_RESULT> context) {
  String zkServers = context.getProps().getProperty(GuaguaConstants.GUAGUA_ZK_SERVERS);
  if(zkServers == null || zkServers.length() == 0 || !ZooKeeperUtils.checkServers(zkServers)) {
    this.isNeedStartZookeeper = true;
    if(fileSystem == null) {
    String zookeeperServer;
    try {
      zookeeperServer = ZooKeeperUtils.startChildZooKeeperProcess(zkJavaOpts);
    } catch (IOException e) {
      LOG.error("Error in start child zookeeper process.", e);

代码示例来源:origin: ShifuML/guagua

@Override
public void preApplication(WorkerContext<MASTER_RESULT, WORKER_RESULT> context) {
  String zkServers = context.getProps().getProperty(GuaguaConstants.GUAGUA_ZK_SERVERS);
  if(zkServers == null || zkServers.length() == 0 || !ZooKeeperUtils.checkServers(zkServers)) {
    this.sleepTime = NumberFormatUtils.getLong(
        context.getProps().getProperty(GuaguaConstants.GUAGUA_COORDINATOR_SLEEP_UNIT), WAIT_SLOT_MILLS);

代码示例来源:origin: ml.shifu/guagua-mapreduce

embedZkClientPort = ZooKeeperUtils.startEmbedZooKeeper();
      } catch (IOException e) {
        throw new RuntimeException(e);
      ZooKeeperUtils.checkIfEmbedZooKeeperStarted(embedZkClientPort);
      try {
        embededZooKeeperServer = InetAddress.getLocalHost().getHostName() + ":" + embedZkClientPort;
      "Zookeeper servers should be provided by '-z' parameter with non-empty value.");
if(ZooKeeperUtils.checkServers(zkServers)) {
  conf.set(GuaguaConstants.GUAGUA_ZK_SERVERS, zkServers.trim());
} else {

代码示例来源:origin: ShifuML/guagua

/**
 * Start zookeeper server in thread of master node.
 */
private String startZookeeperServer(String localHostName) {
  int embedZkClientPort = 0;
  try {
    embedZkClientPort = ZooKeeperUtils.startEmbedZooKeeper();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  // 2. check if it is started.
  ZooKeeperUtils.checkIfEmbedZooKeeperStarted(embedZkClientPort);
  return localHostName + ":" + embedZkClientPort;
}

代码示例来源:origin: ml.shifu/guagua-mapreduce

@Override
public void preApplication(MasterContext<MASTER_RESULT, WORKER_RESULT> context) {
  String zkServers = context.getProps().getProperty(GuaguaConstants.GUAGUA_ZK_SERVERS);
  if(zkServers == null || zkServers.length() == 0 || !ZooKeeperUtils.checkServers(zkServers)) {
    this.isNeedStartZookeeper = true;
    if(fileSystem == null) {
    String zookeeperServer;
    try {
      zookeeperServer = ZooKeeperUtils.startChildZooKeeperProcess(zkJavaOpts);
    } catch (IOException e) {
      LOG.error("Error in start child zookeeper process.", e);

代码示例来源:origin: ShifuML/guagua

@Override
public void preApplication(WorkerContext<MASTER_RESULT, WORKER_RESULT> context) {
  String zkServers = context.getProps().getProperty(GuaguaConstants.GUAGUA_ZK_SERVERS);
  if(zkServers == null || zkServers.length() == 0 || !ZooKeeperUtils.checkServers(zkServers)) {
    this.sleepTime = NumberFormatUtils.getLong(
        context.getProps().getProperty(GuaguaConstants.GUAGUA_COORDINATOR_SLEEP_UNIT), WAIT_SLOT_MILLS);

代码示例来源:origin: ShifuML/guagua

/**
 * Retrieve zookeeper working folder.
 */
private static String getZooKeeperWorkingDir(String subFolder) {
  return getUserDir() + File.separator + subFolder;
}

代码示例来源:origin: ShifuML/guagua

embedZkClientPort = ZooKeeperUtils.startEmbedZooKeeper();
      } catch (IOException e) {
        throw new RuntimeException(e);
      ZooKeeperUtils.checkIfEmbedZooKeeperStarted(embedZkClientPort);
      try {
        embededZooKeeperServer = InetAddress.getLocalHost().getHostName() + ":" + embedZkClientPort;
      "Zookeeper servers should be provided by '-z' parameter with non-empty value.");
if(ZooKeeperUtils.checkServers(zkServers)) {
  conf.set(GuaguaConstants.GUAGUA_ZK_SERVERS, zkServers.trim());
} else {

代码示例来源:origin: ml.shifu/guagua-yarn

/**
 * Start zookeeper server in thread of master node.
 */
private String startZookeeperServer(String localHostName) {
  int embedZkClientPort = 0;
  try {
    embedZkClientPort = ZooKeeperUtils.startEmbedZooKeeper();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  // 2. check if it is started.
  ZooKeeperUtils.checkIfEmbedZooKeeperStarted(embedZkClientPort);
  return localHostName + ":" + embedZkClientPort;
}

代码示例来源:origin: ShifuML/guagua

@Override
public void preApplication(MasterContext<MASTER_RESULT, WORKER_RESULT> context) {
  String zkServers = context.getProps().getProperty(GuaguaConstants.GUAGUA_ZK_SERVERS);
  if(zkServers == null || zkServers.length() == 0 || !ZooKeeperUtils.checkServers(zkServers)) {
    this.isNeedStartZookeeper = true;
    if(fileSystem == null) {
    String zookeeperServer;
    try {
      zookeeperServer = ZooKeeperUtils.startChildZooKeeperProcess(zkJavaOpts);
    } catch (IOException e) {
      LOG.error("Error in start child zookeeper process.", e);

代码示例来源:origin: ml.shifu/guagua-yarn

@Override
public void preApplication(WorkerContext<MASTER_RESULT, WORKER_RESULT> context) {
  String zkServers = context.getProps().getProperty(GuaguaConstants.GUAGUA_ZK_SERVERS);
  if(zkServers == null || zkServers.length() == 0 || !ZooKeeperUtils.checkServers(zkServers)) {
    this.sleepTime = NumberFormatUtils.getLong(
        context.getProps().getProperty(GuaguaConstants.GUAGUA_COORDINATOR_SLEEP_UNIT), WAIT_SLOT_MILLS);

相关文章