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.coprocessor; 019 020import java.io.IOException; 021import java.net.InetAddress; 022import java.security.cert.X509Certificate; 023import org.apache.hadoop.hbase.HBaseInterfaceAudience; 024import org.apache.yetus.audience.InterfaceAudience; 025import org.apache.yetus.audience.InterfaceStability; 026 027import org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos; 028 029/** 030 * Coprocessors implement this interface to observe and mediate RPC events in Master and RS 031 * instances. 032 * <p> 033 * Since most implementations will be interested in only a subset of hooks, this class uses 034 * 'default' functions to avoid having to add unnecessary overrides. When the functions are 035 * non-empty, it's simply to satisfy the compiler by returning value of expected (non-void) type. It 036 * is done in a way that these default definitions act as no-op. So our suggestion to implementation 037 * would be to not call these 'default' methods from overrides. 038 * <p> 039 * <h3>Exception Handling</h3><br> 040 * For all functions, exception handling is done as follows: 041 * <ul> 042 * <li>Exceptions of type {@link IOException} are reported back to client.</li> 043 * <li>For any other kind of exception: 044 * <ul> 045 * <li>Be aware that this coprocessor doesn't support abortion. If the configuration 046 * {@link CoprocessorHost#ABORT_ON_ERROR_KEY} is set to true, the event will be logged, but the RPC 047 * server won't be aborted.</li> 048 * <li>Otherwise, coprocessor is removed from the server.</li> 049 * </ul> 050 * </li> 051 * </ul> 052 */ 053@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC) 054@InterfaceStability.Evolving 055public interface RpcObserver { 056 057 /** 058 * Called before authorizing connection 059 * @param ctx the coprocessor instance's environment 060 */ 061 default void preAuthorizeConnection(ObserverContext<RpcCoprocessorEnvironment> ctx, 062 RPCProtos.ConnectionHeader connectionHeader, InetAddress remoteAddr) throws IOException { 063 } 064 065 /** 066 * Called after successfully authorizing connection 067 * @param ctx the coprocessor instance's environment 068 * @param userName the user name 069 * @param clientCertificateChain list of peer certificates from SSL connection 070 */ 071 default void postAuthorizeConnection(ObserverContext<RpcCoprocessorEnvironment> ctx, 072 String userName, X509Certificate[] clientCertificateChain) throws IOException { 073 } 074}