use of alluxio.client.block.options.GetWorkerReportOptions.WorkerInfoField in project alluxio by Alluxio.
the class CapacityCommand method getOptions.
/**
* Gets the worker info options.
*
* @param cl CommandLine that contains the client options
* @return GetWorkerReportOptions to get worker information
*/
private GetWorkerReportOptions getOptions(CommandLine cl) throws IOException {
if (cl.getOptions().length > 1) {
System.out.println(getUsage());
throw new InvalidArgumentException("Too many arguments passed in.");
}
GetWorkerReportOptions workerOptions = GetWorkerReportOptions.defaults();
Set<WorkerInfoField> fieldRange = new HashSet<>(Arrays.asList(WorkerInfoField.ADDRESS, WorkerInfoField.WORKER_CAPACITY_BYTES, WorkerInfoField.WORKER_CAPACITY_BYTES_ON_TIERS, WorkerInfoField.LAST_CONTACT_SEC, WorkerInfoField.WORKER_USED_BYTES, WorkerInfoField.WORKER_USED_BYTES_ON_TIERS));
workerOptions.setFieldRange(fieldRange);
if (cl.hasOption(ReportCommand.LIVE_OPTION_NAME)) {
workerOptions.setWorkerRange(WorkerRange.LIVE);
} else if (cl.hasOption(ReportCommand.LOST_OPTION_NAME)) {
workerOptions.setWorkerRange(WorkerRange.LOST);
} else if (cl.hasOption(ReportCommand.SPECIFIED_OPTION_NAME)) {
workerOptions.setWorkerRange(WorkerRange.SPECIFIED);
String addressString = cl.getOptionValue(ReportCommand.SPECIFIED_OPTION_NAME);
String[] addressArray = addressString.split(",");
// Addresses in GetWorkerReportOptions is only used when WorkerRange is SPECIFIED
workerOptions.setAddresses(new HashSet<>(Arrays.asList(addressArray)));
}
return workerOptions;
}
use of alluxio.client.block.options.GetWorkerReportOptions.WorkerInfoField in project alluxio by Alluxio.
the class MasterWorkerInfo method generateWorkerInfo.
/**
* Gets the selected field information for this worker.
*
* You should lock externally with {@link MasterWorkerInfo#lockWorkerMeta(EnumSet, boolean)}
* with {@link WorkerMetaLockSection#USAGE} specified.
* A shared lock is required.
*
* @param fieldRange the client selected fields
* @param isLiveWorker the worker is live or not
* @return generated worker information
*/
public WorkerInfo generateWorkerInfo(Set<WorkerInfoField> fieldRange, boolean isLiveWorker) {
WorkerInfo info = new WorkerInfo();
Set<WorkerInfoField> checkedFieldRange = fieldRange != null ? fieldRange : new HashSet<>(Arrays.asList(WorkerInfoField.values()));
for (WorkerInfoField field : checkedFieldRange) {
switch(field) {
case ADDRESS:
info.setAddress(mMeta.mWorkerAddress);
break;
case BLOCK_COUNT:
info.setBlockCount(getBlockCount());
break;
case WORKER_CAPACITY_BYTES:
info.setCapacityBytes(mUsage.mCapacityBytes);
break;
case WORKER_CAPACITY_BYTES_ON_TIERS:
info.setCapacityBytesOnTiers(mUsage.mTotalBytesOnTiers);
break;
case ID:
info.setId(mMeta.mId);
break;
case LAST_CONTACT_SEC:
info.setLastContactSec((int) ((CommonUtils.getCurrentMs() - mLastUpdatedTimeMs.get()) / Constants.SECOND_MS));
break;
case START_TIME_MS:
info.setStartTimeMs(mMeta.mStartTimeMs);
break;
case STATE:
if (isLiveWorker) {
info.setState(LIVE_WORKER_STATE);
} else {
info.setState(LOST_WORKER_STATE);
}
break;
case WORKER_USED_BYTES:
info.setUsedBytes(mUsage.mUsedBytes);
break;
case WORKER_USED_BYTES_ON_TIERS:
info.setUsedBytesOnTiers(mUsage.mUsedBytesOnTiers);
break;
default:
LOG.warn("Unrecognized worker info field: " + field);
}
}
return info;
}
Aggregations