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.balancer; 019 020import java.util.List; 021import org.apache.hadoop.hbase.HConstants; 022import org.apache.hadoop.hbase.master.RegionPlan; 023import org.apache.yetus.audience.InterfaceAudience; 024 025import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList; 026 027@InterfaceAudience.Private 028class AssignRegionAction extends BalanceAction { 029 private final int region; 030 private final int server; 031 032 public AssignRegionAction(int region, int server) { 033 super(Type.ASSIGN_REGION); 034 this.region = region; 035 this.server = server; 036 } 037 038 public int getRegion() { 039 return region; 040 } 041 042 public int getServer() { 043 return server; 044 } 045 046 @Override 047 public BalanceAction undoAction() { 048 // TODO implement this. This action is not being used by the StochasticLB for now 049 // in case it uses it, we should implement this function. 050 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED); 051 } 052 053 @Override 054 List<RegionPlan> toRegionPlans(BalancerClusterState cluster) { 055 return ImmutableList 056 .of(new RegionPlan(cluster.regions[getRegion()], null, cluster.servers[getServer()])); 057 } 058 059 @Override 060 public String toString() { 061 return getType() + ": " + region + ":" + server; 062 } 063}