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.List;
23  import java.util.UUID;
24  
25  import org.apache.hadoop.conf.Configuration;
26  import org.apache.hadoop.fs.FileSystem;
27  import org.apache.hadoop.fs.Path;
28  import org.apache.hadoop.hbase.Stoppable;
29  import org.apache.hadoop.hbase.TableName;
30  import org.apache.hadoop.hbase.replication.regionserver.MetricsSource;
31  import org.apache.hadoop.hbase.replication.regionserver.ReplicationSourceInterface;
32  import org.apache.hadoop.hbase.replication.regionserver.ReplicationSourceManager;
33  import org.apache.hadoop.hbase.util.Pair;
34  
35  /**
36   * Source that does nothing at all, helpful to test ReplicationSourceManager
37   */
38  public class ReplicationSourceDummy implements ReplicationSourceInterface {
39  
40    ReplicationSourceManager manager;
41    String peerClusterId;
42    Path currentPath;
43    MetricsSource metrics;
44  
45    @Override
46    public void init(Configuration conf, FileSystem fs, ReplicationSourceManager manager,
47        ReplicationQueues rq, ReplicationPeers rp, Stoppable stopper, String peerClusterId,
48        UUID clusterId, ReplicationEndpoint replicationEndpoint, MetricsSource metrics)
49            throws IOException {
50  
51      this.manager = manager;
52      this.peerClusterId = peerClusterId;
53      this.metrics = metrics;
54    }
55  
56    @Override
57    public void enqueueLog(Path log) {
58      this.currentPath = log;
59      metrics.incrSizeOfLogQueue();
60    }
61  
62    @Override
63    public Path getCurrentPath() {
64      return this.currentPath;
65    }
66  
67    @Override
68    public void startup() {
69  
70    }
71  
72    @Override
73    public void terminate(String reason) {
74  
75    }
76  
77    @Override
78    public void terminate(String reason, Exception e) {
79  
80    }
81  
82    @Override
83    public String getPeerClusterZnode() {
84      return peerClusterId;
85    }
86  
87    @Override
88    public String getPeerClusterId() {
89      String[] parts = peerClusterId.split("-", 2);
90      return parts.length != 1 ?
91          parts[0] : peerClusterId;
92    }
93  
94    @Override
95    public String getStats() {
96      return "";
97    }
98  
99    @Override
100   public void addHFileRefs(TableName tableName, byte[] family, List<Pair<Path, Path>> files)
101       throws ReplicationException {
102     return;
103   }
104 
105   @Override
106   public MetricsSource getSourceMetrics() {
107     return metrics;
108   }
109 }