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.Optional; 022import org.apache.hadoop.hbase.TableName; 023import org.apache.hadoop.hbase.client.TableDescriptor; 024import org.apache.hadoop.hbase.client.TableDescriptorBuilder; 025import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; 026import org.apache.hadoop.hbase.master.procedure.ModifyTableDescriptorProcedure; 027import org.apache.yetus.audience.InterfaceAudience; 028import org.slf4j.Logger; 029import org.slf4j.LoggerFactory; 030 031/** 032 * Procedure for migrating rs group information to table descriptor. 033 */ 034@InterfaceAudience.Private 035public class MigrateRSGroupProcedure extends ModifyTableDescriptorProcedure { 036 037 private static final Logger LOG = LoggerFactory.getLogger(MigrateRSGroupProcedure.class); 038 039 public MigrateRSGroupProcedure() { 040 } 041 042 public MigrateRSGroupProcedure(MasterProcedureEnv env, TableName tableName) { 043 super(env, tableName); 044 } 045 046 @Override 047 protected Optional<TableDescriptor> modify(MasterProcedureEnv env, TableDescriptor current) 048 throws IOException { 049 if (current.getRegionServerGroup().isPresent()) { 050 // usually this means user has set the rs group using the new code which will set the group 051 // directly on table descriptor, skip. 052 LOG.debug("Skip migrating {} since it is already in group {}", current.getTableName(), 053 current.getRegionServerGroup().get()); 054 return Optional.empty(); 055 } 056 RSGroupInfo group = 057 env.getMasterServices().getRSGroupInfoManager().getRSGroupForTable(current.getTableName()); 058 if (group == null) { 059 LOG.debug("RSGroup for table {} is empty when migrating, usually this should not happen" 060 + " unless we have removed the RSGroup, ignore...", current.getTableName()); 061 return Optional.empty(); 062 } 063 return Optional 064 .of(TableDescriptorBuilder.newBuilder(current).setRegionServerGroup(group.getName()).build()); 065 } 066}