コード例 #1
0
  @Override
  public Configuration getPeerConf(String peerId) throws ReplicationException {
    String znode = ZKUtil.joinZNode(this.peersZNode, peerId);
    byte[] data = null;
    try {
      data = ZKUtil.getData(this.zookeeper, znode);
    } catch (KeeperException e) {
      throw new ReplicationException("Error getting configuration for peer with id=" + peerId, e);
    }
    if (data == null) {
      LOG.error("Could not get configuration for peer because it doesn't exist. peerId=" + peerId);
      return null;
    }
    String otherClusterKey = "";
    try {
      otherClusterKey = parsePeerFrom(data);
    } catch (DeserializationException e) {
      LOG.warn(
          "Failed to parse cluster key from peerId="
              + peerId
              + ", specifically the content from the following znode: "
              + znode);
      return null;
    }

    Configuration otherConf = new Configuration(this.conf);
    try {
      ZKUtil.applyClusterKeyToConf(otherConf, otherClusterKey);
    } catch (IOException e) {
      LOG.error("Can't get peer configuration for peerId=" + peerId + " because:", e);
      return null;
    }
    return otherConf;
  }
コード例 #2
0
ファイル: ReplicationAdmin.java プロジェクト: Guavus/hbase
 private List<ReplicationPeer> listValidReplicationPeers() {
   Map<String, ReplicationPeerConfig> peers = listPeerConfigs();
   if (peers == null || peers.size() <= 0) {
     return null;
   }
   List<ReplicationPeer> validPeers = new ArrayList<ReplicationPeer>(peers.size());
   for (Entry<String, ReplicationPeerConfig> peerEntry : peers.entrySet()) {
     String peerId = peerEntry.getKey();
     String clusterKey = peerEntry.getValue().getClusterKey();
     Configuration peerConf = new Configuration(this.connection.getConfiguration());
     Stat s = null;
     try {
       ZKUtil.applyClusterKeyToConf(peerConf, clusterKey);
       Pair<ReplicationPeerConfig, Configuration> pair = this.replicationPeers.getPeerConf(peerId);
       ReplicationPeer peer = new ReplicationPeerZKImpl(peerConf, peerId, pair.getFirst());
       s =
           zkw.getRecoverableZooKeeper()
               .exists(peerConf.get(HConstants.ZOOKEEPER_ZNODE_PARENT), null);
       if (null == s) {
         LOG.info(peerId + ' ' + clusterKey + " is invalid now.");
         continue;
       }
       validPeers.add(peer);
     } catch (ReplicationException e) {
       LOG.warn(
           "Failed to get valid replication peers. "
               + "Error connecting to peer cluster with peerId="
               + peerId);
       LOG.debug("Failure details to get valid replication peers.", e);
       continue;
     } catch (KeeperException e) {
       LOG.warn(
           "Failed to get valid replication peers. KeeperException code=" + e.code().intValue());
       LOG.debug("Failure details to get valid replication peers.", e);
       continue;
     } catch (InterruptedException e) {
       LOG.warn("Failed to get valid replication peers due to InterruptedException.");
       LOG.debug("Failure details to get valid replication peers.", e);
       Thread.currentThread().interrupt();
       continue;
     } catch (IOException e) {
       LOG.warn("Failed to get valid replication peers due to IOException.");
       LOG.debug("Failure details to get valid replication peers.", e);
       continue;
     }
   }
   return validPeers;
 }