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

The following examples show how to use org.apache.hadoop.util.ZKUtil. These examples are extracted from open source projects. 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 Project: hadoop   Source File: RMZKUtils.java    License: 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 Project: hadoop   Source File: ZKRMStateStore.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Given the {@link Configuration} and {@link ACL}s used (zkAcl) for
 * ZooKeeper access, construct the {@link ACL}s for the store's root node.
 * In the constructed {@link ACL}, all the users allowed by zkAcl are given
 * rwa access, while the current RM has exclude create-delete access.
 *
 * To be called only when HA is enabled and the configuration doesn't set ACL
 * for the root node.
 */
@VisibleForTesting
@Private
@Unstable
protected List<ACL> constructZkRootNodeACL(
    Configuration conf, List<ACL> sourceACLs) throws NoSuchAlgorithmException {
  List<ACL> zkRootNodeAcl = new ArrayList<ACL>();
  for (ACL acl : sourceACLs) {
    zkRootNodeAcl.add(new ACL(
        ZKUtil.removeSpecificPerms(acl.getPerms(), CREATE_DELETE_PERMS),
        acl.getId()));
  }

  zkRootNodeUsername = HAUtil.getConfValueForRMInstance(
      YarnConfiguration.RM_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADDRESS, conf);
  Id rmId = new Id(zkRootNodeAuthScheme,
      DigestAuthenticationProvider.generateDigest(
          zkRootNodeUsername + ":" + zkRootNodePassword));
  zkRootNodeAcl.add(new ACL(CREATE_DELETE_PERMS, rmId));
  return zkRootNodeAcl;
}
 
Example 3
@Test(timeout = 20000)
public void testInvalidZKAclConfiguration() {
  TestZKClient zkClientTester = new TestZKClient();
  YarnConfiguration conf = new YarnConfiguration();
  conf.set(YarnConfiguration.RM_ZK_ACL, "randomstring&*");
  try {
    zkClientTester.getRMStateStore(conf);
    fail("ZKRMStateStore created with bad ACL");
  } catch (ZKUtil.BadAclFormatException bafe) {
    // expected behavior
  } catch (Exception e) {
    String error = "Incorrect exception on BadAclFormat";
    LOG.error(error, e);
    fail(error);
  }
}
 
Example 4
Source Project: big-c   Source File: RMZKUtils.java    License: 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 5
Source Project: big-c   Source File: ZKRMStateStore.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Given the {@link Configuration} and {@link ACL}s used (zkAcl) for
 * ZooKeeper access, construct the {@link ACL}s for the store's root node.
 * In the constructed {@link ACL}, all the users allowed by zkAcl are given
 * rwa access, while the current RM has exclude create-delete access.
 *
 * To be called only when HA is enabled and the configuration doesn't set ACL
 * for the root node.
 */
@VisibleForTesting
@Private
@Unstable
protected List<ACL> constructZkRootNodeACL(
    Configuration conf, List<ACL> sourceACLs) throws NoSuchAlgorithmException {
  List<ACL> zkRootNodeAcl = new ArrayList<ACL>();
  for (ACL acl : sourceACLs) {
    zkRootNodeAcl.add(new ACL(
        ZKUtil.removeSpecificPerms(acl.getPerms(), CREATE_DELETE_PERMS),
        acl.getId()));
  }

  zkRootNodeUsername = HAUtil.getConfValueForRMInstance(
      YarnConfiguration.RM_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADDRESS, conf);
  Id rmId = new Id(zkRootNodeAuthScheme,
      DigestAuthenticationProvider.generateDigest(
          zkRootNodeUsername + ":" + zkRootNodePassword));
  zkRootNodeAcl.add(new ACL(CREATE_DELETE_PERMS, rmId));
  return zkRootNodeAcl;
}
 
