001/* 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019package org.apache.hadoop.hbase.replication; 020 021import java.io.IOException; 022import java.util.List; 023import java.util.UUID; 024import java.util.concurrent.atomic.AtomicBoolean; 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 @Override 050 public void init(Configuration conf, FileSystem fs, ReplicationSourceManager manager, 051 ReplicationQueues rq, ReplicationPeers rp, Server server, String peerClusterId, 052 UUID clusterId, ReplicationEndpoint replicationEndpoint, 053 WALFileLengthProvider walFileLengthProvider, MetricsSource metrics) 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 void startup() { 073 startup.set(true); 074 } 075 076 public boolean isStartup() { 077 return startup.get(); 078 } 079 080 @Override 081 public void terminate(String reason) { 082 083 } 084 085 @Override 086 public void terminate(String reason, Exception e) { 087 088 } 089 090 @Override 091 public String getPeerClusterZnode() { 092 return peerClusterId; 093 } 094 095 @Override 096 public String getPeerId() { 097 String[] parts = peerClusterId.split("-", 2); 098 return parts.length != 1 ? 099 parts[0] : peerClusterId; 100 } 101 102 @Override 103 public String getStats() { 104 return ""; 105 } 106 107 @Override 108 public void addHFileRefs(TableName tableName, byte[] family, List<Pair<Path, Path>> files) 109 throws ReplicationException { 110 return; 111 } 112 113 @Override 114 public boolean isPeerEnabled() { 115 return true; 116 } 117 118 @Override 119 public boolean isSourceActive() { 120 return true; 121 } 122 123 @Override 124 public MetricsSource getSourceMetrics() { 125 return metrics; 126 } 127 128 @Override 129 public ReplicationEndpoint getReplicationEndpoint() { 130 return null; 131 } 132 133 @Override 134 public ReplicationSourceManager getSourceManager() { 135 return manager; 136 } 137 138 @Override 139 public void tryThrottle(int batchSize) throws InterruptedException { 140 } 141 142 @Override 143 public void postShipEdits(List<Entry> entries, int batchSize) { 144 } 145 146 @Override 147 public WALFileLengthProvider getWALFileLengthProvider() { 148 return walFileLengthProvider; 149 } 150 151 @Override 152 public ServerName getServerWALsBelongTo() { 153 return null; 154 } 155}