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