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.rsgroup;
019
020import java.io.IOException;
021import java.util.List;
022import java.util.Map;
023import java.util.Set;
024import org.apache.hadoop.hbase.TableName;
025import org.apache.hadoop.hbase.client.BalanceRequest;
026import org.apache.hadoop.hbase.client.BalanceResponse;
027import org.apache.hadoop.hbase.master.MasterServices;
028import org.apache.hadoop.hbase.net.Address;
029import org.apache.yetus.audience.InterfaceAudience;
030
031/**
032 * Interface used to manage RSGroupInfo storage. An implementation has the option to support offline
033 * mode. See {@code RSGroupBasedLoadBalancer}.
034 */
035@InterfaceAudience.Private
036public interface RSGroupInfoManager {
037
038  void start();
039
040  /**
041   * Add given RSGroupInfo to existing list of group infos.
042   */
043  void addRSGroup(RSGroupInfo rsGroupInfo) throws IOException;
044
045  /**
046   * Remove a region server group.
047   */
048  void removeRSGroup(String groupName) throws IOException;
049
050  /**
051   * Move servers to a new group.
052   */
053  void moveServers(Set<Address> servers, String targetGroupName) throws IOException;
054
055  /**
056   * Gets the group info of server.
057   */
058  RSGroupInfo getRSGroupOfServer(Address serverHostPort) throws IOException;
059
060  /**
061   * Gets {@code RSGroupInfo} for the given group name.
062   */
063  RSGroupInfo getRSGroup(String groupName) throws IOException;
064
065  /**
066   * List the existing {@code RSGroupInfo}s.
067   */
068  List<RSGroupInfo> listRSGroups() throws IOException;
069
070  /**
071   * Whether the manager is able to fully return group metadata
072   * @return whether the manager is in online mode
073   */
074  boolean isOnline();
075
076  /**
077   * Remove decommissioned servers from rsgroup
078   * @param servers set of servers to remove
079   */
080  void removeServers(Set<Address> servers) throws IOException;
081
082  /**
083   * Get {@code RSGroupInfo} for the given table.
084   */
085  RSGroupInfo getRSGroupForTable(TableName tableName) throws IOException;
086
087  static RSGroupInfoManager create(MasterServices master) throws IOException {
088    if (RSGroupUtil.isRSGroupEnabled(master.getConfiguration())) {
089      return RSGroupInfoManagerImpl.getInstance(master);
090    } else {
091      return new DisabledRSGroupInfoManager(master.getServerManager());
092    }
093  }
094
095  /**
096   * Balance a region server group.
097   */
098  BalanceResponse balanceRSGroup(String groupName, BalanceRequest request) throws IOException;
099
100  /**
101   * Set group for tables.
102   */
103  void setRSGroup(Set<TableName> tables, String groupName) throws IOException;
104
105  /**
106   * Determine {@code RSGroupInfo} for the given table.
107   * @param tableName table name
108   * @return rsgroup name
109   */
110  String determineRSGroupInfoForTable(TableName tableName);
111
112  /**
113   * Rename rsgroup
114   * @param oldName old rsgroup name
115   * @param newName new rsgroup name
116   */
117  void renameRSGroup(String oldName, String newName) throws IOException;
118
119  /**
120   * Update RSGroup configuration
121   * @param groupName     the group name
122   * @param configuration new configuration of the group name to be set
123   * @throws IOException if a remote or network exception occurs
124   */
125  void updateRSGroupConfig(String groupName, Map<String, String> configuration) throws IOException;
126
127}