/** * Gets capacity. * * @return the worker capacity in bytes */ public String getCapacity() { return FormatUtils.getSizeFromBytes(mCapacityBytes); }
/** * Gets size. * * @return the file size */ public String getSize() { if (mIsDirectory) { return ""; } else { return FormatUtils.getSizeFromBytes(mSize); } }
/** * Gets capacity. * * @return the capacity */ public String getCapacity() { return FormatUtils.getSizeFromBytes(mCapacityBytes); }
/** * Gets block size bytes. * * @return the block size (in bytes) */ public String getBlockSizeBytes() { if (mIsDirectory) { return ""; } else { return FormatUtils.getSizeFromBytes(mBlockSizeBytes); } }
/** * Gets used memory. * * @return the worker used capacity in bytes */ public String getUsedMemory() { return FormatUtils.getSizeFromBytes(mUsedBytes); }
/** * Gets free capacity. * * @return the free capacity */ public String getFreeCapacity() { return FormatUtils.getSizeFromBytes(mFreeBytes); }
/** * Gets used capacity. * * @return the used capacity */ public String getUsedCapacity() { return FormatUtils.getSizeFromBytes(mUsedBytes); }
/** * Gets the size and its percentage information, if readable option is provided, * get the size in human readable format. * * @param readable whether to print info of human readable format * @param size the size to get information from * @param totalSize the total size to calculate percentage information * @return the formatted value and percentage information */ private String getFormattedValues(boolean readable, long size, long totalSize) { // If size is 1, total size is 5, and readable is true, it will // return a string as "1B (20%)" int percent = totalSize == 0 ? 0 : (int) (size * 100 / totalSize); String subSizeMessage = readable ? FormatUtils.getSizeFromBytes(size) : String.valueOf(size); return String.format(VALUE_AND_PERCENT_FORMAT, subSizeMessage, percent); }
/** * Prints the metrics information. * * @param metricName the metric name to get a metric value * @param nickName the metric name to print * @param valueIsBytes whether the metric value is bytes */ private void printMetric(String metricName, String nickName, boolean valueIsBytes) { if (mMetricsMap == null || !mMetricsMap.containsKey(metricName)) { return; } MetricValue metricValue = mMetricsMap.get(metricName); String formattedValue = valueIsBytes ? FormatUtils.getSizeFromBytes(metricValue.getLongValue()) : getFormattedValue(metricValue); mPrintStream.println(INDENT + String.format(mInfoFormat, nickName == null ? metricName : nickName, formattedValue)); mMetricsMap.remove(metricName); }
} else { inAlluxioState = String.format(IN_ALLUXIO_STATE_FILE_FORMAT, inAlluxioPercentage); sizeStr = hSize ? FormatUtils.getSizeFromBytes(size) : String.valueOf(size);
print("Total Capacity: " + FormatUtils.getSizeFromBytes(mSumCapacityBytes)); mIndentationLevel++; for (Map.Entry<String, Long> totalBytesTier : mSumCapacityBytesOnTierMap.entrySet()) { long value = totalBytesTier.getValue(); print("Tier: " + totalBytesTier.getKey() + " Size: " + FormatUtils.getSizeFromBytes(value)); + FormatUtils.getSizeFromBytes(mSumUsedBytes)); mIndentationLevel++; for (Map.Entry<String, Long> usedBytesTier : mSumUsedBytesOnTierMap.entrySet()) { long value = usedBytesTier.getValue(); print("Tier: " + usedBytesTier.getKey() + " Size: " + FormatUtils.getSizeFromBytes(value));
map.put(workerName, FormatUtils.getSizeFromBytes(value)); mCapacityTierInfoMap.put(tier, map); map.put(workerName, FormatUtils.getSizeFromBytes(value)); mUsedTierInfoMap.put(tier, map);
/** * Prints mount information for a mount table. * * @param mountTable the mount table to get information from */ public static void printMountInfo(Map<String, MountPointInfo> mountTable) { for (Map.Entry<String, MountPointInfo> entry : mountTable.entrySet()) { String mMountPoint = entry.getKey(); MountPointInfo mountPointInfo = entry.getValue(); long capacityBytes = mountPointInfo.getUfsCapacityBytes(); long usedBytes = mountPointInfo.getUfsUsedBytes(); String usedPercentageInfo = ""; if (capacityBytes > 0) { int usedPercentage = (int) (100L * usedBytes / capacityBytes); usedPercentageInfo = String.format("(%s%%)", usedPercentage); } String leftAlignFormat = getAlignFormat(mountTable); System.out.format(leftAlignFormat, mountPointInfo.getUfsUri(), mMountPoint, mountPointInfo.getUfsType(), FormatUtils.getSizeFromBytes(capacityBytes), FormatUtils.getSizeFromBytes(usedBytes) + usedPercentageInfo, mountPointInfo.getReadOnly() ? "" : "not ", mountPointInfo.getShared() ? "" : "not "); System.out.println("properties=" + mountPointInfo.getProperties() + ")"); } }
+ FormatUtils.getSizeFromBytes(blockMasterInfo.getCapacityBytes())); for (Map.Entry<String, Long> capacityBytesTier : totalCapacityOnTiers.entrySet()) { print("Tier: " + capacityBytesTier.getKey() + " Size: " + FormatUtils.getSizeFromBytes(capacityBytesTier.getValue())); + FormatUtils.getSizeFromBytes(blockMasterInfo.getUsedBytes())); for (Map.Entry<String, Long> usedBytesTier: usedCapacityOnTiers.entrySet()) { print("Tier: " + usedBytesTier.getKey() + " Size: " + FormatUtils.getSizeFromBytes(usedBytesTier.getValue())); + FormatUtils.getSizeFromBytes(blockMasterInfo.getFreeBytes()));
/** * Prints worker information when only one tier exists. * * @param workerInfoList the worker info list to get info from */ private void printShortWorkerInfo(List<WorkerInfo> workerInfoList) { String tier = mCapacityTierInfoMap.firstKey(); String shortInfoFormat = getInfoFormat(workerInfoList, true); print(String.format("%n" + shortInfoFormat, "Worker Name", "Last Heartbeat", "Storage", tier)); for (WorkerInfo info : workerInfoList) { long capacityBytes = info.getCapacityBytes(); long usedBytes = info.getUsedBytes(); String usedPercentageInfo = ""; if (capacityBytes != 0) { int usedPercentage = (int) (100L * usedBytes / capacityBytes); usedPercentageInfo = String.format(" (%s%%)", usedPercentage); } print(String.format(shortInfoFormat, info.getAddress().getHost(), info.getLastContactSec(), "capacity", FormatUtils.getSizeFromBytes(capacityBytes))); print(String.format(shortInfoFormat, "", "", "used", FormatUtils.getSizeFromBytes(usedBytes) + usedPercentageInfo)); } }
FormatUtils.getSizeFromBytes(capacityBytes), capacityTierInfo)); print(String.format(longInfoFormat, "", "", "used", FormatUtils.getSizeFromBytes(usedBytes) + usedPercentageInfo, usedTierInfo));
Assert.assertEquals(testCase.mExpected, FormatUtils.getSizeFromBytes(testCase.mInput));
response.setCapacityBytes(FormatUtils.getSizeFromBytes(capacityBytes)) .setUsedBytes(FormatUtils.getSizeFromBytes(usedBytes)).setUsageOnTiers(usageOnTiers) .setVersion(RuntimeConstants.VERSION);
/** * 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); }
String sizeMessage = readable ? FormatUtils.getSizeFromBytes(totalSize) : String.valueOf(totalSize); String inAlluxioMessage = getFormattedValues(readable, sizeInAlluxio / 100, totalSize); if (!status.isFolder()) { long totalSize = status.getLength(); String sizeMessage = readable ? FormatUtils.getSizeFromBytes(totalSize) : String.valueOf(totalSize); String inAlluxioMessage = getFormattedValues(readable,