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.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.janitor.CatalogJanitor; 043import org.apache.hadoop.hbase.master.locking.LockManager; 044import org.apache.hadoop.hbase.master.normalizer.RegionNormalizerManager; 045import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; 046import org.apache.hadoop.hbase.master.replication.ReplicationPeerManager; 047import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; 048import org.apache.hadoop.hbase.master.zksyncer.MetaLocationSyncer; 049import org.apache.hadoop.hbase.procedure.MasterProcedureManagerHost; 050import org.apache.hadoop.hbase.procedure2.LockedResource; 051import org.apache.hadoop.hbase.procedure2.Procedure; 052import org.apache.hadoop.hbase.procedure2.ProcedureEvent; 053import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; 054import org.apache.hadoop.hbase.quotas.MasterQuotaManager; 055import org.apache.hadoop.hbase.replication.ReplicationException; 056import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; 057import org.apache.hadoop.hbase.replication.ReplicationPeerDescription; 058import org.apache.hadoop.hbase.security.access.AccessChecker; 059import org.apache.hadoop.hbase.security.access.ZKPermissionWatcher; 060import org.apache.hadoop.hbase.zookeeper.ZKWatcher; 061 062public class MockNoopMasterServices implements MasterServices { 063 064 private final Configuration conf; 065 private final MetricsMaster metricsMaster; 066 067 public MockNoopMasterServices() { 068 this(null); 069 } 070 071 public MockNoopMasterServices(final Configuration conf) { 072 this.conf = conf; 073 this.metricsMaster = new MetricsMaster(new MetricsMasterWrapperImpl(null)); 074 } 075 076 @Override 077 public void checkTableModifiable(TableName tableName) throws IOException { 078 // no-op 079 } 080 081 @Override 082 public long createTable(final TableDescriptor desc, final byte[][] splitKeys, 083 final long nonceGroup, 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 CatalogJanitor getCatalogJanitor() { 110 return null; 111 } 112 113 @Override 114 public MasterFileSystem getMasterFileSystem() { 115 return null; 116 } 117 118 @Override 119 public MasterWalManager getMasterWalManager() { 120 return null; 121 } 122 123 @Override 124 public MasterCoprocessorHost getMasterCoprocessorHost() { 125 return null; 126 } 127 128 @Override 129 public MasterQuotaManager getMasterQuotaManager() { 130 return null; 131 } 132 133 @Override 134 public RegionNormalizerManager getRegionNormalizerManager() { 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(final TableName tableName, final long nonceGroup, final long nonce) 243 throws IOException { 244 return -1; 245 } 246 247 @Override 248 public long truncateTable(final TableName tableName, final boolean preserveSplits, 249 final long nonceGroup, final long nonce) throws IOException { 250 return -1; 251 } 252 253 @Override 254 public long modifyTable(final TableName tableName, final TableDescriptor descriptor, 255 final long nonceGroup, final long nonce) throws IOException { 256 return -1; 257 } 258 259 @Override 260 public long enableTable(final TableName tableName, final long nonceGroup, final long nonce) 261 throws IOException { 262 return -1; 263 } 264 265 @Override 266 public long disableTable(TableName tableName, final long nonceGroup, final long nonce) 267 throws IOException { 268 return -1; 269 } 270 271 @Override 272 public long addColumn(final TableName tableName, final ColumnFamilyDescriptor columnDescriptor, 273 final long nonceGroup, final long nonce) throws IOException { 274 return -1; 275 } 276 277 @Override 278 public long modifyColumn(final TableName tableName, final ColumnFamilyDescriptor descriptor, 279 final long nonceGroup, final long nonce) throws IOException { 280 return -1; 281 } 282 283 @Override 284 public long deleteColumn(final TableName tableName, final byte[] columnName, 285 final long nonceGroup, final long nonce) throws IOException { 286 return -1; 287 } 288 289 @Override 290 public long mergeRegions(final RegionInfo[] regionsToMerge, final boolean forcible, 291 final long nonceGroup, final long nonce) throws IOException { 292 return -1; 293 } 294 295 @Override 296 public long splitRegion(final RegionInfo regionInfo, final byte[] splitRow, final long nonceGroup, 297 final long nonce) throws IOException { 298 return -1; 299 } 300 301 @Override 302 public TableStateManager getTableStateManager() { 303 return mock(TableStateManager.class); 304 } 305 306 @Override 307 public boolean isActiveMaster() { 308 return true; 309 } 310 311 @Override 312 public boolean isInitialized() { 313 return false; 314 } 315 316 @Override 317 public boolean isInMaintenanceMode() { 318 return false; 319 } 320 321 @Override 322 public boolean skipRegionManagementAction(String action) { 323 return false; 324 } 325 326 @Override 327 public long getLastMajorCompactionTimestamp(TableName table) throws IOException { 328 return 0; 329 } 330 331 @Override 332 public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException { 333 return 0; 334 } 335 336 @Override 337 public ClusterSchema getClusterSchema() { 338 return null; 339 } 340 341 @Override 342 public ClusterConnection getClusterConnection() { 343 return null; 344 } 345 346 @Override 347 public LoadBalancer getLoadBalancer() { 348 return null; 349 } 350 351 @Override 352 public FavoredNodesManager getFavoredNodesManager() { 353 return null; 354 } 355 356 @Override 357 public SnapshotManager getSnapshotManager() { 358 return null; 359 } 360 361 @Override 362 public MasterProcedureManagerHost getMasterProcedureManagerHost() { 363 return null; 364 } 365 366 @Override 367 public boolean isSplitOrMergeEnabled(MasterSwitchType switchType) { 368 return false; 369 } 370 371 @Override 372 public long addReplicationPeer(String peerId, ReplicationPeerConfig peerConfig, boolean enabled) 373 throws ReplicationException { 374 return 0; 375 } 376 377 @Override 378 public long removeReplicationPeer(String peerId) throws ReplicationException { 379 return 0; 380 } 381 382 @Override 383 public long enableReplicationPeer(String peerId) throws ReplicationException, IOException { 384 return 0; 385 } 386 387 @Override 388 public long disableReplicationPeer(String peerId) throws ReplicationException, IOException { 389 return 0; 390 } 391 392 @Override 393 public ReplicationPeerConfig getReplicationPeerConfig(String peerId) 394 throws ReplicationException, IOException { 395 return null; 396 } 397 398 @Override 399 public long updateReplicationPeerConfig(String peerId, ReplicationPeerConfig peerConfig) 400 throws ReplicationException, IOException { 401 return 0; 402 } 403 404 @Override 405 public List<ReplicationPeerDescription> listReplicationPeers(String regex) 406 throws ReplicationException, IOException { 407 return null; 408 } 409 410 @Override 411 public LockManager getLockManager() { 412 return null; 413 } 414 415 @Override 416 public String getRegionServerVersion(ServerName sn) { 417 return "0.0.0"; 418 } 419 420 @Override 421 public void checkIfShouldMoveSystemRegionAsync() { 422 } 423 424 @Override 425 public String getClientIdAuditPrefix() { 426 return null; 427 } 428 429 @Override 430 public ProcedureEvent<?> getInitializedEvent() { 431 return null; 432 } 433 434 @Override 435 public FileSystem getFileSystem() { 436 return null; 437 } 438 439 @Override 440 public Connection createConnection(Configuration conf) throws IOException { 441 return null; 442 } 443 444 @Override 445 public ReplicationPeerManager getReplicationPeerManager() { 446 return null; 447 } 448 449 @Override 450 public boolean isClusterUp() { 451 return true; 452 } 453 454 @Override 455 public AccessChecker getAccessChecker() { 456 return null; 457 } 458 459 @Override 460 public ZKPermissionWatcher getZKPermissionWatcher() { 461 return null; 462 } 463 464 @Override 465 public List<RegionPlan> executeRegionPlansWithThrottling(List<RegionPlan> plans) { 466 return null; 467 } 468 469 @Override 470 public void runReplicationBarrierCleaner() { 471 } 472 473 @Override 474 public boolean normalizeRegions(NormalizeTableFilterParams ntfp, boolean isHighPriority) { 475 return false; 476 } 477 478 @Override 479 public MetaLocationSyncer getMetaLocationSyncer() { 480 return null; 481 } 482 483 @Override 484 public void flushMasterStore() throws IOException { 485 } 486 487 @Override 488 public long modifyTableStoreFileTracker(TableName tableName, String dstSFT, long nonceGroup, 489 long nonce) throws IOException { 490 return -1; 491 } 492 493 @Override 494 public long modifyColumnStoreFileTracker(TableName tableName, byte[] family, String dstSFT, 495 long nonceGroup, long nonce) throws IOException { 496 return -1; 497 } 498}