use of alluxio.grpc.SetAttributePOptions in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method createInternal.
private int createInternal(String path, @mode_t long mode, FuseFileInfo fi) {
final AlluxioURI uri = mPathResolverCache.getUnchecked(path);
if (uri.getName().length() > MAX_NAME_LENGTH) {
LOG.error("Failed to create {}, file name is longer than {} characters", path, MAX_NAME_LENGTH);
return -ErrorCodes.ENAMETOOLONG();
}
try {
if (mOpenFiles.size() >= MAX_OPEN_FILES) {
LOG.error("Cannot create {}: too many open files (MAX_OPEN_FILES: {})", path, MAX_OPEN_FILES);
return -ErrorCodes.EMFILE();
}
SetAttributePOptions.Builder attributeOptionsBuilder = SetAttributePOptions.newBuilder();
FuseContext fc = getContext();
long uid = fc.uid.get();
long gid = fc.gid.get();
if (gid != GID) {
String groupName = AlluxioFuseUtils.getGroupName(gid);
if (groupName.isEmpty()) {
// This should never be reached since input gid is always valid
LOG.error("Failed to get group name from gid {}.", gid);
return -ErrorCodes.EFAULT();
}
attributeOptionsBuilder.setGroup(groupName);
}
if (uid != UID) {
String userName = AlluxioFuseUtils.getUserName(uid);
if (userName.isEmpty()) {
// This should never be reached since input uid is always valid
LOG.error("Failed to get user name from uid {}", uid);
return -ErrorCodes.EFAULT();
}
attributeOptionsBuilder.setOwner(userName);
}
SetAttributePOptions setAttributePOptions = attributeOptionsBuilder.build();
FileOutStream os = mFileSystem.createFile(uri, CreateFilePOptions.newBuilder().setMode(new alluxio.security.authorization.Mode((short) mode).toProto()).build());
long fid = mNextOpenFileId.getAndIncrement();
mOpenFiles.add(new OpenFileEntry(fid, path, null, os));
fi.fh.set(fid);
if (gid != GID || uid != UID) {
LOG.debug("Set attributes of path {} to {}", path, setAttributePOptions);
mFileSystem.setAttribute(uri, setAttributePOptions);
}
} catch (FileAlreadyExistsException e) {
LOG.debug("Failed to create {}, file already exists", path);
return -ErrorCodes.EEXIST();
} catch (InvalidPathException e) {
LOG.debug("Failed to create {}, path is invalid", path);
return -ErrorCodes.ENOENT();
} catch (Throwable t) {
LOG.error("Failed to create {}", path, t);
return AlluxioFuseUtils.getErrorCode(t);
}
return 0;
}
use of alluxio.grpc.SetAttributePOptions in project alluxio by Alluxio.
the class PermissionCheckTest method setStateSuccess.
@Test
public void setStateSuccess() throws Exception {
// set unmask
try (Closeable c = new ConfigurationRule(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK, "000", ServerConfiguration.global()).toResource()) {
String file = PathUtils.concatPath(TEST_DIR_URI, "testState1");
verifyCreateFile(TEST_USER_1, file, false);
SetAttributePOptions expect = getNonDefaultSetState();
SetAttributePOptions result = verifySetState(TEST_USER_2, file, expect);
assertEquals(expect.getCommonOptions().getTtl(), result.getCommonOptions().getTtl());
assertEquals(expect.getCommonOptions().getTtlAction(), result.getCommonOptions().getTtlAction());
assertEquals(expect.getPinned(), result.getPinned());
}
}
use of alluxio.grpc.SetAttributePOptions in project alluxio by Alluxio.
the class AlluxioFuseFileSystemTest method chown.
@Test
public void chown() throws Exception {
long uid = AlluxioFuseUtils.getUid(System.getProperty("user.name"));
long gid = AlluxioFuseUtils.getGid(System.getProperty("user.name"));
mFuseFs.chown("/foo/bar", uid, gid);
String userName = System.getProperty("user.name");
String groupName = AlluxioFuseUtils.getGroupName(gid);
AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
SetAttributePOptions options = SetAttributePOptions.newBuilder().setGroup(groupName).setOwner(userName).build();
verify(mFileSystem).setAttribute(expectedPath, options);
}
use of alluxio.grpc.SetAttributePOptions in project alluxio by Alluxio.
the class AlluxioFuseFileSystemTest method chownWithoutValidGid.
@Test
public void chownWithoutValidGid() throws Exception {
long uid = AlluxioFuseUtils.getUid(System.getProperty("user.name"));
long gid = AlluxioFuseFileSystem.ID_NOT_SET_VALUE;
mFuseFs.chown("/foo/bar", uid, gid);
String userName = System.getProperty("user.name");
String groupName = AlluxioFuseUtils.getGroupName(userName);
AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
SetAttributePOptions options = SetAttributePOptions.newBuilder().setGroup(groupName).setOwner(userName).build();
verify(mFileSystem).setAttribute(expectedPath, options);
gid = AlluxioFuseFileSystem.ID_NOT_SET_VALUE_UNSIGNED;
mFuseFs.chown("/foo/bar", uid, gid);
verify(mFileSystem, times(2)).setAttribute(expectedPath, options);
}
use of alluxio.grpc.SetAttributePOptions in project alluxio by Alluxio.
the class AlluxioFuseFileSystemTest method chmod.
@Test
public void chmod() throws Exception {
long mode = 123;
mFuseFs.chmod("/foo/bar", mode);
AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
SetAttributePOptions options = SetAttributePOptions.newBuilder().setMode(new Mode((short) mode).toProto()).build();
verify(mFileSystem).setAttribute(expectedPath, options);
}
Aggregations