@Override public ClientNamenodeProtocolProtos.GetMissingBlockLocationsResponseProto getMissingBlockLocations( RpcController controller, ClientNamenodeProtocolProtos.GetMissingBlockLocationsRequestProto req) throws ServiceException { try { LocatedBlocks b = server.getMissingBlockLocations(req.getFilePath()); ClientNamenodeProtocolProtos.GetMissingBlockLocationsResponseProto.Builder builder = ClientNamenodeProtocolProtos.GetMissingBlockLocationsResponseProto .newBuilder(); if (b != null) { builder.setLocations(PBHelper.convert(b)).build(); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ClientNamenodeProtocolProtos.GetBlockChecksumResponseProto getBlockChecksum( RpcController controller, ClientNamenodeProtocolProtos.GetBlockChecksumRequestProto req) throws ServiceException { try { long checksum = server.getBlockChecksum(req.getSrc(), req.getBlockIndex()); ClientNamenodeProtocolProtos.GetBlockChecksumResponseProto.Builder builder = ClientNamenodeProtocolProtos.GetBlockChecksumResponseProto .newBuilder().setChecksum(checksum); return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ClientNamenodeProtocolProtos.GetEncodingStatusResponseProto getEncodingStatus( RpcController controller, ClientNamenodeProtocolProtos.GetEncodingStatusRequestProto request) throws ServiceException { try { EncodingStatus status = server.getEncodingStatus(request.getPath()); ClientNamenodeProtocolProtos.GetEncodingStatusResponseProto.Builder builder = ClientNamenodeProtocolProtos.GetEncodingStatusResponseProto .newBuilder(); builder.setEncodingStatus(PBHelper.convert(status)); return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ClientNamenodeProtocolProtos.GetRepairedBlockLocationsResponseProto getRepairedBlockLocations( RpcController controller, ClientNamenodeProtocolProtos.GetRepairedBlockLocationsRequsestProto request) throws ServiceException { try { LocatedBlock b = server.getRepairedBlockLocations(request.getSourcePath(), request.getParityPath(), PBHelper.convert(request.getBlock()), request.getIsParity()); ClientNamenodeProtocolProtos.GetRepairedBlockLocationsResponseProto.Builder builder = ClientNamenodeProtocolProtos.GetRepairedBlockLocationsResponseProto .newBuilder(); if (b != null) { builder.setLocatedBlocks(PBHelper.convert(b)).build(); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public LocatedBlock getRepairedBlockLocations(String sourcePath, String parityPath, LocatedBlock block, boolean isParity) throws IOException { ClientNamenodeProtocolProtos.GetRepairedBlockLocationsRequsestProto request = ClientNamenodeProtocolProtos.GetRepairedBlockLocationsRequsestProto .newBuilder().setSourcePath(sourcePath).setParityPath(parityPath) .setIsParity(isParity).setBlock(PBHelper.convert(block)).build(); try { return PBHelper.convert( rpcProxy.getRepairedBlockLocations(null, request).getLocatedBlocks()); } catch (ServiceException e) { throw ProtobufHelper.getRemoteException(e); } }
@Override public void flushCache(String userName, String groupName) throws IOException { try { ClientNamenodeProtocolProtos.FlushUsersCacheRequestProto.Builder req = ClientNamenodeProtocolProtos.FlushUsersCacheRequestProto.newBuilder(); if(userName != null) { req.setUserName(userName); } if(groupName != null) { req.setGroupName(groupName); } rpcProxy.flushCache(null, req.build()); } catch (ServiceException ex) { throw ProtobufHelper.getRemoteException(ex); } }
public static SafeModeAction convert( ClientNamenodeProtocolProtos.SafeModeActionProto a) { switch (a) { case SAFEMODE_LEAVE: return SafeModeAction.SAFEMODE_LEAVE; case SAFEMODE_ENTER: return SafeModeAction.SAFEMODE_ENTER; case SAFEMODE_GET: return SafeModeAction.SAFEMODE_GET; default: throw new IllegalArgumentException("Unexpected SafeModeAction :" + a); } }
public void start() throws IOException { int rpcHandlerCount = conf.getInt(ProxyConfig.PROXY_HANDLER_COUNT, ProxyConfig.PROXY_HANDLER_COUNT_DEFAULT); RPC.setProtocolEngine(conf, ClientNamenodeProtocolPB.class, ProtobufRpcEngine.class); RPC.setProtocolEngine(conf, NamenodeProtocolPB.class, ProtobufRpcEngine.class); this.protocol = (ClientProtocol) Proxy.newProxyInstance( this.getClass().getClassLoader(), new Class[]{ClientProtocol.class}, this.invocationHandler); ClientNamenodeProtocolPB proxy = new ClientNamenodeProtocolServerSideTranslatorPB(this.protocol); BlockingService clientNNPbService = ClientNamenodeProtocolProtos.ClientNamenodeProtocol. newReflectiveBlockingService(proxy); int port = conf.getInt(ProxyConfig.RPC_PORT, ProxyConfig.RPC_PORT_DEFAULT); this.rpcServer = new RPC.Builder(conf) .setProtocol(org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolPB.class) .setInstance(clientNNPbService).setBindAddress("0.0.0.0") .setPort(port).setNumHandlers(rpcHandlerCount) .setVerbose(false).build(); this.rpcServer.start(); InetSocketAddress listenAddr = rpcServer.getListenerAddress(); rpcAddress = new InetSocketAddress("0.0.0.0", listenAddr.getPort()); }
public static ClientNamenodeProtocolProtos.EncodingStatusProto convert( EncodingStatus encodingStatus) { ClientNamenodeProtocolProtos.EncodingStatusProto.Builder builder = ClientNamenodeProtocolProtos.EncodingStatusProto.newBuilder(); if (encodingStatus.getInodeId() != null) { builder.setInodeId(encodingStatus.getInodeId()); } if (encodingStatus.getParityInodeId() != null) { builder.setParityInodeId(encodingStatus.getParityInodeId()); } builder.setStatus(encodingStatus.getStatus().ordinal()); if (encodingStatus.getParityStatus() != null) { builder.setParityStatus(encodingStatus.getParityStatus().ordinal()); } if (encodingStatus.getEncodingPolicy() != null) { builder.setPolicy(PBHelper.convert( encodingStatus.getEncodingPolicy())); } if (encodingStatus.getStatusModificationTime() != null) { builder.setStatusModificationTime( encodingStatus.getStatusModificationTime()); } if (encodingStatus.getParityStatusModificationTime() != null) { builder.setParityStatusModificationTime( encodingStatus.getParityStatusModificationTime()); } if (encodingStatus.getParityFileName() != null) { builder.setParityFileName(encodingStatus.getParityFileName()); } if (encodingStatus.getLostBlocks() != null) { builder.setLostBlocks(encodingStatus.getLostBlocks()); } if (encodingStatus.getLostParityBlocks() != null) { builder.setLostParityBlocks(encodingStatus.getLostParityBlocks()); } if (encodingStatus.getRevoked() != null) { builder.setRevoked(encodingStatus.getRevoked()); } return builder.build(); }
public static ClientNamenodeProtocolProtos.EncodingPolicyProto convert( EncodingPolicy encodingPolicy) { ClientNamenodeProtocolProtos.EncodingPolicyProto.Builder builder = ClientNamenodeProtocolProtos.EncodingPolicyProto.newBuilder(); builder.setCodec(encodingPolicy.getCodec()); builder.setTargetReplication(encodingPolicy.getTargetReplication()); return builder.build(); }
@Override public ClientNamenodeProtocolProtos.AddBlockChecksumResponseProto addBlockChecksum( RpcController controller, ClientNamenodeProtocolProtos.AddBlockChecksumRequestProto req) throws ServiceException { try { server.addBlockChecksum(req.getSrc(), req.getBlockIndex(), req.getChecksum()); } catch (IOException e) { throw new ServiceException(e); } return VOID_ADDBLOCKCHECKSUM_RESPONSE; }
@Override public ClientNamenodeProtocolProtos.SetMetaEnabledResponseProto setMetaEnabled( RpcController controller, ClientNamenodeProtocolProtos.SetMetaEnabledRequestProto req) throws ServiceException { try { server.setMetaEnabled(req.getSrc(), req.getMetaEnabled()); } catch (IOException e) { throw new ServiceException(e); } return VOID_SET_META_ENABLED_RESPONSE; }
@Override public ClientNamenodeProtocolProtos.PingResponseProto ping( RpcController controller, ClientNamenodeProtocolProtos.PingRequestProto request) throws ServiceException { try { server.ping(); PingResponseProto.Builder builder = PingResponseProto.newBuilder(); return builder.build(); } catch (IOException ex) { throw new ServiceException(ex); } }
@Override public ClientNamenodeProtocolProtos.EncodeFileResponseProto encodeFile( RpcController controller, ClientNamenodeProtocolProtos.EncodeFileRequestProto request) throws ServiceException { try { server .encodeFile(request.getPath(), PBHelper.convert(request.getPolicy())); ClientNamenodeProtocolProtos.EncodeFileResponseProto.Builder builder = ClientNamenodeProtocolProtos.EncodeFileResponseProto.newBuilder(); return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ClientNamenodeProtocolProtos.RevokeEncodingResponseProto revokeEncoding( RpcController controller, ClientNamenodeProtocolProtos.RevokeEncodingRequestProto request) throws ServiceException { try { server .revokeEncoding(request.getPath(), (short) request.getReplication()); ClientNamenodeProtocolProtos.RevokeEncodingResponseProto.Builder builder = ClientNamenodeProtocolProtos.RevokeEncodingResponseProto.newBuilder(); return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ClientNamenodeProtocolProtos.ActiveNamenodeListResponseProto getActiveNamenodesForClient( RpcController controller, ClientNamenodeProtocolProtos.ActiveNamenodeListRequestProto request) throws ServiceException { try { SortedActiveNodeList anl = server.getActiveNamenodesForClient(); ClientNamenodeProtocolProtos.ActiveNamenodeListResponseProto response = convertANListToResponseProto(anl); return response; } catch (IOException e) { throw new ServiceException(e); } }
private ClientNamenodeProtocolProtos.ActiveNamenodeListResponseProto convertANListToResponseProto( SortedActiveNodeList anlWrapper) { List<ActiveNode> anl = anlWrapper.getActiveNodes(); ClientNamenodeProtocolProtos.ActiveNamenodeListResponseProto.Builder anlrpb = ClientNamenodeProtocolProtos.ActiveNamenodeListResponseProto .newBuilder(); for (ActiveNode anAnl : anl) { ActiveNodeProtos.ActiveNodeProto anp = convertANToResponseProto(anAnl); anlrpb.addNamenodes(anp); } return anlrpb.build(); }
@Override public ClientNamenodeProtocolProtos.ChangeConfResponseProto changeConf( RpcController controller, ClientNamenodeProtocolProtos.ChangeConfProto request) throws ServiceException { try { server.changeConf(request.getPropsList(), request.getNewValsList()); return VOID_CHANGECONF_RESPONSE; } catch (IOException ex) { throw new ServiceException(ex); } }
@Override public ClientNamenodeProtocolProtos.FlushUsersCacheResponseProto flushCache( RpcController controller, ClientNamenodeProtocolProtos.FlushUsersCacheRequestProto request) throws ServiceException { try { server.flushCache(request.getUserName(), request.getGroupName()); return VOID_FLUSH_CACHE; } catch (IOException ex) { throw new ServiceException(ex); } }
@Override public LocatedBlocks getMissingBlockLocations(String filePath) throws AccessControlException, FileNotFoundException, UnresolvedLinkException, IOException { ClientNamenodeProtocolProtos.GetMissingBlockLocationsRequestProto req = ClientNamenodeProtocolProtos.GetMissingBlockLocationsRequestProto .newBuilder().setFilePath(filePath).build(); try { ClientNamenodeProtocolProtos.GetMissingBlockLocationsResponseProto resp = rpcProxy.getMissingBlockLocations(null, req); return resp.hasLocations() ? PBHelper.convert(resp.getLocations()) : null; } catch (ServiceException e) { throw ProtobufHelper.getRemoteException(e); } }
@Override public void addBlockChecksum(String src, int blockIndex, long checksum) throws IOException { ClientNamenodeProtocolProtos.AddBlockChecksumRequestProto req = ClientNamenodeProtocolProtos.AddBlockChecksumRequestProto.newBuilder() .setSrc(src).setBlockIndex(blockIndex).setChecksum(checksum) .build(); try { rpcProxy.addBlockChecksum(null, req); } catch (ServiceException e) { throw ProtobufHelper.getRemoteException(e); } }
@Override public long getBlockChecksum(String src, int blockIndex) throws IOException { ClientNamenodeProtocolProtos.GetBlockChecksumRequestProto req = ClientNamenodeProtocolProtos.GetBlockChecksumRequestProto.newBuilder() .setSrc(src).setBlockIndex(blockIndex).build(); try { ClientNamenodeProtocolProtos.GetBlockChecksumResponseProto resp = rpcProxy.getBlockChecksum(null, req); return resp.getChecksum(); } catch (ServiceException e) { throw ProtobufHelper.getRemoteException(e); } }
@Override public void setMetaEnabled(String src, boolean metaEnabled) throws AccessControlException, FileNotFoundException, SafeModeException, UnresolvedLinkException, IOException { ClientNamenodeProtocolProtos.SetMetaEnabledRequestProto req = ClientNamenodeProtocolProtos.SetMetaEnabledRequestProto.newBuilder() .setSrc(src).setMetaEnabled(metaEnabled).build(); try { rpcProxy.setMetaEnabled(null, req); } catch (ServiceException e) { throw ProtobufHelper.getRemoteException(e); } }
@Override public SortedActiveNodeList getActiveNamenodesForClient() throws IOException { try { ClientNamenodeProtocolProtos.ActiveNamenodeListRequestProto.Builder request = ClientNamenodeProtocolProtos.ActiveNamenodeListRequestProto .newBuilder(); ClientNamenodeProtocolProtos.ActiveNamenodeListResponseProto response = rpcProxy.getActiveNamenodesForClient(null, request.build()); SortedActiveNodeList anl = convertProtoANListToANList(response); return anl; } catch (ServiceException se) { throw ProtobufHelper.getRemoteException(se); } }
@Override public EncodingStatus getEncodingStatus(String filePath) throws IOException { try { ClientNamenodeProtocolProtos.GetEncodingStatusRequestProto request = ClientNamenodeProtocolProtos.GetEncodingStatusRequestProto .newBuilder().setPath(filePath).build(); return PBHelper.convert( rpcProxy.getEncodingStatus(null, request).getEncodingStatus()); } catch (ServiceException e) { throw ProtobufHelper.getRemoteException(e); } }
@Override public void encodeFile(String filePath, EncodingPolicy policy) throws IOException { try { ClientNamenodeProtocolProtos.EncodeFileRequestProto request = ClientNamenodeProtocolProtos.EncodeFileRequestProto.newBuilder() .setPath(filePath).setPolicy(PBHelper.convert(policy)).build(); rpcProxy.encodeFile(null, request); } catch (ServiceException e) { throw ProtobufHelper.getRemoteException(e); } }
@Override public void revokeEncoding(String filePath, short replication) throws IOException { try { ClientNamenodeProtocolProtos.RevokeEncodingRequestProto request = ClientNamenodeProtocolProtos.RevokeEncodingRequestProto.newBuilder() .setPath(filePath).setReplication(replication).build(); rpcProxy.revokeEncoding(null, request); } catch (ServiceException e) { throw ProtobufHelper.getRemoteException(e); } }
private SortedActiveNodeList convertProtoANListToANList( ClientNamenodeProtocolProtos.ActiveNamenodeListResponseProto p) { List<ActiveNode> anl = new ArrayList<>(); List<ActiveNodeProtos.ActiveNodeProto> anlp = p.getNamenodesList(); for (ActiveNodeProtos.ActiveNodeProto anAnlp : anlp) { ActiveNode an = convertProtoANToAN(anAnlp); anl.add(an); } return new SortedActiveNodeListPBImpl(anl); }
@Override public void changeConf(List<String> props, List<String> newVals) throws IOException { try { ClientNamenodeProtocolProtos.ChangeConfProto.Builder req = ClientNamenodeProtocolProtos.ChangeConfProto.newBuilder(); req.addAllProps(props); req.addAllNewVals(newVals); rpcProxy.changeConf(null, req.build()); } catch (ServiceException ex) { throw ProtobufHelper.getRemoteException(ex); } }
public static EncodingStatus convert( ClientNamenodeProtocolProtos.EncodingStatusProto encodingStatusProto) { EncodingStatus status = new EncodingStatus(); if (encodingStatusProto.hasInodeId()) { status.setInodeId(encodingStatusProto.getInodeId()); } if (encodingStatusProto.hasParityInodeId()) { status.setParityInodeId(encodingStatusProto.getParityInodeId()); } status.setStatus(EncodingStatus.Status.values()[ encodingStatusProto.getStatus()]); if (encodingStatusProto.hasParityStatus()) { status.setParityStatus(EncodingStatus.ParityStatus.values()[ encodingStatusProto.getParityStatus()]); } if (encodingStatusProto.hasPolicy()) { status.setEncodingPolicy( PBHelper.convert(encodingStatusProto.getPolicy())); } if (encodingStatusProto.hasStatusModificationTime()) { status.setStatusModificationTime( encodingStatusProto.getStatusModificationTime()); } if (encodingStatusProto.hasParityStatusModificationTime()) { status.setParityStatusModificationTime( encodingStatusProto.getParityStatusModificationTime()); } if (encodingStatusProto.hasParityFileName()) { status.setParityFileName(encodingStatusProto.getParityFileName()); } if (encodingStatusProto.hasLostBlocks()) { status.setLostBlocks(encodingStatusProto.getLostBlocks()); } if (encodingStatusProto.hasLostParityBlocks()) { status.setLostParityBlocks(encodingStatusProto.getLostParityBlocks()); } if (encodingStatusProto.hasRevoked()) { status.setRevoked(encodingStatusProto.getRevoked()); } return status; }
public static EncodingPolicy convert( ClientNamenodeProtocolProtos.EncodingPolicyProto encodingPolicyProto) { return new EncodingPolicy(encodingPolicyProto.getCodec(), (short) encodingPolicyProto.getTargetReplication()); }