return -ErrorCodes.EINVAL(); optionsBuilder.setOwner(userName); return -ErrorCodes.EINVAL(); optionsBuilder.setGroup(groupName); } else if (!userName.isEmpty()) { groupName = AlluxioFuseUtils.getGroupName(userName); optionsBuilder.setGroup(groupName); } else if (userName.isEmpty()) { LOG.info("Change group of file {} to {}", path, groupName); mFileSystem.setAttribute(uri, optionsBuilder.build()); } else { LOG.info("Change owner of file {} to {}", path, groupName); mFileSystem.setAttribute(uri, optionsBuilder.build());
long opTimeMs = System.currentTimeMillis(); setAttributeSingleFile(rpcContext, inodePath, false, opTimeMs, SetAttributeContext .defaults(SetAttributePOptions.newBuilder().setOwner(ufsFpParsed.getTag(Tag.OWNER)) .setGroup(ufsFpParsed.getTag(Tag.GROUP)).setMode(new Mode(mode).toProto())) .setUfsFingerprint(ufsFingerprint));
.defaults(SetAttributePOptions.newBuilder().setRecursive(false).setPinned(false)); setAttributeSingleFile(rpcContext, descedant, true, opTimeMs, setAttributeContext);
SetAttributeContext.defaults(SetAttributePOptions.newBuilder().setPersisted(true)));
public Builder mergeFrom(alluxio.grpc.SetAttributePOptions other) { if (other == alluxio.grpc.SetAttributePOptions.getDefaultInstance()) return this; if (other.hasPinned()) { setPinned(other.getPinned()); setTtl(other.getTtl()); setTtlAction(other.getTtlAction()); setPersisted(other.getPersisted()); onChanged(); onChanged(); mergeMode(other.getMode()); setRecursive(other.getRecursive()); setReplicationMax(other.getReplicationMax()); setReplicationMin(other.getReplicationMin()); mergeCommonOptions(other.getCommonOptions()); this.mergeUnknownFields(other.unknownFields); onChanged(); return this;
/** * Tests the {@link FileSystemMaster#setAttribute(AlluxioURI, SetAttributeContext)} method and * that an exception is thrown when trying to set a TTL for a directory. */ @Test public void setAttribute() throws Exception { mFileSystemMaster.createFile(NESTED_FILE_URI, mNestedFileContext); FileInfo fileInfo = mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT); assertFalse(fileInfo.isPinned()); assertEquals(Constants.NO_TTL, fileInfo.getTtl()); // No State. mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeContext.defaults()); fileInfo = mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT); assertFalse(fileInfo.isPinned()); assertEquals(Constants.NO_TTL, fileInfo.getTtl()); // Just set pinned flag. mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeContext.defaults(SetAttributePOptions.newBuilder().setPinned(true))); fileInfo = mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT); assertTrue(fileInfo.isPinned()); assertEquals(Constants.NO_TTL, fileInfo.getTtl()); // Both pinned flag and ttl value. mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeContext.defaults(SetAttributePOptions.newBuilder().setPinned(false).setTtl(1))); fileInfo = mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT); assertFalse(fileInfo.isPinned()); assertEquals(1, fileInfo.getTtl()); mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.defaults(SetAttributePOptions.newBuilder().setTtl(1))); }
boolean ownerOrGroupChanged = false; if (username != null && !username.isEmpty()) { optionsBuilder.setOwner(username).setRecursive(false); ownerOrGroupChanged = true; optionsBuilder.setGroup(groupname).setRecursive(false); ownerOrGroupChanged = true; mFileSystem.setAttribute(uri, optionsBuilder.build()); } catch (AlluxioException e) { throw new IOException(e);
/** * Tests that an exception is thrown when trying to get information about a Directory after * it has been deleted because of a TTL of 0. */ @Test public void setTtlForDirectoryWithNoTtl() throws Exception { CreateDirectoryContext directoryContext = CreateDirectoryContext .defaults(CreateDirectoryPOptions.newBuilder().setRecursive(true)); mFileSystemMaster.createDirectory(NESTED_URI, directoryContext); mFileSystemMaster.createDirectory(NESTED_DIR_URI, directoryContext); CreateFileContext createFileContext = CreateFileContext.defaults( CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB).setRecursive(true)); long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, createFileContext); HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK); // Since no TTL is set, the file should not be deleted. assertEquals(fileId, mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT).getFileId()); // Set ttl. mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.defaults(SetAttributePOptions.newBuilder().setTtl(0))); HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK); // TTL is set to 0, the file and directory should have been deleted during last TTL check. mThrown.expect(FileDoesNotExistException.class); mFileSystemMaster.getFileInfo(NESTED_URI, GET_STATUS_CONTEXT); mFileSystemMaster.getFileInfo(NESTED_DIR_URI, GET_STATUS_CONTEXT); mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT); }
private void verifySetAcl(TestUser runUser, String path, String owner, String group, short mode, boolean recursive) throws Exception { try (Closeable r = new AuthenticatedUserRule(runUser.getUser(), ServerConfiguration.global()).toResource()) { SetAttributeContext context = SetAttributeContext.defaults(SetAttributePOptions.newBuilder() .setMode(new Mode(mode).toProto()).setRecursive(recursive)); if (owner != null) { context.getOptions().setOwner(owner); } if (group != null) { context.getOptions().setGroup(group); } mFileSystemMaster.setAttribute(new AlluxioURI(path), context); } try (Closeable r = new AuthenticatedUserRule(TEST_USER_ADMIN.getUser(), ServerConfiguration.global()).toResource()) { FileInfo fileInfo = mFileSystemMaster.getFileInfo(mFileSystemMaster.getFileId(new AlluxioURI(path))); if (owner != null) { assertEquals(owner, fileInfo.getOwner()); } if (group != null) { assertEquals(group, fileInfo.getGroup()); } if (mode != -1) { assertEquals(mode, fileInfo.getMode()); } } }
@Test public void deleteDirRecursiveWithInsufficientPermissions() throws Exception { // userA has permissions to delete directory but not one of the nested files createFileWithSingleBlock(NESTED_FILE_URI); createFileWithSingleBlock(NESTED_FILE2_URI); mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext .defaults(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto()))); mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeContext .defaults(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0700).toProto()))); mFileSystemMaster.setAttribute(NESTED_FILE2_URI, SetAttributeContext .defaults(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto()))); try (AuthenticatedClientUserResource userA = new AuthenticatedClientUserResource("userA", ServerConfiguration.global())) { mFileSystemMaster.delete(NESTED_URI, DeleteContext.defaults(DeletePOptions.newBuilder().setRecursive(true))); fail("Deleting a directory w/ insufficient permission on child should fail"); } catch (AccessControlException e) { String expectedChildMessage = ExceptionMessage.PERMISSION_DENIED .getMessage("user=userA, access=-w-, path=" + NESTED_FILE_URI + ": failed at file"); assertTrue(e.getMessage().startsWith(ExceptionMessage.DELETE_FAILED_DIR_CHILDREN .getMessage(NESTED_URI, expectedChildMessage))); } assertNotEquals(IdUtils.INVALID_FILE_ID, mFileSystemMaster.getFileId(NESTED_URI)); assertNotEquals(IdUtils.INVALID_FILE_ID, mFileSystemMaster.getFileId(NESTED_FILE_URI)); assertNotEquals(IdUtils.INVALID_FILE_ID, mFileSystemMaster.getFileId(NESTED_FILE2_URI)); }
@Override public FileSystemCommand workerHeartbeat(long workerId, List<Long> persistedFiles, WorkerHeartbeatContext context) throws IOException { List<String> persistedUfsFingerprints = context.getOptions().getPersistedFileFingerprintsList(); boolean hasPersistedFingerprints = persistedUfsFingerprints.size() == persistedFiles.size(); for (int i = 0; i < persistedFiles.size(); i++) { long fileId = persistedFiles.get(i); String ufsFingerprint = hasPersistedFingerprints ? persistedUfsFingerprints.get(i) : Constants.INVALID_UFS_FINGERPRINT; try { // Permission checking for each file is performed inside setAttribute setAttribute(getPath(fileId), SetAttributeContext .defaults(SetAttributePOptions.newBuilder().setPersisted(true)) .setUfsFingerprint(ufsFingerprint)); } catch (FileDoesNotExistException | AccessControlException | InvalidPathException e) { LOG.error("Failed to set file {} as persisted, because {}", fileId, e); } } // TODO(zac) Clean up master and worker code since this is taken care of by job service now. // Worker should not persist any files. Instead, files are persisted through job service. List<PersistFile> filesToPersist = new ArrayList<>(); FileSystemCommandOptions commandOptions = new FileSystemCommandOptions(); commandOptions.setPersistOptions(new PersistCommandOptions(filesToPersist)); return new FileSystemCommand(CommandType.Persist, commandOptions); }
@Test public void listStatusRecursivePermissions() throws Exception { final int files = 10; List<FileInfo> infos; List<String> filenames; // Test files in root directory. for (int i = 0; i < files; i++) { createFileWithSingleBlock(ROOT_URI.join("file" + String.format("%05d", i))); } // Test files in nested directory. for (int i = 0; i < files; i++) { createFileWithSingleBlock(NESTED_URI.join("file" + String.format("%05d", i))); } // Test with permissions mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.defaults(SetAttributePOptions .newBuilder().setMode(new Mode((short) 0400).toProto()).setRecursive(true))); try (Closeable r = new AuthenticatedUserRule("test_user1", ServerConfiguration.global()) .toResource()) { // Test recursive listStatus infos = mFileSystemMaster.listStatus(ROOT_URI, ListStatusContext.defaults(ListStatusPOptions .newBuilder().setLoadMetadataType(LoadMetadataPType.ALWAYS).setRecursive(true))); // 10 files in each directory, 1 level of directories assertEquals(files + 1, infos.size()); } }
/** * Changes the replication level of directory or file with the path specified in args. * * @param path The {@link AlluxioURI} path as the input of the command * @param replicationMax the max replicas, null if not to set * @param replicationMin the min replicas, null if not to set * @param recursive Whether change the permission recursively * @throws AlluxioException when Alluxio exception occurs * @throws IOException when non-Alluxio exception occurs */ private void setReplication(AlluxioURI path, Integer replicationMax, Integer replicationMin, boolean recursive) throws AlluxioException, IOException { SetAttributePOptions.Builder optionsBuilder = SetAttributePOptions.newBuilder().setRecursive(recursive); String message = "Changed the replication level of " + path + "\n"; if (replicationMax != null) { optionsBuilder.setReplicationMax(replicationMax); message += "replicationMax was set to " + replicationMax + "\n"; } if (replicationMin != null) { optionsBuilder.setReplicationMin(replicationMin); message += "replicationMin was set to " + replicationMin + "\n"; } mFileSystem.setAttribute(path, optionsBuilder.build()); System.out.println(message); }
/** * Tests that TTL free of a directory is not forgotten across restarts. */ @Test public void ttlDirectoryFreeReplay() throws Exception { CreateDirectoryContext directoryContext = CreateDirectoryContext .defaults(CreateDirectoryPOptions.newBuilder().setRecursive(true)); mFileSystemMaster.createDirectory(NESTED_URI, directoryContext); long blockId = createFileWithSingleBlock(NESTED_FILE_URI); assertEquals(1, mBlockMaster.getBlockInfo(blockId).getLocations().size()); // Set ttl & operation. mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.defaults( SetAttributePOptions.newBuilder().setTtl(0).setTtlAction(alluxio.grpc.TtlAction.FREE))); // Simulate restart. stopServices(); startServices(); Command heartbeat = mBlockMaster.workerHeartbeat(mWorkerId1, null, ImmutableMap.of("MEM", (long) Constants.KB), ImmutableList.of(blockId), ImmutableMap.<String, List<Long>>of(), mMetrics); // Verify the muted Free command on worker1. assertEquals(Command.newBuilder().setCommandType(CommandType.Nothing).build(), heartbeat); assertEquals(0, mBlockMaster.getBlockInfo(blockId).getLocations().size()); }
/** * Tests that an exception is thrown when trying to get information about a file after it * has been deleted after the TTL has been set to 0. */ @Test public void setSmallerTtlForFileWithTtl() throws Exception { CreateFileContext context = CreateFileContext.defaults(CreateFilePOptions.newBuilder() .setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(Constants.HOUR_MS)) .setBlockSizeBytes(Constants.KB).setRecursive(true)); long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, context); HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK); // Since TTL is 1 hour, the file won't be deleted during last TTL check. assertEquals(fileId, mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT).getFileId()); mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeContext.defaults(SetAttributePOptions.newBuilder().setTtl(0))); HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK); // TTL is reset to 0, the file should have been deleted during last TTL check. mThrown.expect(FileDoesNotExistException.class); mFileSystemMaster.getFileInfo(fileId); }
/** * Tests {@link FileSystemMaster#free} on pinned file when forced flag is true. */ @Test public void freePinnedFileWithForce() throws Exception { mNestedFileContext.setPersisted(true); long blockId = createFileWithSingleBlock(NESTED_FILE_URI); mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeContext.defaults(SetAttributePOptions.newBuilder().setPinned(true))); assertEquals(1, mBlockMaster.getBlockInfo(blockId).getLocations().size()); // free the file mFileSystemMaster.free(NESTED_FILE_URI, FreeContext.defaults(FreePOptions.newBuilder().setForced(true))); // Update the heartbeat of removedBlockId received from worker 1. Command heartbeat = mBlockMaster.workerHeartbeat(mWorkerId1, null, ImmutableMap.of("MEM", (long) Constants.KB), ImmutableList.of(blockId), ImmutableMap.<String, List<Long>>of(), mMetrics); // Verify the muted Free command on worker1. assertEquals(Command.newBuilder().setCommandType(CommandType.Nothing).build(), heartbeat); assertEquals(0, mBlockMaster.getBlockInfo(blockId).getLocations().size()); }
@Test public void setAclNestedWithoutOwner() throws Exception { createFileWithSingleBlock(NESTED_FILE_URI); mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.defaults(SetAttributePOptions .newBuilder().setMode(new Mode((short) 0777).toProto()).setOwner("userA"))); Set<String> entries = Sets.newHashSet(mFileSystemMaster .getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT).convertAclToStringEntries()); assertEquals(3, entries.size()); // recursive setAcl should fail if one of the child is not owned by the user mThrown.expect(AccessControlException.class); try (AuthenticatedClientUserResource userA = new AuthenticatedClientUserResource("userA", ServerConfiguration.global())) { Set<String> newEntries = Sets.newHashSet("user::rwx", "group::rwx", "other::rwx"); mFileSystemMaster.setAcl(NESTED_URI, SetAclAction.REPLACE, newEntries.stream().map(AclEntry::fromCliString).collect(Collectors.toList()), SetAclContext.defaults(SetAclPOptions.newBuilder().setRecursive(true))); entries = Sets.newHashSet(mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT) .convertAclToStringEntries()); assertEquals(newEntries, entries); } }
/** * Tests that an exception is thrown when trying to get information about a Directory after * it has been deleted after the TTL has been set to 0. */ @Test public void setSmallerTtlForDirectoryWithTtl() throws Exception { CreateDirectoryContext directoryContext = CreateDirectoryContext.defaults(CreateDirectoryPOptions.newBuilder() .setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(Constants.HOUR_MS)) .setRecursive(true)); mFileSystemMaster.createDirectory(NESTED_URI, directoryContext); HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK); assertTrue( mFileSystemMaster.getFileInfo(NESTED_URI, GET_STATUS_CONTEXT).getName() != null); mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.defaults(SetAttributePOptions.newBuilder().setTtl(0))); HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK); // TTL is reset to 0, the file should have been deleted during last TTL check. mThrown.expect(FileDoesNotExistException.class); mFileSystemMaster.getFileInfo(NESTED_URI, GET_STATUS_CONTEXT); }
/** * Tests that file information is still present after it has been freed after the parent * directory's TTL has been set to 0. */ @Test public void ttlDirectoryFree() throws Exception { CreateDirectoryContext directoryContext = CreateDirectoryContext .defaults(CreateDirectoryPOptions.newBuilder().setRecursive(true)); mFileSystemMaster.createDirectory(NESTED_URI, directoryContext); long blockId = createFileWithSingleBlock(NESTED_FILE_URI); assertEquals(1, mBlockMaster.getBlockInfo(blockId).getLocations().size()); // Set ttl & operation. mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.defaults( SetAttributePOptions.newBuilder().setTtl(0).setTtlAction(alluxio.grpc.TtlAction.FREE))); Command heartbeat = mBlockMaster.workerHeartbeat(mWorkerId1, null, ImmutableMap.of("MEM", (long) Constants.KB), ImmutableList.of(blockId), ImmutableMap.<String, List<Long>>of(), mMetrics); // Verify the muted Free command on worker1. assertEquals(Command.newBuilder().setCommandType(CommandType.Nothing).build(), heartbeat); assertEquals(0, mBlockMaster.getBlockInfo(blockId).getLocations().size()); }
/** * Tests the {@link FileSystemMaster#free} method with a directory with a file pinned when * forced flag is true. */ @Test public void freeDirWithPinnedFileAndForced() throws Exception { mNestedFileContext.setPersisted(true); long blockId = createFileWithSingleBlock(NESTED_FILE_URI); mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeContext.defaults(SetAttributePOptions.newBuilder().setPinned(true))); // free the parent dir of a pinned file with "forced" mFileSystemMaster.free(NESTED_FILE_URI.getParent(), FreeContext.defaults(FreePOptions.newBuilder().setForced(true).setRecursive(true))); // Update the heartbeat of removedBlockId received from worker 1. Command heartbeat = mBlockMaster.workerHeartbeat(mWorkerId1, null, ImmutableMap.of("MEM", (long) Constants.KB), ImmutableList.of(blockId), ImmutableMap.<String, List<Long>>of(), mMetrics); // Verify the muted Free command on worker1. assertEquals(Command.newBuilder().setCommandType(CommandType.Nothing).build(), heartbeat); assertEquals(0, mBlockMaster.getBlockInfo(blockId).getLocations().size()); }