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 ReplicationSourceInterface startup() {
074    startup.set(true);
075    return this;
076  }
077
078  public boolean isStartup() {
079    return startup.get();
080  }
081
082  @Override
083  public void terminate(String reason) {
084    terminate(reason, null);
085  }
086
087  @Override
088  public void terminate(String reason, Exception e) {
089    terminate(reason, e, true);
090  }
091
092  @Override
093  public void terminate(String reason, Exception e, boolean clearMetrics) {
094    if (clearMetrics) {
095      this.metrics.clear();
096    }
097  }
098
099  @Override
100  public String getQueueId() {
101    return peerClusterId;
102  }
103
104  @Override
105  public String getPeerId() {
106    String[] parts = peerClusterId.split("-", 2);
107    return parts.length != 1 ?
108        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, int 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}