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;
019
020import org.apache.hadoop.hbase.client.VersionInfoUtil;
021import org.apache.yetus.audience.InterfaceAudience;
022
023import org.apache.hbase.thirdparty.com.google.protobuf.RpcController;
024import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException;
025
026import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos;
027import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.GetLiveRegionServersRequest;
028import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.GetLiveRegionServersResponse;
029
030/**
031 * A wrapper class for MasterRpcServices shortcut that ensures a client version is available to the
032 * callee without a current RPC call.
033 */
034@InterfaceAudience.Private
035public class MasterRpcServicesVersionWrapper
036  implements RegionServerStatusProtos.RegionServerStatusService.BlockingInterface {
037
038  @FunctionalInterface
039  public interface ServiceCallFunction<Req, Resp>
040    extends VersionInfoUtil.ServiceCallFunction<RpcController, Req, Resp, ServiceException> {
041  }
042
043  private final MasterRpcServices masterRpcServices;
044  private final ServiceCallFunction<RegionServerStatusProtos.RegionServerStartupRequest,
045    RegionServerStatusProtos.RegionServerStartupResponse> startupCall;
046  private final ServiceCallFunction<RegionServerStatusProtos.RegionServerReportRequest,
047    RegionServerStatusProtos.RegionServerReportResponse> reportCall;
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, RegionServerStatusProtos.ReportRegionStateTransitionRequest request)
086    throws ServiceException {
087    return masterRpcServices.reportRegionStateTransition(controller, request);
088  }
089
090  @Override
091  public RegionServerStatusProtos.RegionSpaceUseReportResponse reportRegionSpaceUse(
092    RpcController controller, RegionServerStatusProtos.RegionSpaceUseReportRequest request)
093    throws ServiceException {
094    return masterRpcServices.reportRegionSpaceUse(controller, request);
095  }
096
097  @Override
098  public RegionServerStatusProtos.ReportProcedureDoneResponse reportProcedureDone(
099    RpcController controller, RegionServerStatusProtos.ReportProcedureDoneRequest request)
100    throws ServiceException {
101    return masterRpcServices.reportProcedureDone(controller, request);
102  }
103
104  @Override
105  public RegionServerStatusProtos.FileArchiveNotificationResponse reportFileArchival(
106    RpcController controller, RegionServerStatusProtos.FileArchiveNotificationRequest request)
107    throws ServiceException {
108    return masterRpcServices.reportFileArchival(controller, request);
109  }
110
111  @Override
112  public GetLiveRegionServersResponse getLiveRegionServers(RpcController controller,
113    GetLiveRegionServersRequest request) throws ServiceException {
114    return masterRpcServices.getLiveRegionServers(controller, request);
115  }
116}