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 */
018
019package org.apache.hadoop.hbase.master;
020
021import org.apache.hadoop.hbase.client.VersionInfoUtil;
022import org.apache.yetus.audience.InterfaceAudience;
023
024import org.apache.hbase.thirdparty.com.google.protobuf.RpcController;
025import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException;
026
027import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos;
028
029/**
030 * A wrapper class for MasterRpcServices shortcut that ensures a client version is available
031 * to the callee without a current RPC call.
032 */
033@InterfaceAudience.Private
034public class MasterRpcServicesVersionWrapper
035    implements RegionServerStatusProtos.RegionServerStatusService.BlockingInterface {
036
037  @FunctionalInterface
038  public interface ServiceCallFunction<Req, Resp>
039      extends VersionInfoUtil.ServiceCallFunction<RpcController, Req, Resp, ServiceException> {
040  }
041
042  private final MasterRpcServices masterRpcServices;
043  private final ServiceCallFunction<RegionServerStatusProtos.RegionServerStartupRequest,
044    RegionServerStatusProtos.RegionServerStartupResponse> startupCall;
045  private final ServiceCallFunction<RegionServerStatusProtos.RegionServerReportRequest,
046    RegionServerStatusProtos.RegionServerReportResponse> reportCall;
047
048
049  public MasterRpcServicesVersionWrapper(MasterRpcServices masterRpcServices) {
050    this.masterRpcServices = masterRpcServices;
051    this.startupCall = (c, req) -> masterRpcServices.regionServerStartup(c, req);
052    this.reportCall = (c, req) -> masterRpcServices.regionServerReport(c, req);
053  }
054
055  @Override
056  public RegionServerStatusProtos.RegionServerStartupResponse regionServerStartup(
057      RpcController controller, RegionServerStatusProtos.RegionServerStartupRequest request)
058      throws ServiceException {
059    return VersionInfoUtil.callWithVersion(startupCall, controller, request);
060  }
061
062  @Override
063  public RegionServerStatusProtos.RegionServerReportResponse regionServerReport(
064      RpcController controller, RegionServerStatusProtos.RegionServerReportRequest request)
065      throws ServiceException {
066    return VersionInfoUtil.callWithVersion(reportCall, controller, request);
067  }
068
069  @Override
070  public RegionServerStatusProtos.ReportRSFatalErrorResponse reportRSFatalError(
071      RpcController controller, RegionServerStatusProtos.ReportRSFatalErrorRequest request)
072      throws ServiceException {
073    return masterRpcServices.reportRSFatalError(controller, request);
074  }
075
076  @Override
077  public RegionServerStatusProtos.GetLastFlushedSequenceIdResponse getLastFlushedSequenceId(
078      RpcController controller, RegionServerStatusProtos.GetLastFlushedSequenceIdRequest request)
079      throws ServiceException {
080    return masterRpcServices.getLastFlushedSequenceId(controller, request);
081  }
082
083  @Override
084  public RegionServerStatusProtos.ReportRegionStateTransitionResponse reportRegionStateTransition(
085      RpcController controller,
086      RegionServerStatusProtos.ReportRegionStateTransitionRequest request)
087      throws ServiceException {
088    return masterRpcServices.reportRegionStateTransition(controller, request);
089  }
090
091  @Override
092  public RegionServerStatusProtos.RegionSpaceUseReportResponse reportRegionSpaceUse(
093      RpcController controller, RegionServerStatusProtos.RegionSpaceUseReportRequest request)
094      throws ServiceException {
095    return masterRpcServices.reportRegionSpaceUse(controller, request);
096  }
097
098  @Override
099  public RegionServerStatusProtos.ReportProcedureDoneResponse reportProcedureDone(
100      RpcController controller, RegionServerStatusProtos.ReportProcedureDoneRequest request)
101      throws ServiceException {
102    return masterRpcServices.reportProcedureDone(controller, request);
103  }
104
105  @Override
106  public RegionServerStatusProtos.FileArchiveNotificationResponse reportFileArchival(
107      RpcController controller, RegionServerStatusProtos.FileArchiveNotificationRequest request)
108      throws ServiceException {
109    return masterRpcServices.reportFileArchival(controller, request);
110  }
111}