@Test public void getMostAvailableWorker() { List<BlockWorkerInfo> workerInfoList = new ArrayList<>(); workerInfoList.add(new BlockWorkerInfo(new WorkerNetAddress().setHost("worker1") .setRpcPort(PORT).setDataPort(PORT).setWebPort(PORT), Constants.GB, 0)); workerInfoList.add(new BlockWorkerInfo(new WorkerNetAddress().setHost("worker2") .setRpcPort(PORT).setDataPort(PORT).setWebPort(PORT), 2 * (long) Constants.GB, 0)); workerInfoList.add(new BlockWorkerInfo(new WorkerNetAddress().setHost("worker3") .setRpcPort(PORT).setDataPort(PORT).setWebPort(PORT), 3 * (long) Constants.GB, 0)); MostAvailableFirstPolicy policy = new MostAvailableFirstPolicy(null); GetWorkerOptions options = GetWorkerOptions.defaults() .setBlockWorkerInfos(workerInfoList).setBlockInfo(new BlockInfo().setLength(Constants.MB)); Assert.assertEquals("worker3", policy.getWorker(options).getHost()); }
@Override public WorkerNetAddress getWorker(GetWorkerOptions options) { long mostAvailableBytes = -1; WorkerNetAddress result = null; for (BlockWorkerInfo workerInfo : options.getBlockWorkerInfos()) { if (workerInfo.getCapacityBytes() - workerInfo.getUsedBytes() > mostAvailableBytes) { mostAvailableBytes = workerInfo.getCapacityBytes() - workerInfo.getUsedBytes(); result = workerInfo.getNetAddress(); } } return result; }
MostAvailableFirstPolicy implements BlockLocationPolicy { @Override public WorkerNetAddress getWorker(GetWorkerOptions options) { long mostAvailableBytes = -1; WorkerNetAddress result = null; for (BlockWorkerInfo workerInfo : options.getBlockWorkerInfos()) { if (workerInfo.getCapacityBytes() - workerInfo.getUsedBytes() > mostAvailableBytes) { mostAvailableBytes = workerInfo.getCapacityBytes() - workerInfo.getUsedBytes(); result = workerInfo.getNetAddress(); } } return result; } }
MostAvailableFirstPolicy implements BlockLocationPolicy { @Override public WorkerNetAddress getWorker(GetWorkerOptions options) { long mostAvailableBytes = -1; WorkerNetAddress result = null; for (BlockWorkerInfo workerInfo : options.getBlockWorkerInfos()) { if (workerInfo.getCapacityBytes() - workerInfo.getUsedBytes() > mostAvailableBytes) { mostAvailableBytes = workerInfo.getCapacityBytes() - workerInfo.getUsedBytes(); result = workerInfo.getNetAddress(); } } return result; } MostAvailableFirstPolicy(AlluxioConfiguration conf); }
MostAvailableFirstPolicy implements BlockLocationPolicy { @Override public WorkerNetAddress getWorker(GetWorkerOptions options) { long mostAvailableBytes = -1; WorkerNetAddress result = null; for (BlockWorkerInfo workerInfo : options.getBlockWorkerInfos()) { if (workerInfo.getCapacityBytes() - workerInfo.getUsedBytes() > mostAvailableBytes) { mostAvailableBytes = workerInfo.getCapacityBytes() - workerInfo.getUsedBytes(); result = workerInfo.getNetAddress(); } } return result; } MostAvailableFirstPolicy(AlluxioConfiguration conf); @Override WorkerNetAddress getWorker(GetWorkerOptions options); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
MostAvailableFirstPolicy implements BlockLocationPolicy { @Override public WorkerNetAddress getWorker(GetWorkerOptions options) { long mostAvailableBytes = -1; WorkerNetAddress result = null; for (BlockWorkerInfo workerInfo : options.getBlockWorkerInfos()) { if (workerInfo.getCapacityBytes() - workerInfo.getUsedBytes() > mostAvailableBytes) { mostAvailableBytes = workerInfo.getCapacityBytes() - workerInfo.getUsedBytes(); result = workerInfo.getNetAddress(); } } return result; } MostAvailableFirstPolicy(AlluxioConfiguration conf); @Override WorkerNetAddress getWorker(GetWorkerOptions options); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }