private static List<TargetInfo> getTargetInfos(String[] targets, AlluxioConfiguration conf) throws IOException { List<TargetInfo> targetInfoList = new ArrayList<>(); for (String target : targets) { if (target.equals(ROLE_MASTER)) { String masterHost = NetworkAddressUtils.getConnectHost(ServiceType.MASTER_WEB, conf); int masterPort = NetworkAddressUtils.getPort(ServiceType.MASTER_WEB, conf); targetInfoList.add(new TargetInfo(masterHost, masterPort, ROLE_MASTER)); } else if (target.equals(ROLE_WORKERS)) { AlluxioBlockStore alluxioBlockStore = AlluxioBlockStore.create(FileSystemContext.create(ClientContext.create(conf))); List<BlockWorkerInfo> workerInfoList = alluxioBlockStore.getAllWorkers(); for (BlockWorkerInfo workerInfo : workerInfoList) { WorkerNetAddress netAddress = workerInfo.getNetAddress(); targetInfoList.add( new TargetInfo(netAddress.getHost(), netAddress.getWebPort(), ROLE_WORKER)); } } else if (target.contains(":")) { String[] hostPortPair = target.split(":"); int port = Integer.parseInt(hostPortPair[1]); targetInfoList.add(new TargetInfo(hostPortPair[0], port, ROLE_WORKER)); } else { throw new IOException("Unrecognized target argument: " + target); } } return targetInfoList; }
/** * Instantiates a new Node info. * * @param workerInfo the worker info */ public NodeInfo(WorkerInfo workerInfo) { mHost = workerInfo.getAddress().getHost(); mWebPort = workerInfo.getAddress().getWebPort(); mLastContactSec = Integer.toString(workerInfo.getLastContactSec()); mWorkerState = workerInfo.getState(); mCapacityBytes = workerInfo.getCapacityBytes(); mUsedBytes = workerInfo.getUsedBytes(); if (mCapacityBytes != 0) { mUsedPercent = (int) (100L * mUsedBytes / mCapacityBytes); } else { mUsedPercent = 0; } mFreePercent = 100 - mUsedPercent; mUptimeClockTime = WebUtils.convertMsToShortClockTime( System.currentTimeMillis() - workerInfo.getStartTimeMs()); mWorkerId = workerInfo.getId(); }
public void checkEquality(WorkerNetAddress a, WorkerNetAddress b) { Assert.assertEquals(a.getHost(), b.getHost()); Assert.assertEquals(a.getRpcPort(), b.getRpcPort()); Assert.assertEquals(a.getDataPort(), b.getDataPort()); Assert.assertEquals(a.getWebPort(), b.getWebPort()); Assert.assertEquals(a.getTieredIdentity(), b.getTieredIdentity()); Assert.assertEquals(a, b); }
/** * Converts wire type to proto type. * * @param workerNetAddress the wire representation to convert * @return the converted proto representation */ public static alluxio.grpc.WorkerNetAddress toProto(WorkerNetAddress workerNetAddress) { alluxio.grpc.WorkerNetAddress.Builder address = alluxio.grpc.WorkerNetAddress.newBuilder() .setHost(workerNetAddress.getHost()).setRpcPort(workerNetAddress.getRpcPort()) .setDataPort(workerNetAddress.getDataPort()).setWebPort(workerNetAddress.getWebPort()) .setDomainSocketPath(workerNetAddress.getDomainSocketPath()); if (workerNetAddress.getTieredIdentity() != null) { address.setTieredIdentity(toProto(workerNetAddress.getTieredIdentity())); } return address.build(); }
private NodeInfo(WorkerInfo workerInfo) { mHost = workerInfo.getAddress().getHost(); mWebPort = workerInfo.getAddress().getWebPort(); mLastContactSec = Integer.toString(workerInfo.getLastContactSec()); mWorkerState = workerInfo.getState(); mCapacityBytes = workerInfo.getCapacityBytes(); mUsedBytes = workerInfo.getUsedBytes(); if (mCapacityBytes != 0) { mUsedPercent = (int) (100L * mUsedBytes / mCapacityBytes); } else { mUsedPercent = 0; } mFreePercent = 100 - mUsedPercent; mUptimeClockTime = WebUtils.convertMsToShortClockTime( System.currentTimeMillis() - workerInfo.getStartTimeMs()); mWorkerId = workerInfo.getId(); }