/** * Convenience method which ensures the given path exists, wrapping any {@link AlluxioException} * in {@link IOException}. * * @param path the path to look up */ private void ensureExists(AlluxioURI path) throws IOException { try { mFileSystem.getStatus(path); } catch (AlluxioException e) { throw new IOException(e); } }
private List<FileBlockInfo> getFileBlocks(AlluxioURI path) throws IOException { try { return mFileSystem.getStatus(path).getFileBlockInfos(); } catch (AlluxioException e) { throw new IOException(e); } }
@Override public void check(FileSystem fs) throws Exception { for (AlluxioURI file : Arrays.asList(PATH, NESTED, THROUGH, TTL)) { assertTrue(fs.exists(file)); } assertEquals(TEST_MODE, new Mode((short) fs.getStatus(MODE).getMode())); assertTrue(fs.getStatus(THROUGH).isPersisted()); assertEquals(TEST_TTL, fs.getStatus(TTL).getTtl()); assertEquals(TtlAction.FREE, fs.getStatus(TTL).getTtlAction()); } }
@Override public void check(Clients clients) throws Exception { for (AlluxioURI uri : Arrays.asList(PATH, NESTED_PATH, NESTED_PATH.getParent())) { assertTrue(clients.getFileSystemClient().getStatus(uri).isPersisted()); } } }
@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); } }
@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 checkBucketIsAlluxioDirectory(String bucketPath) throws S3Exception { try { URIStatus status = mFileSystem.getStatus(new AlluxioURI(bucketPath)); if (!status.isFolder()) { throw new InvalidPathException("Bucket name is not a valid Alluxio directory."); } } catch (Exception e) { throw toBucketS3Exception(e, bucketPath); } }
@Override public void check(FileSystem fs) throws Exception { Assert.assertTrue(fs.getStatus(ALLUXIO_MOUNT_PATH).isMountPoint()); Assert.assertFalse(fs.exists(ALLUXIO_UNMOUNT_PATH)); } }
@Override protected void runPlainPath(AlluxioURI plainPath, CommandLine cl) throws AlluxioException, IOException { URIStatus status = mFileSystem.getStatus(plainPath); System.out.println(plainPath + " with file id " + status.getFileId() + " is on nodes: "); AlluxioBlockStore blockStore = AlluxioBlockStore.create(mFsContext); for (long blockId : status.getBlockIds()) { for (BlockLocation location : blockStore.getInfo(blockId).getLocations()) { System.out.println(location.getWorkerAddress().getHost()); } } }
/** * Creates a directory in the Alluxio filesystem space. It will not throw any exception if the * destination directory already exists. * * @param dstPath the {@link AlluxioURI} of the destination directory which will be created */ private void createDstDir(AlluxioURI dstPath) throws AlluxioException, IOException { try { mFileSystem.createDirectory(dstPath); } catch (FileAlreadyExistsException e) { // it's fine if the directory already exists } URIStatus dstStatus = mFileSystem.getStatus(dstPath); if (!dstStatus.isFolder()) { throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage()); } }
/** * Tells the mock to throw FileDoesNotExistException when the given path is queried. */ private void setPathToNotExist(String path) throws Exception { AlluxioURI uri = new AlluxioURI(path); when(mMockFileSystem.getStatus(uri)).thenThrow(new FileDoesNotExistException(uri)); when(mMockFileSystem.listStatus(uri)).thenThrow(new FileDoesNotExistException(uri)); } }
@Override public void apply(Clients clients) throws Exception { FileSystem fs = clients.getFileSystemClient(); Utils.createFile(fs, PATH); clients.getFileSystemMasterClient().scheduleAsyncPersist(PATH); Utils.createFile(fs, NESTED_PATH); clients.getFileSystemMasterClient().scheduleAsyncPersist(NESTED_PATH); CommonUtils.waitFor("file to be async persisted", () -> { try { return fs.getStatus(PATH).isPersisted() && fs.getStatus(NESTED_PATH).isPersisted(); } catch (Exception e) { throw new RuntimeException(e); } }, WaitForOptions.defaults().setTimeoutMs(10 * Constants.SECOND_MS)); }
@Override public boolean setReplication(Path path, short replication) throws IOException { AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); try { if (!mFileSystem.exists(uri) || mFileSystem.getStatus(uri).isFolder()) { return false; } mFileSystem.setAttribute(uri, (SetAttributePOptions) SetAttributePOptions.newBuilder() .setReplicationMin(replication).build()); return true; } catch (AlluxioException e) { throw new IOException(e); } }
/** * Creates a directory with the given name. * * @return file info for the created directory */ private FileInfo createDirectory(String name) throws Exception { // Call all directories mount points to force cross-mount functionality. FileInfo info = new FileInfo().setFolder(true).setPath(name).setMountPoint(true); when(mMockFileSystem.getStatus(new AlluxioURI(name))).thenReturn(new URIStatus(info)); return info; }
private void checkUploadId(AlluxioURI multipartTemporaryDir, long uploadId) throws S3Exception { try { if (!mFileSystem.exists(multipartTemporaryDir)) { throw new S3Exception(multipartTemporaryDir.getPath(), S3ErrorCode.NO_SUCH_UPLOAD); } long tmpDirId = mFileSystem.getStatus(multipartTemporaryDir).getFileId(); if (uploadId != tmpDirId) { throw new S3Exception(multipartTemporaryDir.getPath(), S3ErrorCode.NO_SUCH_UPLOAD); } } catch (Exception e) { throw toObjectS3Exception(e, multipartTemporaryDir.getPath()); } }
private FileInfo createFileWithNoLocations(String testFile, int numOfBlocks) throws Exception { FileInfo testFileInfo = new FileInfo(); AlluxioURI uri = new AlluxioURI(testFile); List<FileBlockInfo> blockInfos = Lists.newArrayList(); for (int i = 0; i < numOfBlocks; i++) { blockInfos.add(new FileBlockInfo() .setBlockInfo(new BlockInfo().setLocations(Lists.<BlockLocation>newArrayList()))); } testFileInfo.setFolder(false).setPath(testFile).setFileBlockInfos(blockInfos); Mockito.when(mMockFileSystem.listStatus(uri)) .thenReturn(Lists.newArrayList(new URIStatus(testFileInfo))); Mockito.when(mMockFileSystem.getStatus(uri)).thenReturn(new URIStatus(testFileInfo)); return testFileInfo; } }
/** * Tests for the {@link BaseFileSystem#getStatus(AlluxioURI, GetStatusPOptions)} method. */ @Test public void getStatus() throws Exception { AlluxioURI file = new AlluxioURI("/file"); URIStatus status = new URIStatus(new FileInfo()); GetStatusPOptions getStatusOptions = GetStatusPOptions.getDefaultInstance(); when(mFileSystemMasterClient.getStatus(file, getStatusOptions)).thenReturn(status); assertSame(status, mFileSystem.getStatus(file, getStatusOptions)); verify(mFileSystemMasterClient).getStatus(file, getStatusOptions); verifyFilesystemContextAcquiredAndReleased(); }