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.master.normalizer; 019 020import org.apache.hadoop.conf.Configuration; 021import org.apache.hadoop.hbase.HConstants; 022import org.apache.hadoop.hbase.TableName; 023import org.apache.hadoop.hbase.master.HMaster; 024import org.apache.hadoop.hbase.zookeeper.RegionNormalizerTracker; 025import org.apache.hadoop.hbase.zookeeper.ZKWatcher; 026import org.apache.hadoop.util.ReflectionUtils; 027import org.apache.yetus.audience.InterfaceAudience; 028 029/** 030 * Factory to create instance of {@link RegionNormalizer} as configured. 031 */ 032@InterfaceAudience.Private 033public final class RegionNormalizerFactory { 034 035 private RegionNormalizerFactory() { 036 } 037 038 public static RegionNormalizerManager createNormalizerManager( 039 final Configuration conf, 040 final ZKWatcher zkWatcher, 041 final HMaster master // TODO: consolidate this down to MasterServices 042 ) { 043 final RegionNormalizer regionNormalizer = getRegionNormalizer(conf); 044 regionNormalizer.setMasterServices(master); 045 final RegionNormalizerTracker tracker = new RegionNormalizerTracker(zkWatcher, master); 046 final RegionNormalizerChore chore = 047 master.isInMaintenanceMode() ? null : new RegionNormalizerChore(master); 048 final RegionNormalizerWorkQueue<TableName> workQueue = 049 master.isInMaintenanceMode() ? null : new RegionNormalizerWorkQueue<>(); 050 final RegionNormalizerWorker worker = master.isInMaintenanceMode() 051 ? null 052 : new RegionNormalizerWorker(conf, master, regionNormalizer, workQueue); 053 return new RegionNormalizerManager(tracker, chore, workQueue, worker); 054 } 055 056 /** 057 * Create a region normalizer from the given conf. 058 * @param conf configuration 059 * @return {@link RegionNormalizer} implementation 060 */ 061 private static RegionNormalizer getRegionNormalizer(Configuration conf) { 062 // Create instance of Region Normalizer 063 Class<? extends RegionNormalizer> balancerKlass = 064 conf.getClass(HConstants.HBASE_MASTER_NORMALIZER_CLASS, SimpleRegionNormalizer.class, 065 RegionNormalizer.class); 066 return ReflectionUtils.newInstance(balancerKlass, conf); 067 } 068}