View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.replication;
20  
21  import java.io.IOException;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.UUID;
26  
27  import org.apache.hadoop.conf.Configuration;
28  import org.apache.hadoop.fs.FileSystem;
29  import org.apache.hadoop.fs.Path;
30  import org.apache.hadoop.hbase.Stoppable;
31  import org.apache.hadoop.hbase.TableName;
32  import org.apache.hadoop.hbase.replication.regionserver.MetricsSource;
33  import org.apache.hadoop.hbase.replication.regionserver.ReplicationSourceInterface;
34  import org.apache.hadoop.hbase.replication.regionserver.ReplicationSourceManager;
35  import org.apache.hadoop.hbase.replication.regionserver.ReplicationStatus;
36  import org.apache.hadoop.hbase.util.Pair;
37  
38  /**
39   * Source that does nothing at all, helpful to test ReplicationSourceManager
40   */
41  public class ReplicationSourceDummy implements ReplicationSourceInterface {
42  
43    ReplicationSourceManager manager;
44    String peerClusterId;
45    Path currentPath;
46    MetricsSource metrics;
47    public static final String fakeExceptionMessage = "Fake Exception";
48  
49    @Override
50    public void init(Configuration conf, FileSystem fs, ReplicationSourceManager manager,
51        ReplicationQueues rq, ReplicationPeers rp, Stoppable stopper, String peerClusterId,
52        UUID clusterId, ReplicationEndpoint replicationEndpoint, MetricsSource metrics)
53            throws IOException {
54  
55      this.manager = manager;
56      this.peerClusterId = peerClusterId;
57      this.metrics = metrics;
58    }
59  
60    @Override
61    public void enqueueLog(Path log) {
62      this.currentPath = log;
63      metrics.incrSizeOfLogQueue();
64    }
65  
66    @Override
67    public Path getCurrentPath() {
68      return this.currentPath;
69    }
70  
71    @Override
72    public void startup() {
73  
74    }
75  
76    @Override
77    public void terminate(String reason) {
78  
79    }
80  
81    @Override
82    public void terminate(String reason, Exception e) {
83  
84    }
85  
86    @Override
87    public String getPeerClusterZnode() {
88      return peerClusterId;
89    }
90  
91    @Override
92    public String getPeerClusterId() {
93      String[] parts = peerClusterId.split("-", 2);
94      return parts.length != 1 ?
95          parts[0] : peerClusterId;
96    }
97  
98    @Override
99    public String getStats() {
100     return "";
101   }
102 
103   @Override
104   public void addHFileRefs(TableName tableName, byte[] family, List<Pair<Path, Path>> files)
105       throws ReplicationException {
106     return;
107   }
108 
109   @Override
110   public MetricsSource getSourceMetrics() {
111     return metrics;
112   }
113 
114   @Override
115   public Map<String, ReplicationStatus> getWalGroupStatus() {
116     return new HashMap<>();
117   }
118 }