Example 6
@Test(timeout = 20000)
public void testInvalidZKAclConfiguration() {
  TestZKClient zkClientTester = new TestZKClient();
  YarnConfiguration conf = new YarnConfiguration();
  conf.set(YarnConfiguration.RM_ZK_ACL, "randomstring&*");
  try {
    zkClientTester.getRMStateStore(conf);
    fail("ZKRMStateStore created with bad ACL");
  } catch (ZKUtil.BadAclFormatException bafe) {
    // expected behavior
  } catch (Exception e) {
    String error = "Incorrect exception on BadAclFormat";
    LOG.error(error, e);
    fail(error);
  }
}
 
Example 7
Source Project: kylin-on-parquet-v2   Source File: ZookeeperAclBuilder.java    License: 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 8
Source Project: kylin-on-parquet-v2   Source File: ZookeeperAclBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public static List<ACL> getZKAcls() throws Exception {
    // Parse ACLs from configuration.
    String zkAclConf = KylinConfig.getInstanceFromEnv().getZKAcls();
    try {
        zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
        return ZKUtil.parseACLs(zkAclConf);
    } catch (Exception e) {
        logger.error("Couldn't read ACLs based on 'kylin.env.zookeeper.zk-acl' in kylin.properties");
        throw e;
    }
}
 
Example 9
Source Project: hadoop   Source File: EmbeddedElectorService.java    License: 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 10
Source Project: hadoop   Source File: RMZKUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Utility method to fetch the ZK ACLs from the configuration
 */
public static List<ACL> getZKAcls(Configuration conf) throws Exception {
  // Parse authentication from configuration.
  String zkAclConf =
      conf.get(YarnConfiguration.RM_ZK_ACL,
          YarnConfiguration.DEFAULT_RM_ZK_ACL);
  try {
    zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
    return ZKUtil.parseACLs(zkAclConf);
  } catch (Exception e) {
    LOG.error("Couldn't read ACLs based on " + YarnConfiguration.RM_ZK_ACL);
    throw e;
  }
}
 
