Esempio n. 1
0
  /**
   * This returns true if the host running this process is in the list of master servers. The index
   * is set in the FlumeConfiguration. If the host doesn't match, false is returned. If the
   * hostnames in the master server list fail to resolve, an exception is thrown.
   */
  public static boolean inferMasterHostID() throws UnknownHostException, SocketException {
    String masters = FlumeConfiguration.get().getMasterServers();
    String[] mtrs = masters.split(",");

    int idx = NetUtils.findHostIndex(mtrs);
    if (idx < 0) {

      String localhost = NetUtils.localhost();
      LOG.error(
          "Attempted to start a master '{}' that is not " + "in the master servers list: '{}'",
          localhost,
          mtrs);
      // localhost ips weren't in the list.
      return false;
    }

    FlumeConfiguration.get().setInt(FlumeConfiguration.MASTER_SERVER_ID, idx);
    LOG.info("Inferred master server index {}", idx);
    return true;
  }