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