Java Code Examples for org.apache.hadoop.hbase.replication.ReplicationPeerConfig#newBuilder()

The following examples show how to use org.apache.hadoop.hbase.replication.ReplicationPeerConfig#newBuilder() . 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: ReplicationPeerManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
public void updatePeerConfig(String peerId, ReplicationPeerConfig peerConfig)
    throws ReplicationException {
  // the checking rules are too complicated here so we give up checking whether this is a retry.
  ReplicationPeerDescription desc = peers.get(peerId);
  ReplicationPeerConfig oldPeerConfig = desc.getPeerConfig();
  ReplicationPeerConfigBuilder newPeerConfigBuilder =
    ReplicationPeerConfig.newBuilder(peerConfig);
  // we need to use the new conf to overwrite the old one.
  newPeerConfigBuilder.putAllConfiguration(oldPeerConfig.getConfiguration());
  newPeerConfigBuilder.putAllConfiguration(peerConfig.getConfiguration());
  newPeerConfigBuilder.putAllConfiguration(oldPeerConfig.getConfiguration());
  newPeerConfigBuilder.putAllConfiguration(peerConfig.getConfiguration());
  ReplicationPeerConfig newPeerConfig = newPeerConfigBuilder.build();
  peerStorage.updatePeerConfig(peerId, newPeerConfig);
  peers.put(peerId, new ReplicationPeerDescription(peerId, desc.isEnabled(), newPeerConfig,
    desc.getSyncReplicationState()));
}
 
Example 2
Source File: TestReplicationAdminForSyncReplication.java    From hbase with Apache License 2.0 5 votes vote down vote up
private ReplicationPeerConfig buildSyncReplicationPeerConfig(String clusterKey,
    TableName tableName) throws IOException {
  Path rootDir = TEST_UTIL.getDataTestDirOnTestFS("remoteWAL");
  ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder();
  builder.setClusterKey(clusterKey);
  builder.setRemoteWALDir(rootDir.makeQualified(TEST_UTIL.getTestFileSystem().getUri(),
      TEST_UTIL.getTestFileSystem().getWorkingDirectory()).toString());
  builder.setReplicateAllUserTables(false);
  Map<TableName, List<String>> tableCfs = new HashMap<>();
  tableCfs.put(tableName, new ArrayList<>());
  builder.setTableCFsMap(tableCfs);
  return builder.build();
}
 
Example 3
Source File: ReplicationPeerConfigUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static ReplicationPeerConfig appendTableCFsToReplicationPeerConfig(
    Map<TableName, List<String>> tableCfs, ReplicationPeerConfig peerConfig) {
  ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder(peerConfig);
  Map<TableName, List<String>> preTableCfs = peerConfig.getTableCFsMap();
  if (preTableCfs == null) {
    builder.setTableCFsMap(tableCfs);
  } else {
    builder.setTableCFsMap(mergeTableCFs(preTableCfs, tableCfs));
  }
  return builder.build();
}
 
Example 4
Source File: ReplicationPeerConfigUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static ReplicationPeerConfig appendExcludeTableCFsToReplicationPeerConfig(
    Map<TableName, List<String>> excludeTableCfs, ReplicationPeerConfig peerConfig)
    throws ReplicationException {
  if (excludeTableCfs == null) {
    throw new ReplicationException("exclude tableCfs is null");
  }
  ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder(peerConfig);
  Map<TableName, List<String>> preExcludeTableCfs = peerConfig.getExcludeTableCFsMap();
  if (preExcludeTableCfs == null) {
    builder.setExcludeTableCFsMap(excludeTableCfs);
  } else {
    builder.setExcludeTableCFsMap(mergeTableCFs(preExcludeTableCfs, excludeTableCfs));
  }
  return builder.build();
}
 
