001/* 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020package org.apache.hadoop.hbase.coprocessor; 021 022import java.io.IOException; 023 024import org.apache.hadoop.conf.Configuration; 025import org.apache.hadoop.hbase.CoprocessorEnvironment; 026import org.apache.hadoop.hbase.HBaseInterfaceAudience; 027import org.apache.hadoop.hbase.ServerName; 028import org.apache.hadoop.hbase.client.Connection; 029import org.apache.hadoop.hbase.metrics.MetricRegistry; 030import org.apache.yetus.audience.InterfaceAudience; 031import org.apache.yetus.audience.InterfaceStability; 032 033@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC) 034@InterfaceStability.Evolving 035public interface MasterCoprocessorEnvironment extends CoprocessorEnvironment<MasterCoprocessor> { 036 /** 037 * @return Hosting Server's ServerName 038 */ 039 ServerName getServerName(); 040 041 /** 042 * Returns the hosts' Connection to the Cluster. <b>Do not close! This is a shared connection 043 * with the hosting server. Throws {@link UnsupportedOperationException} if you try to close 044 * or abort it</b>. 045 * 046 * For light-weight usage only. Heavy-duty usage will pull down 047 * the hosting RegionServer responsiveness as well as that of other Coprocessors making use of 048 * this Connection. Use to create table on start or to do administrative operations. Coprocessors 049 * should create their own Connections if heavy usage to avoid impinging on hosting Server 050 * operation. To create a Connection or if a Coprocessor requires a region with a particular 051 * Configuration, use {@link org.apache.hadoop.hbase.client.ConnectionFactory} or 052 * {@link #createConnection(Configuration)}}. 053 * 054 * <p>Be aware that operations that make use of this Connection are executed as the RegionServer 055 * User, the hbase super user that started this server process. Exercise caution running 056 * operations as this User (See {@link #createConnection(Configuration)}} to run as other than 057 * the RegionServer User). 058 * 059 * <p>Be careful RPC'ing from a Coprocessor context. RPC's will fail, stall, retry, and/or crawl 060 * because the remote side is not online, is struggling or it is on the other side of a network 061 * partition. Any use of Connection from inside a Coprocessor must be able to handle all such 062 * hiccups. 063 * 064 * @see #createConnection(Configuration) 065 * @return The host's Connection to the Cluster. 066 */ 067 Connection getConnection(); 068 069 /** 070 * Creates a cluster connection using the passed Configuration. 071 * 072 * Creating a Connection is a heavy-weight operation. The resultant Connection's cache of 073 * region locations will be empty. Therefore you should cache and reuse Connections rather than 074 * create a Connection on demand. Create on start of your Coprocessor. You will have to cast 075 * the CoprocessorEnvironment appropriately to get at this API at start time because 076 * Coprocessor start method is passed a subclass of this CoprocessorEnvironment or fetch 077 * Connection using a synchronized accessor initializing the Connection on first access. Close 078 * the returned Connection when done to free resources. Using this API rather 079 * than {@link org.apache.hadoop.hbase.client.ConnectionFactory#createConnection(Configuration)} 080 * returns a Connection that will short-circuit RPC if the target is a local resource. Use 081 * ConnectionFactory if you don't need this ability. 082 * 083 * <p>Be careful RPC'ing from a Coprocessor context. RPC's will fail, stall, retry, and/or crawl 084 * because the remote side is not online, is struggling or it is on the other side of a network 085 * partition. Any use of Connection from inside a Coprocessor must be able to handle all such 086 * hiccups. 087 * @return Connection created using the passed conf. 088 */ 089 Connection createConnection(Configuration conf) throws IOException; 090 091 /** 092 * Returns a MetricRegistry that can be used to track metrics at the master level. 093 * 094 * <p>See ExampleMasterObserverWithMetrics class in the hbase-examples modules for examples 095 * of how metrics can be instantiated and used.</p> 096 * @return A MetricRegistry for the coprocessor class to track and export metrics. 097 */ 098 MetricRegistry getMetricRegistryForMaster(); 099}