/** * Gets the used bytes of Alluxio's BlockStore. * * @return the used bytes of Alluxio's BlockStore */ public long getUsedBytes() throws IOException { try (CloseableResource<BlockMasterClient> blockMasterClientResource = mContext.acquireBlockMasterClientResource()) { return blockMasterClientResource.get().getUsedBytes(); } } }
/** * Gets the block info of a block, if it exists. * * @param blockId the blockId to obtain information about * @return a {@link BlockInfo} containing the metadata of the block */ public BlockInfo getInfo(long blockId) throws IOException { try (CloseableResource<BlockMasterClient> masterClientResource = mContext.acquireBlockMasterClientResource()) { return masterClientResource.get().getBlockInfo(blockId); } }
/** * Gets the total capacity of Alluxio's BlockStore. * * @return the capacity in bytes */ public long getCapacityBytes() throws IOException { try (CloseableResource<BlockMasterClient> blockMasterClientResource = mContext.acquireBlockMasterClientResource()) { return blockMasterClientResource.get().getCapacityBytes(); } }
/** * @return the info of all block workers */ public List<BlockWorkerInfo> getAllWorkers() throws IOException { try (CloseableResource<BlockMasterClient> masterClientResource = mContext.acquireBlockMasterClientResource()) { return masterClientResource.get().getWorkerInfoList().stream() .map(w -> new BlockWorkerInfo(w.getAddress(), w.getCapacityBytes(), w.getUsedBytes())) .collect(toList()); } }
mContext.acquireBlockMasterClientResource()) { info = masterClientResource.get().getBlockInfo(blockId);
/** * Gets a stream to write data to a block. The stream can only be backed by Alluxio storage. * * @param blockId the block to write * @param blockSize the standard block size to write, or -1 if the block already exists (and this * stream is just storing the block in Alluxio again) * @param address the address of the worker to write the block to, fails if the worker cannot * serve the request * @param options the output stream options * @return an {@link BlockOutStream} which can be used to write data to the block in a streaming * fashion */ public BlockOutStream getOutStream(long blockId, long blockSize, WorkerNetAddress address, OutStreamOptions options) throws IOException { if (blockSize == -1) { try (CloseableResource<BlockMasterClient> blockMasterClientResource = mContext.acquireBlockMasterClientResource()) { blockSize = blockMasterClientResource.get().getBlockInfo(blockId).getLength(); } } // No specified location to write to. if (address == null) { throw new ResourceExhaustedException(ExceptionMessage.NO_SPACE_FOR_BLOCK_ON_WORKER .getMessage(FormatUtils.getSizeFromBytes(blockSize))); } LOG.debug("Create block outstream for {} of block size {} at address {}, using options: {}", blockId, blockSize, address, options); return BlockOutStream.create(mContext, blockId, blockSize, address, options); }
@Before public void before() throws Exception { mMasterClient = PowerMockito.mock(BlockMasterClient.class); mWorkerClient = PowerMockito.mock(BlockWorkerClient.class); mContext = PowerMockito.mock(FileSystemContext.class); when(mContext.acquireBlockMasterClientResource()) .thenReturn(new DummyCloseableResource<>(mMasterClient)); when(mContext.getClientContext()).thenReturn(ClientContext.create(sConf)); when(mContext.getConf()).thenReturn(sConf); mLocalAddr = new WorkerNetAddress().setHost(NetworkAddressUtils.getLocalHostName( (int) sConf.getMs(PropertyKey.NETWORK_HOST_RESOLUTION_TIMEOUT_MS))); mBlockStore = new AlluxioBlockStore(mContext, TieredIdentityFactory.fromString("node=" + WORKER_HOSTNAME_LOCAL, sConf)); when(mContext.acquireBlockWorkerClient(any(WorkerNetAddress.class))) .thenReturn(mWorkerClient); mStreamObserver = PowerMockito.mock(ClientCallStreamObserver.class); when(mWorkerClient.writeBlock(any(StreamObserver.class))) .thenReturn(mStreamObserver); when(mWorkerClient.openLocalBlock(any(StreamObserver.class))) .thenReturn(mStreamObserver); when(mStreamObserver.isReady()).thenReturn(true); }