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.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.snapshot.SnapshotManager;
049import org.apache.hadoop.hbase.master.zksyncer.MetaLocationSyncer;
050import org.apache.hadoop.hbase.procedure.MasterProcedureManagerHost;
051import org.apache.hadoop.hbase.procedure2.LockedResource;
052import org.apache.hadoop.hbase.procedure2.Procedure;
053import org.apache.hadoop.hbase.procedure2.ProcedureEvent;
054import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
055import org.apache.hadoop.hbase.quotas.MasterQuotaManager;
056import org.apache.hadoop.hbase.replication.ReplicationException;
057import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
058import org.apache.hadoop.hbase.replication.ReplicationPeerDescription;
059import org.apache.hadoop.hbase.security.access.AccessChecker;
060import org.apache.hadoop.hbase.security.access.ZKPermissionWatcher;
061import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
062
063public class MockNoopMasterServices implements MasterServices {
064
065  private final Configuration conf;
066  private final MetricsMaster metricsMaster;
067
068  public MockNoopMasterServices(final Configuration conf) {
069    this.conf = conf;
070    this.metricsMaster = new MetricsMaster(new MetricsMasterWrapperImpl(mock(HMaster.class)));
071  }
072
073  @Override
074  public void checkTableModifiable(TableName tableName) throws IOException {
075    // no-op
076  }
077
078  @Override
079  public long truncateRegion(RegionInfo regionInfo, long nonceGroup, long nonce)
080    throws IOException {
081    return 0;
082  }
083
084  @Override
085  public long createTable(final TableDescriptor desc, final byte[][] splitKeys,
086    final long nonceGroup, final long nonce) throws IOException {
087    // no-op
088    return -1;
089  }
090
091  @Override
092  public long createSystemTable(final TableDescriptor tableDescriptor) throws IOException {
093    return -1;
094  }
095
096  @Override
097  public AssignmentManager getAssignmentManager() {
098    return null;
099  }
100
101  @Override
102  public ExecutorService getExecutorService() {
103    return null;
104  }
105
106  @Override
107  public ChoreService getChoreService() {
108    return null;
109  }
110
111  @Override
112  public CatalogJanitor getCatalogJanitor() {
113    return null;
114  }
115
116  @Override
117  public HbckChore getHbckChore() {
118    return null;
119  }
120
121  @Override
122  public MasterFileSystem getMasterFileSystem() {
123    return null;
124  }
125
126  @Override
127  public MasterWalManager getMasterWalManager() {
128    return null;
129  }
130
131  @Override
132  public MasterCoprocessorHost getMasterCoprocessorHost() {
133    return null;
134  }
135
136  @Override
137  public MasterQuotaManager getMasterQuotaManager() {
138    return null;
139  }
140
141  @Override
142  public RegionNormalizerManager getRegionNormalizerManager() {
143    return null;
144  }
145
146  @Override
147  public ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() {
148    return null;
149  }
150
151  @Override
152  public MetricsMaster getMasterMetrics() {
153    return metricsMaster;
154  }
155
156  @Override
157  public ServerManager getServerManager() {
158    return null;
159  }
160
161  @Override
162  public ZKWatcher getZooKeeper() {
163    return null;
164  }
165
166  @Override
167  public CoordinatedStateManager getCoordinatedStateManager() {
168    return null;
169  }
170
171  @Override
172  public ClusterConnection getConnection() {
173    return null;
174  }
175
176  @Override
177  public Configuration getConfiguration() {
178    return conf;
179  }
180
181  @Override
182  public ServerName getServerName() {
183    return ServerName.valueOf("mock.master", 12345, 1);
184  }
185
186  @Override
187  public void abort(String why, Throwable e) {
188    // no-op
189  }
190
191  @Override
192  public boolean isAborted() {
193    return false;
194  }
195
196  private boolean stopped = false;
197
198  @Override
199  public void stop(String why) {
200    stopped = true;
201  }
202
203  @Override
204  public boolean isStopping() {
205    return stopped;
206  }
207
208  @Override
209  public boolean isStopped() {
210    return stopped;
211  }
212
213  @Override
214  public TableDescriptors getTableDescriptors() {
215    return null;
216  }
217
218  @Override
219  public boolean registerService(Service instance) {
220    return false;
221  }
222
223  @Override
224  public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning)
225    throws IOException {
226    return false; // To change body of implemented methods use File | Settings | File Templates.
227  }
228
229  @Override
230  public List<Procedure<?>> getProcedures() throws IOException {
231    return null; // To change body of implemented methods use File | Settings | File Templates.
232  }
233
234  @Override
235  public List<LockedResource> getLocks() throws IOException {
236    return null;
237  }
238
239  @Override
240  public List<TableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException {
241    return null; // To change body of implemented methods use File | Settings | File Templates.
242  }
243
244  @Override
245  public List<TableName> listTableNamesByNamespace(String name) throws IOException {
246    return null;
247  }
248
249  @Override
250  public long deleteTable(final TableName tableName, final long nonceGroup, final long nonce)
251    throws IOException {
252    return -1;
253  }
254
255  @Override
256  public long truncateTable(final TableName tableName, final boolean preserveSplits,
257    final long nonceGroup, final long nonce) throws IOException {
258    return -1;
259  }
260
261  @Override
262  public long modifyTable(final TableName tableName, final TableDescriptor descriptor,
263    final long nonceGroup, final long nonce) throws IOException {
264    return -1;
265  }
266
267  @Override
268  public long modifyTable(TableName tableName, TableDescriptor descriptor, long nonceGroup,
269    long nonce, boolean reopenRegions) throws IOException {
270    return -1;
271  }
272
273  @Override
274  public long enableTable(final TableName tableName, final long nonceGroup, final long nonce)
275    throws IOException {
276    return -1;
277  }
278
279  @Override
280  public long disableTable(TableName tableName, final long nonceGroup, final long nonce)
281    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(final RegionInfo[] regionsToMerge, final boolean forcible,
305    final long nonceGroup, final long nonce) throws IOException {
306    return -1;
307  }
308
309  @Override
310  public long splitRegion(final RegionInfo regionInfo, final byte[] splitRow, final long nonceGroup,
311    final long nonce) throws IOException {
312    return -1;
313  }
314
315  @Override
316  public TableStateManager getTableStateManager() {
317    return mock(TableStateManager.class);
318  }
319
320  @Override
321  public boolean isActiveMaster() {
322    return true;
323  }
324
325  @Override
326  public boolean isInitialized() {
327    return false;
328  }
329
330  @Override
331  public boolean isInMaintenanceMode() {
332    return false;
333  }
334
335  @Override
336  public boolean skipRegionManagementAction(String action) {
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)
408    throws ReplicationException, 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  }
486
487  @Override
488  public boolean normalizeRegions(NormalizeTableFilterParams ntfp, boolean isHighPriority) {
489    return false;
490  }
491
492  @Override
493  public MetaLocationSyncer getMetaLocationSyncer() {
494    return null;
495  }
496
497  @Override
498  public void flushMasterStore() throws IOException {
499  }
500
501  @Override
502  public long modifyTableStoreFileTracker(TableName tableName, String dstSFT, long nonceGroup,
503    long nonce) throws IOException {
504    return -1;
505  }
506
507  @Override
508  public long modifyColumnStoreFileTracker(TableName tableName, byte[] family, String dstSFT,
509    long nonceGroup, long nonce) throws IOException {
510    return -1;
511  }
512
513  @Override
514  public boolean replicationPeerModificationSwitch(boolean on) throws IOException {
515    return false;
516  }
517
518  @Override
519  public boolean isReplicationPeerModificationEnabled() {
520    return false;
521  }
522
523  @Override
524  public long flushTable(TableName tableName, List<byte[]> columnFamilies, long nonceGroup,
525    long nonce) throws IOException {
526    return 0;
527  }
528}