public static WorkerInfo createRandom() { WorkerInfo result = new WorkerInfo(); Random random = new Random(); long id = random.nextLong(); WorkerNetAddress address = WorkerNetAddressTest.createRandom(); int lastContactSec = random.nextInt(); long capacityBytes = random.nextLong(); long usedBytes = random.nextLong(); long startTimeMs = random.nextLong(); Map<String, Long> capacityBytesOnTiers = new HashMap<>(); capacityBytesOnTiers.put("MEM", capacityBytes); Map<String, Long> usedBytesOnTiers = new HashMap<>(); usedBytesOnTiers.put("MEM", usedBytes); String state = random.nextInt(1) == 1 ? "In Service" : "Out of Service"; result.setId(id); result.setAddress(address); result.setLastContactSec(lastContactSec); result.setCapacityBytes(capacityBytes); result.setUsedBytes(usedBytes); result.setStartTimeMs(startTimeMs); result.setState(state); result.setCapacityBytesOnTiers(capacityBytesOnTiers); result.setUsedBytesOnTiers(usedBytesOnTiers); return result; } }
break; case WORKER_USED_BYTES_ON_TIERS: info.setUsedBytesOnTiers(mUsedBytesOnTiers); break; default:
/** * Converts a proto type to a wire type. * * @param workerInfo the proto type to convert * @return the converted wire type */ public static WorkerInfo fromProto(alluxio.grpc.WorkerInfo workerInfo) { return new WorkerInfo().setAddress(fromProto(workerInfo.getAddress())) .setCapacityBytes(workerInfo.getCapacityBytes()) .setCapacityBytesOnTiers(workerInfo.getCapacityBytesOnTiers()).setId(workerInfo.getId()) .setLastContactSec(workerInfo.getLastContactSec()) .setStartTimeMs(workerInfo.getStartTimeMs()).setState(workerInfo.getState()) .setUsedBytes(workerInfo.getUsedBytes()) .setUsedBytesOnTiers(workerInfo.getUsedBytesOnTiersMap()); }
break; case USED_BYTES_ON_TIERS: info.setUsedBytesOnTiers(mUsedBytesOnTiers); break; default:
/** * Creates a new instance of {@link WorkerInfo} from a thrift representation. * * @param workerInfo the thrift representation of a worker information * @return the instance */ public static WorkerInfo fromThrift(alluxio.thrift.WorkerInfo workerInfo) { return new WorkerInfo() .setAddress(WorkerNetAddress.fromThrift(workerInfo.getAddress())) .setCapacityBytes(workerInfo.getCapacityBytes()) .setCapacityBytesOnTiers(workerInfo.getCapacityBytesOnTiers()) .setId(workerInfo.getId()) .setLastContactSec(workerInfo.getLastContactSec()) .setStartTimeMs(workerInfo.getStartTimeMs()) .setState(workerInfo.getState()) .setUsedBytes(workerInfo.getUsedBytes()) .setUsedBytesOnTiers(workerInfo.getUsedBytesOnTiers()); }