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 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 ? 107 parts[0] : peerClusterId; 108 } 109 110 @Override 111 public String getStats() { 112 return ""; 113 } 114 115 @Override 116 public void addHFileRefs(TableName tableName, byte[] family, List<Pair<Path, Path>> files) 117 throws ReplicationException { 118 return; 119 } 120 121 @Override 122 public boolean isPeerEnabled() { 123 return true; 124 } 125 126 @Override 127 public boolean isSourceActive() { 128 return true; 129 } 130 131 @Override 132 public MetricsSource getSourceMetrics() { 133 return metrics; 134 } 135 136 @Override 137 public ReplicationEndpoint getReplicationEndpoint() { 138 return null; 139 } 140 141 @Override 142 public ReplicationSourceManager getSourceManager() { 143 return manager; 144 } 145 146 @Override 147 public void tryThrottle(int batchSize) throws InterruptedException { 148 } 149 150 @Override 151 public void postShipEdits(List<Entry> entries, int batchSize) { 152 } 153 154 @Override 155 public WALFileLengthProvider getWALFileLengthProvider() { 156 return walFileLengthProvider; 157 } 158 159 @Override 160 public ServerName getServerWALsBelongTo() { 161 return null; 162 } 163}