private void checkClusterKey(String clusterKey, ReplicationEndpoint endpoint)
    throws DoNotRetryIOException {
    if (endpoint != null && !(endpoint instanceof HBaseReplicationEndpoint)) {
      return;
    }
    // Endpoints implementing HBaseReplicationEndpoint need to check cluster key
    URI connectionUri = ConnectionRegistryFactory.tryParseAsConnectionURI(clusterKey);
    try {
      if (connectionUri != null) {
        ConnectionRegistryFactory.validate(connectionUri);
      } else {
        ZKConfig.validateClusterKey(clusterKey);
      }
    } catch (IOException e) {
      throw new DoNotRetryIOException("Invalid cluster key: " + clusterKey, e);
    }
    if (endpoint != null && endpoint.canReplicateToSameCluster()) {
      return;
    }
    // make sure we do not replicate to same cluster
    String peerClusterId;
    try {
      if (connectionUri != null) {
        // fetch cluster id through standard admin API
        try (Connection conn = ConnectionFactory.createConnection(connectionUri, conf);
          Admin admin = conn.getAdmin()) {
          peerClusterId =
            admin.getClusterMetrics(EnumSet.of(ClusterMetrics.Option.CLUSTER_ID)).getClusterId();
        }
      } else {
        // Create the peer cluster config for get peer cluster id
        Configuration peerConf = HBaseConfiguration.createClusterConf(conf, clusterKey);
        try (ZKWatcher zkWatcher = new ZKWatcher(peerConf, this + "check-peer-cluster-id", null)) {
          peerClusterId = ZKClusterId.readClusterIdZNode(zkWatcher);
        }
      }
    } catch (IOException | KeeperException e) {
      // we just want to check whether we will replicate to the same cluster, so if we get an error
      // while getting the cluster id of the peer cluster, it means we are not connecting to
      // ourselves, as we are still alive. So here we just log the error and continue
      LOG.warn("Can't get peerClusterId for clusterKey=" + clusterKey, e);
      return;
    }
    // In rare case, zookeeper setting may be messed up. That leads to the incorrect
    // peerClusterId value, which is the same as the source clusterId
    if (clusterId.equals(peerClusterId)) {
      throw new DoNotRetryIOException("Invalid cluster key: " + clusterKey
        + ", should not replicate to itself for HBaseInterClusterReplicationEndpoint");
    }
  }
Returns the old desciption of the peer
hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ReplicationPeerManager.java