Search in sources :

Example 11 with ReplicationPeerConfigBuilder

use of org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder in project hbase by apache.

the class ReplicationPeerConfigUtil method removeTableCFsFromReplicationPeerConfig.

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();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerConfigBuilder(org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) List(java.util.List) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with ReplicationPeerConfigBuilder

use of org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder in project hbase by apache.

the class ReplicationPeerConfigUtil method updateReplicationBasePeerConfigs.

/**
 * Helper method to add/removev base peer configs from Configuration to ReplicationPeerConfig
 *
 * This merges the user supplied peer configuration
 * {@link org.apache.hadoop.hbase.replication.ReplicationPeerConfig} with peer configs
 * provided as property hbase.replication.peer.base.configs in hbase configuration.
 * Expected format for this hbase configuration is "k1=v1;k2=v2,v2_1;k3=""".
 * If value is empty, it will remove the existing key-value from peer config.
 *
 * @param conf Configuration
 * @return ReplicationPeerConfig containing updated configs.
 */
public static ReplicationPeerConfig updateReplicationBasePeerConfigs(Configuration conf, ReplicationPeerConfig receivedPeerConfig) {
    ReplicationPeerConfigBuilder copiedPeerConfigBuilder = ReplicationPeerConfig.newBuilder(receivedPeerConfig);
    Map<String, String> receivedPeerConfigMap = receivedPeerConfig.getConfiguration();
    String basePeerConfigs = conf.get(HBASE_REPLICATION_PEER_BASE_CONFIG, "");
    if (basePeerConfigs.length() != 0) {
        Map<String, String> basePeerConfigMap = Splitter.on(';').trimResults().omitEmptyStrings().withKeyValueSeparator("=").split(basePeerConfigs);
        for (Map.Entry<String, String> entry : basePeerConfigMap.entrySet()) {
            String configName = entry.getKey();
            String configValue = entry.getValue();
            // is required so that it doesn't remove any other config unknowingly.
            if (Strings.isNullOrEmpty(configValue)) {
                copiedPeerConfigBuilder.removeConfiguration(configName);
            } else if (!receivedPeerConfigMap.getOrDefault(configName, "").equals(configValue)) {
                // update the configuration if exact config and value doesn't exists
                copiedPeerConfigBuilder.putConfiguration(configName, configValue);
            }
        }
    }
    return copiedPeerConfigBuilder.build();
}
Also used : ReplicationPeerConfigBuilder(org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with ReplicationPeerConfigBuilder

use of org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder in project hbase by apache.

the class ReplicationPeerConfigUtil method appendTableCFsToReplicationPeerConfig.

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();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerConfigBuilder(org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with ReplicationPeerConfigBuilder

use of org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder in project hbase by apache.

the class ReplicationPeerConfigUtil method convert.

public static ReplicationPeerConfig convert(ReplicationProtos.ReplicationPeer peer) {
    ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder();
    if (peer.hasClusterkey()) {
        builder.setClusterKey(peer.getClusterkey());
    }
    if (peer.hasReplicationEndpointImpl()) {
        builder.setReplicationEndpointImpl(peer.getReplicationEndpointImpl());
    }
    for (HBaseProtos.BytesBytesPair pair : peer.getDataList()) {
        builder.putPeerData(pair.getFirst().toByteArray(), pair.getSecond().toByteArray());
    }
    for (HBaseProtos.NameStringPair pair : peer.getConfigurationList()) {
        builder.putConfiguration(pair.getName(), pair.getValue());
    }
    Map<TableName, List<String>> tableCFsMap = convert2Map(peer.getTableCfsList().toArray(new ReplicationProtos.TableCF[peer.getTableCfsCount()]));
    if (tableCFsMap != null) {
        builder.setTableCFsMap(tableCFsMap);
    }
    List<ByteString> namespacesList = peer.getNamespacesList();
    if (namespacesList != null && namespacesList.size() != 0) {
        builder.setNamespaces(namespacesList.stream().map(ByteString::toStringUtf8).collect(Collectors.toSet()));
    }
    if (peer.hasBandwidth()) {
        builder.setBandwidth(peer.getBandwidth());
    }
    if (peer.hasReplicateAll()) {
        builder.setReplicateAllUserTables(peer.getReplicateAll());
    }
    if (peer.hasSerial()) {
        builder.setSerial(peer.getSerial());
    }
    Map<TableName, List<String>> excludeTableCFsMap = convert2Map(peer.getExcludeTableCfsList().toArray(new ReplicationProtos.TableCF[peer.getExcludeTableCfsCount()]));
    if (excludeTableCFsMap != null) {
        builder.setExcludeTableCFsMap(excludeTableCFsMap);
    }
    List<ByteString> excludeNamespacesList = peer.getExcludeNamespacesList();
    if (excludeNamespacesList != null && excludeNamespacesList.size() != 0) {
        builder.setExcludeNamespaces(excludeNamespacesList.stream().map(ByteString::toStringUtf8).collect(Collectors.toSet()));
    }
    if (peer.hasRemoteWALDir()) {
        builder.setRemoteWALDir(peer.getRemoteWALDir());
    }
    return builder.build();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerConfigBuilder(org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) List(java.util.List) HBaseProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos)

Aggregations

ReplicationPeerConfigBuilder (org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder)14 List (java.util.List)10 TableName (org.apache.hadoop.hbase.TableName)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 Test (org.junit.Test)6 HashSet (java.util.HashSet)4 ReplicationException (org.apache.hadoop.hbase.replication.ReplicationException)4 ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)4 Map (java.util.Map)3 Set (java.util.Set)2 CompletionException (java.util.concurrent.CompletionException)2 Path (org.apache.hadoop.fs.Path)1 ReplicationPeerConfig (org.apache.hadoop.hbase.replication.ReplicationPeerConfig)1 ReplicationPeerDescription (org.apache.hadoop.hbase.replication.ReplicationPeerDescription)1 HBaseProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos)1