public void setFileLocations(List<NetAddress> fileLocations) { for (NetAddress addr : fileLocations) { mFileLocations.add(addr.getHost() + ":" + addr.getRpcPort()); } } }
private void addLocations(FileBlockInfo fileBlockInfo) { Set<String> locations = Sets.newHashSet(); // add tachyon locations for (BlockLocation location : fileBlockInfo.getBlockInfo().getLocations()) { locations.add(location.getWorkerAddress().getHost()); } // add underFS locations for (NetAddress address : fileBlockInfo.getUfsLocations()) { locations.add(address.getHost()); } mLocations.addAll(locations); }
/** * Gets the worker address based on its hostname by querying the master. * * @param hostname hostname of the worker to query, empty string denotes any worker * @return NetAddress of hostname, or null if no worker found */ private synchronized NetAddress getWorkerAddress(String hostname) { BlockMasterClient masterClient = acquireMasterClient(); try { List<WorkerInfo> workers = masterClient.getWorkerInfoList(); if (hostname.isEmpty() && !workers.isEmpty()) { // TODO(calvin): Do this in a more defined way. return workers.get(0).getAddress(); } for (WorkerInfo worker : workers) { if (worker.getAddress().getHost().equals(hostname)) { return worker.getAddress(); } } } catch (IOException ioe) { Throwables.propagate(ioe); } finally { releaseMasterClient(masterClient); } return null; }
for (BlockLocation location : blockInfo.locations) { NetAddress workerNetAddress = location.getWorkerAddress(); if (workerNetAddress.getHost().equals(localHostName)) { new InetSocketAddress(workerNetAddress.getHost(), workerNetAddress.getDataPort())); } catch (IOException e) { LOG.warn("Failed to open local stream for block " + blockId + ". " + e.getMessage()); new InetSocketAddress(workerNetAddress.getHost(), workerNetAddress.getDataPort())); } finally { mContext.releaseMasterClient(masterClient);
private NodeInfo(WorkerInfo workerInfo) { mHost = workerInfo.getAddress().getHost(); 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 = Utils.convertMsToShortClockTime(System.currentTimeMillis() - workerInfo.getStartTimeMs()); }
/** * Displays a list of hosts that have the file specified in argv stored. * * @param path The TachyonURI path as the input of the command * @return 0 if command is successful, -1 if an error occurred * @throws IOException */ public int location(TachyonURI path) throws IOException { TachyonFile fd; FileInfo fInfo; try { fd = mTfs.open(path); fInfo = mTfs.getInfo(fd); } catch (TachyonException e) { throw new IOException(e.getMessage()); } System.out.println(path + " with file id " + fd.getFileId() + " is on nodes: "); for (long blockId : fInfo.getBlockIds()) { for (BlockLocation location : TachyonBlockStore.get().getInfo(blockId).getLocations()) { System.out.println(location.getWorkerAddress().getHost()); } } return 0; }
/** * Attempts to promote a block in Tachyon space. If the block is not present, this method will * return without an error. If the block is present in multiple workers, only one worker will * receive the promotion request. * * @param blockId the id of the block to promote * @throws IOException if the block does not exist */ public void promote(long blockId) throws IOException { BlockMasterClient blockMasterClient = mContext.acquireMasterClient(); try { BlockInfo info = blockMasterClient.getBlockInfo(blockId); if (info.getLocations().isEmpty()) { // Nothing to promote return; } // Get the first worker address for now, as this will likely be the location being read from // TODO: Get this location via a policy (possibly location is a parameter to promote) NetAddress workerAddr = info.getLocations().get(0).getWorkerAddress(); WorkerClient workerClient = mContext.acquireWorkerClient(workerAddr.getHost()); try { workerClient.promoteBlock(blockId); } finally { mContext.releaseWorkerClient(workerClient); } } finally { mContext.releaseMasterClient(blockMasterClient); } } }