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.assignment;
019
020import java.io.IOException;
021
022import org.apache.hadoop.hbase.ServerName;
023import org.apache.hadoop.hbase.client.RegionInfo;
024import org.apache.hadoop.hbase.ipc.HBaseRpcController;
025import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
026import org.apache.yetus.audience.InterfaceAudience;
027
028import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException;
029import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
030import org.apache.hadoop.hbase.shaded.protobuf.RequestConverter;
031import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService;
032import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest;
033import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoResponse;
034
035/**
036 * Utility for this assignment package only.
037 */
038@InterfaceAudience.Private
039class Util {
040  private Util() {}
041
042  /**
043   * Raw call to remote regionserver to get info on a particular region.
044   * @throws IOException Let it out so can report this IOE as reason for failure
045   */
046  static GetRegionInfoResponse getRegionInfoResponse(final MasterProcedureEnv env,
047      final ServerName regionLocation, final RegionInfo hri)
048  throws IOException {
049    return getRegionInfoResponse(env, regionLocation, hri, false);
050  }
051
052  static GetRegionInfoResponse getRegionInfoResponse(final MasterProcedureEnv env,
053      final ServerName regionLocation, final RegionInfo hri, boolean includeBestSplitRow)
054  throws IOException {
055    // TODO: There is no timeout on this controller. Set one!
056    HBaseRpcController controller = env.getMasterServices().getClusterConnection().
057        getRpcControllerFactory().newController();
058    final AdminService.BlockingInterface admin =
059        env.getMasterServices().getClusterConnection().getAdmin(regionLocation);
060    GetRegionInfoRequest request = null;
061    if (includeBestSplitRow) {
062      request = RequestConverter.buildGetRegionInfoRequest(hri.getRegionName(), false, true);
063    } else {
064      request = RequestConverter.buildGetRegionInfoRequest(hri.getRegionName());
065    }
066    try {
067      return admin.getRegionInfo(controller, request);
068    } catch (ServiceException e) {
069      throw ProtobufUtil.handleRemoteException(e);
070    }
071  }
072}