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    } else {
096      this.metrics.terminate();
097    }
098  }
099
100  @Override
101  public String getQueueId() {
102    return peerClusterId;
103  }
104
105  @Override
106  public String getPeerId() {
107    String[] parts = peerClusterId.split("-", 2);
108    return parts.length != 1 ? parts[0] : peerClusterId;
109  }
110
111  @Override
112  public String getStats() {
113    return "";
114  }
115
116  @Override
117  public void addHFileRefs(TableName tableName, byte[] family, List<Pair<Path, Path>> files)
118    throws ReplicationException {
119    return;
120  }
121
122  @Override
123  public boolean isPeerEnabled() {
124    return true;
125  }
126
127  @Override
128  public boolean isSourceActive() {
129    return true;
130  }
131
132  @Override
133  public MetricsSource getSourceMetrics() {
134    return metrics;
135  }
136
137  @Override
138  public ReplicationEndpoint getReplicationEndpoint() {
139    return null;
140  }
141
142  @Override
143  public ReplicationSourceManager getSourceManager() {
144    return manager;
145  }
146
147  @Override
148  public void tryThrottle(int batchSize) throws InterruptedException {
149  }
150
151  @Override
152  public void postShipEdits(List<Entry> entries, long batchSize) {
153  }
154
155  @Override
156  public WALFileLengthProvider getWALFileLengthProvider() {
157    return walFileLengthProvider;
158  }
159
160  @Override
161  public ServerName getServerWALsBelongTo() {
162    return null;
163  }
164
165  @Override
166  public ReplicationQueueStorage getReplicationQueueStorage() {
167    return null;
168  }
169}