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 */
018package org.apache.hadoop.hbase.replication;
019
020import java.io.IOException;
021import java.util.List;
022import java.util.UUID;
023import java.util.concurrent.atomic.AtomicBoolean;
024
025import org.apache.hadoop.conf.Configuration;
026import org.apache.hadoop.fs.FileSystem;
027import org.apache.hadoop.fs.Path;
028import org.apache.hadoop.hbase.Server;
029import org.apache.hadoop.hbase.ServerName;
030import org.apache.hadoop.hbase.TableName;
031import org.apache.hadoop.hbase.replication.regionserver.MetricsSource;
032import org.apache.hadoop.hbase.replication.regionserver.ReplicationSourceInterface;
033import org.apache.hadoop.hbase.replication.regionserver.ReplicationSourceManager;
034import org.apache.hadoop.hbase.replication.regionserver.WALFileLengthProvider;
035import org.apache.hadoop.hbase.util.Pair;
036import org.apache.hadoop.hbase.wal.WAL.Entry;
037
038/**
039 * Source that does nothing at all, helpful to test ReplicationSourceManager
040 */
041public class ReplicationSourceDummy implements ReplicationSourceInterface {
042
043  ReplicationSourceManager manager;
044  String peerClusterId;
045  Path currentPath;
046  MetricsSource metrics;
047  WALFileLengthProvider walFileLengthProvider;
048  AtomicBoolean startup = new AtomicBoolean(false);
049
050  @Override
051  public void init(Configuration conf, FileSystem fs, ReplicationSourceManager manager,
052      ReplicationQueueStorage rq, ReplicationPeer rp, Server server, String peerClusterId,
053      UUID clusterId, WALFileLengthProvider walFileLengthProvider, MetricsSource metrics)
054      throws IOException {
055    this.manager = manager;
056    this.peerClusterId = peerClusterId;
057    this.metrics = metrics;
058    this.walFileLengthProvider = walFileLengthProvider;
059  }
060
061  @Override
062  public void enqueueLog(Path log) {
063    this.currentPath = log;
064    metrics.incrSizeOfLogQueue();
065  }
066
067  @Override
068  public Path getCurrentPath() {
069    return this.currentPath;
070  }
071
072  @Override
073  public void startup() {
074    startup.set(true);
075  }
076
077  public boolean isStartup() {
078    return startup.get();
079  }
080
081  @Override
082  public void terminate(String reason) {
083    terminate(reason, null);
084  }
085
086  @Override
087  public void terminate(String reason, Exception e) {
088    this.metrics.clear();
089  }
090
091  @Override
092  public String getQueueId() {
093    return peerClusterId;
094  }
095
096  @Override
097  public String getPeerId() {
098    String[] parts = peerClusterId.split("-", 2);
099    return parts.length != 1 ?
100        parts[0] : peerClusterId;
101  }
102
103  @Override
104  public String getStats() {
105    return "";
106  }
107
108  @Override
109  public void addHFileRefs(TableName tableName, byte[] family, List<Pair<Path, Path>> files)
110      throws ReplicationException {
111    return;
112  }
113
114  @Override
115  public boolean isPeerEnabled() {
116    return true;
117  }
118
119  @Override
120  public boolean isSourceActive() {
121    return true;
122  }
123
124  @Override
125  public MetricsSource getSourceMetrics() {
126    return metrics;
127  }
128
129  @Override
130  public ReplicationEndpoint getReplicationEndpoint() {
131    return null;
132  }
133
134  @Override
135  public ReplicationSourceManager getSourceManager() {
136    return manager;
137  }
138
139  @Override
140  public void tryThrottle(int batchSize) throws InterruptedException {
141  }
142
143  @Override
144  public void postShipEdits(List<Entry> entries, int batchSize) {
145  }
146
147  @Override
148  public WALFileLengthProvider getWALFileLengthProvider() {
149    return walFileLengthProvider;
150  }
151
152  @Override
153  public ServerName getServerWALsBelongTo() {
154    return null;
155  }
156}