/** * Returns whether or not filePath matches patternPath. * * @param filePath path of a given file * @param patternPath path that can contain wildcards * @return true if matches; false if not */ public static boolean match(String filePath, String patternPath) { return match(new AlluxioURI(filePath), new AlluxioURI(patternPath)); } }
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; }
/** * Clean the path by creating a URI and turning it back to a string. * * @param path the path to validate * @return validated path */ protected static String validatePath(String path) { return new AlluxioURI(path).toString(); } }
/** * @param path the path to strip the scheme from * @return the path, with the optional scheme stripped away */ private String stripPath(String path) { return new AlluxioURI(path).getPath(); } }
/** * Tests the {@link AlluxioURI#AlluxioURI(String)} constructor to work with file URIs * appropriately. */ @Test public void fileUriTests() { AlluxioURI uri = new AlluxioURI("file:///foo/bar"); assertFalse(uri.hasAuthority()); assertEquals("/foo/bar", uri.getPath()); assertEquals("file:///foo/bar", uri.toString()); }
private void checkPersistedDirectoriesDeleted(int levels, AlluxioURI ufsMount, List<AlluxioURI> except) throws Exception { checkPersistedDirectoryDeletedLevel(levels, new AlluxioURI(MOUNT_URI).join(DIR_TOP_LEVEL), ufsMount.join(DIR_TOP_LEVEL), except); }
@Test public void semicolonMultiMasterUri() { AlluxioURI uri = new AlluxioURI("alluxio://host1:1323;host2:54325;host3:64354/xy z/a b c"); assertTrue(uri.hasAuthority()); assertEquals("host1:1323,host2:54325,host3:64354", uri.getAuthority().toString()); assertTrue(uri.getAuthority() instanceof MultiMasterAuthority); MultiMasterAuthority authority = (MultiMasterAuthority) uri.getAuthority(); assertEquals("host1:1323,host2:54325,host3:64354", authority.getMasterAddresses()); }
/** * 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())); }
/** * Tests the {@link AlluxioURI#getParent()} method. */ @Test public void getParentTests() { assertEquals(null, new AlluxioURI("/").getParent()); assertEquals(null, new AlluxioURI("alluxio://localhost/").getParent()); assertEquals(new AlluxioURI("alluxio://localhost/"), new AlluxioURI("alluxio://localhost/a").getParent()); assertEquals(new AlluxioURI("/a"), new AlluxioURI("/a/b/../c").getParent()); assertEquals(new AlluxioURI("alluxio:/a"), new AlluxioURI("alluxio:/a/b/../c").getParent()); assertEquals(new AlluxioURI("alluxio://localhost:80/a"), new AlluxioURI( "alluxio://localhost:80/a/b/../c").getParent()); }
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); } }
/** * @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); }
@Override public String toString() { return mUri.toString(); } }
/** * Tests the {@link AlluxioURI#getName()} method. */ @Test public void getNameTests() { assertEquals(".", new AlluxioURI(".").getName()); assertEquals("", new AlluxioURI("/").getName()); assertEquals("", new AlluxioURI("alluxio://localhost/").getName()); assertEquals("", new AlluxioURI("alluxio:/").getName()); assertEquals("a", new AlluxioURI("alluxio:/a/").getName()); assertEquals("a.txt", new AlluxioURI("alluxio:/a.txt/").getName()); assertEquals(" b.txt", new AlluxioURI("alluxio:/a/ b.txt").getName()); assertEquals("a.txt", new AlluxioURI("/a/a.txt").getName()); }
/** * Tests the {@link AlluxioURI#getAuthority()} method. */ @Test public void getAuthorityTests() { String[] authorities = new String[] {"localhost", "localhost:8080", "127.0.0.1", "127.0.0.1:8080", "localhost"}; for (String authority : authorities) { AlluxioURI uri = new AlluxioURI("file", Authority.fromString(authority), "/a/b"); assertEquals(authority, uri.getAuthority().toString()); } assertEquals("", new AlluxioURI("file", Authority.fromString(""), "/b/c").getAuthority().toString()); assertEquals("", new AlluxioURI("file", null, "/b/c").getAuthority().toString()); assertEquals("", new AlluxioURI("file", Authority.fromString(null), "/b/c").getAuthority().toString()); assertEquals("", new AlluxioURI("file:///b/c").getAuthority().toString()); }
/** * Returns true if the current AlluxioURI is an ancestor of another AlluxioURI. * otherwise, return false. * @param alluxioURI potential children to check * @return true the current alluxioURI is an ancestor of the AlluxioURI */ public boolean isAncestorOf(AlluxioURI alluxioURI) throws InvalidPathException { // To be an ancestor of another URI, authority and scheme must match if (!Objects.equals(getAuthority(), alluxioURI.getAuthority())) { return false; } if (!Objects.equals(getScheme(), alluxioURI.getScheme())) { return false; } return PathUtils.hasPrefix(PathUtils.normalizePath(alluxioURI.getPath(), SEPARATOR), PathUtils.normalizePath(getPath(), SEPARATOR)); }
/** * Tests the {@link FileSystemMaster#free} method with a directory with a file non-persisted. */ @Test public void freeDirWithNonPersistedFile() 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 the parent dir of a non-persisted file mFileSystemMaster.free(NESTED_FILE_URI.getParent(), FreeContext.defaults(FreePOptions.newBuilder().setForced(false).setRecursive(true))); }
@Override public boolean isAbsent(AlluxioURI path) { MountInfo mountInfo = getMountInfo(path); if (mountInfo == null) { return false; } AlluxioURI mountBaseUri = mountInfo.getAlluxioUri(); while (path != null && !path.equals(mountBaseUri)) { Long cached = mCache.getIfPresent(path.getPath()); if (cached != null && cached == mountInfo.getMountId()) { return true; } path = path.getParent(); } // Reached the root, without finding anything in the cache. return false; }
private void createPersistedDirectoryLevel(int levels, AlluxioURI ufsTop) throws Exception { if (levels <= 0) { return; } // Create files and nested directories in UFS. for (int i = 0; i < DIR_WIDTH; ++i) { Files.createFile(Paths.get(ufsTop.join(FILE_PREFIX + i).getPath())); Files.createDirectories(Paths.get(ufsTop.join(DIR_PREFIX + i).getPath())); createPersistedDirectoryLevel(levels - 1, ufsTop.join(DIR_PREFIX + i)); } }
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); } }