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.RefreshAuthorizationPolicyProtocolProtos.RefreshServiceAclRequestProto;
025    import org.apache.hadoop.ipc.ProtobufHelper;
026    import org.apache.hadoop.ipc.ProtocolMetaInterface;
027    import org.apache.hadoop.ipc.RPC;
028    import org.apache.hadoop.ipc.RpcClientUtil;
029    import org.apache.hadoop.security.authorize.RefreshAuthorizationPolicyProtocol;
030    
031    import com.google.protobuf.RpcController;
032    import com.google.protobuf.ServiceException;
033    
034    public class RefreshAuthorizationPolicyProtocolClientSideTranslatorPB implements
035        ProtocolMetaInterface, RefreshAuthorizationPolicyProtocol, Closeable {
036    
037      /** RpcController is not used and hence is set to null */
038      private final static RpcController NULL_CONTROLLER = null;
039      private final RefreshAuthorizationPolicyProtocolPB rpcProxy;
040      
041      private final static RefreshServiceAclRequestProto
042      VOID_REFRESH_SERVICE_ACL_REQUEST =
043          RefreshServiceAclRequestProto.newBuilder().build();
044    
045      public RefreshAuthorizationPolicyProtocolClientSideTranslatorPB(
046          RefreshAuthorizationPolicyProtocolPB rpcProxy) {
047        this.rpcProxy = rpcProxy;
048      }
049    
050      @Override
051      public void close() throws IOException {
052        RPC.stopProxy(rpcProxy);
053      }
054    
055      @Override
056      public void refreshServiceAcl() throws IOException {
057        try {
058          rpcProxy.refreshServiceAcl(NULL_CONTROLLER,
059              VOID_REFRESH_SERVICE_ACL_REQUEST);
060        } catch (ServiceException se) {
061          throw ProtobufHelper.getRemoteException(se);
062        }
063      }
064    
065      @Override
066      public boolean isMethodSupported(String methodName) throws IOException {
067        return RpcClientUtil.isMethodSupported(rpcProxy,
068            RefreshAuthorizationPolicyProtocolPB.class,
069            RPC.RpcKind.RPC_PROTOCOL_BUFFER,
070            RPC.getProtocolVersion(RefreshAuthorizationPolicyProtocolPB.class),
071            methodName);
072      }
073    }