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 */
018
019package org.apache.hadoop.hbase.coprocessor;
020
021import java.io.IOException;
022import java.util.List;
023import java.util.Set;
024import org.apache.hadoop.hbase.ClusterMetrics;
025import org.apache.hadoop.hbase.HBaseInterfaceAudience;
026import org.apache.hadoop.hbase.MetaMutationAnnotation;
027import org.apache.hadoop.hbase.NamespaceDescriptor;
028import org.apache.hadoop.hbase.ServerName;
029import org.apache.hadoop.hbase.TableName;
030import org.apache.hadoop.hbase.client.MasterSwitchType;
031import org.apache.hadoop.hbase.client.Mutation;
032import org.apache.hadoop.hbase.client.RegionInfo;
033import org.apache.hadoop.hbase.client.SnapshotDescription;
034import org.apache.hadoop.hbase.client.TableDescriptor;
035import org.apache.hadoop.hbase.master.RegionPlan;
036import org.apache.hadoop.hbase.net.Address;
037import org.apache.hadoop.hbase.quotas.GlobalQuotaSettings;
038import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
039import org.apache.hadoop.hbase.security.access.Permission;
040import org.apache.hadoop.hbase.security.access.UserPermission;
041import org.apache.yetus.audience.InterfaceAudience;
042import org.apache.yetus.audience.InterfaceStability;
043
044
045/**
046 * Defines coprocessor hooks for interacting with operations on the
047 * {@link org.apache.hadoop.hbase.master.HMaster} process.
048 * <br><br>
049 *
050 * Since most implementations will be interested in only a subset of hooks, this class uses
051 * 'default' functions to avoid having to add unnecessary overrides. When the functions are
052 * non-empty, it's simply to satisfy the compiler by returning value of expected (non-void) type.
053 * It is done in a way that these default definitions act as no-op. So our suggestion to
054 * implementation would be to not call these 'default' methods from overrides.
055 * <br><br>
056 *
057 * <h3>Exception Handling</h3>
058 * For all functions, exception handling is done as follows:
059 * <ul>
060 *   <li>Exceptions of type {@link IOException} are reported back to client.</li>
061 *   <li>For any other kind of exception:
062 *     <ul>
063 *       <li>If the configuration {@link CoprocessorHost#ABORT_ON_ERROR_KEY} is set to true, then
064 *         the server aborts.</li>
065 *       <li>Otherwise, coprocessor is removed from the server and
066 *         {@link org.apache.hadoop.hbase.DoNotRetryIOException} is returned to the client.</li>
067 *     </ul>
068 *   </li>
069 * </ul>
070 */
071@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
072@InterfaceStability.Evolving
073public interface MasterObserver {
074
075  /**
076   * Called before we create the region infos for this table. Called as part of create table RPC
077   * call.
078   * @param ctx the environment to interact with the framework and master
079   * @param desc the TableDescriptor for the table
080   * @return the TableDescriptor used to create the table. Default is the one passed in. Return
081   *         {@code null} means cancel the creation.
082   */
083  default TableDescriptor preCreateTableRegionsInfos(
084      final ObserverContext<MasterCoprocessorEnvironment> ctx, TableDescriptor desc)
085      throws IOException {
086    return desc;
087  }
088
089  /**
090   * Called before a new table is created by
091   * {@link org.apache.hadoop.hbase.master.HMaster}.  Called as part of create
092   * table RPC call.
093   * @param ctx the environment to interact with the framework and master
094   * @param desc the TableDescriptor for the table
095   * @param regions the initial regions created for the table
096   */
097  default void preCreateTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
098      TableDescriptor desc, RegionInfo[] regions) throws IOException {}
099
100  /**
101   * Called after the createTable operation has been requested.  Called as part
102   * of create table RPC call.
103   * @param ctx the environment to interact with the framework and master
104   * @param desc the TableDescriptor for the table
105   * @param regions the initial regions created for the table
106   */
107  default void postCreateTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
108      TableDescriptor desc, RegionInfo[] regions) throws IOException {}
109
110  /**
111   * Called before a new table is created by
112   * {@link org.apache.hadoop.hbase.master.HMaster}.  Called as part of create
113   * table procedure and it is async to the create RPC call.
114   *
115   * @param ctx the environment to interact with the framework and master
116   * @param desc the TableDescriptor for the table
117   * @param regions the initial regions created for the table
118   */
119  default void preCreateTableAction(
120      final ObserverContext<MasterCoprocessorEnvironment> ctx,
121      final TableDescriptor desc,
122      final RegionInfo[] regions) throws IOException {}
123
124  /**
125   * Called after the createTable operation has been requested.  Called as part
126   * of create table RPC call.  Called as part of create table procedure and
127   * it is async to the create RPC call.
128   *
129   * @param ctx the environment to interact with the framework and master
130   * @param desc the TableDescriptor for the table
131   * @param regions the initial regions created for the table
132   */
133  default void postCompletedCreateTableAction(
134      final ObserverContext<MasterCoprocessorEnvironment> ctx,
135      final TableDescriptor desc,
136      final RegionInfo[] regions) throws IOException {}
137
138  /**
139   * Called before {@link org.apache.hadoop.hbase.master.HMaster} deletes a
140   * table.  Called as part of delete table RPC call.
141   * @param ctx the environment to interact with the framework and master
142   * @param tableName the name of the table
143   */
144  default void preDeleteTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
145      TableName tableName) throws IOException {}
146
147  /**
148   * Called after the deleteTable operation has been requested.  Called as part
149   * of delete table RPC call.
150   * @param ctx the environment to interact with the framework and master
151   * @param tableName the name of the table
152   */
153  default void postDeleteTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
154      TableName tableName) throws IOException {}
155
156  /**
157   * Called before {@link org.apache.hadoop.hbase.master.HMaster} deletes a
158   * table.  Called as part of delete table procedure and
159   * it is async to the delete RPC call.
160   *
161   * @param ctx the environment to interact with the framework and master
162   * @param tableName the name of the table
163   */
164  default void preDeleteTableAction(
165      final ObserverContext<MasterCoprocessorEnvironment> ctx, final TableName tableName)
166      throws IOException {}
167
168  /**
169   * Called after {@link org.apache.hadoop.hbase.master.HMaster} deletes a
170   * table.  Called as part of delete table procedure and it is async to the
171   * delete RPC call.
172   *
173   * @param ctx the environment to interact with the framework and master
174   * @param tableName the name of the table
175   */
176  default void postCompletedDeleteTableAction(
177      final ObserverContext<MasterCoprocessorEnvironment> ctx, final TableName tableName)
178      throws IOException {}
179
180  /**
181   * Called before {@link org.apache.hadoop.hbase.master.HMaster} truncates a
182   * table.  Called as part of truncate table RPC call.
183   * @param ctx the environment to interact with the framework and master
184   * @param tableName the name of the table
185   */
186  default void preTruncateTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
187      TableName tableName) throws IOException {}
188
189  /**
190   * Called after the truncateTable operation has been requested.  Called as part
191   * of truncate table RPC call.
192   * The truncate is synchronous, so this method will be called when the
193   * truncate operation is terminated.
194   * @param ctx the environment to interact with the framework and master
195   * @param tableName the name of the table
196   */
197  default void postTruncateTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
198      TableName tableName) throws IOException {}
199
200  /**
201   * Called before {@link org.apache.hadoop.hbase.master.HMaster} truncates a
202   * table.  Called as part of truncate table procedure and it is async
203   * to the truncate RPC call.
204   *
205   * @param ctx the environment to interact with the framework and master
206   * @param tableName the name of the table
207   */
208  default void preTruncateTableAction(
209      final ObserverContext<MasterCoprocessorEnvironment> ctx, final TableName tableName)
210      throws IOException {}
211
212  /**
213   * Called after {@link org.apache.hadoop.hbase.master.HMaster} truncates a
214   * table.  Called as part of truncate table procedure and it is async to the
215   * truncate RPC call.
216   *
217   * @param ctx the environment to interact with the framework and master
218   * @param tableName the name of the table
219   */
220  default void postCompletedTruncateTableAction(
221      final ObserverContext<MasterCoprocessorEnvironment> ctx, final TableName tableName)
222      throws IOException {}
223
224  /**
225   * Called prior to modifying a table's properties.  Called as part of modify
226   * table RPC call.
227   * @param ctx the environment to interact with the framework and master
228   * @param tableName the name of the table
229   * @param newDescriptor after modify operation, table will have this descriptor
230   * @deprecated Since 2.1. Will be removed in 3.0.
231   */
232  @Deprecated
233  default void preModifyTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
234    final TableName tableName, TableDescriptor newDescriptor) throws IOException {}
235
236  /**
237   * Called prior to modifying a table's properties.  Called as part of modify
238   * table RPC call.
239   * @param ctx the environment to interact with the framework and master
240   * @param tableName the name of the table
241   * @param currentDescriptor current TableDescriptor of the table
242   * @param newDescriptor after modify operation, table will have this descriptor
243   */
244  default TableDescriptor preModifyTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
245      final TableName tableName, TableDescriptor currentDescriptor, TableDescriptor newDescriptor)
246      throws IOException {
247    return newDescriptor;
248  }
249
250  /**
251   * Called after the modifyTable operation has been requested.  Called as part
252   * of modify table RPC call.
253   * @param ctx the environment to interact with the framework and master
254   * @param tableName the name of the table
255   * @param currentDescriptor current TableDescriptor of the table
256   * @deprecated Since 2.1. Will be removed in 3.0.
257   */
258  @Deprecated
259  default void postModifyTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
260    final TableName tableName, TableDescriptor currentDescriptor) throws IOException {}
261
262  /**
263   * Called after the modifyTable operation has been requested.  Called as part
264   * of modify table RPC call.
265   * @param ctx the environment to interact with the framework and master
266   * @param tableName the name of the table
267   * @param oldDescriptor descriptor of table before modify operation happened
268   * @param currentDescriptor current TableDescriptor of the table
269   */
270  default void postModifyTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
271      final TableName tableName, TableDescriptor oldDescriptor, TableDescriptor currentDescriptor)
272    throws IOException {
273    postModifyTable(ctx, tableName, currentDescriptor);
274  }
275
276  /**
277   * Called prior to modifying a table's properties.  Called as part of modify
278   * table procedure and it is async to the modify table RPC call.
279   *
280   * @param ctx the environment to interact with the framework and master
281   * @param tableName the name of the table
282   * @param newDescriptor after modify operation, table will have this descriptor
283   * @deprecated Since 2.1. Will be removed in 3.0.
284   */
285  @Deprecated
286  default void preModifyTableAction(
287    final ObserverContext<MasterCoprocessorEnvironment> ctx,
288    final TableName tableName,
289    final TableDescriptor newDescriptor) throws IOException {}
290
291  /**
292   * Called prior to modifying a table's properties.  Called as part of modify
293   * table procedure and it is async to the modify table RPC call.
294   *
295   * @param ctx the environment to interact with the framework and master
296   * @param tableName the name of the table
297   * @param currentDescriptor current TableDescriptor of the table
298   * @param newDescriptor after modify operation, table will have this descriptor
299   */
300  default void preModifyTableAction(
301      final ObserverContext<MasterCoprocessorEnvironment> ctx,
302      final TableName tableName,
303      final TableDescriptor currentDescriptor,
304      final TableDescriptor newDescriptor) throws IOException {
305    preModifyTableAction(ctx, tableName, newDescriptor);
306  }
307
308  /**
309   * Called after to modifying a table's properties.  Called as part of modify
310   * table procedure and it is async to the modify table RPC call.
311   *
312   * @param ctx the environment to interact with the framework and master
313   * @param tableName the name of the table
314   * @param currentDescriptor current TableDescriptor of the table
315   * @deprecated Since 2.1. Will be removed in 3.0.
316   */
317  @Deprecated
318  default void postCompletedModifyTableAction(
319    final ObserverContext<MasterCoprocessorEnvironment> ctx,
320    final TableName tableName,
321    final TableDescriptor currentDescriptor) throws IOException {}
322
323  /**
324   * Called after to modifying a table's properties.  Called as part of modify
325   * table procedure and it is async to the modify table RPC call.
326   *
327   * @param ctx the environment to interact with the framework and master
328   * @param tableName the name of the table
329   * @param oldDescriptor descriptor of table before modify operation happened
330   * @param currentDescriptor current TableDescriptor of the table
331   */
332  default void postCompletedModifyTableAction(
333      final ObserverContext<MasterCoprocessorEnvironment> ctx,
334      final TableName tableName,
335      final TableDescriptor oldDescriptor,
336      final TableDescriptor currentDescriptor) throws IOException {
337    postCompletedModifyTableAction(ctx, tableName, currentDescriptor);
338  }
339
340  /**
341   * Called prior to enabling a table.  Called as part of enable table RPC call.
342   * @param ctx the environment to interact with the framework and master
343   * @param tableName the name of the table
344   */
345  default void preEnableTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
346      final TableName tableName) throws IOException {}
347
348  /**
349   * Called after the enableTable operation has been requested.  Called as part
350   * of enable table RPC call.
351   * @param ctx the environment to interact with the framework and master
352   * @param tableName the name of the table
353   */
354  default void postEnableTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
355      final TableName tableName) throws IOException {}
356
357  /**
358   * Called prior to enabling a table.  Called as part of enable table procedure
359   * and it is async to the enable table RPC call.
360   *
361   * @param ctx the environment to interact with the framework and master
362   * @param tableName the name of the table
363   */
364  default void preEnableTableAction(
365      final ObserverContext<MasterCoprocessorEnvironment> ctx,
366      final TableName tableName) throws IOException {}
367
368  /**
369   * Called after the enableTable operation has been requested.  Called as part
370   * of enable table procedure and it is async to the enable table RPC call.
371   *
372   * @param ctx the environment to interact with the framework and master
373   * @param tableName the name of the table
374   */
375  default void postCompletedEnableTableAction(
376      final ObserverContext<MasterCoprocessorEnvironment> ctx,
377      final TableName tableName) throws IOException {}
378
379  /**
380   * Called prior to disabling a table.  Called as part of disable table RPC
381   * call.
382   * @param ctx the environment to interact with the framework and master
383   * @param tableName the name of the table
384   */
385  default void preDisableTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
386      final TableName tableName) throws IOException {}
387
388  /**
389   * Called after the disableTable operation has been requested.  Called as part
390   * of disable table RPC call.
391   * @param ctx the environment to interact with the framework and master
392   * @param tableName the name of the table
393   */
394  default void postDisableTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
395      final TableName tableName) throws IOException {}
396
397  /**
398   * Called prior to disabling a table.  Called as part of disable table procedure
399   * and it is asyn to the disable table RPC call.
400   *
401   * @param ctx the environment to interact with the framework and master
402   * @param tableName the name of the table
403   */
404  default void preDisableTableAction(
405      final ObserverContext<MasterCoprocessorEnvironment> ctx,
406      final TableName tableName) throws IOException {}
407
408  /**
409   * Called after the disableTable operation has been requested.  Called as part
410   * of disable table procedure and it is asyn to the disable table RPC call.
411   *
412   * @param ctx the environment to interact with the framework and master
413   * @param tableName the name of the table
414   */
415  default void postCompletedDisableTableAction(
416      final ObserverContext<MasterCoprocessorEnvironment> ctx,
417      final TableName tableName) throws IOException {}
418
419  /**
420   * Called before a abortProcedure request has been processed.
421   * @param ctx the environment to interact with the framework and master
422   * @param procId the Id of the procedure
423   */
424  default void preAbortProcedure(
425      ObserverContext<MasterCoprocessorEnvironment> ctx, final long procId) throws IOException {}
426
427  /**
428   * Called after a abortProcedure request has been processed.
429   * @param ctx the environment to interact with the framework and master
430   */
431  default void postAbortProcedure(ObserverContext<MasterCoprocessorEnvironment> ctx)
432      throws IOException {}
433
434  /**
435   * Called before a getProcedures request has been processed.
436   * @param ctx the environment to interact with the framework and master
437   */
438  default void preGetProcedures(ObserverContext<MasterCoprocessorEnvironment> ctx)
439      throws IOException {}
440
441  /**
442   * Called after a getProcedures request has been processed.
443   * @param ctx the environment to interact with the framework and master
444   */
445  default void postGetProcedures(ObserverContext<MasterCoprocessorEnvironment> ctx)
446      throws IOException {}
447
448  /**
449   * Called before a getLocks request has been processed.
450   * @param ctx the environment to interact with the framework and master
451   * @throws IOException if something went wrong
452   */
453  default void preGetLocks(ObserverContext<MasterCoprocessorEnvironment> ctx)
454      throws IOException {}
455
456  /**
457   * Called after a getLocks request has been processed.
458   * @param ctx the environment to interact with the framework and master
459   * @throws IOException if something went wrong
460   */
461  default void postGetLocks(
462      ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException {}
463
464  /**
465   * Called prior to moving a given region from one region server to another.
466   * @param ctx the environment to interact with the framework and master
467   * @param region the RegionInfo
468   * @param srcServer the source ServerName
469   * @param destServer the destination ServerName
470   */
471  default void preMove(final ObserverContext<MasterCoprocessorEnvironment> ctx,
472      final RegionInfo region, final ServerName srcServer,
473      final ServerName destServer)
474    throws IOException {}
475
476  /**
477   * Called after the region move has been requested.
478   * @param ctx the environment to interact with the framework and master
479   * @param region the RegionInfo
480   * @param srcServer the source ServerName
481   * @param destServer the destination ServerName
482   */
483  default void postMove(final ObserverContext<MasterCoprocessorEnvironment> ctx,
484      final RegionInfo region, final ServerName srcServer,
485      final ServerName destServer)
486    throws IOException {}
487
488  /**
489   * Called prior to assigning a specific region.
490   * @param ctx the environment to interact with the framework and master
491   * @param regionInfo the regionInfo of the region
492   */
493  default void preAssign(final ObserverContext<MasterCoprocessorEnvironment> ctx,
494      final RegionInfo regionInfo) throws IOException {}
495
496  /**
497   * Called after the region assignment has been requested.
498   * @param ctx the environment to interact with the framework and master
499   * @param regionInfo the regionInfo of the region
500   */
501  default void postAssign(final ObserverContext<MasterCoprocessorEnvironment> ctx,
502      final RegionInfo regionInfo) throws IOException {}
503
504  /**
505   * Called prior to unassigning a given region.
506   * @param ctx the environment to interact with the framework and master
507   * @param regionInfo
508   * @param force whether to force unassignment or not
509   */
510  default void preUnassign(final ObserverContext<MasterCoprocessorEnvironment> ctx,
511      final RegionInfo regionInfo, final boolean force) throws IOException {}
512
513  /**
514   * Called after the region unassignment has been requested.
515   * @param ctx the environment to interact with the framework and master
516   * @param regionInfo
517   * @param force whether to force unassignment or not
518   */
519  default void postUnassign(final ObserverContext<MasterCoprocessorEnvironment> ctx,
520      final RegionInfo regionInfo, final boolean force) throws IOException {}
521
522  /**
523   * Called prior to marking a given region as offline.
524   * @param ctx the environment to interact with the framework and master
525   * @param regionInfo
526   */
527  default void preRegionOffline(final ObserverContext<MasterCoprocessorEnvironment> ctx,
528      final RegionInfo regionInfo) throws IOException {}
529
530  /**
531   * Called after the region has been marked offline.
532   * @param ctx the environment to interact with the framework and master
533   * @param regionInfo
534   */
535  default void postRegionOffline(final ObserverContext<MasterCoprocessorEnvironment> ctx,
536      final RegionInfo regionInfo) throws IOException {}
537
538  /**
539   * Called prior to requesting rebalancing of the cluster regions, though after
540   * the initial checks for regions in transition and the balance switch flag.
541   * @param ctx the environment to interact with the framework and master
542   */
543  default void preBalance(final ObserverContext<MasterCoprocessorEnvironment> ctx)
544      throws IOException {}
545
546  /**
547   * Called after the balancing plan has been submitted.
548   * @param ctx the environment to interact with the framework and master
549   * @param plans the RegionPlans which master has executed. RegionPlan serves as hint
550   * as for the final destination for the underlying region but may not represent the
551   * final state of assignment
552   */
553  default void postBalance(final ObserverContext<MasterCoprocessorEnvironment> ctx, List<RegionPlan> plans)
554      throws IOException {}
555
556  /**
557   * Called prior to setting split / merge switch
558   * Supports Coprocessor 'bypass'.
559   * @param ctx the coprocessor instance's environment
560   * @param newValue the new value submitted in the call
561   * @param switchType type of switch
562   */
563  default void preSetSplitOrMergeEnabled(final ObserverContext<MasterCoprocessorEnvironment> ctx,
564      final boolean newValue, final MasterSwitchType switchType) throws IOException {}
565
566  /**
567   * Called after setting split / merge switch
568   * @param ctx the coprocessor instance's environment
569   * @param newValue the new value submitted in the call
570   * @param switchType type of switch
571   */
572  default void postSetSplitOrMergeEnabled(final ObserverContext<MasterCoprocessorEnvironment> ctx,
573      final boolean newValue, final MasterSwitchType switchType) throws IOException {}
574
575  /**
576   * Called before the split region procedure is called.
577   * @param c the environment to interact with the framework and master
578   * @param tableName the table where the region belongs to
579   * @param splitRow split point
580   */
581  default void preSplitRegion(
582      final ObserverContext<MasterCoprocessorEnvironment> c,
583      final TableName tableName,
584      final byte[] splitRow)
585      throws IOException {}
586
587  /**
588   * Called before the region is split.
589   * @param c the environment to interact with the framework and master
590   * @param tableName the table where the region belongs to
591   * @param splitRow split point
592   */
593  default void preSplitRegionAction(
594      final ObserverContext<MasterCoprocessorEnvironment> c,
595      final TableName tableName,
596      final byte[] splitRow)
597      throws IOException {}
598
599  /**
600   * Called after the region is split.
601   * @param c the environment to interact with the framework and master
602   * @param regionInfoA the left daughter region
603   * @param regionInfoB the right daughter region
604   */
605  default void postCompletedSplitRegionAction(
606      final ObserverContext<MasterCoprocessorEnvironment> c,
607      final RegionInfo regionInfoA,
608      final RegionInfo regionInfoB) throws IOException {}
609
610  /**
611   * This will be called before update META step as part of split transaction.
612   * @param ctx the environment to interact with the framework and master
613   * @param splitKey
614   * @param metaEntries
615   */
616  default void preSplitRegionBeforeMETAAction(
617      final ObserverContext<MasterCoprocessorEnvironment> ctx,
618      final byte[] splitKey,
619      final List<Mutation> metaEntries) throws IOException {}
620
621
622  /**
623   * This will be called after update META step as part of split transaction
624   * @param ctx the environment to interact with the framework and master
625   */
626  default void preSplitRegionAfterMETAAction(
627      final ObserverContext<MasterCoprocessorEnvironment> ctx)
628      throws IOException {}
629
630  /**
631   * This will be called after the roll back of the split region is completed
632   * @param ctx the environment to interact with the framework and master
633   */
634  default void postRollBackSplitRegionAction(
635      final ObserverContext<MasterCoprocessorEnvironment> ctx)
636      throws IOException {}
637
638  /**
639   * Called before the regions merge.
640   * @param ctx the environment to interact with the framework and master
641   */
642  default void preMergeRegionsAction(
643      final ObserverContext<MasterCoprocessorEnvironment> ctx,
644      final RegionInfo[] regionsToMerge) throws IOException {}
645
646  /**
647   * called after the regions merge.
648   * @param ctx the environment to interact with the framework and master
649   */
650  default void postCompletedMergeRegionsAction(
651      final ObserverContext<MasterCoprocessorEnvironment> ctx,
652      final RegionInfo[] regionsToMerge,
653      final RegionInfo mergedRegion) throws IOException {}
654
655  /**
656   * This will be called before update META step as part of regions merge transaction.
657   * @param ctx the environment to interact with the framework and master
658   * @param metaEntries mutations to execute on hbase:meta atomically with regions merge updates.
659   *        Any puts or deletes to execute on hbase:meta can be added to the mutations.
660   */
661  default void preMergeRegionsCommitAction(
662      final ObserverContext<MasterCoprocessorEnvironment> ctx,
663      final RegionInfo[] regionsToMerge,
664      @MetaMutationAnnotation List<Mutation> metaEntries) throws IOException {}
665
666  /**
667   * This will be called after META step as part of regions merge transaction.
668   * @param ctx the environment to interact with the framework and master
669   */
670  default void postMergeRegionsCommitAction(
671      final ObserverContext<MasterCoprocessorEnvironment> ctx,
672      final RegionInfo[] regionsToMerge,
673      final RegionInfo mergedRegion) throws IOException {}
674
675  /**
676   * This will be called after the roll back of the regions merge.
677   * @param ctx the environment to interact with the framework and master
678   */
679  default void postRollBackMergeRegionsAction(
680      final ObserverContext<MasterCoprocessorEnvironment> ctx,
681      final RegionInfo[] regionsToMerge) throws IOException {}
682
683  /**
684   * Called prior to modifying the flag used to enable/disable region balancing.
685   * @param ctx the coprocessor instance's environment
686   */
687  default void preBalanceSwitch(final ObserverContext<MasterCoprocessorEnvironment> ctx,
688      final boolean newValue) throws IOException {}
689
690  /**
691   * Called after the flag to enable/disable balancing has changed.
692   * @param ctx the coprocessor instance's environment
693   * @param oldValue the previously set balanceSwitch value
694   * @param newValue the newly set balanceSwitch value
695   */
696  default void postBalanceSwitch(final ObserverContext<MasterCoprocessorEnvironment> ctx,
697      final boolean oldValue, final boolean newValue) throws IOException {}
698
699  /**
700   * Called prior to shutting down the full HBase cluster, including this
701   * {@link org.apache.hadoop.hbase.master.HMaster} process.
702   */
703  default void preShutdown(final ObserverContext<MasterCoprocessorEnvironment> ctx)
704      throws IOException {}
705
706
707  /**
708   * Called immediately prior to stopping this
709   * {@link org.apache.hadoop.hbase.master.HMaster} process.
710   */
711  default void preStopMaster(final ObserverContext<MasterCoprocessorEnvironment> ctx)
712      throws IOException {}
713
714  /**
715   * Called immediately after an active master instance has completed
716   * initialization.  Will not be called on standby master instances unless
717   * they take over the active role.
718   */
719  default void postStartMaster(final ObserverContext<MasterCoprocessorEnvironment> ctx)
720      throws IOException {}
721
722  /**
723   * Call before the master initialization is set to true.
724   * {@link org.apache.hadoop.hbase.master.HMaster} process.
725   */
726  default void preMasterInitialization(final ObserverContext<MasterCoprocessorEnvironment> ctx)
727      throws IOException {}
728
729  /**
730   * Called before a new snapshot is taken.
731   * Called as part of snapshot RPC call.
732   * @param ctx the environment to interact with the framework and master
733   * @param snapshot the SnapshotDescriptor for the snapshot
734   * @param tableDescriptor the TableDescriptor of the table to snapshot
735   */
736  default void preSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
737      final SnapshotDescription snapshot, final TableDescriptor tableDescriptor)
738      throws IOException {}
739
740  /**
741   * Called after the snapshot operation has been requested.
742   * Called as part of snapshot RPC call.
743   * @param ctx the environment to interact with the framework and master
744   * @param snapshot the SnapshotDescriptor for the snapshot
745   * @param tableDescriptor the TableDescriptor of the table to snapshot
746   */
747  default void postSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
748      final SnapshotDescription snapshot, final TableDescriptor tableDescriptor)
749      throws IOException {}
750
751  /**
752   * Called before listSnapshots request has been processed.
753   * @param ctx the environment to interact with the framework and master
754   * @param snapshot the SnapshotDescriptor of the snapshot to list
755   */
756  default void preListSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
757      final SnapshotDescription snapshot) throws IOException {}
758
759  /**
760   * Called after listSnapshots request has been processed.
761   * @param ctx the environment to interact with the framework and master
762   * @param snapshot the SnapshotDescriptor of the snapshot to list
763   */
764  default void postListSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
765      final SnapshotDescription snapshot) throws IOException {}
766
767  /**
768   * Called before a snapshot is cloned.
769   * Called as part of restoreSnapshot RPC call.
770   * @param ctx the environment to interact with the framework and master
771   * @param snapshot the SnapshotDescriptor for the snapshot
772   * @param tableDescriptor the TableDescriptor of the table to create
773   */
774  default void preCloneSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
775      final SnapshotDescription snapshot, final TableDescriptor tableDescriptor)
776      throws IOException {}
777
778  /**
779   * Called after a snapshot clone operation has been requested.
780   * Called as part of restoreSnapshot RPC call.
781   * @param ctx the environment to interact with the framework and master
782   * @param snapshot the SnapshotDescriptor for the snapshot
783   * @param tableDescriptor the v of the table to create
784   */
785  default void postCloneSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
786      final SnapshotDescription snapshot, final TableDescriptor tableDescriptor)
787      throws IOException {}
788
789  /**
790   * Called before a snapshot is restored.
791   * Called as part of restoreSnapshot RPC call.
792   * @param ctx the environment to interact with the framework and master
793   * @param snapshot the SnapshotDescriptor for the snapshot
794   * @param tableDescriptor the TableDescriptor of the table to restore
795   */
796  default void preRestoreSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
797      final SnapshotDescription snapshot, final TableDescriptor tableDescriptor)
798      throws IOException {}
799
800  /**
801   * Called after a snapshot restore operation has been requested.
802   * Called as part of restoreSnapshot RPC call.
803   * @param ctx the environment to interact with the framework and master
804   * @param snapshot the SnapshotDescriptor for the snapshot
805   * @param tableDescriptor the TableDescriptor of the table to restore
806   */
807  default void postRestoreSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
808      final SnapshotDescription snapshot, final TableDescriptor tableDescriptor)
809      throws IOException {}
810
811  /**
812   * Called before a snapshot is deleted.
813   * Called as part of deleteSnapshot RPC call.
814   * @param ctx the environment to interact with the framework and master
815   * @param snapshot the SnapshotDescriptor of the snapshot to delete
816   */
817  default void preDeleteSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
818      final SnapshotDescription snapshot) throws IOException {}
819
820  /**
821   * Called after the delete snapshot operation has been requested.
822   * Called as part of deleteSnapshot RPC call.
823   * @param ctx the environment to interact with the framework and master
824   * @param snapshot the SnapshotDescriptor of the snapshot to delete
825   */
826  default void postDeleteSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
827      final SnapshotDescription snapshot) throws IOException {}
828
829  /**
830   * Called before a getTableDescriptors request has been processed.
831   * @param ctx the environment to interact with the framework and master
832   * @param tableNamesList the list of table names, or null if querying for all
833   * @param descriptors an empty list, can be filled with what to return in coprocessor
834   * @param regex regular expression used for filtering the table names
835   */
836  default void preGetTableDescriptors(ObserverContext<MasterCoprocessorEnvironment> ctx,
837      List<TableName> tableNamesList, List<TableDescriptor> descriptors,
838      String regex) throws IOException {}
839
840  /**
841   * Called after a getTableDescriptors request has been processed.
842   * @param ctx the environment to interact with the framework and master
843   * @param tableNamesList the list of table names, or null if querying for all
844   * @param descriptors the list of descriptors about to be returned
845   * @param regex regular expression used for filtering the table names
846   */
847  default void postGetTableDescriptors(ObserverContext<MasterCoprocessorEnvironment> ctx,
848      List<TableName> tableNamesList, List<TableDescriptor> descriptors,
849      String regex) throws IOException {}
850
851  /**
852   * Called before a getTableNames request has been processed.
853   * @param ctx the environment to interact with the framework and master
854   * @param descriptors an empty list, can be filled with what to return by coprocessor
855   * @param regex regular expression used for filtering the table names
856   */
857  default void preGetTableNames(ObserverContext<MasterCoprocessorEnvironment> ctx,
858      List<TableDescriptor> descriptors, String regex) throws IOException {}
859
860  /**
861   * Called after a getTableNames request has been processed.
862   * @param ctx the environment to interact with the framework and master
863   * @param descriptors the list of descriptors about to be returned
864   * @param regex regular expression used for filtering the table names
865   */
866  default void postGetTableNames(ObserverContext<MasterCoprocessorEnvironment> ctx,
867      List<TableDescriptor> descriptors, String regex) throws IOException {}
868
869
870
871  /**
872   * Called before a new namespace is created by
873   * {@link org.apache.hadoop.hbase.master.HMaster}.
874   * @param ctx the environment to interact with the framework and master
875   * @param ns the NamespaceDescriptor for the table
876   */
877  default void preCreateNamespace(final ObserverContext<MasterCoprocessorEnvironment> ctx,
878      NamespaceDescriptor ns) throws IOException {}
879  /**
880   * Called after the createNamespace operation has been requested.
881   * @param ctx the environment to interact with the framework and master
882   * @param ns the NamespaceDescriptor for the table
883   */
884  default void postCreateNamespace(final ObserverContext<MasterCoprocessorEnvironment> ctx,
885       NamespaceDescriptor ns) throws IOException {}
886
887  /**
888   * Called before {@link org.apache.hadoop.hbase.master.HMaster} deletes a
889   * namespace
890   * @param ctx the environment to interact with the framework and master
891   * @param namespace the name of the namespace
892   */
893  default void preDeleteNamespace(final ObserverContext<MasterCoprocessorEnvironment> ctx,
894      String namespace) throws IOException {}
895
896  /**
897   * Called after the deleteNamespace operation has been requested.
898   * @param ctx the environment to interact with the framework and master
899   * @param namespace the name of the namespace
900   */
901  default void postDeleteNamespace(final ObserverContext<MasterCoprocessorEnvironment> ctx,
902      String namespace) throws IOException {}
903
904  /**
905   * Called prior to modifying a namespace's properties.
906   * @param ctx the environment to interact with the framework and master
907   * @param newNsDescriptor after modify operation, namespace will have this descriptor
908   * @deprecated Since 2.1. Will be removed in 3.0.
909   */
910  @Deprecated
911  default void preModifyNamespace(final ObserverContext<MasterCoprocessorEnvironment> ctx,
912    NamespaceDescriptor newNsDescriptor) throws IOException {}
913
914  /**
915   * Called prior to modifying a namespace's properties.
916   * @param ctx the environment to interact with the framework and master
917   * @param currentNsDescriptor current NamespaceDescriptor of the namespace
918   * @param newNsDescriptor after modify operation, namespace will have this descriptor
919   */
920  default void preModifyNamespace(final ObserverContext<MasterCoprocessorEnvironment> ctx,
921      NamespaceDescriptor currentNsDescriptor, NamespaceDescriptor newNsDescriptor)
922    throws IOException {
923    preModifyNamespace(ctx, newNsDescriptor);
924  }
925
926  /**
927   * Called after the modifyNamespace operation has been requested.
928   * @param ctx the environment to interact with the framework and master
929   * @param currentNsDescriptor current NamespaceDescriptor of the namespace
930   * @deprecated Since 2.1. Will be removed in 3.0.
931   */
932  @Deprecated
933  default void postModifyNamespace(final ObserverContext<MasterCoprocessorEnvironment> ctx,
934    NamespaceDescriptor currentNsDescriptor) throws IOException {}
935
936  /**
937   * Called after the modifyNamespace operation has been requested.
938   * @param ctx the environment to interact with the framework and master
939   * @param oldNsDescriptor descriptor of namespace before modify operation happened
940   * @param currentNsDescriptor current NamespaceDescriptor of the namespace
941   */
942  default void postModifyNamespace(final ObserverContext<MasterCoprocessorEnvironment> ctx,
943      NamespaceDescriptor oldNsDescriptor, NamespaceDescriptor currentNsDescriptor)
944    throws IOException {
945    postModifyNamespace(ctx, currentNsDescriptor);
946  }
947
948  /**
949   * Called before a getNamespaceDescriptor request has been processed.
950   * @param ctx the environment to interact with the framework and master
951   * @param namespace the name of the namespace
952   */
953  default void preGetNamespaceDescriptor(ObserverContext<MasterCoprocessorEnvironment> ctx,
954      String namespace) throws IOException {}
955
956  /**
957   * Called after a getNamespaceDescriptor request has been processed.
958   * @param ctx the environment to interact with the framework and master
959   * @param ns the NamespaceDescriptor
960   */
961  default void postGetNamespaceDescriptor(ObserverContext<MasterCoprocessorEnvironment> ctx,
962      NamespaceDescriptor ns) throws IOException {}
963
964  /**
965   * Called before a listNamespaceDescriptors request has been processed.
966   * @param ctx the environment to interact with the framework and master
967   * @param descriptors an empty list, can be filled with what to return by coprocessor
968   */
969  default void preListNamespaceDescriptors(ObserverContext<MasterCoprocessorEnvironment> ctx,
970      List<NamespaceDescriptor> descriptors) throws IOException {}
971
972  /**
973   * Called after a listNamespaceDescriptors request has been processed.
974   * @param ctx the environment to interact with the framework and master
975   * @param descriptors the list of descriptors about to be returned
976   */
977  default void postListNamespaceDescriptors(ObserverContext<MasterCoprocessorEnvironment> ctx,
978      List<NamespaceDescriptor> descriptors) throws IOException {}
979
980
981  /**
982   * Called before the table memstore is flushed to disk.
983   * @param ctx the environment to interact with the framework and master
984   * @param tableName the name of the table
985   */
986  default void preTableFlush(final ObserverContext<MasterCoprocessorEnvironment> ctx,
987      final TableName tableName) throws IOException {}
988
989  /**
990   * Called after the table memstore is flushed to disk.
991   * @param ctx the environment to interact with the framework and master
992   * @param tableName the name of the table
993   */
994  default void postTableFlush(final ObserverContext<MasterCoprocessorEnvironment> ctx,
995      final TableName tableName) throws IOException {}
996
997  /**
998   * Called before the quota for the user is stored.
999   * @param ctx the environment to interact with the framework and master
1000   * @param userName the name of user
1001   * @param quotas the current quota for the user
1002   */
1003  default void preSetUserQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1004      final String userName, final GlobalQuotaSettings quotas) throws IOException {}
1005
1006  /**
1007   * Called after the quota for the user is stored.
1008   * @param ctx the environment to interact with the framework and master
1009   * @param userName the name of user
1010   * @param quotas the resulting quota for the user
1011   */
1012  default void postSetUserQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1013      final String userName, final GlobalQuotaSettings quotas) throws IOException {}
1014
1015  /**
1016   * Called before the quota for the user on the specified table is stored.
1017   * @param ctx the environment to interact with the framework and master
1018   * @param userName the name of user
1019   * @param tableName the name of the table
1020   * @param quotas the current quota for the user on the table
1021   */
1022  default void preSetUserQuota(
1023      final ObserverContext<MasterCoprocessorEnvironment> ctx, final String userName,
1024      final TableName tableName, final GlobalQuotaSettings quotas) throws IOException {}
1025
1026  /**
1027   * Called after the quota for the user on the specified table is stored.
1028   * @param ctx the environment to interact with the framework and master
1029   * @param userName the name of user
1030   * @param tableName the name of the table
1031   * @param quotas the resulting quota for the user on the table
1032   */
1033  default void postSetUserQuota(
1034      final ObserverContext<MasterCoprocessorEnvironment> ctx, final String userName,
1035      final TableName tableName, final GlobalQuotaSettings quotas) throws IOException {}
1036
1037  /**
1038   * Called before the quota for the user on the specified namespace is stored.
1039   * @param ctx the environment to interact with the framework and master
1040   * @param userName the name of user
1041   * @param namespace the name of the namespace
1042   * @param quotas the current quota for the user on the namespace
1043   */
1044  default void preSetUserQuota(
1045      final ObserverContext<MasterCoprocessorEnvironment> ctx, final String userName,
1046      final String namespace, final GlobalQuotaSettings quotas) throws IOException {}
1047
1048  /**
1049   * Called after the quota for the user on the specified namespace is stored.
1050   * @param ctx the environment to interact with the framework and master
1051   * @param userName the name of user
1052   * @param namespace the name of the namespace
1053   * @param quotas the resulting quota for the user on the namespace
1054   */
1055  default void postSetUserQuota(
1056      final ObserverContext<MasterCoprocessorEnvironment> ctx, final String userName,
1057      final String namespace, final GlobalQuotaSettings quotas) throws IOException {}
1058
1059  /**
1060   * Called before the quota for the table is stored.
1061   * @param ctx the environment to interact with the framework and master
1062   * @param tableName the name of the table
1063   * @param quotas the current quota for the table
1064   */
1065  default void preSetTableQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1066      final TableName tableName, final GlobalQuotaSettings quotas) throws IOException {}
1067
1068  /**
1069   * Called after the quota for the table is stored.
1070   * @param ctx the environment to interact with the framework and master
1071   * @param tableName the name of the table
1072   * @param quotas the resulting quota for the table
1073   */
1074  default void postSetTableQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1075      final TableName tableName, final GlobalQuotaSettings quotas) throws IOException {}
1076
1077  /**
1078   * Called before the quota for the namespace is stored.
1079   * @param ctx the environment to interact with the framework and master
1080   * @param namespace the name of the namespace
1081   * @param quotas the current quota for the namespace
1082   */
1083  default void preSetNamespaceQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1084      final String namespace, final GlobalQuotaSettings quotas) throws IOException {}
1085
1086  /**
1087   * Called after the quota for the namespace is stored.
1088   * @param ctx the environment to interact with the framework and master
1089   * @param namespace the name of the namespace
1090   * @param quotas the resulting quota for the namespace
1091   */
1092  default void postSetNamespaceQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1093      final String namespace, final GlobalQuotaSettings quotas) throws IOException {}
1094
1095  /**
1096   * Called before the quota for the region server is stored.
1097   * @param ctx the environment to interact with the framework and master
1098   * @param regionServer the name of the region server
1099   * @param quotas the current quota for the region server
1100   */
1101  default void preSetRegionServerQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1102      final String regionServer, final GlobalQuotaSettings quotas) throws IOException {}
1103
1104  /**
1105   * Called after the quota for the region server is stored.
1106   * @param ctx the environment to interact with the framework and master
1107   * @param regionServer the name of the region server
1108   * @param quotas the resulting quota for the region server
1109   */
1110  default void postSetRegionServerQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1111      final String regionServer, final GlobalQuotaSettings quotas) throws IOException {}
1112
1113  /**
1114   * Called before merge regions request.
1115   * @param ctx coprocessor environment
1116   * @param regionsToMerge regions to be merged
1117   */
1118  default void preMergeRegions(
1119      final ObserverContext<MasterCoprocessorEnvironment> ctx,
1120      final RegionInfo[] regionsToMerge) throws IOException {}
1121
1122  /**
1123   * called after merge regions request.
1124   * @param c coprocessor environment
1125   * @param regionsToMerge regions to be merged
1126   */
1127  default void postMergeRegions(
1128      final ObserverContext<MasterCoprocessorEnvironment> c,
1129      final RegionInfo[] regionsToMerge) throws IOException {}
1130
1131  /**
1132   * Called before servers are moved to target region server group
1133   * @param ctx the environment to interact with the framework and master
1134   * @param servers set of servers to move
1135   * @param targetGroup destination group
1136   */
1137  default void preMoveServersAndTables(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1138                      Set<Address> servers, Set<TableName> tables, String targetGroup) throws IOException {}
1139
1140  /**
1141   * Called after servers are moved to target region server group
1142   * @param ctx the environment to interact with the framework and master
1143   * @param servers set of servers to move
1144   * @param targetGroup name of group
1145   */
1146  default void postMoveServersAndTables(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1147      Set<Address> servers, Set<TableName> tables, String targetGroup) throws IOException {}
1148
1149  /**
1150   * Called before servers are moved to target region server group
1151   * @param ctx the environment to interact with the framework and master
1152   * @param servers set of servers to move
1153   * @param targetGroup destination group
1154   */
1155  default void preMoveServers(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1156                      Set<Address> servers, String targetGroup) throws IOException {}
1157
1158  /**
1159   * Called after servers are moved to target region server group
1160   * @param ctx the environment to interact with the framework and master
1161   * @param servers set of servers to move
1162   * @param targetGroup name of group
1163   */
1164  default void postMoveServers(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1165                       Set<Address> servers, String targetGroup) throws IOException {}
1166
1167  /**
1168   * Called before tables are moved to target region server group
1169   * @param ctx the environment to interact with the framework and master
1170   * @param tables set of tables to move
1171   * @param targetGroup name of group
1172   */
1173  default void preMoveTables(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1174                     Set<TableName> tables, String targetGroup) throws IOException {}
1175
1176  /**
1177   * Called after servers are moved to target region server group
1178   * @param ctx the environment to interact with the framework and master
1179   * @param tables set of tables to move
1180   * @param targetGroup name of group
1181   */
1182  default void postMoveTables(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1183                      Set<TableName> tables, String targetGroup) throws IOException {}
1184
1185  /**
1186   * Called before a new region server group is added
1187   * @param ctx the environment to interact with the framework and master
1188   * @param name group name
1189   */
1190  default void preAddRSGroup(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1191                     String name) throws IOException {}
1192
1193  /**
1194   * Called after a new region server group is added
1195   * @param ctx the environment to interact with the framework and master
1196   * @param name group name
1197   */
1198  default void postAddRSGroup(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1199                      String name) throws IOException {}
1200
1201  /**
1202   * Called before a region server group is removed
1203   * @param ctx the environment to interact with the framework and master
1204   * @param name group name
1205   */
1206  default void preRemoveRSGroup(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1207                        String name) throws IOException {}
1208
1209  /**
1210   * Called after a region server group is removed
1211   * @param ctx the environment to interact with the framework and master
1212   * @param name group name
1213   */
1214  default void postRemoveRSGroup(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1215                         String name) throws IOException {}
1216
1217  /**
1218   * Called before a region server group is removed
1219   * @param ctx the environment to interact with the framework and master
1220   * @param groupName group name
1221   */
1222  default void preBalanceRSGroup(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1223                         String groupName) throws IOException {}
1224
1225  /**
1226   * Called after a region server group is removed
1227   * @param ctx the environment to interact with the framework and master
1228   * @param groupName group name
1229   */
1230  default void postBalanceRSGroup(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1231                          String groupName, boolean balancerRan) throws IOException {}
1232
1233  /**
1234   * Called before servers are removed from rsgroup
1235   * @param ctx the environment to interact with the framework and master
1236   * @param servers set of decommissioned servers to remove
1237   */
1238  default void preRemoveServers(
1239      final ObserverContext<MasterCoprocessorEnvironment> ctx,
1240      Set<Address> servers) throws IOException {}
1241
1242  /**
1243   * Called after servers are removed from rsgroup
1244   * @param ctx the environment to interact with the framework and master
1245   * @param servers set of servers to remove
1246   */
1247  default void postRemoveServers(
1248      final ObserverContext<MasterCoprocessorEnvironment> ctx,
1249      Set<Address> servers) throws IOException {}
1250
1251  /**
1252   * Called before add a replication peer
1253   * @param ctx the environment to interact with the framework and master
1254   * @param peerId a short name that identifies the peer
1255   * @param peerConfig configuration for the replication peer
1256   */
1257  default void preAddReplicationPeer(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1258      String peerId, ReplicationPeerConfig peerConfig) throws IOException {}
1259
1260  /**
1261   * Called after add a replication peer
1262   * @param ctx the environment to interact with the framework and master
1263   * @param peerId a short name that identifies the peer
1264   * @param peerConfig configuration for the replication peer
1265   */
1266  default void postAddReplicationPeer(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1267      String peerId, ReplicationPeerConfig peerConfig) throws IOException {}
1268
1269  /**
1270   * Called before remove a replication peer
1271   * @param ctx
1272   * @param peerId a short name that identifies the peer
1273   */
1274  default void preRemoveReplicationPeer(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1275      String peerId) throws IOException {}
1276
1277  /**
1278   * Called after remove a replication peer
1279   * @param ctx
1280   * @param peerId a short name that identifies the peer
1281   */
1282  default void postRemoveReplicationPeer(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1283      String peerId) throws IOException {}
1284
1285  /**
1286   * Called before enable a replication peer
1287   * @param ctx
1288   * @param peerId a short name that identifies the peer
1289   */
1290  default void preEnableReplicationPeer(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1291      String peerId) throws IOException {}
1292
1293  /**
1294   * Called after enable a replication peer
1295   * @param ctx
1296   * @param peerId a short name that identifies the peer
1297   */
1298  default void postEnableReplicationPeer(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1299      String peerId) throws IOException {}
1300
1301  /**
1302   * Called before disable a replication peer
1303   * @param ctx
1304   * @param peerId a short name that identifies the peer
1305   */
1306  default void preDisableReplicationPeer(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1307      String peerId) throws IOException {}
1308
1309  /**
1310   * Called after disable a replication peer
1311   * @param ctx
1312   * @param peerId a short name that identifies the peer
1313   */
1314  default void postDisableReplicationPeer(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1315      String peerId) throws IOException {}
1316
1317  /**
1318   * Called before get the configured ReplicationPeerConfig for the specified peer
1319   * @param ctx
1320   * @param peerId a short name that identifies the peer
1321   */
1322  default void preGetReplicationPeerConfig(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1323      String peerId) throws IOException {}
1324
1325  /**
1326   * Called after get the configured ReplicationPeerConfig for the specified peer
1327   * @param ctx
1328   * @param peerId a short name that identifies the peer
1329   */
1330  default void postGetReplicationPeerConfig(
1331      final ObserverContext<MasterCoprocessorEnvironment> ctx, String peerId) throws IOException {}
1332
1333  /**
1334   * Called before update peerConfig for the specified peer
1335   * @param ctx
1336   * @param peerId a short name that identifies the peer
1337   */
1338  default void preUpdateReplicationPeerConfig(
1339      final ObserverContext<MasterCoprocessorEnvironment> ctx, String peerId,
1340      ReplicationPeerConfig peerConfig) throws IOException {}
1341
1342  /**
1343   * Called after update peerConfig for the specified peer
1344   * @param ctx the environment to interact with the framework and master
1345   * @param peerId a short name that identifies the peer
1346   */
1347  default void postUpdateReplicationPeerConfig(
1348      final ObserverContext<MasterCoprocessorEnvironment> ctx, String peerId,
1349      ReplicationPeerConfig peerConfig) throws IOException {}
1350
1351  /**
1352   * Called before list replication peers.
1353   * @param ctx the environment to interact with the framework and master
1354   * @param regex The regular expression to match peer id
1355   */
1356  default void preListReplicationPeers(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1357      String regex) throws IOException {}
1358
1359  /**
1360   * Called after list replication peers.
1361   * @param ctx the environment to interact with the framework and master
1362   * @param regex The regular expression to match peer id
1363   */
1364  default void postListReplicationPeers(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1365      String regex) throws IOException {}
1366
1367  /**
1368   * Called before new LockProcedure is queued.
1369   * @param ctx the environment to interact with the framework and master
1370   */
1371  default void preRequestLock(ObserverContext<MasterCoprocessorEnvironment> ctx, String namespace,
1372      TableName tableName, RegionInfo[] regionInfos, String description) throws IOException {}
1373
1374  /**
1375   * Called after new LockProcedure is queued.
1376   * @param ctx the environment to interact with the framework and master
1377   */
1378  default void postRequestLock(ObserverContext<MasterCoprocessorEnvironment> ctx, String namespace,
1379      TableName tableName, RegionInfo[] regionInfos, String description) throws IOException {}
1380
1381  /**
1382   * Called before heartbeat to a lock.
1383   * @param ctx the environment to interact with the framework and master
1384   */
1385  default void preLockHeartbeat(ObserverContext<MasterCoprocessorEnvironment> ctx,
1386      TableName tn, String description) throws IOException {}
1387
1388  /**
1389   * Called after heartbeat to a lock.
1390   * @param ctx the environment to interact with the framework and master
1391   */
1392  default void postLockHeartbeat(ObserverContext<MasterCoprocessorEnvironment> ctx)
1393      throws IOException {}
1394
1395  /**
1396   * Called before get cluster status.
1397   */
1398  default void preGetClusterMetrics(ObserverContext<MasterCoprocessorEnvironment> ctx)
1399      throws IOException {}
1400
1401  /**
1402   * Called after get cluster status.
1403   */
1404  default void postGetClusterMetrics(ObserverContext<MasterCoprocessorEnvironment> ctx,
1405    ClusterMetrics status) throws IOException {}
1406
1407  /**
1408   * Called before clear dead region servers.
1409   */
1410  default void preClearDeadServers(ObserverContext<MasterCoprocessorEnvironment> ctx)
1411      throws IOException {}
1412
1413  /**
1414   * Called after clear dead region servers.
1415   */
1416  default void postClearDeadServers(ObserverContext<MasterCoprocessorEnvironment> ctx,
1417      List<ServerName> servers, List<ServerName> notClearedServers)
1418      throws IOException {}
1419
1420  /**
1421   * Called before decommission region servers.
1422   */
1423  default void preDecommissionRegionServers(ObserverContext<MasterCoprocessorEnvironment> ctx,
1424      List<ServerName> servers, boolean offload) throws IOException {}
1425
1426  /**
1427   * Called after decommission region servers.
1428   */
1429  default void postDecommissionRegionServers(ObserverContext<MasterCoprocessorEnvironment> ctx,
1430      List<ServerName> servers, boolean offload) throws IOException {}
1431
1432  /**
1433   * Called before list decommissioned region servers.
1434   */
1435  default void preListDecommissionedRegionServers(ObserverContext<MasterCoprocessorEnvironment> ctx)
1436      throws IOException {}
1437
1438  /**
1439   * Called after list decommissioned region servers.
1440   */
1441  default void postListDecommissionedRegionServers(ObserverContext<MasterCoprocessorEnvironment> ctx)
1442      throws IOException {}
1443
1444  /**
1445   * Called before recommission region server.
1446   */
1447  default void preRecommissionRegionServer(ObserverContext<MasterCoprocessorEnvironment> ctx,
1448      ServerName server, List<byte[]> encodedRegionNames) throws IOException {}
1449
1450  /**
1451   * Called after recommission region server.
1452   */
1453  default void postRecommissionRegionServer(ObserverContext<MasterCoprocessorEnvironment> ctx,
1454      ServerName server, List<byte[]> encodedRegionNames) throws IOException {}
1455
1456  /**
1457   * Called before switching rpc throttle enabled state.
1458   * @param ctx the coprocessor instance's environment
1459   * @param enable the rpc throttle value
1460   */
1461  default void preSwitchRpcThrottle(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1462      final boolean enable) throws IOException {
1463  }
1464
1465  /**
1466   * Called after switching rpc throttle enabled state.
1467   * @param ctx the coprocessor instance's environment
1468   * @param oldValue the previously rpc throttle value
1469   * @param newValue the newly rpc throttle value
1470   */
1471  default void postSwitchRpcThrottle(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1472      final boolean oldValue, final boolean newValue) throws IOException {
1473  }
1474
1475  /**
1476   * Called before getting if is rpc throttle enabled.
1477   * @param ctx the coprocessor instance's environment
1478   */
1479  default void preIsRpcThrottleEnabled(final ObserverContext<MasterCoprocessorEnvironment> ctx)
1480      throws IOException {
1481  }
1482
1483  /**
1484   * Called after getting if is rpc throttle enabled.
1485   * @param ctx the coprocessor instance's environment
1486   * @param rpcThrottleEnabled the rpc throttle enabled value
1487   */
1488  default void postIsRpcThrottleEnabled(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1489      final boolean rpcThrottleEnabled) throws IOException {
1490  }
1491
1492  /**
1493   * Called before switching exceed throttle quota state.
1494   * @param ctx the coprocessor instance's environment
1495   * @param enable the exceed throttle quota value
1496   */
1497  default void preSwitchExceedThrottleQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
1498      final boolean enable) throws IOException {
1499  }
1500
1501  /**
1502   * Called after switching exceed throttle quota state.
1503   * @param ctx the coprocessor instance's environment
1504   * @param oldValue the previously exceed throttle quota value
1505   * @param newValue the newly exceed throttle quota value
1506   */
1507  default void postSwitchExceedThrottleQuota(
1508      final ObserverContext<MasterCoprocessorEnvironment> ctx, final boolean oldValue,
1509      final boolean newValue) throws IOException {
1510  }
1511
1512  /**
1513   * Called before granting user permissions.
1514   * @param ctx the coprocessor instance's environment
1515   * @param userPermission the user and permissions
1516   * @param mergeExistingPermissions True if merge with previous granted permissions
1517   */
1518  default void preGrant(ObserverContext<MasterCoprocessorEnvironment> ctx,
1519      UserPermission userPermission, boolean mergeExistingPermissions) throws IOException {
1520  }
1521
1522  /**
1523   * Called after granting user permissions.
1524   * @param ctx the coprocessor instance's environment
1525   * @param userPermission the user and permissions
1526   * @param mergeExistingPermissions True if merge with previous granted permissions
1527   */
1528  default void postGrant(ObserverContext<MasterCoprocessorEnvironment> ctx,
1529      UserPermission userPermission, boolean mergeExistingPermissions) throws IOException {
1530  }
1531
1532  /**
1533   * Called before revoking user permissions.
1534   * @param ctx the coprocessor instance's environment
1535   * @param userPermission the user and permissions
1536   */
1537  default void preRevoke(ObserverContext<MasterCoprocessorEnvironment> ctx,
1538      UserPermission userPermission) throws IOException {
1539  }
1540
1541  /**
1542   * Called after revoking user permissions.
1543   * @param ctx the coprocessor instance's environment
1544   * @param userPermission the user and permissions
1545   */
1546  default void postRevoke(ObserverContext<MasterCoprocessorEnvironment> ctx,
1547      UserPermission userPermission) throws IOException {
1548  }
1549
1550  /**
1551   * Called before getting user permissions.
1552   * @param ctx the coprocessor instance's environment
1553   * @param userName the user name, null if get all user permissions
1554   * @param namespace the namespace, null if don't get namespace permission
1555   * @param tableName the table name, null if don't get table permission
1556   * @param family the table column family, null if don't get table family permission
1557   * @param qualifier the table column qualifier, null if don't get table qualifier permission
1558   * @throws IOException if something went wrong
1559   */
1560  default void preGetUserPermissions(ObserverContext<MasterCoprocessorEnvironment> ctx,
1561      String userName, String namespace, TableName tableName, byte[] family, byte[] qualifier)
1562      throws IOException {
1563  }
1564
1565  /**
1566   * Called after getting user permissions.
1567   * @param ctx the coprocessor instance's environment
1568   * @param userName the user name, null if get all user permissions
1569   * @param namespace the namespace, null if don't get namespace permission
1570   * @param tableName the table name, null if don't get table permission
1571   * @param family the table column family, null if don't get table family permission
1572   * @param qualifier the table column qualifier, null if don't get table qualifier permission
1573   * @throws IOException if something went wrong
1574   */
1575  default void postGetUserPermissions(ObserverContext<MasterCoprocessorEnvironment> ctx,
1576      String userName, String namespace, TableName tableName, byte[] family, byte[] qualifier)
1577      throws IOException {
1578  }
1579
1580  /*
1581   * Called before checking if user has permissions.
1582   * @param ctx the coprocessor instance's environment
1583   * @param userName the user name
1584   * @param permissions the permission list
1585   */
1586  default void preHasUserPermissions(ObserverContext<MasterCoprocessorEnvironment> ctx,
1587      String userName, List<Permission> permissions) throws IOException {
1588  }
1589
1590  /**
1591   * Called after checking if user has permissions.
1592   * @param ctx the coprocessor instance's environment
1593   * @param userName the user name
1594   * @param permissions the permission list
1595   */
1596  default void postHasUserPermissions(ObserverContext<MasterCoprocessorEnvironment> ctx,
1597      String userName, List<Permission> permissions) throws IOException {
1598  }
1599}