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.master; 019 020import static org.mockito.Mockito.mock; 021 022import com.google.protobuf.Service; 023import java.io.IOException; 024import java.util.List; 025import org.apache.hadoop.conf.Configuration; 026import org.apache.hadoop.fs.FileSystem; 027import org.apache.hadoop.hbase.ChoreService; 028import org.apache.hadoop.hbase.CoordinatedStateManager; 029import org.apache.hadoop.hbase.ServerName; 030import org.apache.hadoop.hbase.TableDescriptors; 031import org.apache.hadoop.hbase.TableName; 032import org.apache.hadoop.hbase.client.ClusterConnection; 033import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; 034import org.apache.hadoop.hbase.client.Connection; 035import org.apache.hadoop.hbase.client.MasterSwitchType; 036import org.apache.hadoop.hbase.client.RegionInfo; 037import org.apache.hadoop.hbase.client.TableDescriptor; 038import org.apache.hadoop.hbase.executor.ExecutorService; 039import org.apache.hadoop.hbase.favored.FavoredNodesManager; 040import org.apache.hadoop.hbase.master.assignment.AssignmentManager; 041import org.apache.hadoop.hbase.master.locking.LockManager; 042import org.apache.hadoop.hbase.master.normalizer.RegionNormalizer; 043import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; 044import org.apache.hadoop.hbase.master.replication.ReplicationPeerManager; 045import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; 046import org.apache.hadoop.hbase.procedure.MasterProcedureManagerHost; 047import org.apache.hadoop.hbase.procedure2.LockedResource; 048import org.apache.hadoop.hbase.procedure2.Procedure; 049import org.apache.hadoop.hbase.procedure2.ProcedureEvent; 050import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; 051import org.apache.hadoop.hbase.quotas.MasterQuotaManager; 052import org.apache.hadoop.hbase.replication.ReplicationException; 053import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; 054import org.apache.hadoop.hbase.replication.ReplicationPeerDescription; 055import org.apache.hadoop.hbase.security.access.AccessChecker; 056import org.apache.hadoop.hbase.security.access.ZKPermissionWatcher; 057import org.apache.hadoop.hbase.zookeeper.ZKWatcher; 058 059public class MockNoopMasterServices implements MasterServices { 060 061 private final Configuration conf; 062 private final MetricsMaster metricsMaster; 063 064 public MockNoopMasterServices() { 065 this(null); 066 } 067 068 public MockNoopMasterServices(final Configuration conf) { 069 this.conf = conf; 070 this.metricsMaster = new MetricsMaster(new MetricsMasterWrapperImpl(null)); 071 } 072 073 @Override 074 public void checkTableModifiable(TableName tableName) throws IOException { 075 //no-op 076 } 077 078 @Override 079 public long createTable( 080 final TableDescriptor desc, 081 final byte[][] splitKeys, 082 final long nonceGroup, 083 final long nonce) throws IOException { 084 // no-op 085 return -1; 086 } 087 088 @Override 089 public long createSystemTable(final TableDescriptor tableDescriptor) throws IOException { 090 return -1; 091 } 092 093 @Override 094 public AssignmentManager getAssignmentManager() { 095 return null; 096 } 097 098 @Override 099 public ExecutorService getExecutorService() { 100 return null; 101 } 102 103 @Override 104 public ChoreService getChoreService() { 105 return null; 106 } 107 108 @Override 109 public RegionNormalizer getRegionNormalizer() { 110 return null; 111 } 112 113 @Override 114 public CatalogJanitor getCatalogJanitor() { 115 return null; 116 } 117 118 @Override 119 public MasterFileSystem getMasterFileSystem() { 120 return null; 121 } 122 123 @Override 124 public MasterWalManager getMasterWalManager() { 125 return null; 126 } 127 128 @Override 129 public MasterCoprocessorHost getMasterCoprocessorHost() { 130 return null; 131 } 132 133 @Override 134 public MasterQuotaManager getMasterQuotaManager() { 135 return null; 136 } 137 138 @Override 139 public ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() { 140 return null; 141 } 142 143 @Override 144 public MetricsMaster getMasterMetrics() { 145 return metricsMaster; 146 } 147 148 @Override 149 public ServerManager getServerManager() { 150 return null; 151 } 152 153 @Override 154 public ZKWatcher getZooKeeper() { 155 return null; 156 } 157 158 @Override 159 public CoordinatedStateManager getCoordinatedStateManager() { 160 return null; 161 } 162 163 @Override 164 public ClusterConnection getConnection() { 165 return null; 166 } 167 168 @Override 169 public Configuration getConfiguration() { 170 return conf; 171 } 172 173 @Override 174 public ServerName getServerName() { 175 return ServerName.valueOf("mock.master", 12345, 1); 176 } 177 178 @Override 179 public void abort(String why, Throwable e) { 180 //no-op 181 } 182 183 @Override 184 public boolean isAborted() { 185 return false; 186 } 187 188 private boolean stopped = false; 189 190 @Override 191 public void stop(String why) { 192 stopped = true; 193 } 194 195 @Override 196 public boolean isStopping() { 197 return stopped; 198 } 199 200 @Override 201 public boolean isStopped() { 202 return stopped; 203 } 204 205 @Override 206 public TableDescriptors getTableDescriptors() { 207 return null; 208 } 209 210 @Override 211 public boolean registerService(Service instance) { 212 return false; 213 } 214 215 @Override 216 public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning) 217 throws IOException { 218 return false; //To change body of implemented methods use File | Settings | File Templates. 219 } 220 221 @Override 222 public List<Procedure<?>> getProcedures() throws IOException { 223 return null; //To change body of implemented methods use File | Settings | File Templates. 224 } 225 226 @Override 227 public List<LockedResource> getLocks() throws IOException { 228 return null; 229 } 230 231 @Override 232 public List<TableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException { 233 return null; //To change body of implemented methods use File | Settings | File Templates. 234 } 235 236 @Override 237 public List<TableName> listTableNamesByNamespace(String name) throws IOException { 238 return null; 239 } 240 241 @Override 242 public long deleteTable( 243 final TableName tableName, 244 final long nonceGroup, 245 final long nonce) throws IOException { 246 return -1; 247 } 248 249 @Override 250 public long truncateTable( 251 final TableName tableName, 252 final boolean preserveSplits, 253 final long nonceGroup, 254 final long nonce) throws IOException { 255 return -1; 256 } 257 258 259 @Override 260 public long modifyTable( 261 final TableName tableName, 262 final TableDescriptor descriptor, 263 final long nonceGroup, 264 final long nonce) throws IOException { 265 return -1; 266 } 267 268 @Override 269 public long enableTable( 270 final TableName tableName, 271 final long nonceGroup, 272 final long nonce) throws IOException { 273 return -1; 274 } 275 276 @Override 277 public long disableTable( 278 TableName tableName, 279 final long nonceGroup, 280 final long nonce) throws IOException { 281 return -1; 282 } 283 284 @Override 285 public long addColumn(final TableName tableName, final ColumnFamilyDescriptor columnDescriptor, 286 final long nonceGroup, final long nonce) throws IOException { 287 return -1; 288 } 289 290 @Override 291 public long modifyColumn(final TableName tableName, final ColumnFamilyDescriptor descriptor, 292 final long nonceGroup, final long nonce) throws IOException { 293 return -1; 294 } 295 296 @Override 297 public long deleteColumn(final TableName tableName, final byte[] columnName, 298 final long nonceGroup, final long nonce) throws IOException { 299 return -1; 300 } 301 302 @Override 303 public long mergeRegions( 304 final RegionInfo[] regionsToMerge, 305 final boolean forcible, 306 final long nonceGroup, 307 final long nonce) throws IOException { 308 return -1; 309 } 310 311 @Override 312 public long splitRegion( 313 final RegionInfo regionInfo, 314 final byte[] splitRow, 315 final long nonceGroup, 316 final long nonce) throws IOException { 317 return -1; 318 } 319 320 @Override 321 public TableStateManager getTableStateManager() { 322 return mock(TableStateManager.class); 323 } 324 325 @Override 326 public boolean isActiveMaster() { 327 return true; 328 } 329 330 @Override 331 public boolean isInitialized() { 332 return false; 333 } 334 335 @Override 336 public boolean isInMaintenanceMode() { 337 return false; 338 } 339 340 @Override 341 public long getLastMajorCompactionTimestamp(TableName table) throws IOException { 342 return 0; 343 } 344 345 @Override 346 public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException { 347 return 0; 348 } 349 350 @Override 351 public ClusterSchema getClusterSchema() { 352 return null; 353 } 354 355 @Override 356 public ClusterConnection getClusterConnection() { 357 return null; 358 } 359 360 @Override 361 public LoadBalancer getLoadBalancer() { 362 return null; 363 } 364 365 @Override 366 public FavoredNodesManager getFavoredNodesManager() { 367 return null; 368 } 369 370 @Override 371 public SnapshotManager getSnapshotManager() { 372 return null; 373 } 374 375 @Override 376 public MasterProcedureManagerHost getMasterProcedureManagerHost() { 377 return null; 378 } 379 380 @Override 381 public boolean isSplitOrMergeEnabled(MasterSwitchType switchType) { 382 return false; 383 } 384 385 @Override 386 public long addReplicationPeer(String peerId, ReplicationPeerConfig peerConfig, boolean enabled) 387 throws ReplicationException { 388 return 0; 389 } 390 391 @Override 392 public long removeReplicationPeer(String peerId) throws ReplicationException { 393 return 0; 394 } 395 396 @Override 397 public long enableReplicationPeer(String peerId) throws ReplicationException, IOException { 398 return 0; 399 } 400 401 @Override 402 public long disableReplicationPeer(String peerId) throws ReplicationException, IOException { 403 return 0; 404 } 405 406 @Override 407 public ReplicationPeerConfig getReplicationPeerConfig(String peerId) throws ReplicationException, 408 IOException { 409 return null; 410 } 411 412 @Override 413 public long updateReplicationPeerConfig(String peerId, ReplicationPeerConfig peerConfig) 414 throws ReplicationException, IOException { 415 return 0; 416 } 417 418 @Override 419 public List<ReplicationPeerDescription> listReplicationPeers(String regex) 420 throws ReplicationException, IOException { 421 return null; 422 } 423 424 @Override 425 public LockManager getLockManager() { 426 return null; 427 } 428 429 @Override 430 public String getRegionServerVersion(ServerName sn) { 431 return "0.0.0"; 432 } 433 434 @Override 435 public void checkIfShouldMoveSystemRegionAsync() { 436 } 437 438 @Override 439 public String getClientIdAuditPrefix() { 440 return null; 441 } 442 443 @Override 444 public ProcedureEvent<?> getInitializedEvent() { 445 return null; 446 } 447 448 @Override 449 public FileSystem getFileSystem() { 450 return null; 451 } 452 453 @Override 454 public Connection createConnection(Configuration conf) throws IOException { 455 return null; 456 } 457 458 @Override 459 public ReplicationPeerManager getReplicationPeerManager() { 460 return null; 461 } 462 463 @Override 464 public boolean isClusterUp() { 465 return true; 466 } 467 468 @Override 469 public AccessChecker getAccessChecker() { 470 return null; 471 } 472 473 @Override 474 public ZKPermissionWatcher getZKPermissionWatcher() { 475 return null; 476 } 477 478 @Override 479 public List<RegionPlan> executeRegionPlansWithThrottling(List<RegionPlan> plans) { 480 return null; 481 } 482 483 @Override 484 public void runReplicationBarrierCleaner() {} 485}