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  private ReplicationSourceManager manager;
043  private ReplicationPeer replicationPeer;
044  private ReplicationQueueId queueId;
045  private Path currentPath;
046  private MetricsSource metrics;
047  private WALFileLengthProvider walFileLengthProvider;
048  private 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, ReplicationQueueData queueData,
053    UUID clusterId, WALFileLengthProvider walFileLengthProvider, MetricsSource metrics)
054    throws IOException {
055    this.manager = manager;
056    this.queueId = queueData.getId();
057    this.metrics = metrics;
058    this.walFileLengthProvider = walFileLengthProvider;
059    this.replicationPeer = rp;
060  }
061
062  @Override
063  public void enqueueLog(Path log) {
064    this.currentPath = log;
065    metrics.incrSizeOfLogQueue();
066  }
067
068  @Override
069  public Path getCurrentPath() {
070    return this.currentPath;
071  }
072
073  @Override
074  public ReplicationSourceInterface startup() {
075    startup.set(true);
076    return this;
077  }
078
079  public boolean isStartup() {
080    return startup.get();
081  }
082
083  @Override
084  public void terminate(String reason) {
085    terminate(reason, null);
086  }
087
088  @Override
089  public void terminate(String reason, Exception e) {
090    terminate(reason, e, true);
091  }
092
093  @Override
094  public void terminate(String reason, Exception e, boolean clearMetrics) {
095    if (clearMetrics) {
096      this.metrics.clear();
097    } else {
098      this.metrics.terminate();
099    }
100  }
101
102  @Override
103  public ReplicationQueueId getQueueId() {
104    return queueId;
105  }
106
107  @Override
108  public String getPeerId() {
109    return queueId.getPeerId();
110  }
111
112  @Override
113  public String getStats() {
114    return "";
115  }
116
117  @Override
118  public void addHFileRefs(TableName tableName, byte[] family, List<Pair<Path, Path>> files)
119    throws ReplicationException {
120    return;
121  }
122
123  @Override
124  public boolean isPeerEnabled() {
125    return true;
126  }
127
128  @Override
129  public boolean isSourceActive() {
130    return true;
131  }
132
133  @Override
134  public MetricsSource getSourceMetrics() {
135    return metrics;
136  }
137
138  @Override
139  public ReplicationEndpoint getReplicationEndpoint() {
140    return null;
141  }
142
143  @Override
144  public ReplicationSourceManager getSourceManager() {
145    return manager;
146  }
147
148  @Override
149  public void tryThrottle(int batchSize) throws InterruptedException {
150  }
151
152  @Override
153  public void postShipEdits(List<Entry> entries, long batchSize) {
154  }
155
156  @Override
157  public WALFileLengthProvider getWALFileLengthProvider() {
158    return walFileLengthProvider;
159  }
160
161  @Override
162  public ServerName getServerWALsBelongTo() {
163    return null;
164  }
165
166  @Override
167  public ReplicationQueueStorage getReplicationQueueStorage() {
168    return null;
169  }
170
171  @Override
172  public ReplicationPeer getPeer() {
173    return replicationPeer;
174  }
175}