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.security.protocolPB;
020
021import java.io.Closeable;
022import java.io.IOException;
023
024import org.apache.hadoop.ipc.ProtobufHelper;
025import org.apache.hadoop.ipc.ProtocolMetaInterface;
026import org.apache.hadoop.ipc.RPC;
027import org.apache.hadoop.ipc.RpcClientUtil;
028import org.apache.hadoop.security.RefreshUserMappingsProtocol;
029import org.apache.hadoop.security.proto.RefreshUserMappingsProtocolProtos.RefreshSuperUserGroupsConfigurationRequestProto;
030import org.apache.hadoop.security.proto.RefreshUserMappingsProtocolProtos.RefreshUserToGroupsMappingsRequestProto;
031
032import com.google.protobuf.RpcController;
033import com.google.protobuf.ServiceException;
034
035public class RefreshUserMappingsProtocolClientSideTranslatorPB implements
036    ProtocolMetaInterface, RefreshUserMappingsProtocol, Closeable {
037
038  /** RpcController is not used and hence is set to null */
039  private final static RpcController NULL_CONTROLLER = null;
040  private final RefreshUserMappingsProtocolPB rpcProxy;
041  
042  private final static RefreshUserToGroupsMappingsRequestProto 
043  VOID_REFRESH_USER_TO_GROUPS_MAPPING_REQUEST = 
044      RefreshUserToGroupsMappingsRequestProto.newBuilder().build();
045
046  private final static RefreshSuperUserGroupsConfigurationRequestProto
047  VOID_REFRESH_SUPERUSER_GROUPS_CONFIGURATION_REQUEST = 
048      RefreshSuperUserGroupsConfigurationRequestProto.newBuilder().build();
049
050  public RefreshUserMappingsProtocolClientSideTranslatorPB(
051      RefreshUserMappingsProtocolPB rpcProxy) {
052    this.rpcProxy = rpcProxy;
053  }
054
055  @Override
056  public void close() throws IOException {
057    RPC.stopProxy(rpcProxy);
058  }
059
060  @Override
061  public void refreshUserToGroupsMappings() throws IOException {
062    try {
063      rpcProxy.refreshUserToGroupsMappings(NULL_CONTROLLER,
064          VOID_REFRESH_USER_TO_GROUPS_MAPPING_REQUEST);
065    } catch (ServiceException se) {
066      throw ProtobufHelper.getRemoteException(se);
067    }
068  }
069
070  @Override
071  public void refreshSuperUserGroupsConfiguration() throws IOException {
072    try {
073      rpcProxy.refreshSuperUserGroupsConfiguration(NULL_CONTROLLER,
074          VOID_REFRESH_SUPERUSER_GROUPS_CONFIGURATION_REQUEST);
075    } catch (ServiceException se) {
076      throw ProtobufHelper.getRemoteException(se);
077    }
078  }
079
080  @Override
081  public boolean isMethodSupported(String methodName) throws IOException {
082    return RpcClientUtil
083        .isMethodSupported(rpcProxy, RefreshUserMappingsProtocolPB.class,
084            RPC.RpcKind.RPC_PROTOCOL_BUFFER,
085            RPC.getProtocolVersion(RefreshUserMappingsProtocolPB.class),
086            methodName);
087  }
088}