@Override public GetBlockLocationsResponseProto getBlockLocations( RpcController controller, GetBlockLocationsRequestProto req) throws ServiceException { try { LocatedBlocks b = server.getBlockLocations(req.getSrc(), req.getOffset(), req.getLength()); Builder builder = GetBlockLocationsResponseProto .newBuilder(); if (b != null) { builder.setLocations(PBHelper.convert(b)).build(); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public AppendResponseProto append(RpcController controller, AppendRequestProto req) throws ServiceException { try { EnumSetWritable<CreateFlag> flags = req.hasFlag() ? PBHelper.convertCreateFlag(req.getFlag()) : new EnumSetWritable<>(EnumSet.of(CreateFlag.APPEND)); LastBlockWithStatus result = server.append(req.getSrc(), req.getClientName(), flags); AppendResponseProto.Builder builder = AppendResponseProto.newBuilder(); if (result.getLastBlock() != null) { builder.setBlock(PBHelper.convert(result.getLastBlock())); } if (result.getFileStatus() != null) { builder.setStat(PBHelper.convert(result.getFileStatus())); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public GetDelegationTokenResponseProto getDelegationToken( RpcController controller, GetDelegationTokenRequestProto req) throws ServiceException { try { Token<DelegationTokenIdentifier> token = server .getDelegationToken(new Text(req.getRenewer())); GetDelegationTokenResponseProto.Builder rspBuilder = GetDelegationTokenResponseProto.newBuilder(); if (token != null) { rspBuilder.setToken(PBHelper.convert(token)); } return rspBuilder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public GetDataEncryptionKeyResponseProto getDataEncryptionKey( RpcController controller, GetDataEncryptionKeyRequestProto request) throws ServiceException { try { GetDataEncryptionKeyResponseProto.Builder builder = GetDataEncryptionKeyResponseProto.newBuilder(); DataEncryptionKey encryptionKey = server.getDataEncryptionKey(); if (encryptionKey != null) { builder.setDataEncryptionKey(PBHelper.convert(encryptionKey)); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public CreateSnapshotResponseProto createSnapshot(RpcController controller, CreateSnapshotRequestProto req) throws ServiceException { try { final CreateSnapshotResponseProto.Builder builder = CreateSnapshotResponseProto.newBuilder(); final String snapshotPath = server.createSnapshot(req.getSnapshotRoot(), req.hasSnapshotName()? req.getSnapshotName(): null); if (snapshotPath != null) { builder.setSnapshotPath(snapshotPath); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ListCacheDirectivesResponseProto listCacheDirectives( RpcController controller, ListCacheDirectivesRequestProto request) throws ServiceException { try { CacheDirectiveInfo filter = PBHelper.convert(request.getFilter()); BatchedEntries<CacheDirectiveEntry> entries = server.listCacheDirectives(request.getPrevId(), filter); ListCacheDirectivesResponseProto.Builder builder = ListCacheDirectivesResponseProto.newBuilder(); builder.setHasMore(entries.hasMore()); for (int i=0, n=entries.size(); i<n; i++) { builder.addElements(PBHelper.convert(entries.get(i))); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ListCachePoolsResponseProto listCachePools(RpcController controller, ListCachePoolsRequestProto request) throws ServiceException { try { BatchedEntries<CachePoolEntry> entries = server.listCachePools(request.getPrevPoolName()); ListCachePoolsResponseProto.Builder responseBuilder = ListCachePoolsResponseProto.newBuilder(); responseBuilder.setHasMore(entries.hasMore()); for (int i=0, n=entries.size(); i<n; i++) { responseBuilder.addEntries(PBHelper.convert(entries.get(i))); } return responseBuilder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public GetEZForPathResponseProto getEZForPath( RpcController controller, GetEZForPathRequestProto req) throws ServiceException { try { GetEZForPathResponseProto.Builder builder = GetEZForPathResponseProto.newBuilder(); final EncryptionZone ret = server.getEZForPath(req.getSrc()); if (ret != null) { builder.setZone(PBHelper.convert(ret)); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ListEncryptionZonesResponseProto listEncryptionZones( RpcController controller, ListEncryptionZonesRequestProto req) throws ServiceException { try { BatchedEntries<EncryptionZone> entries = server .listEncryptionZones(req.getId()); ListEncryptionZonesResponseProto.Builder builder = ListEncryptionZonesResponseProto.newBuilder(); builder.setHasMore(entries.hasMore()); for (int i=0; i<entries.size(); i++) { builder.addZones(PBHelper.convert(entries.get(i))); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public GetStoragePoliciesResponseProto getStoragePolicies( RpcController controller, GetStoragePoliciesRequestProto request) throws ServiceException { try { BlockStoragePolicy[] policies = server.getStoragePolicies(); GetStoragePoliciesResponseProto.Builder builder = GetStoragePoliciesResponseProto.newBuilder(); if (policies == null) { return builder.build(); } for (BlockStoragePolicy policy : policies) { builder.addPolicies(PBHelper.convert(policy)); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public GetBlockLocationsResponseProto getBlockLocations( RpcController controller, GetBlockLocationsRequestProto req) throws ServiceException { try { LocatedBlocks b = server.getBlockLocations(req.getSrc(), req.getOffset(), req.getLength()); Builder builder = GetBlockLocationsResponseProto .newBuilder(); if (b != null) { builder.setLocations(PBHelperClient.convert(b)).build(); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public AppendResponseProto append(RpcController controller, AppendRequestProto req) throws ServiceException { try { EnumSetWritable<CreateFlag> flags = req.hasFlag() ? PBHelperClient.convertCreateFlag(req.getFlag()) : new EnumSetWritable<>(EnumSet.of(CreateFlag.APPEND)); LastBlockWithStatus result = server.append(req.getSrc(), req.getClientName(), flags); AppendResponseProto.Builder builder = AppendResponseProto.newBuilder(); if (result.getLastBlock() != null) { builder.setBlock(PBHelperClient.convertLocatedBlock( result.getLastBlock())); } if (result.getFileStatus() != null) { builder.setStat(PBHelperClient.convert(result.getFileStatus())); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public GetDelegationTokenResponseProto getDelegationToken( RpcController controller, GetDelegationTokenRequestProto req) throws ServiceException { try { Token<DelegationTokenIdentifier> token = server .getDelegationToken(new Text(req.getRenewer())); GetDelegationTokenResponseProto.Builder rspBuilder = GetDelegationTokenResponseProto.newBuilder(); if (token != null) { rspBuilder.setToken(PBHelperClient.convert(token)); } return rspBuilder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public GetDataEncryptionKeyResponseProto getDataEncryptionKey( RpcController controller, GetDataEncryptionKeyRequestProto request) throws ServiceException { try { GetDataEncryptionKeyResponseProto.Builder builder = GetDataEncryptionKeyResponseProto.newBuilder(); DataEncryptionKey encryptionKey = server.getDataEncryptionKey(); if (encryptionKey != null) { builder.setDataEncryptionKey(PBHelperClient.convert(encryptionKey)); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ListCacheDirectivesResponseProto listCacheDirectives( RpcController controller, ListCacheDirectivesRequestProto request) throws ServiceException { try { CacheDirectiveInfo filter = PBHelperClient.convert(request.getFilter()); BatchedEntries<CacheDirectiveEntry> entries = server.listCacheDirectives(request.getPrevId(), filter); ListCacheDirectivesResponseProto.Builder builder = ListCacheDirectivesResponseProto.newBuilder(); builder.setHasMore(entries.hasMore()); for (int i=0, n=entries.size(); i<n; i++) { builder.addElements(PBHelperClient.convert(entries.get(i))); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ListCachePoolsResponseProto listCachePools(RpcController controller, ListCachePoolsRequestProto request) throws ServiceException { try { BatchedEntries<CachePoolEntry> entries = server.listCachePools(request.getPrevPoolName()); ListCachePoolsResponseProto.Builder responseBuilder = ListCachePoolsResponseProto.newBuilder(); responseBuilder.setHasMore(entries.hasMore()); for (int i=0, n=entries.size(); i<n; i++) { responseBuilder.addEntries(PBHelperClient.convert(entries.get(i))); } return responseBuilder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public GetEZForPathResponseProto getEZForPath( RpcController controller, GetEZForPathRequestProto req) throws ServiceException { try { GetEZForPathResponseProto.Builder builder = GetEZForPathResponseProto.newBuilder(); final EncryptionZone ret = server.getEZForPath(req.getSrc()); if (ret != null) { builder.setZone(PBHelperClient.convert(ret)); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ListEncryptionZonesResponseProto listEncryptionZones( RpcController controller, ListEncryptionZonesRequestProto req) throws ServiceException { try { BatchedEntries<EncryptionZone> entries = server .listEncryptionZones(req.getId()); ListEncryptionZonesResponseProto.Builder builder = ListEncryptionZonesResponseProto.newBuilder(); builder.setHasMore(entries.hasMore()); for (int i=0; i<entries.size(); i++) { builder.addZones(PBHelperClient.convert(entries.get(i))); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public GetStoragePoliciesResponseProto getStoragePolicies( RpcController controller, GetStoragePoliciesRequestProto request) throws ServiceException { try { BlockStoragePolicy[] policies = server.getStoragePolicies(); GetStoragePoliciesResponseProto.Builder builder = GetStoragePoliciesResponseProto.newBuilder(); if (policies == null) { return builder.build(); } for (BlockStoragePolicy policy : policies) { builder.addPolicies(PBHelperClient.convert(policy)); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }