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.tools.protocolPB;
020
021 import java.io.Closeable;
022 import java.io.IOException;
023 import org.apache.hadoop.ipc.ProtobufHelper;
024 import org.apache.hadoop.ipc.ProtocolMetaInterface;
025 import org.apache.hadoop.ipc.RPC;
026 import org.apache.hadoop.ipc.RpcClientUtil;
027 import org.apache.hadoop.tools.GetUserMappingsProtocol;
028 import org.apache.hadoop.tools.proto.GetUserMappingsProtocolProtos.GetGroupsForUserRequestProto;
029 import org.apache.hadoop.tools.proto.GetUserMappingsProtocolProtos.GetGroupsForUserResponseProto;
030
031 import com.google.protobuf.RpcController;
032 import com.google.protobuf.ServiceException;
033
034 public class GetUserMappingsProtocolClientSideTranslatorPB implements
035 ProtocolMetaInterface, GetUserMappingsProtocol, Closeable {
036
037 /** RpcController is not used and hence is set to null */
038 private final static RpcController NULL_CONTROLLER = null;
039 private final GetUserMappingsProtocolPB rpcProxy;
040
041 public GetUserMappingsProtocolClientSideTranslatorPB(
042 GetUserMappingsProtocolPB rpcProxy) {
043 this.rpcProxy = rpcProxy;
044 }
045
046 @Override
047 public void close() throws IOException {
048 RPC.stopProxy(rpcProxy);
049 }
050
051 @Override
052 public String[] getGroupsForUser(String user) throws IOException {
053 GetGroupsForUserRequestProto request = GetGroupsForUserRequestProto
054 .newBuilder().setUser(user).build();
055 GetGroupsForUserResponseProto resp;
056 try {
057 resp = rpcProxy.getGroupsForUser(NULL_CONTROLLER, request);
058 } catch (ServiceException se) {
059 throw ProtobufHelper.getRemoteException(se);
060 }
061 return resp.getGroupsList().toArray(new String[resp.getGroupsCount()]);
062 }
063
064 @Override
065 public boolean isMethodSupported(String methodName) throws IOException {
066 return RpcClientUtil.isMethodSupported(rpcProxy,
067 GetUserMappingsProtocolPB.class, RPC.RpcKind.RPC_PROTOCOL_BUFFER,
068 RPC.getProtocolVersion(GetUserMappingsProtocolPB.class), methodName);
069 }
070 }