Java Code Examples for org.apache.hadoop.util.ZKUtil#ZKAuthInfo

The following examples show how to use org.apache.hadoop.util.ZKUtil#ZKAuthInfo . 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: RMZKUtils.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Utility method to fetch ZK auth info from the configuration
 */
public static List<ZKUtil.ZKAuthInfo> getZKAuths(Configuration conf)
    throws Exception {
  String zkAuthConf = conf.get(YarnConfiguration.RM_ZK_AUTH);
  try {
    zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
    if (zkAuthConf != null) {
      return ZKUtil.parseAuth(zkAuthConf);
    } else {
      return Collections.emptyList();
    }
  } catch (Exception e) {
    LOG.error("Couldn't read Auth based on " + YarnConfiguration.RM_ZK_AUTH);
    throw e;
  }
}
 
Example 2
Source File: RMZKUtils.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Utility method to fetch ZK auth info from the configuration
 */
public static List<ZKUtil.ZKAuthInfo> getZKAuths(Configuration conf)
    throws Exception {
  String zkAuthConf = conf.get(YarnConfiguration.RM_ZK_AUTH);
  try {
    zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
    if (zkAuthConf != null) {
      return ZKUtil.parseAuth(zkAuthConf);
    } else {
      return Collections.emptyList();
    }
  } catch (Exception e) {
    LOG.error("Couldn't read Auth based on " + YarnConfiguration.RM_ZK_AUTH);
    throw e;
  }
}
 
Example 3
Source File: ZookeeperAclBuilder.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static List<ZKUtil.ZKAuthInfo> getZKAuths() throws Exception {
    // Parse Auths from configuration.
    String zkAuthConf = KylinConfig.getInstanceFromEnv().getZKAuths();
    try {
        zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
        if (zkAuthConf != null) {
            return ZKUtil.parseAuth(zkAuthConf);
        } else {
            return Collections.emptyList();
        }
    } catch (Exception e) {
        logger.error("Couldn't read Auth based on 'kylin.env.zookeeper.zk-auth' in kylin.properties");
        throw e;
    }
}
 
Example 4
Source File: EmbeddedElectorService.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
protected void serviceInit(Configuration conf)
    throws Exception {
  conf = conf instanceof YarnConfiguration ? conf : new YarnConfiguration(conf);

  String zkQuorum = conf.get(YarnConfiguration.RM_ZK_ADDRESS);
  if (zkQuorum == null) {
   throw new YarnRuntimeException("Embedded automatic failover " +
        "is enabled, but " + YarnConfiguration.RM_ZK_ADDRESS +
        " is not set");
  }

  String rmId = HAUtil.getRMHAId(conf);
  String clusterId = YarnConfiguration.getClusterId(conf);
  localActiveNodeInfo = createActiveNodeInfo(clusterId, rmId);

  String zkBasePath = conf.get(YarnConfiguration.AUTO_FAILOVER_ZK_BASE_PATH,
      YarnConfiguration.DEFAULT_AUTO_FAILOVER_ZK_BASE_PATH);
  String electionZNode = zkBasePath + "/" + clusterId;

  long zkSessionTimeout = conf.getLong(YarnConfiguration.RM_ZK_TIMEOUT_MS,
      YarnConfiguration.DEFAULT_RM_ZK_TIMEOUT_MS);

  List<ACL> zkAcls = RMZKUtils.getZKAcls(conf);
  List<ZKUtil.ZKAuthInfo> zkAuths = RMZKUtils.getZKAuths(conf);

  int maxRetryNum = conf.getInt(
      CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_KEY,
      CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_DEFAULT);
  elector = new ActiveStandbyElector(zkQuorum, (int) zkSessionTimeout,
      electionZNode, zkAcls, zkAuths, this, maxRetryNum);

  elector.ensureParentZNode();
  if (!isParentZnodeSafe(clusterId)) {
    notifyFatalError(electionZNode + " znode has invalid data! "+
        "Might need formatting!");
  }

  super.serviceInit(conf);
}
 
