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.procedure; 019 020import java.io.IOException; 021import org.apache.hadoop.hbase.Stoppable; 022import org.apache.hadoop.hbase.master.MasterServices; 023import org.apache.hadoop.hbase.master.MetricsMaster; 024import org.apache.hadoop.hbase.security.User; 025import org.apache.hadoop.hbase.security.access.AccessChecker; 026import org.apache.yetus.audience.InterfaceAudience; 027import org.apache.zookeeper.KeeperException; 028 029import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ProcedureDescription; 030 031/** 032 * A life-cycle management interface for globally barriered procedures on master. See the following 033 * doc on details of globally barriered procedure: 034 * https://issues.apache.org/jira/secure/attachment/12555103/121127-global-barrier-proc.pdf To 035 * implement a custom globally barriered procedure, user needs to extend two classes: 036 * {@link MasterProcedureManager} and {@link RegionServerProcedureManager}. Implementation of 037 * {@link MasterProcedureManager} is loaded into {@link org.apache.hadoop.hbase.master.HMaster} 038 * process via configuration parameter 'hbase.procedure.master.classes', while implementation of 039 * {@link RegionServerProcedureManager} is loaded into 040 * {@link org.apache.hadoop.hbase.regionserver.HRegionServer} process via configuration parameter 041 * 'hbase.procedure.regionserver.classes'. An example of globally barriered procedure implementation 042 * is {@link org.apache.hadoop.hbase.master.snapshot.SnapshotManager} and 043 * {@link org.apache.hadoop.hbase.regionserver.snapshot.RegionServerSnapshotManager}. A globally 044 * barriered procedure is identified by its signature (usually it is the name of the procedure 045 * znode). During the initialization phase, the initialize methods are called by both 046 * {@link org.apache.hadoop.hbase.master.HMaster} and 047 * {@link org.apache.hadoop.hbase.regionserver.HRegionServer} which create the procedure znode and 048 * register the listeners. A procedure can be triggered by its signature and an instant name 049 * (encapsulated in a {@link ProcedureDescription} object). When the servers are shutdown, the stop 050 * methods on both classes are called to clean up the data associated with the procedure. 051 */ 052@InterfaceAudience.Private 053public abstract class MasterProcedureManager extends ProcedureManager implements Stoppable { 054 /** 055 * Initialize a globally barriered procedure for master. 056 * @param master Master service interface 057 */ 058 public abstract void initialize(MasterServices master, MetricsMaster metricsMaster) 059 throws KeeperException, IOException, UnsupportedOperationException; 060 061 /** 062 * Execute a distributed procedure on cluster 063 * @param desc Procedure description 064 */ 065 public void execProcedure(ProcedureDescription desc) throws IOException { 066 } 067 068 /** 069 * Execute a distributed procedure on cluster with return data. 070 * @param desc Procedure description 071 * @return data returned from the procedure execution, null if no data 072 */ 073 public byte[] execProcedureWithRet(ProcedureDescription desc) throws IOException { 074 return null; 075 } 076 077 /** 078 * Check for required permissions before executing the procedure. 079 * @throws IOException if permissions requirements are not met. 080 */ 081 public abstract void checkPermissions(ProcedureDescription desc, AccessChecker accessChecker, 082 User user) throws IOException; 083 084 /** 085 * Check if the procedure is finished successfully 086 * @param desc Procedure description 087 * @return true if the specified procedure is finished successfully 088 */ 089 public abstract boolean isProcedureDone(ProcedureDescription desc) throws IOException; 090}