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