Example 5
Source File: ZKRMStateStore.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private synchronized void createConnection()
    throws IOException, InterruptedException {
  closeZkClients();
  for (int retries = 0; retries < numRetries && zkClient == null;
      retries++) {
    try {
      activeZkClient = getNewZooKeeper();
      zkClient = activeZkClient;
      for (ZKUtil.ZKAuthInfo zkAuth : zkAuths) {
        zkClient.addAuthInfo(zkAuth.getScheme(), zkAuth.getAuth());
      }
      if (useDefaultFencingScheme) {
        zkClient.addAuthInfo(zkRootNodeAuthScheme,
            (zkRootNodeUsername + ":" + zkRootNodePassword).getBytes(Charset.forName("UTF-8")));
      }
    } catch (IOException ioe) {
      // Retry in case of network failures
      LOG.info("Failed to connect to the ZooKeeper on attempt - " +
          (retries + 1));
      ioe.printStackTrace();
    }
  }
  if (zkClient == null) {
    LOG.error("Unable to connect to Zookeeper");
    throw new YarnRuntimeException("Unable to connect to Zookeeper");
  }
  ZKRMStateStore.this.notifyAll();
  LOG.info("Created new ZK connection");
}
 
Example 6
Source File: EmbeddedElectorService.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
protected void serviceInit(Configuration conf)
    throws Exception {
  conf = conf instanceof YarnConfiguration ? conf : new YarnConfiguration(conf);

  String zkQuorum = conf.get(YarnConfiguration.RM_ZK_ADDRESS);
  if (zkQuorum == null) {
   throw new YarnRuntimeException("Embedded automatic failover " +
        "is enabled, but " + YarnConfiguration.RM_ZK_ADDRESS +
        " is not set");
  }

  String rmId = HAUtil.getRMHAId(conf);
  String clusterId = YarnConfiguration.getClusterId(conf);
  localActiveNodeInfo = createActiveNodeInfo(clusterId, rmId);

  String zkBasePath = conf.get(YarnConfiguration.AUTO_FAILOVER_ZK_BASE_PATH,
      YarnConfiguration.DEFAULT_AUTO_FAILOVER_ZK_BASE_PATH);
  String electionZNode = zkBasePath + "/" + clusterId;

  long zkSessionTimeout = conf.getLong(YarnConfiguration.RM_ZK_TIMEOUT_MS,
      YarnConfiguration.DEFAULT_RM_ZK_TIMEOUT_MS);

  List<ACL> zkAcls = RMZKUtils.getZKAcls(conf);
  List<ZKUtil.ZKAuthInfo> zkAuths = RMZKUtils.getZKAuths(conf);

  int maxRetryNum = conf.getInt(
      CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_KEY,
      CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_DEFAULT);
  elector = new ActiveStandbyElector(zkQuorum, (int) zkSessionTimeout,
      electionZNode, zkAcls, zkAuths, this, maxRetryNum);

  elector.ensureParentZNode();
  if (!isParentZnodeSafe(clusterId)) {
    notifyFatalError(electionZNode + " znode has invalid data! "+
        "Might need formatting!");
  }

  super.serviceInit(conf);
}
 
Example 7
Source File: ZKRMStateStore.java    From big-c with Apache License 2.0 5 votes vote down vote up
private synchronized void createConnection()
    throws IOException, InterruptedException {
  closeZkClients();
  for (int retries = 0; retries < numRetries && zkClient == null;
      retries++) {
    try {
      activeZkClient = getNewZooKeeper();
      zkClient = activeZkClient;
      for (ZKUtil.ZKAuthInfo zkAuth : zkAuths) {
        zkClient.addAuthInfo(zkAuth.getScheme(), zkAuth.getAuth());
      }
      if (useDefaultFencingScheme) {
        zkClient.addAuthInfo(zkRootNodeAuthScheme,
            (zkRootNodeUsername + ":" + zkRootNodePassword).getBytes(Charset.forName("UTF-8")));
      }
    } catch (IOException ioe) {
      // Retry in case of network failures
      LOG.info("Failed to connect to the ZooKeeper on attempt - " +
          (retries + 1));
      ioe.printStackTrace();
    }
  }
  if (zkClient == null) {
    LOG.error("Unable to connect to Zookeeper");
    throw new YarnRuntimeException("Unable to connect to Zookeeper");
  }
  ZKRMStateStore.this.notifyAll();
  LOG.info("Created new ZK connection");
}
 
Example 8
Source File: ZookeeperAclBuilder.java    From kylin with Apache License 2.0 5 votes vote down vote up
public static List<ZKUtil.ZKAuthInfo> getZKAuths() throws Exception {
    // Parse Auths from configuration.
    String zkAuthConf = KylinConfig.getInstanceFromEnv().getZKAuths();
    try {
        zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
        if (zkAuthConf != null) {
            return ZKUtil.parseAuth(zkAuthConf);
        } else {
            return Collections.emptyList();
        }
    } catch (Exception e) {
        logger.error("Couldn't read Auth based on 'kylin.env.zookeeper.zk-auth' in kylin.properties");
        throw e;
    }
}