Example 11
Source Project: hadoop   Source File: ZKRMStateStore.java    License: 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 12
Source Project: hadoop   Source File: RegistrySecurity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parse an ACL list. This includes configuration indirection
 * {@link ZKUtil#resolveConfIndirection(String)}
 * @param zkAclConf configuration string
 * @return an ACL list
 * @throws IOException on a bad ACL parse
 */
public List<ACL> parseACLs(String zkAclConf) throws IOException {
  try {
    return ZKUtil.parseACLs(ZKUtil.resolveConfIndirection(zkAclConf));
  } catch (ZKUtil.BadAclFormatException e) {
    throw new IOException("Parsing " + zkAclConf + " :" + e, e);
  }
}
 
Example 13
Source Project: hadoop   Source File: ZKFailoverController.java    License: Apache License 2.0 5 votes vote down vote up
private void initZK() throws HadoopIllegalArgumentException, IOException,
    KeeperException {
  zkQuorum = conf.get(ZK_QUORUM_KEY);
  int zkTimeout = conf.getInt(ZK_SESSION_TIMEOUT_KEY,
      ZK_SESSION_TIMEOUT_DEFAULT);
  // Parse ACLs from configuration.
  String zkAclConf = conf.get(ZK_ACL_KEY, ZK_ACL_DEFAULT);
  zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
  List<ACL> zkAcls = ZKUtil.parseACLs(zkAclConf);
  if (zkAcls.isEmpty()) {
    zkAcls = Ids.CREATOR_ALL_ACL;
  }
  
  // Parse authentication from configuration.
  String zkAuthConf = conf.get(ZK_AUTH_KEY);
  zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
  List<ZKAuthInfo> zkAuths;
  if (zkAuthConf != null) {
    zkAuths = ZKUtil.parseAuth(zkAuthConf);
  } else {
    zkAuths = Collections.emptyList();
  }

  // Sanity check configuration.
  Preconditions.checkArgument(zkQuorum != null,
      "Missing required configuration '%s' for ZooKeeper quorum",
      ZK_QUORUM_KEY);
  Preconditions.checkArgument(zkTimeout > 0,
      "Invalid ZK session timeout %s", zkTimeout);
  
  int maxRetryNum = conf.getInt(
      CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_KEY,
      CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_DEFAULT);
  elector = new ActiveStandbyElector(zkQuorum,
      zkTimeout, getParentZnode(), zkAcls, zkAuths,
      new ElectorCallbacks(), maxRetryNum);
}
 
Example 14
Source Project: big-c   Source File: EmbeddedElectorService.java    License: 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 15
Source Project: big-c   Source File: RMZKUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Utility method to fetch the ZK ACLs from the configuration
 */
public static List<ACL> getZKAcls(Configuration conf) throws Exception {
  // Parse authentication from configuration.
  String zkAclConf =
      conf.get(YarnConfiguration.RM_ZK_ACL,
          YarnConfiguration.DEFAULT_RM_ZK_ACL);
  try {
    zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
    return ZKUtil.parseACLs(zkAclConf);
  } catch (Exception e) {
    LOG.error("Couldn't read ACLs based on " + YarnConfiguration.RM_ZK_ACL);
    throw e;
  }
}
 
Example 16
Source Project: big-c   Source File: ZKRMStateStore.java    License: 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 17
Source Project: big-c   Source File: RegistrySecurity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parse an ACL list. This includes configuration indirection
 * {@link ZKUtil#resolveConfIndirection(String)}
 * @param zkAclConf configuration string
 * @return an ACL list
 * @throws IOException on a bad ACL parse
 */
public List<ACL> parseACLs(String zkAclConf) throws IOException {
  try {
    return ZKUtil.parseACLs(ZKUtil.resolveConfIndirection(zkAclConf));
  } catch (ZKUtil.BadAclFormatException e) {
    throw new IOException("Parsing " + zkAclConf + " :" + e, e);
  }
}
 
Example 18
Source Project: big-c   Source File: ZKFailoverController.java    License: Apache License 2.0 5 votes vote down vote up
private void initZK() throws HadoopIllegalArgumentException, IOException,
    KeeperException {
  zkQuorum = conf.get(ZK_QUORUM_KEY);
  int zkTimeout = conf.getInt(ZK_SESSION_TIMEOUT_KEY,
      ZK_SESSION_TIMEOUT_DEFAULT);
  // Parse ACLs from configuration.
  String zkAclConf = conf.get(ZK_ACL_KEY, ZK_ACL_DEFAULT);
  zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
  List<ACL> zkAcls = ZKUtil.parseACLs(zkAclConf);
  if (zkAcls.isEmpty()) {
    zkAcls = Ids.CREATOR_ALL_ACL;
  }
  
  // Parse authentication from configuration.
  String zkAuthConf = conf.get(ZK_AUTH_KEY);
  zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
  List<ZKAuthInfo> zkAuths;
  if (zkAuthConf != null) {
    zkAuths = ZKUtil.parseAuth(zkAuthConf);
  } else {
    zkAuths = Collections.emptyList();
  }

  // Sanity check configuration.
  Preconditions.checkArgument(zkQuorum != null,
      "Missing required configuration '%s' for ZooKeeper quorum",
      ZK_QUORUM_KEY);
  Preconditions.checkArgument(zkTimeout > 0,
      "Invalid ZK session timeout %s", zkTimeout);
  
  int maxRetryNum = conf.getInt(
      CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_KEY,
      CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_DEFAULT);
  elector = new ActiveStandbyElector(zkQuorum,
      zkTimeout, getParentZnode(), zkAcls, zkAuths,
      new ElectorCallbacks(), maxRetryNum);
}
 
Example 19
Source Project: kylin   Source File: ZookeeperAclBuilder.java    License: 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 20
Source Project: kylin   Source File: ZookeeperAclBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public static List<ACL> getZKAcls() throws Exception {
    // Parse ACLs from configuration.
    String zkAclConf = KylinConfig.getInstanceFromEnv().getZKAcls();
    try {
        zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
        return ZKUtil.parseACLs(zkAclConf);
    } catch (Exception e) {
        logger.error("Couldn't read ACLs based on 'kylin.env.zookeeper.zk-acl' in kylin.properties");
        throw e;
    }
}
 
Example 21
Source Project: hadoop   Source File: ZKRMStateStore.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public synchronized void initInternal(Configuration conf) throws Exception {
  zkHostPort = conf.get(YarnConfiguration.RM_ZK_ADDRESS);
  if (zkHostPort == null) {
    throw new YarnRuntimeException("No server address specified for " +
        "zookeeper state store for Resource Manager recovery. " +
        YarnConfiguration.RM_ZK_ADDRESS + " is not configured.");
  }
  numRetries =
      conf.getInt(YarnConfiguration.RM_ZK_NUM_RETRIES,
          YarnConfiguration.DEFAULT_ZK_RM_NUM_RETRIES);
  znodeWorkingPath =
      conf.get(YarnConfiguration.ZK_RM_STATE_STORE_PARENT_PATH,
          YarnConfiguration.DEFAULT_ZK_RM_STATE_STORE_PARENT_PATH);
  zkSessionTimeout =
      conf.getInt(YarnConfiguration.RM_ZK_TIMEOUT_MS,
          YarnConfiguration.DEFAULT_RM_ZK_TIMEOUT_MS);

  if (HAUtil.isHAEnabled(conf)) {
    zkRetryInterval = zkSessionTimeout / numRetries;
  } else {
    zkRetryInterval =
        conf.getLong(YarnConfiguration.RM_ZK_RETRY_INTERVAL_MS,
            YarnConfiguration.DEFAULT_RM_ZK_RETRY_INTERVAL_MS);
  }
  zkResyncWaitTime = zkRetryInterval * numRetries;

  zkAcl = RMZKUtils.getZKAcls(conf);
  zkAuths = RMZKUtils.getZKAuths(conf);

  zkRootNodePath = getNodePath(znodeWorkingPath, ROOT_ZNODE_NAME);
  rmAppRoot = getNodePath(zkRootNodePath, RM_APP_ROOT);

  /* Initialize fencing related paths, acls, and ops */
  fencingNodePath = getNodePath(zkRootNodePath, FENCING_LOCK);
  createFencingNodePathOp = Op.create(fencingNodePath, new byte[0], zkAcl,
      CreateMode.PERSISTENT);
  deleteFencingNodePathOp = Op.delete(fencingNodePath, -1);
  if (HAUtil.isHAEnabled(conf)) {
    String zkRootNodeAclConf = HAUtil.getConfValueForRMInstance
        (YarnConfiguration.ZK_RM_STATE_STORE_ROOT_NODE_ACL, conf);
    if (zkRootNodeAclConf != null) {
      zkRootNodeAclConf = ZKUtil.resolveConfIndirection(zkRootNodeAclConf);
      try {
        zkRootNodeAcl = ZKUtil.parseACLs(zkRootNodeAclConf);
      } catch (ZKUtil.BadAclFormatException bafe) {
        LOG.error("Invalid format for " +
            YarnConfiguration.ZK_RM_STATE_STORE_ROOT_NODE_ACL);
        throw bafe;
      }
    } else {
      useDefaultFencingScheme = true;
      zkRootNodeAcl = constructZkRootNodeACL(conf, zkAcl);
    }
  }

  rmDTSecretManagerRoot =
      getNodePath(zkRootNodePath, RM_DT_SECRET_MANAGER_ROOT);
  dtMasterKeysRootPath = getNodePath(rmDTSecretManagerRoot,
      RM_DT_MASTER_KEYS_ROOT_ZNODE_NAME);
  delegationTokensRootPath = getNodePath(rmDTSecretManagerRoot,
      RM_DELEGATION_TOKENS_ROOT_ZNODE_NAME);
  dtSequenceNumberPath = getNodePath(rmDTSecretManagerRoot,
      RM_DT_SEQUENTIAL_NUMBER_ZNODE_NAME);
  amrmTokenSecretManagerRoot =
      getNodePath(zkRootNodePath, AMRMTOKEN_SECRET_MANAGER_ROOT);
}
 
Example 22
Source Project: big-c   Source File: ZKRMStateStore.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public synchronized void initInternal(Configuration conf) throws Exception {
  zkHostPort = conf.get(YarnConfiguration.RM_ZK_ADDRESS);
  if (zkHostPort == null) {
    throw new YarnRuntimeException("No server address specified for " +
        "zookeeper state store for Resource Manager recovery. " +
        YarnConfiguration.RM_ZK_ADDRESS + " is not configured.");
  }
  numRetries =
      conf.getInt(YarnConfiguration.RM_ZK_NUM_RETRIES,
          YarnConfiguration.DEFAULT_ZK_RM_NUM_RETRIES);
  znodeWorkingPath =
      conf.get(YarnConfiguration.ZK_RM_STATE_STORE_PARENT_PATH,
          YarnConfiguration.DEFAULT_ZK_RM_STATE_STORE_PARENT_PATH);
  zkSessionTimeout =
      conf.getInt(YarnConfiguration.RM_ZK_TIMEOUT_MS,
          YarnConfiguration.DEFAULT_RM_ZK_TIMEOUT_MS);

  if (HAUtil.isHAEnabled(conf)) {
    zkRetryInterval = zkSessionTimeout / numRetries;
  } else {
    zkRetryInterval =
        conf.getLong(YarnConfiguration.RM_ZK_RETRY_INTERVAL_MS,
            YarnConfiguration.DEFAULT_RM_ZK_RETRY_INTERVAL_MS);
  }
  zkResyncWaitTime = zkRetryInterval * numRetries;

  zkAcl = RMZKUtils.getZKAcls(conf);
  zkAuths = RMZKUtils.getZKAuths(conf);

  zkRootNodePath = getNodePath(znodeWorkingPath, ROOT_ZNODE_NAME);
  rmAppRoot = getNodePath(zkRootNodePath, RM_APP_ROOT);

  /* Initialize fencing related paths, acls, and ops */
  fencingNodePath = getNodePath(zkRootNodePath, FENCING_LOCK);
  createFencingNodePathOp = Op.create(fencingNodePath, new byte[0], zkAcl,
      CreateMode.PERSISTENT);
  deleteFencingNodePathOp = Op.delete(fencingNodePath, -1);
  if (HAUtil.isHAEnabled(conf)) {
    String zkRootNodeAclConf = HAUtil.getConfValueForRMInstance
        (YarnConfiguration.ZK_RM_STATE_STORE_ROOT_NODE_ACL, conf);
    if (zkRootNodeAclConf != null) {
      zkRootNodeAclConf = ZKUtil.resolveConfIndirection(zkRootNodeAclConf);
      try {
        zkRootNodeAcl = ZKUtil.parseACLs(zkRootNodeAclConf);
      } catch (ZKUtil.BadAclFormatException bafe) {
        LOG.error("Invalid format for " +
            YarnConfiguration.ZK_RM_STATE_STORE_ROOT_NODE_ACL);
        throw bafe;
      }
    } else {
      useDefaultFencingScheme = true;
      zkRootNodeAcl = constructZkRootNodeACL(conf, zkAcl);
    }
  }

  rmDTSecretManagerRoot =
      getNodePath(zkRootNodePath, RM_DT_SECRET_MANAGER_ROOT);
  dtMasterKeysRootPath = getNodePath(rmDTSecretManagerRoot,
      RM_DT_MASTER_KEYS_ROOT_ZNODE_NAME);
  delegationTokensRootPath = getNodePath(rmDTSecretManagerRoot,
      RM_DELEGATION_TOKENS_ROOT_ZNODE_NAME);
  dtSequenceNumberPath = getNodePath(rmDTSecretManagerRoot,
      RM_DT_SEQUENTIAL_NUMBER_ZNODE_NAME);
  amrmTokenSecretManagerRoot =
      getNodePath(zkRootNodePath, AMRMTOKEN_SECRET_MANAGER_ROOT);
}