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