Search in sources :

Example 1 with WorkerRange

use of alluxio.client.block.options.GetWorkerReportOptions.WorkerRange in project alluxio by Alluxio.

the class DefaultBlockMaster method getWorkerReport.

@Override
public List<WorkerInfo> getWorkerReport(GetWorkerReportOptions options) throws UnavailableException, InvalidArgumentException {
    if (mSafeModeManager.isInSafeMode()) {
        throw new UnavailableException(ExceptionMessage.MASTER_IN_SAFEMODE.getMessage());
    }
    Set<MasterWorkerInfo> selectedLiveWorkers = new HashSet<>();
    Set<MasterWorkerInfo> selectedLostWorkers = new HashSet<>();
    WorkerRange workerRange = options.getWorkerRange();
    switch(workerRange) {
        case ALL:
            selectedLiveWorkers.addAll(mWorkers);
            selectedLostWorkers.addAll(mLostWorkers);
            break;
        case LIVE:
            selectedLiveWorkers.addAll(mWorkers);
            break;
        case LOST:
            selectedLostWorkers.addAll(mLostWorkers);
            break;
        case SPECIFIED:
            Set<String> addresses = options.getAddresses();
            Set<String> workerNames = new HashSet<>();
            selectedLiveWorkers = selectInfoByAddress(addresses, mWorkers, workerNames);
            selectedLostWorkers = selectInfoByAddress(addresses, mLostWorkers, workerNames);
            if (!addresses.isEmpty()) {
                String info = String.format("Unrecognized worker names: %s%n" + "Supported worker names: %s%n", addresses.toString(), workerNames.toString());
                throw new InvalidArgumentException(info);
            }
            break;
        default:
            throw new InvalidArgumentException("Unrecognized worker range: " + workerRange);
    }
    List<WorkerInfo> workerInfoList = new ArrayList<>(selectedLiveWorkers.size() + selectedLostWorkers.size());
    for (MasterWorkerInfo worker : selectedLiveWorkers) {
        // extractWorkerInfo handles the locking internally
        workerInfoList.add(extractWorkerInfo(worker, options.getFieldRange(), true));
    }
    for (MasterWorkerInfo worker : selectedLostWorkers) {
        // extractWorkerInfo handles the locking internally
        workerInfoList.add(extractWorkerInfo(worker, options.getFieldRange(), false));
    }
    return workerInfoList;
}
Also used : InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) UnavailableException(alluxio.exception.status.UnavailableException) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) WorkerRange(alluxio.client.block.options.GetWorkerReportOptions.WorkerRange) ArrayList(java.util.ArrayList) WorkerInfo(alluxio.wire.WorkerInfo) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) ConcurrentHashSet(alluxio.collections.ConcurrentHashSet) HashSet(java.util.HashSet)

Aggregations

WorkerRange (alluxio.client.block.options.GetWorkerReportOptions.WorkerRange)1 ConcurrentHashSet (alluxio.collections.ConcurrentHashSet)1 InvalidArgumentException (alluxio.exception.status.InvalidArgumentException)1 UnavailableException (alluxio.exception.status.UnavailableException)1 MasterWorkerInfo (alluxio.master.block.meta.MasterWorkerInfo)1 WorkerInfo (alluxio.wire.WorkerInfo)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1