001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.hadoop.hbase.replication;
020
021import java.util.List;
022import java.util.Map;
023import java.util.Set;
024
025import org.apache.hadoop.hbase.TableName;
026import org.apache.yetus.audience.InterfaceAudience;
027
028/**
029 * For creating {@link ReplicationPeerConfig}.
030 */
031@InterfaceAudience.Public
032public interface ReplicationPeerConfigBuilder {
033
034  /**
035   * Set the clusterKey which is the concatenation of the slave cluster's:
036   * hbase.zookeeper.quorum:hbase.zookeeper.property.clientPort:zookeeper.znode.parent
037   */
038  ReplicationPeerConfigBuilder setClusterKey(String clusterKey);
039
040  /**
041   * Sets the ReplicationEndpoint plugin class for this peer.
042   * @param replicationEndpointImpl a class implementing ReplicationEndpoint
043   */
044  ReplicationPeerConfigBuilder setReplicationEndpointImpl(String replicationEndpointImpl);
045
046  /**
047   * Sets a "raw" configuration property for this replication peer. For experts only.
048   * @param key Configuration property key
049   * @param value Configuration property value
050   * @return {@code this}
051   */
052  @InterfaceAudience.Private
053  ReplicationPeerConfigBuilder putConfiguration(String key, String value);
054
055  /**
056   * Adds all of the provided "raw" configuration entries to {@code this}.
057   * @param configuration A collection of raw configuration entries
058   * @return {@code this}
059   */
060  @InterfaceAudience.Private
061  default ReplicationPeerConfigBuilder putAllConfiguration(Map<String, String> configuration) {
062    configuration.forEach(this::putConfiguration);
063    return this;
064  }
065
066  /**
067   * Sets the serialized peer configuration data
068   * @return {@code this}
069   */
070  @InterfaceAudience.Private
071  ReplicationPeerConfigBuilder putPeerData(byte[] key, byte[] value);
072
073  /**
074   * Sets all of the provided serialized peer configuration data.
075   * @return {@code this}
076   */
077  @InterfaceAudience.Private
078  default ReplicationPeerConfigBuilder putAllPeerData(Map<byte[], byte[]> peerData) {
079    peerData.forEach(this::putPeerData);
080    return this;
081  }
082
083  /**
084   * Sets an explicit map of tables and column families in those tables that should be replicated
085   * to the given peer. Use {@link #setReplicateAllUserTables(boolean)} to replicate all tables
086   * to a peer.
087   *
088   * @param tableCFsMap A map from tableName to column family names. An empty collection can be
089   *    passed to indicate replicating all column families.
090   * @return {@code this}
091   * @see #setReplicateAllUserTables(boolean)
092   */
093  ReplicationPeerConfigBuilder
094      setTableCFsMap(Map<TableName, List<String>> tableCFsMap);
095
096  /**
097   * Sets a unique collection of HBase namespaces that should be replicated to this peer.
098   * @param namespaces A set of namespaces to be replicated to this peer.
099   * @return {@code this}
100   */
101  ReplicationPeerConfigBuilder setNamespaces(Set<String> namespaces);
102
103  /**
104   * Sets the speed, in bytes per second, for any one RegionServer to replicate data to the peer.
105   * @param bandwidth Bytes per second
106   * @return {@code this}.
107   */
108  ReplicationPeerConfigBuilder setBandwidth(long bandwidth);
109
110  /**
111   * Configures HBase to replicate all user tables (not system tables) to the peer. Default is
112   * {@code true}.
113   * @param replicateAllUserTables True if all user tables should be replicated, else false.
114   * @return {@code this}
115   */
116  ReplicationPeerConfigBuilder setReplicateAllUserTables(boolean replicateAllUserTables);
117
118  /**
119   * Sets the mapping of table name to column families which should not be replicated. This
120   * method sets state which is mutually exclusive to {@link #setTableCFsMap(Map)}. Invoking this
121   * method is only relevant when all user tables are being replicated.
122   *
123   * @param tableCFsMap A mapping of table names to column families which should not be
124   *    replicated. An empty list of column families implies all families for the table.
125   * @return {@code this}.
126   */
127  ReplicationPeerConfigBuilder setExcludeTableCFsMap(Map<TableName, List<String>> tableCFsMap);
128
129  /**
130   * Sets the collection of namespaces which should not be replicated when all user tables are
131   * configured to be replicated. This method sets state which is mutually exclusive to
132   * {@link #setNamespaces(Set)}. Invoking this method is only relevant when all user tables are
133   * being replicated.
134   *
135   * @param namespaces A set of namespaces whose tables should not be replicated.
136   * @return {@code this}
137   */
138  ReplicationPeerConfigBuilder setExcludeNamespaces(Set<String> namespaces);
139
140  /**
141   * <p>
142   * Sets whether we should preserve order when replicating, i.e, serial replication.
143   * </p>
144   * <p>
145   * Default {@code false}.
146   * </p>
147   * @param serial {@code true} means preserve order, otherwise {@code false}.
148   * @return {@code this}
149   */
150  ReplicationPeerConfigBuilder setSerial(boolean serial);
151
152  /**
153   * Builds the configuration object from the current state of {@code this}.
154   * @return A {@link ReplicationPeerConfig} instance.
155   */
156  ReplicationPeerConfig build();
157}