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.io.IOException;
022import java.util.Arrays;
023
024import org.apache.hadoop.hbase.client.Admin;
025import org.apache.hadoop.hbase.client.RegionInfo;
026import org.apache.yetus.audience.InterfaceAudience;
027import org.slf4j.Logger;
028import org.slf4j.LoggerFactory;
029
030/**
031 * Normalization plan to split region.
032 */
033@InterfaceAudience.Private
034public class SplitNormalizationPlan implements NormalizationPlan {
035  private static final Logger LOG = LoggerFactory.getLogger(SplitNormalizationPlan.class.getName());
036
037  private RegionInfo regionInfo;
038  private byte[] splitPoint;
039
040  public SplitNormalizationPlan(RegionInfo regionInfo, byte[] splitPoint) {
041    this.regionInfo = regionInfo;
042    this.splitPoint = splitPoint;
043  }
044
045  @Override
046  public PlanType getType() {
047    return PlanType.SPLIT;
048  }
049
050  public RegionInfo getRegionInfo() {
051    return regionInfo;
052  }
053
054  public void setRegionInfo(RegionInfo regionInfo) {
055    this.regionInfo = regionInfo;
056  }
057
058  public byte[] getSplitPoint() {
059    return splitPoint;
060  }
061
062  public void setSplitPoint(byte[] splitPoint) {
063    this.splitPoint = splitPoint;
064  }
065
066  @Override
067  public String toString() {
068    return "SplitNormalizationPlan{" +
069      "regionInfo=" + regionInfo +
070      ", splitPoint=" + Arrays.toString(splitPoint) +
071      '}';
072  }
073
074  /**
075   * {@inheritDoc}
076   */
077  @Override
078  public void execute(Admin admin) {
079    LOG.info("Executing splitting normalization plan: " + this);
080    try {
081      admin.splitRegion(regionInfo.getRegionName());
082    } catch (IOException ex) {
083      LOG.error("Error during region split: ", ex);
084    }
085  }
086}