View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.replication;
20  
21  import java.util.Collection;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.Set;
26  import java.util.TreeMap;
27
28  import org.apache.hadoop.hbase.TableName;
29  import org.apache.hadoop.hbase.classification.InterfaceAudience;
30  import org.apache.hadoop.hbase.classification.InterfaceStability;
31  import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos;
32  import org.apache.hadoop.hbase.util.Bytes;
33
34  /**
35   * A configuration for the replication peer cluster.
36   */
37  @InterfaceAudience.Public
38  @InterfaceStability.Evolving
39  public class ReplicationPeerConfig {
40
41    private String clusterKey;
42    private String replicationEndpointImpl;
43    private final Map<byte[], byte[]> peerData;
44    private final Map<String, String> configuration;
45    private Map<TableName, ? extends Collection<String>> tableCFsMap = null;
46    private Set<String> namespaces = null;
47
48    public ReplicationPeerConfig() {
49      this.peerData = new TreeMap<byte[], byte[]>(Bytes.BYTES_COMPARATOR);
50      this.configuration = new HashMap<String, String>(0);
51    }
52
53    /**
54     * Set the clusterKey which is the concatenation of the slave cluster's:
55     *          hbase.zookeeper.quorum:hbase.zookeeper.property.clientPort:zookeeper.znode.parent
56     */
57    public ReplicationPeerConfig setClusterKey(String clusterKey) {
58      this.clusterKey = clusterKey;
59      return this;
60    }
61
62    /**
63     * Sets the ReplicationEndpoint plugin class for this peer.
64     * @param replicationEndpointImpl a class implementing ReplicationEndpoint
65     */
66    public ReplicationPeerConfig setReplicationEndpointImpl(String replicationEndpointImpl) {
67      this.replicationEndpointImpl = replicationEndpointImpl;
68      return this;
69    }
70
71    public String getClusterKey() {
72      return clusterKey;
73    }
74
75    public String getReplicationEndpointImpl() {
76      return replicationEndpointImpl;
77    }
78
79    public Map<byte[], byte[]> getPeerData() {
80      return peerData;
81    }
82
83    public Map<String, String> getConfiguration() {
84      return configuration;
85    }
86
87    public Map<TableName, List<String>> getTableCFsMap() {
88      return (Map<TableName, List<String>>) tableCFsMap;
89    }
90
91    public ReplicationPeerConfig setTableCFsMap(Map<TableName,
92                                                ? extends Collection<String>> tableCFsMap) {
93      this.tableCFsMap = tableCFsMap;
94      return this;
95    }
96
97    public Set<String> getNamespaces() {
98      return this.namespaces;
99    }
100
101   public ReplicationPeerConfig setNamespaces(Set<String> namespaces) {
102     this.namespaces = namespaces;
103     return this;
104   }
105
106   @Override
107   public String toString() {
108     StringBuilder builder = new StringBuilder("clusterKey=").append(clusterKey).append(",");
109     builder.append("replicationEndpointImpl=").append(replicationEndpointImpl).append(",");
110     if (namespaces != null) {
111       builder.append("namespaces=").append(namespaces.toString()).append(",");
112     }
113     if (tableCFsMap != null) {
114       builder.append("tableCFs=").append(tableCFsMap.toString());
115     }
116     return builder.toString();
117   }
118 }