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.net.Address;
028import org.apache.yetus.audience.InterfaceAudience;
029
030/**
031 * Group user API interface used between client and server.
032 */
033@InterfaceAudience.Private
034public interface RSGroupAdmin {
035  /**
036   * Gets {@code RSGroupInfo} for given group name.
037   */
038  RSGroupInfo getRSGroupInfo(String groupName) throws IOException;
039
040  /**
041   * Gets {@code RSGroupInfo} for the given table's group.
042   */
043  RSGroupInfo getRSGroupInfoOfTable(TableName tableName) throws IOException;
044
045  /**
046   * Move given set of servers to the specified target RegionServer group.
047   */
048  void moveServers(Set<Address> servers, String targetGroup) throws IOException;
049
050  /**
051   * Move given set of tables to the specified target RegionServer group. This will unassign all of
052   * a table's region so it can be reassigned to the correct group.
053   */
054  void moveTables(Set<TableName> tables, String targetGroup) throws IOException;
055
056  /**
057   * Creates a new RegionServer group with the given name.
058   */
059  void addRSGroup(String groupName) throws IOException;
060
061  /**
062   * Removes RegionServer group associated with the given name.
063   */
064  void removeRSGroup(String groupName) throws IOException;
065
066  /**
067   * Balance regions in the given RegionServer group.
068   * @return boolean Whether balance ran or not
069   */
070  default BalanceResponse balanceRSGroup(String groupName) throws IOException {
071    return balanceRSGroup(groupName, BalanceRequest.defaultInstance());
072  }
073
074  /**
075   * Balance regions in the given RegionServer group, running based on the given
076   * {@link BalanceRequest}.
077   * @return boolean Whether balance ran or not
078   */
079  BalanceResponse balanceRSGroup(String groupName, BalanceRequest request) throws IOException;
080
081  /**
082   * Lists current set of RegionServer groups.
083   */
084  List<RSGroupInfo> listRSGroups() throws IOException;
085
086  /**
087   * Retrieve the RSGroupInfo a server is affiliated to
088   * @param hostPort HostPort to get RSGroupInfo for
089   */
090  RSGroupInfo getRSGroupOfServer(Address hostPort) throws IOException;
091
092  /**
093   * Move given set of servers and tables to the specified target RegionServer group.
094   * @param servers     set of servers to move
095   * @param tables      set of tables to move
096   * @param targetGroup the target group name
097   * @throws IOException if moving the server and tables fail
098   */
099  void moveServersAndTables(Set<Address> servers, Set<TableName> tables, String targetGroup)
100    throws IOException;
101
102  /**
103   * Remove decommissioned servers from rsgroup. 1. Sometimes we may find the server aborted due to
104   * some hardware failure and we must offline the server for repairing. Or we need to move some
105   * servers to join other clusters. So we need to remove these servers from the rsgroup. 2.
106   * Dead/recovering/live servers will be disallowed.
107   * @param servers set of servers to remove
108   */
109  void removeServers(Set<Address> servers) throws IOException;
110
111  /**
112   * Rename rsgroup.
113   * @param oldName old rsgroup name
114   * @param newName new rsgroup name
115   */
116  void renameRSGroup(String oldName, String newName) throws IOException;
117
118  /**
119   * Update RSGroup configuration
120   * @param groupName     the group name
121   * @param configuration new configuration of the group name to be set
122   * @throws IOException if a remote or network exception occurs
123   */
124  void updateRSGroupConfig(String groupName, Map<String, String> configuration) throws IOException;
125
126  /**
127   * Update the configuration and trigger an online config change on all the regionservers in the
128   * RSGroup.
129   * @param groupName the group name
130   * @throws IOException if a remote or network exception occurs
131   */
132  void updateConfiguration(String groupName) throws IOException;
133}