Java Code Examples for org.apache.zookeeper.server.ServerConfig#readFrom()

The following examples show how to use org.apache.zookeeper.server.ServerConfig#readFrom() . 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: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example 2
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example 3
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example 4
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example 5
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example 6
Source File: KafkaDemoClient.java    From iotplatform with Apache License 2.0 6 votes vote down vote up
private static void startZkLocal() throws Exception {
    final File zkTmpDir = File.createTempFile("zookeeper", "test");
    if (zkTmpDir.delete() && zkTmpDir.mkdir()) {
        Properties zkProperties = new Properties();
        zkProperties.setProperty("dataDir", zkTmpDir.getAbsolutePath());
        zkProperties.setProperty("clientPort", String.valueOf(ZK_PORT));

        ServerConfig configuration = new ServerConfig();
        QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
        quorumConfiguration.parseProperties(zkProperties);
        configuration.readFrom(quorumConfiguration);

        new Thread() {
            public void run() {
                try {
                    new ZooKeeperServerMain().runFromConfig(configuration);
                } catch (IOException e) {
                    System.out.println("Start of Local ZooKeeper Failed");
                    e.printStackTrace(System.err);
                }
            }
        }.start();
    } else {
        System.out.println("Failed to delete or create data dir for Zookeeper");
    }
}
 
Example 7
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
            + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    }
    catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        }
        else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example 8
Source File: LocalServer.java    From flow-platform-x with Apache License 2.0 5 votes vote down vote up
public void run() {
    try {
        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        ServerConfig configuration = new ServerConfig();

        quorumPeerConfig.parseProperties(properties);
        configuration.readFrom(quorumPeerConfig);

        this.runFromConfig(configuration);
    } catch (IOException | ConfigException e) {
        throw new ZookeeperException("Unable to start embedded zookeeper server: {}", e.getMessage());
    }
}
 
Example 9
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
            + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    }
    catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        }
        else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example 10
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
            + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    }
    catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        }
        else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example 11
Source File: HQuorumPeer.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static void runZKServer(QuorumPeerConfig zkConfig)
        throws IOException, AdminServer.AdminServerException {
  if (zkConfig.isDistributed()) {
    QuorumPeerMain qp = new QuorumPeerMain();
    qp.runFromConfig(zkConfig);
  } else {
    ZooKeeperServerMain zk = new ZooKeeperServerMain();
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(zkConfig);
    zk.runFromConfig(serverConfig);
  }
}
 
Example 12
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
            + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    }
    catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        }
        else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example 13
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
            + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    }
    catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        }
        else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example 14
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
            + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    }
    catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        }
        else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example 15
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
            + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    }
    catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        }
        else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example 16
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
            + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    }
    catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        }
        else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example 17
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
            + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    }
    catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        }
        else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example 18
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
            + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    }
    catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        }
        else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example 19
Source File: ZkStarter.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
@Override
public void runFromConfig(final ServerConfig config)
    throws IOException {
  ServerConfig newServerConfig = new ServerConfig() {

    public void parse(String[] args) {
      config.parse(args);
    }

    public void parse(String path)
        throws QuorumPeerConfig.ConfigException {
      config.parse(path);
    }

    public void readFrom(QuorumPeerConfig otherConfig) {
      config.readFrom(otherConfig);
    }

    public InetSocketAddress getClientPortAddress() {
      return config.getClientPortAddress();
    }

    public String getDataDir() {
      return config.getDataDir();
    }

    public String getDataLogDir() {
      return config.getDataLogDir();
    }

    public int getTickTime() {
      return config.getTickTime();
    }

    public int getMaxClientCnxns() {
      dataDir = getDataDir();
      dataLogDir = getDataLogDir();
      tickTime = getTickTime();
      minSessionTimeout = getMinSessionTimeout();
      maxSessionTimeout = getMaxSessionTimeout();
      maxClientCnxns = 0;
      return 0;
    }

    public int getMinSessionTimeout() {
      return config.getMinSessionTimeout();
    }

    public int getMaxSessionTimeout() {
      return config.getMaxSessionTimeout();
    }
  };

  newServerConfig.getMaxClientCnxns();

  super.runFromConfig(newServerConfig);
}
 
Example 20
Source File: ZkServer.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public void init() throws Exception {
  logger.info("Starting Zookeeper");

  final Properties startupProperties = new Properties();
  final File dir = new File(storageDir, "zookeeper");
  startupProperties.put("dataDir", dir.toString());
  final ServerConfig configuration = new ServerConfig();
  final QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();

  while (true) {
    startupProperties.put("clientPort", port);
    quorumConfiguration.parseProperties(startupProperties);
    configuration.readFrom(quorumConfiguration);
    this.zkEmbeddedServer = new ZkEmbeddedServer(configuration);
    this.zkThread = new Thread(zkEmbeddedServer, "dremio-embedded-zookeeper@" + port);
    zkThread.start();
    // wait for zk server to start cleanly, max wait half a sec
    int maxWait = ZK_SERVER_STARTUP_TIME;
    while (zkEmbeddedServer.error == null && maxWait > 0) {
      try {
        Thread.currentThread().sleep(100);
      } catch (InterruptedException ite) {
        break;
      }
      maxWait -= 100;
    }
    if (zkEmbeddedServer.error != null) {
      zkEmbeddedServer.shutDown();
      zkThread.join();
      if (autoPort && zkEmbeddedServer.error instanceof BindException) {
        logger.info("ZooKeeper failed to start on port {}, trying next port {}", port, port + 1);
        port++;
      } else {
        logger.error("ZooKeeper startup failed", zkEmbeddedServer.error);
        Throwables.propagate(zkEmbeddedServer.error);
        break;
      }
    } else {
      break;
    }
  }

  logger.info("Zookeeper is up at localhost:{}", port);
}