1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.replication;
20
21 import com.google.common.base.Splitter;
22
23 import java.util.Collection;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.TreeMap;
28
29 import org.apache.hadoop.conf.Configuration;
30 import org.apache.hadoop.hbase.TableName;
31 import org.apache.hadoop.hbase.classification.InterfaceAudience;
32 import org.apache.hadoop.hbase.classification.InterfaceStability;
33 import org.apache.hadoop.hbase.util.Bytes;
34
35
36
37
38 @InterfaceAudience.Public
39 @InterfaceStability.Evolving
40 public class ReplicationPeerConfig {
41
42 private String clusterKey;
43 private String replicationEndpointImpl;
44 private final Map<byte[], byte[]> peerData;
45 private final Map<String, String> configuration;
46 private Map<TableName, ? extends Collection<String>> tableCFsMap = null;
47 private long bandwidth = 0;
48
49 public static final String HBASE_REPLICATION_PEER_BASE_CONFIG =
50 "hbase.replication.peer.base.config";
51
52 public ReplicationPeerConfig() {
53 this.peerData = new TreeMap<byte[], byte[]>(Bytes.BYTES_COMPARATOR);
54 this.configuration = new HashMap<String, String>(0);
55 }
56
57
58
59
60
61 public ReplicationPeerConfig setClusterKey(String clusterKey) {
62 this.clusterKey = clusterKey;
63 return this;
64 }
65
66
67
68
69
70 public ReplicationPeerConfig setReplicationEndpointImpl(String replicationEndpointImpl) {
71 this.replicationEndpointImpl = replicationEndpointImpl;
72 return this;
73 }
74
75 public String getClusterKey() {
76 return clusterKey;
77 }
78
79 public String getReplicationEndpointImpl() {
80 return replicationEndpointImpl;
81 }
82
83 public Map<byte[], byte[]> getPeerData() {
84 return peerData;
85 }
86
87 public Map<String, String> getConfiguration() {
88 return configuration;
89 }
90
91 public Map<TableName, List<String>> getTableCFsMap() {
92 return (Map<TableName, List<String>>) tableCFsMap;
93 }
94
95 public void setTableCFsMap(Map<TableName, ? extends Collection<String>> tableCFsMap) {
96 this.tableCFsMap = tableCFsMap;
97 }
98
99 public long getBandwidth() {
100 return this.bandwidth;
101 }
102
103 public ReplicationPeerConfig setBandwidth(long bandwidth) {
104 this.bandwidth = bandwidth;
105 return this;
106 }
107
108
109
110
111
112
113
114
115
116
117
118
119
120 public void addBasePeerConfigsIfNotPresent(Configuration conf) {
121 String basePeerConfigs = conf.get(HBASE_REPLICATION_PEER_BASE_CONFIG, "");
122
123 if (basePeerConfigs.length() != 0) {
124 Map<String, String> basePeerConfigMap = Splitter.on(';').trimResults().omitEmptyStrings()
125 .withKeyValueSeparator("=").split(basePeerConfigs);
126 for (Map.Entry<String,String> entry : basePeerConfigMap.entrySet()) {
127 String configName = entry.getKey();
128 String configValue = entry.getValue();
129
130 if (!this.getConfiguration().containsKey(configName)) {
131 this.getConfiguration().put(configName, configValue);
132 }
133 }
134 }
135 }
136
137 @Override
138 public String toString() {
139 StringBuilder builder = new StringBuilder("clusterKey=").append(clusterKey).append(",");
140 builder.append("replicationEndpointImpl=").append(replicationEndpointImpl);
141 if (tableCFsMap != null) {
142 builder.append(tableCFsMap.toString()).append(",");
143 }
144 builder.append("bandwidth=").append(bandwidth);
145 return builder.toString();
146 }
147 }