/** * Returns whether or not fileURI matches the patternURI. * * @param fileURI the {@link AlluxioURI} of a particular file * @param patternURI the URI that can contain wildcards * @return true if matches; false if not */ private static boolean match(AlluxioURI fileURI, AlluxioURI patternURI) { return escape(fileURI.getPath()).matches(replaceWildcards(patternURI.getPath())); }
/** * @return the normalized path stripped of the folder path component */ public String getRootPath() { String rootPath = this.toString(); if (this.getPath() != null) { rootPath = rootPath.substring(0, rootPath.lastIndexOf(this.getPath())); } return PathUtils.normalizePath(rootPath, AlluxioURI.SEPARATOR); }
/** * @param uri an Alluxio path URI * @return whether the given uri is a mount point */ public boolean isMountPoint(AlluxioURI uri) { try (LockResource r = new LockResource(mReadLock)) { return mState.getMountTable().containsKey(uri.getPath()); } }
private AlluxioURI reverseResolve(AlluxioURI mountPoint, AlluxioURI ufsUriMountPoint, AlluxioURI ufsUri) throws InvalidPathException { String relativePath = PathUtils.subtractPaths( PathUtils.normalizePath(ufsUri.getPath(), AlluxioURI.SEPARATOR), PathUtils.normalizePath(ufsUriMountPoint.getPath(), AlluxioURI.SEPARATOR)); if (relativePath.isEmpty()) { return mountPoint; } else { return mountPoint.joinUnsafe(relativePath); } }
private LockingScheme createLockingScheme(AlluxioURI path, FileSystemMasterCommonPOptions options, LockPattern desiredLockMode) { boolean shouldSync = mUfsSyncPathCache.shouldSyncPath(path.getPath(), options.getSyncIntervalMs()); return new LockingScheme(path, desiredLockMode, shouldSync); }
@Override public void setAcl(AlluxioURI path, SetAclAction action, List<AclEntry> entries, SetAclPOptions options) throws AlluxioStatusException { retryRPC(() -> mClient.setAcl( SetAclPRequest.newBuilder().setPath(path.getPath()).setAction(action) .addAllEntries(entries.stream().map(GrpcUtils::toProto).collect(Collectors.toList())) .setOptions(options).build()), "SetAcl"); }
@Override protected void runPlainPath(AlluxioURI plainPath, CommandLine cl) throws AlluxioException, IOException { URIStatus status = mFileSystem.getStatus(plainPath); if (status.isFolder()) { throw new FileDoesNotExistException( ExceptionMessage.PATH_MUST_BE_FILE.getMessage(plainPath.getPath())); } String str = calculateChecksum(plainPath); System.out.println("md5sum: " + str + "\n"); }
private void checkNestedBucketIsUnderMountPoint(String bucketPath) throws S3Exception { // Assure that the bucket is directly under a mount point. AlluxioURI parent = new AlluxioURI(bucketPath).getParent(); try { if (!mFileSystem.getMountTable().containsKey(parent.getPath())) { throw new S3Exception(bucketPath, S3ErrorCode.INVALID_NESTED_BUCKET_NAME); } } catch (Exception e) { throw toBucketS3Exception(e, bucketPath); } }
@Override public long replicate(AlluxioURI uri, long blockId, int numReplicas) throws AlluxioException, IOException { JobMasterClient client = mJobMasterClientPool.acquire(); try { return client.run(new ReplicateConfig(uri.getPath(), blockId, numReplicas)); } finally { mJobMasterClientPool.release(client); } } }
@Override public void scheduleAsyncPersist(final AlluxioURI path) throws AlluxioStatusException { retryRPC( () -> mClient.scheduleAsyncPersistence( ScheduleAsyncPersistencePRequest.newBuilder().setPath(path.getPath()).build()), "ScheduleAsyncPersist"); }
@Override public synchronized void stopSync(final AlluxioURI path) throws AlluxioStatusException { retryRPC(() -> mClient.stopSync(StopSyncPRequest.newBuilder().setPath(path.getPath()).build()), "StopSync"); }
@Override public void createDirectory(final AlluxioURI path, final CreateDirectoryPOptions options) throws AlluxioStatusException { retryRPC( () -> mClient.createDirectory(CreateDirectoryPRequest.newBuilder() .setPath(path.getPath()).setOptions(options).build()), "CreateDirectory"); }
@Override public void completeFile(final AlluxioURI path, final CompleteFilePOptions options) throws AlluxioStatusException { retryRPC(() -> mClient.completeFile(CompleteFilePRequest.newBuilder() .setPath(path.getPath()).setOptions(options).build()), "CompleteFile"); }
@Override public void delete(final AlluxioURI path, final DeletePOptions options) throws AlluxioStatusException { retryRPC(() -> mClient.remove(DeletePRequest.newBuilder().setPath(path.getPath()) .setOptions(options).build()), "Delete"); }
@Override public void setAttribute(final AlluxioURI path, final SetAttributePOptions options) throws AlluxioStatusException { retryRPC(() -> mClient.setAttribute(SetAttributePRequest.newBuilder() .setPath(path.getPath()).setOptions(options).build()), "SetAttribute"); }
private AlluxioURI createPersistedDirectories(int levels) throws Exception { AlluxioURI ufsMount = new AlluxioURI(mTestFolder.newFolder().getAbsolutePath()); // Create top-level directory in UFS. Files.createDirectory(Paths.get(ufsMount.join(DIR_TOP_LEVEL).getPath())); createPersistedDirectoryLevel(levels, ufsMount.join(DIR_TOP_LEVEL)); return ufsMount; }
@Override public long getNewBlockIdForFile(final AlluxioURI path) throws AlluxioStatusException { return retryRPC( () -> mClient .getNewBlockIdForFile(GetNewBlockIdForFilePRequest.newBuilder().setPath(path.getPath()) .setOptions(GetNewBlockIdForFilePOptions.newBuilder().build()).build()) .getId(), "GetNewBlockIdForFile"); }
/** * Tests {@link FileSystemMaster#free} on non-persisted file. */ @Test public void freeNonPersistedFile() throws Exception { createFileWithSingleBlock(NESTED_FILE_URI); mThrown.expect(UnexpectedAlluxioException.class); mThrown.expectMessage(ExceptionMessage.CANNOT_FREE_NON_PERSISTED_FILE .getMessage(NESTED_FILE_URI.getPath())); // cannot free a non-persisted file mFileSystemMaster.free(NESTED_FILE_URI, FreeContext.defaults()); }
/** * Tests the {@link AlluxioURI#AlluxioURI(String)} constructor to work with Windows paths * appropriately. */ @Test public void windowsPathTests() { assumeTrue(WINDOWS); AlluxioURI uri = new AlluxioURI("C:\\foo\\bar"); assertFalse(uri.hasAuthority()); assertEquals("/C:/foo/bar", uri.getPath()); assertEquals("C:/foo/bar", uri.toString()); }