2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
;
20 import com
.google
.protobuf
.Service
;
21 import java
.io
.IOException
;
22 import java
.net
.InetSocketAddress
;
23 import java
.util
.Collection
;
24 import java
.util
.Collections
;
25 import java
.util
.HashMap
;
26 import java
.util
.List
;
28 import java
.util
.Map
.Entry
;
29 import java
.util
.Optional
;
30 import java
.util
.concurrent
.ConcurrentSkipListMap
;
31 import java
.util
.concurrent
.atomic
.AtomicBoolean
;
32 import org
.apache
.hadoop
.conf
.Configuration
;
33 import org
.apache
.hadoop
.fs
.FileSystem
;
34 import org
.apache
.hadoop
.hbase
.client
.AsyncClusterConnection
;
35 import org
.apache
.hadoop
.hbase
.client
.Connection
;
36 import org
.apache
.hadoop
.hbase
.client
.RegionInfo
;
37 import org
.apache
.hadoop
.hbase
.client
.locking
.EntityLock
;
38 import org
.apache
.hadoop
.hbase
.executor
.ExecutorService
;
39 import org
.apache
.hadoop
.hbase
.fs
.HFileSystem
;
40 import org
.apache
.hadoop
.hbase
.io
.hfile
.BlockCache
;
41 import org
.apache
.hadoop
.hbase
.ipc
.RpcServerInterface
;
42 import org
.apache
.hadoop
.hbase
.mob
.MobFileCache
;
43 import org
.apache
.hadoop
.hbase
.quotas
.RegionServerRpcQuotaManager
;
44 import org
.apache
.hadoop
.hbase
.quotas
.RegionServerSpaceQuotaManager
;
45 import org
.apache
.hadoop
.hbase
.quotas
.RegionSizeStore
;
46 import org
.apache
.hadoop
.hbase
.regionserver
.FlushRequester
;
47 import org
.apache
.hadoop
.hbase
.regionserver
.HRegion
;
48 import org
.apache
.hadoop
.hbase
.regionserver
.HeapMemoryManager
;
49 import org
.apache
.hadoop
.hbase
.regionserver
.LeaseManager
;
50 import org
.apache
.hadoop
.hbase
.regionserver
.MetricsRegionServer
;
51 import org
.apache
.hadoop
.hbase
.regionserver
.Region
;
52 import org
.apache
.hadoop
.hbase
.regionserver
.RegionServerAccounting
;
53 import org
.apache
.hadoop
.hbase
.regionserver
.RegionServerServices
;
54 import org
.apache
.hadoop
.hbase
.regionserver
.ReplicationSourceService
;
55 import org
.apache
.hadoop
.hbase
.regionserver
.SecureBulkLoadManager
;
56 import org
.apache
.hadoop
.hbase
.regionserver
.ServerNonceManager
;
57 import org
.apache
.hadoop
.hbase
.regionserver
.compactions
.CompactionRequester
;
58 import org
.apache
.hadoop
.hbase
.regionserver
.throttle
.ThroughputController
;
59 import org
.apache
.hadoop
.hbase
.security
.access
.AccessChecker
;
60 import org
.apache
.hadoop
.hbase
.security
.access
.ZKPermissionWatcher
;
61 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
62 import org
.apache
.hadoop
.hbase
.wal
.WAL
;
63 import org
.apache
.hadoop
.hbase
.zookeeper
.ZKWatcher
;
64 import org
.slf4j
.Logger
;
65 import org
.slf4j
.LoggerFactory
;
67 import org
.apache
.hadoop
.hbase
.shaded
.protobuf
.generated
.HBaseProtos
;
70 * Basic mock region server services. Should only be instantiated by HBaseTestingUtility.b
72 public class MockRegionServerServices
implements RegionServerServices
{
73 protected static final Logger LOG
= LoggerFactory
.getLogger(MockRegionServerServices
.class);
74 private final Map
<String
, Region
> regions
= new HashMap
<>();
75 private final ConcurrentSkipListMap
<byte[], Boolean
> rit
=
76 new ConcurrentSkipListMap
<>(Bytes
.BYTES_COMPARATOR
);
77 private HFileSystem hfs
= null;
78 private final Configuration conf
;
79 private ZKWatcher zkw
= null;
80 private ServerName serverName
= null;
81 private RpcServerInterface rpcServer
= null;
82 private volatile boolean abortRequested
;
83 private volatile boolean stopping
= false;
84 private final AtomicBoolean running
= new AtomicBoolean(true);
86 MockRegionServerServices(ZKWatcher zkw
) {
90 MockRegionServerServices(ZKWatcher zkw
, ServerName serverName
) {
92 this.serverName
= serverName
;
93 this.conf
= (zkw
== null ?
new Configuration() : zkw
.getConfiguration());
96 MockRegionServerServices(){
100 public MockRegionServerServices(Configuration conf
) {
105 public boolean removeRegion(HRegion r
, ServerName destination
) {
106 return this.regions
.remove(r
.getRegionInfo().getEncodedName()) != null;
110 public Region
getRegion(String encodedRegionName
) {
111 return this.regions
.get(encodedRegionName
);
115 public List
<Region
> getRegions(TableName tableName
) throws IOException
{
120 public List
<Region
> getRegions() {
125 public void addRegion(HRegion r
) {
126 this.regions
.put(r
.getRegionInfo().getEncodedName(), r
);
130 public void postOpenDeployTasks(PostOpenDeployContext context
) throws IOException
{
131 addRegion(context
.getRegion());
135 public boolean isStopping() {
136 return this.stopping
;
140 public RpcServerInterface
getRpcServer() {
144 public void setRpcServer(RpcServerInterface rpc
) {
145 this.rpcServer
= rpc
;
149 public ConcurrentSkipListMap
<byte[], Boolean
> getRegionsInTransitionInRS() {
154 public FlushRequester
getFlushRequester() {
159 public CompactionRequester
getCompactionRequestor() {
164 public Connection
getConnection() {
169 public ZKWatcher
getZooKeeper() {
174 public CoordinatedStateManager
getCoordinatedStateManager() {
179 public RegionServerAccounting
getRegionServerAccounting() {
184 public RegionServerRpcQuotaManager
getRegionServerRpcQuotaManager() {
189 public ServerName
getServerName() {
190 return this.serverName
;
194 public Configuration
getConfiguration() {
199 public void abort(String why
, Throwable e
) {
200 this.abortRequested
= true;
205 public void stop(String why
) {
206 this.stopping
= true;
207 if (running
.compareAndSet(true, false)) {
208 LOG
.info("Shutting down due to request '" + why
+ "'");
213 public boolean isStopped() {
214 return !(running
.get());
218 public boolean isAborted() {
219 return this.abortRequested
;
223 public HFileSystem
getFileSystem() {
227 public void setFileSystem(FileSystem hfs
) {
228 this.hfs
= (HFileSystem
)hfs
;
232 public LeaseManager
getLeaseManager() {
237 public List
<WAL
> getWALs() throws IOException
{
238 return Collections
.emptyList();
242 public WAL
getWAL(RegionInfo regionInfo
) throws IOException
{
247 public ExecutorService
getExecutorService() {
252 public ChoreService
getChoreService() {
257 public void updateRegionFavoredNodesMapping(String encodedRegionName
,
258 List
<HBaseProtos
.ServerName
> favoredNodes
) {
262 public InetSocketAddress
[] getFavoredNodesForRegion(String encodedRegionName
) {
267 public ServerNonceManager
getNonceManager() {
272 public boolean reportRegionStateTransition(RegionStateTransitionContext context
) {
277 public boolean registerService(Service service
) {
282 public HeapMemoryManager
getHeapMemoryManager() {
287 public double getCompactionPressure() {
292 public ThroughputController
getFlushThroughputController() {
297 public double getFlushPressure() {
302 public MetricsRegionServer
getMetrics() {
307 public EntityLock
regionLock(List
<RegionInfo
> regionInfos
, String description
, Abortable abort
)
313 public SecureBulkLoadManager
getSecureBulkLoadManager() {
318 public void unassign(byte[] regionName
) throws IOException
{
322 public RegionServerSpaceQuotaManager
getRegionServerSpaceQuotaManager() {
327 public Connection
createConnection(Configuration conf
) throws IOException
{
332 public boolean reportRegionSizesForQuotas(RegionSizeStore sizeStore
) {
337 public boolean reportFileArchivalForQuotas(
338 TableName tableName
, Collection
<Entry
<String
,Long
>> archivedFiles
) {
343 public boolean isClusterUp() {
348 public ReplicationSourceService
getReplicationSourceService() {
353 public TableDescriptors
getTableDescriptors() {
358 public Optional
<BlockCache
> getBlockCache() {
359 return Optional
.empty();
363 public Optional
<MobFileCache
> getMobFileCache() {
364 return Optional
.empty();
368 public AccessChecker
getAccessChecker() {
373 public ZKPermissionWatcher
getZKPermissionWatcher() {
378 public AsyncClusterConnection
getAsyncClusterConnection() {