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.Arrays; 022import java.util.List; 023import java.util.Map; 024import java.util.Set; 025import java.util.SortedSet; 026import java.util.TreeSet; 027import org.apache.hadoop.hbase.DoNotRetryIOException; 028import org.apache.hadoop.hbase.ServerName; 029import org.apache.hadoop.hbase.TableName; 030import org.apache.hadoop.hbase.client.BalanceRequest; 031import org.apache.hadoop.hbase.client.BalanceResponse; 032import org.apache.hadoop.hbase.master.ServerManager; 033import org.apache.hadoop.hbase.net.Address; 034import org.apache.yetus.audience.InterfaceAudience; 035 036/** 037 * A dummy RSGroupInfoManager which only contains a default rs group. 038 */ 039@InterfaceAudience.Private 040class DisabledRSGroupInfoManager implements RSGroupInfoManager { 041 042 private final ServerManager serverManager; 043 044 public DisabledRSGroupInfoManager(ServerManager serverManager) { 045 this.serverManager = serverManager; 046 } 047 048 @Override 049 public void start() { 050 } 051 052 @Override 053 public void addRSGroup(RSGroupInfo rsGroupInfo) throws IOException { 054 throw new DoNotRetryIOException("RSGroup is disabled"); 055 } 056 057 @Override 058 public void removeRSGroup(String groupName) throws IOException { 059 throw new DoNotRetryIOException("RSGroup is disabled"); 060 } 061 062 @Override 063 public void moveServers(Set<Address> servers, String targetGroupName) throws IOException { 064 throw new DoNotRetryIOException("RSGroup is disabled"); 065 } 066 067 private SortedSet<Address> getOnlineServers() { 068 SortedSet<Address> onlineServers = new TreeSet<Address>(); 069 serverManager.getOnlineServers().keySet().stream().map(ServerName::getAddress) 070 .forEach(onlineServers::add); 071 return onlineServers; 072 } 073 074 @Override 075 public RSGroupInfo getRSGroupOfServer(Address serverHostPort) throws IOException { 076 SortedSet<Address> onlineServers = getOnlineServers(); 077 if (onlineServers.contains(serverHostPort)) { 078 return new RSGroupInfo(RSGroupInfo.DEFAULT_GROUP, onlineServers); 079 } else { 080 return null; 081 } 082 } 083 084 @Override 085 public RSGroupInfo getRSGroup(String groupName) throws IOException { 086 if (RSGroupInfo.DEFAULT_GROUP.equals(groupName)) { 087 return new RSGroupInfo(RSGroupInfo.DEFAULT_GROUP, getOnlineServers()); 088 } else { 089 return null; 090 } 091 } 092 093 @Override 094 public List<RSGroupInfo> listRSGroups() throws IOException { 095 return Arrays.asList(new RSGroupInfo(RSGroupInfo.DEFAULT_GROUP, getOnlineServers())); 096 } 097 098 @Override 099 public boolean isOnline() { 100 return true; 101 } 102 103 @Override 104 public void removeServers(Set<Address> servers) throws IOException { 105 } 106 107 @Override 108 public RSGroupInfo getRSGroupForTable(TableName tableName) throws IOException { 109 return null; 110 } 111 112 @Override 113 public BalanceResponse balanceRSGroup(String groupName, BalanceRequest request) 114 throws IOException { 115 throw new DoNotRetryIOException("RSGroup is disabled"); 116 } 117 118 @Override 119 public void setRSGroup(Set<TableName> tables, String groupName) throws IOException { 120 throw new DoNotRetryIOException("RSGroup is disabled"); 121 } 122 123 @Override 124 public String determineRSGroupInfoForTable(TableName tableName) { 125 return RSGroupInfo.DEFAULT_GROUP; 126 } 127 128 @Override 129 public void renameRSGroup(String oldName, String newName) throws IOException { 130 } 131 132 @Override 133 public void updateRSGroupConfig(String groupName, Map<String, String> configuration) 134 throws IOException { 135 throw new DoNotRetryIOException("RSGroup is disabled"); 136 } 137}