001/**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019package org.apache.hadoop.hbase.master.normalizer;
020
021import java.util.Arrays;
022import org.apache.hadoop.hbase.client.Admin;
023import org.apache.hadoop.hbase.client.RegionInfo;
024import org.apache.yetus.audience.InterfaceAudience;
025import org.slf4j.Logger;
026import org.slf4j.LoggerFactory;
027
028/**
029 * Normalization plan to split region.
030 */
031@InterfaceAudience.Private
032public class SplitNormalizationPlan implements NormalizationPlan {
033  private static final Logger LOG = LoggerFactory.getLogger(SplitNormalizationPlan.class.getName());
034
035  private RegionInfo regionInfo;
036  private byte[] splitPoint;
037
038  public SplitNormalizationPlan(RegionInfo regionInfo, byte[] splitPoint) {
039    this.regionInfo = regionInfo;
040    this.splitPoint = splitPoint;
041  }
042
043  @Override
044  public PlanType getType() {
045    return PlanType.SPLIT;
046  }
047
048  public RegionInfo getRegionInfo() {
049    return regionInfo;
050  }
051
052  public void setRegionInfo(RegionInfo regionInfo) {
053    this.regionInfo = regionInfo;
054  }
055
056  public byte[] getSplitPoint() {
057    return splitPoint;
058  }
059
060  public void setSplitPoint(byte[] splitPoint) {
061    this.splitPoint = splitPoint;
062  }
063
064  @Override
065  public String toString() {
066    return "SplitNormalizationPlan{" +
067      "regionInfo=" + regionInfo +
068      ", splitPoint=" + Arrays.toString(splitPoint) +
069      '}';
070  }
071
072  /**
073   * {@inheritDoc}
074   */
075  @Override
076  public void execute(Admin admin) {
077    LOG.info("Executing splitting normalization plan: " + this);
078    try {
079      admin.splitRegionAsync(regionInfo.getRegionName()).get();
080    } catch (Exception ex) {
081      LOG.error("Error during region split: ", ex);
082    }
083  }
084}