/** * @param source an Alluxio URI * @param fileSystem the Alluxio file system * @return whether the URI is a file or a directory which contains files (including recursively) * @throws Exception if an unexpected exception occurs */ private static boolean hasFiles(AlluxioURI source, FileSystem fileSystem) throws Exception { Stack<AlluxioURI> dirsToCheck = new Stack<>(); dirsToCheck.add(source); while (!dirsToCheck.isEmpty()) { try { for (URIStatus status : fileSystem.listStatus(dirsToCheck.pop())) { if (!status.isFolder()) { return true; } dirsToCheck.push(new AlluxioURI(status.getPath())); } } catch (FileDoesNotExistException e) { // This probably means another worker has deleted the directory already, so we can probably // return false here. To be safe though, we will fall through and complete the search. } } return false; }
for (URIStatus childStatus : childStatuses) { if (childStatus.isFolder()) { pathsToConsider.push(new AlluxioURI(childStatus.getPath())); } else { allStatuses.add(childStatus);
@Override protected void runPlainPath(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { URIStatus status = mFileSystem.getStatus(path); System.out.println("# file: " + status.getPath()); System.out.println("# owner: " + status.getOwner()); System.out.println("# group: " + status.getGroup()); for (String entry : status.getAcl().toStringEntries()) { System.out.println(entry); } List<String> defaultAclEntries = status.getDefaultAcl().toStringEntries(); for (String entry: defaultAclEntries) { System.out.println(entry); } }
} else if (!cur.getName().endsWith(Constants.S3_MULTIPART_TEMPORARY_DIR_SUFFIX)) { List<URIStatus> curChildren = mFileSystem.listStatus(new AlluxioURI(cur.getPath())); if (curChildren.isEmpty()) {
private void queueNonPersistedRecursive(URIStatus status, Queue<AlluxioURI> toPersist) throws AlluxioException, IOException { AlluxioURI uri = new AlluxioURI(status.getPath()); if (status.isFolder()) { List<URIStatus> statuses = mFileSystem.listStatus(uri); for (URIStatus s : statuses) { queueNonPersistedRecursive(s, toPersist); } } else if (!status.isPersisted()) { toPersist.add(uri); } }
File subDstFile = new File(dstFile.getAbsolutePath(), status.getName()); copyToLocal( new AlluxioURI(srcPath.getScheme(), srcPath.getAuthority(), status.getPath()), new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), subDstFile.getPath())); } catch (IOException e) {
@Override public FileStatus[] listStatus(Path path) throws IOException { LOG.debug("listStatus({})", path); if (mStatistics != null) { mStatistics.incrementReadOps(1); } AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); List<URIStatus> statuses; try { statuses = mFileSystem.listStatus(uri); } catch (FileDoesNotExistException e) { throw new FileNotFoundException(HadoopUtils.getPathWithoutScheme(path)); } catch (AlluxioException e) { throw new IOException(e); } FileStatus[] ret = new FileStatus[statuses.size()]; for (int k = 0; k < statuses.size(); k++) { URIStatus status = statuses.get(k); ret[k] = new FileStatus(status.getLength(), status.isFolder(), getReplica(status), status.getBlockSizeBytes(), status.getLastModificationTimeMs(), status.getCreationTimeMs(), new FsPermission((short) status.getMode()), status.getOwner(), status.getGroup(), new Path(mAlluxioHeader + status.getPath())); } return ret; }
moveDirectory(status.getPath(), source.getPath(), destination.getPath()); } else { WorkerInfo bestJobWorker = getBestJobWorker(status, alluxioWorkerInfoList, jobWorkerInfoList, hostnameToWorker); String destinationPath = computeTargetPath(status.getPath(), source.getPath(), destination.getPath()); assignments.putIfAbsent(bestJobWorker, Lists.<MoveCommand>newArrayList()); assignments.get(bestJobWorker).add(new MoveCommand(status.getPath(), destinationPath));
/** * Returns a list of files at a given {@code path}. * * @param fs a {@link FileSystem} handler * @param path a path in alluxio file system * @return a list of strings representing the file names under the given path */ public static List<String> listFiles(FileSystem fs, String path) { try { List<URIStatus> statuses = fs.listStatus(new AlluxioURI(path)); List<String> res = new ArrayList<>(); for (URIStatus status : statuses) { res.add(status.getPath()); if (status.isFolder()) { res.addAll(listFiles(fs, status.getPath())); } } return res; } catch (IOException | AlluxioException e) { throw new RuntimeException(e); } }
private long[] countHelper(AlluxioURI path) throws AlluxioException, IOException { URIStatus status = mFileSystem.getStatus(path); if (!status.isFolder()) { return new long[]{ 1L, 0L, status.getLength() }; } long[] rtn = new long[]{ 0L, 1L, 0L }; List<URIStatus> statuses; try { statuses = mFileSystem.listStatus(path); } catch (AlluxioException e) { throw new IOException(e.getMessage()); } for (URIStatus uriStatus : statuses) { long[] toAdd = countHelper(new AlluxioURI(uriStatus.getPath())); rtn[0] += toAdd[0]; rtn[1] += toAdd[1]; rtn[2] += toAdd[2]; } return rtn; }
/** * Loads a file or directory in Alluxio space, makes it resident in memory. * * @param filePath The {@link AlluxioURI} path to load into Alluxio memory * @throws AlluxioException when Alluxio exception occurs * @throws IOException when non-Alluxio exception occurs */ private void load(AlluxioURI filePath, int replication) throws AlluxioException, IOException, InterruptedException { URIStatus status = mFileSystem.getStatus(filePath); if (status.isFolder()) { List<URIStatus> statuses = mFileSystem.listStatus(filePath); for (URIStatus uriStatus : statuses) { AlluxioURI newPath = new AlluxioURI(uriStatus.getPath()); load(newPath, replication); } } else { Thread thread = JobGrpcClientUtils.createProgressThread(System.out); thread.start(); try { JobGrpcClientUtils.run(new LoadConfig(filePath.getPath(), replication), 3, mFsContext.getConf()); } finally { thread.interrupt(); } } System.out.println(filePath + " loaded"); }
new AlluxioURI(inputURI.getScheme(), inputURI.getAuthority(), status.getPath()); if (match(fileURI, inputURI)) { // if it matches res.add(fileURI); if (status.isFolder()) { // if it is a folder, we do it recursively AlluxioURI dirURI = new AlluxioURI(inputURI.getScheme(), inputURI.getAuthority(), status.getPath()); String prefix = inputURI.getLeadingPath(dirURI.getDepth()); if (prefix != null && match(dirURI, new AlluxioURI(prefix))) {
List<URIStatus> statuses = mFileSystem.listStatus(filePath); for (URIStatus uriStatus : statuses) { AlluxioURI newPath = new AlluxioURI(uriStatus.getPath()); load(newPath, local);
for (URIStatus status : statuses) { try { copy(new AlluxioURI(srcPath.getScheme(), srcPath.getAuthority(), status.getPath()), new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), PathUtils.concatPath(dstPath.getPath(), status.getName())), recursive);
private void printLsString(URIStatus status, boolean hSize) { // detect the extended acls boolean hasExtended = status.getAcl().hasExtended() || !status.getDefaultAcl().isEmpty(); System.out.print(formatLsString(hSize, SecurityUtils.isSecurityEnabled(mFsContext.getConf()), status.isFolder(), FormatUtils.formatMode((short) status.getMode(), status.isFolder(), hasExtended), status.getOwner(), status.getGroup(), status.getLength(), status.getLastModificationTimeMs(), status.getInAlluxioPercentage(), status.getPersistenceState(), status.getPath(), mFsContext.getConf().get(PropertyKey.USER_DATE_FORMAT_PATTERN))); }
String inMemMessage = addMemory ? getFormattedValues(readable, status.getInMemoryPercentage() * totalSize / 100, totalSize) : ""; printInfo(sizeMessage, inAlluxioMessage, inMemMessage, status.getPath());
/** * Creates a new instance of {@link alluxio.util.webui.UIFileInfo}. * * @param status underlying {@link URIStatus} */ public UIFileInfo(URIStatus status) { // detect the extended acls boolean hasExtended = status.getAcl().hasExtended() || !status.getDefaultAcl().isEmpty(); mId = status.getFileId(); mName = status.getName(); mAbsolutePath = status.getPath(); mBlockSizeBytes = status.getBlockSizeBytes(); mSize = status.getLength(); mCreationTimeMs = status.getCreationTimeMs(); mLastModificationTimeMs = status.getLastModificationTimeMs(); mInAlluxio = (100 == status.getInAlluxioPercentage()); mInAlluxioPercentage = status.getInAlluxioPercentage(); mIsDirectory = status.isFolder(); mPinned = status.isPinned(); mOwner = status.getOwner(); mGroup = status.getGroup(); mMode = FormatUtils.formatMode((short) status.getMode(), status.isFolder(), hasExtended); mPersistenceState = status.getPersistenceState(); mFileLocations = new ArrayList<>(); }
Assert.assertEquals(uriStatus.getLength(), fileInfo.getLength()); Assert.assertEquals(uriStatus.getName(), fileInfo.getName()); Assert.assertEquals(uriStatus.getPath(), fileInfo.getPath()); Assert.assertEquals(uriStatus.getMode(), fileInfo.getMode()); Assert.assertEquals(uriStatus.getPersistenceState(),