コード例 #1
0
 /**
  * @return the info of all active block workers
  * @throws IOException when work info list cannot be obtained from master
  * @throws AlluxioException if network connection failed
  */
 public List<BlockWorkerInfo> getWorkerInfoList() throws IOException, AlluxioException {
   List<BlockWorkerInfo> infoList = Lists.newArrayList();
   try (CloseableResource<BlockMasterClient> masterClientResource =
       mContext.acquireMasterClientResource()) {
     for (WorkerInfo workerInfo : masterClientResource.get().getWorkerInfoList()) {
       infoList.add(
           new BlockWorkerInfo(
               workerInfo.getAddress(), workerInfo.getCapacityBytes(), workerInfo.getUsedBytes()));
     }
     return infoList;
   }
 }
コード例 #2
0
 /**
  * Gets the worker addresses with the given hostname by querying the master. Returns all the
  * addresses, if the hostname is an empty string.
  *
  * @param hostname hostname of the worker to query, empty string denotes any worker
  * @return a list of {@link WorkerNetAddress} with the given hostname
  */
 private List<WorkerNetAddress> getWorkerAddresses(String hostname) {
   List<WorkerNetAddress> addresses = new ArrayList<>();
   try (CloseableResource<BlockMasterClient> masterClient = acquireMasterClientResource()) {
     List<WorkerInfo> workers = masterClient.get().getWorkerInfoList();
     for (WorkerInfo worker : workers) {
       if (hostname.isEmpty() || worker.getAddress().getHost().equals(hostname)) {
         addresses.add(worker.getAddress());
       }
     }
   } catch (Exception e) {
     Throwables.propagate(e);
   }
   return addresses;
 }