Example 5
Source File: ReplicationPeerConfigUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static ReplicationPeerConfig removeTableCFsFromReplicationPeerConfig(
    Map<TableName, List<String>> tableCfs, ReplicationPeerConfig peerConfig,
    String id) throws ReplicationException {
  Map<TableName, List<String>> preTableCfs = peerConfig.getTableCFsMap();
  if (preTableCfs == null) {
    throw new ReplicationException("Table-Cfs for peer: " + id + " is null");
  }
  Map<TableName, List<String>> newTableCfs = copyTableCFsMap(preTableCfs);
  for (Map.Entry<TableName, ? extends Collection<String>> entry : tableCfs.entrySet()) {
    TableName table = entry.getKey();
    Collection<String> removeCfs = entry.getValue();
    if (newTableCfs.containsKey(table)) {
      List<String> cfs = newTableCfs.get(table);
      if (cfs == null && (removeCfs == null || removeCfs.isEmpty())) {
        newTableCfs.remove(table);
      } else if (cfs != null && (removeCfs != null && !removeCfs.isEmpty())) {
        Set<String> cfSet = new HashSet<String>(cfs);
        cfSet.removeAll(removeCfs);
        if (cfSet.isEmpty()) {
          newTableCfs.remove(table);
        } else {
          newTableCfs.put(table, Lists.newArrayList(cfSet));
        }
      } else if (cfs == null && (removeCfs != null && !removeCfs.isEmpty())) {
        throw new ReplicationException("Cannot remove cf of table: " + table
            + " which doesn't specify cfs from table-cfs config in peer: " + id);
      } else if (cfs != null && (removeCfs == null || removeCfs.isEmpty())) {
        throw new ReplicationException("Cannot remove table: " + table
            + " which has specified cfs from table-cfs config in peer: " + id);
      }
    } else {
      throw new ReplicationException(
          "No table: " + table + " in table-cfs config of peer: " + id);
    }
  }
  ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder(peerConfig);
  builder.setTableCFsMap(newTableCfs);
  return builder.build();
}
 
Example 6
Source File: ReplicationPeerConfigUtil.java    From hbase with Apache License 2.0 4 votes vote down vote up
public static ReplicationPeerConfig removeExcludeTableCFsFromReplicationPeerConfig(
    Map<TableName, List<String>> excludeTableCfs, ReplicationPeerConfig peerConfig, String id)
    throws ReplicationException {
  if (excludeTableCfs == null) {
    throw new ReplicationException("exclude tableCfs is null");
  }
  Map<TableName, List<String>> preExcludeTableCfs = peerConfig.getExcludeTableCFsMap();
  if (preExcludeTableCfs == null) {
    throw new ReplicationException("exclude-Table-Cfs for peer: " + id + " is null");
  }
  Map<TableName, List<String>> newExcludeTableCfs = copyTableCFsMap(preExcludeTableCfs);
  for (Map.Entry<TableName, ? extends Collection<String>> entry : excludeTableCfs.entrySet()) {
    TableName table = entry.getKey();
    Collection<String> removeCfs = entry.getValue();
    if (newExcludeTableCfs.containsKey(table)) {
      List<String> cfs = newExcludeTableCfs.get(table);
      if (cfs == null && (removeCfs == null || removeCfs.isEmpty())) {
        newExcludeTableCfs.remove(table);
      } else if (cfs != null && (removeCfs != null && !removeCfs.isEmpty())) {
        Set<String> cfSet = new HashSet<String>(cfs);
        cfSet.removeAll(removeCfs);
        if (cfSet.isEmpty()) {
          newExcludeTableCfs.remove(table);
        } else {
          newExcludeTableCfs.put(table, Lists.newArrayList(cfSet));
        }
      } else if (cfs == null && (removeCfs != null && !removeCfs.isEmpty())) {
        throw new ReplicationException("Cannot remove cf of table: " + table
            + " which doesn't specify cfs from exclude-table-cfs config in peer: " + id);
      } else if (cfs != null && (removeCfs == null || removeCfs.isEmpty())) {
        throw new ReplicationException("Cannot remove table: " + table
            + " which has specified cfs from exclude-table-cfs config in peer: " + id);
      }
    } else {
      throw new ReplicationException(
          "No table: " + table + " in exclude-table-cfs config of peer: " + id);
    }
  }
  ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder(peerConfig);
  builder.setExcludeTableCFsMap(newExcludeTableCfs);
  return builder.build();
}