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    
019    package org.apache.hadoop.hdfs.protocolPB;
020    
021    import java.io.Closeable;
022    import java.io.IOException;
023    
024    import org.apache.hadoop.hdfs.protocol.proto.RefreshUserMappingsProtocolProtos.RefreshSuperUserGroupsConfigurationRequestProto;
025    import org.apache.hadoop.hdfs.protocol.proto.RefreshUserMappingsProtocolProtos.RefreshUserToGroupsMappingsRequestProto;
026    import org.apache.hadoop.ipc.ProtobufHelper;
027    import org.apache.hadoop.ipc.ProtocolMetaInterface;
028    import org.apache.hadoop.ipc.RPC;
029    import org.apache.hadoop.ipc.RpcClientUtil;
030    import org.apache.hadoop.security.RefreshUserMappingsProtocol;
031    
032    import com.google.protobuf.RpcController;
033    import com.google.protobuf.ServiceException;
034    
035    public 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      public RefreshUserMappingsProtocolClientSideTranslatorPB(
043          RefreshUserMappingsProtocolPB rpcProxy) {
044        this.rpcProxy = rpcProxy;
045      }
046    
047      @Override
048      public void close() throws IOException {
049        RPC.stopProxy(rpcProxy);
050      }
051    
052      @Override
053      public void refreshUserToGroupsMappings() throws IOException {
054        RefreshUserToGroupsMappingsRequestProto request = 
055            RefreshUserToGroupsMappingsRequestProto.newBuilder().build();
056        try {
057          rpcProxy.refreshUserToGroupsMappings(NULL_CONTROLLER, request);
058        } catch (ServiceException se) {
059          throw ProtobufHelper.getRemoteException(se);
060        }
061      }
062    
063      @Override
064      public void refreshSuperUserGroupsConfiguration() throws IOException {
065        RefreshSuperUserGroupsConfigurationRequestProto request = 
066            RefreshSuperUserGroupsConfigurationRequestProto.newBuilder().build();
067        try {
068          rpcProxy.refreshSuperUserGroupsConfiguration(NULL_CONTROLLER, request);
069        } catch (ServiceException se) {
070          throw ProtobufHelper.getRemoteException(se);
071        }
072      }
073    
074      @Override
075      public boolean isMethodSupported(String methodName) throws IOException {
076        return RpcClientUtil
077            .isMethodSupported(rpcProxy, RefreshUserMappingsProtocolPB.class,
078                RPC.RpcKind.RPC_PROTOCOL_BUFFER,
079                RPC.getProtocolVersion(RefreshUserMappingsProtocolPB.class),
080                methodName);
081      }
082    }