Search in sources :

Example 26 with SetAttributePOptions

use of alluxio.grpc.SetAttributePOptions in project alluxio by Alluxio.

the class AlluxioFuseFileSystemTest method chownWithoutValidUid.

@Test
public void chownWithoutValidUid() throws Exception {
    String userName = System.getProperty("user.name");
    long uid = AlluxioFuseFileSystem.ID_NOT_SET_VALUE;
    long gid = AlluxioFuseUtils.getGid(userName);
    mFuseFs.chown("/foo/bar", uid, gid);
    String groupName = AlluxioFuseUtils.getGroupName(userName);
    AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
    SetAttributePOptions options = SetAttributePOptions.newBuilder().setGroup(groupName).build();
    verify(mFileSystem).setAttribute(expectedPath, options);
    uid = AlluxioFuseFileSystem.ID_NOT_SET_VALUE_UNSIGNED;
    mFuseFs.chown("/foo/bar", uid, gid);
    verify(mFileSystem, times(2)).setAttribute(expectedPath, options);
}
Also used : SetAttributePOptions(alluxio.grpc.SetAttributePOptions) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 27 with SetAttributePOptions

use of alluxio.grpc.SetAttributePOptions in project alluxio by Alluxio.

the class AlluxioJniFuseFileSystemTest method chownWithoutValidUid.

@Test
public void chownWithoutValidUid() throws Exception {
    String userName = System.getProperty("user.name");
    long uid = AlluxioFuseUtils.ID_NOT_SET_VALUE;
    long gid = AlluxioFuseUtils.getGid(userName);
    mFuseFs.chown("/foo/bar", uid, gid);
    String groupName = AlluxioFuseUtils.getGroupName(userName);
    AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
    SetAttributePOptions options = SetAttributePOptions.newBuilder().setGroup(groupName).build();
    verify(mFileSystem).setAttribute(expectedPath, options);
    uid = AlluxioFuseUtils.ID_NOT_SET_VALUE_UNSIGNED;
    mFuseFs.chown("/foo/bar", uid, gid);
    verify(mFileSystem, times(2)).setAttribute(expectedPath, options);
}
Also used : SetAttributePOptions(alluxio.grpc.SetAttributePOptions) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 28 with SetAttributePOptions

use of alluxio.grpc.SetAttributePOptions in project alluxio by Alluxio.

the class AlluxioJniFuseFileSystemTest 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);
}
Also used : SetAttributePOptions(alluxio.grpc.SetAttributePOptions) Mode(alluxio.security.authorization.Mode) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 29 with SetAttributePOptions

use of alluxio.grpc.SetAttributePOptions in project alluxio by Alluxio.

the class SystemUserGroupAuthPolicy method setUserGroupIfNeeded.

@Override
public void setUserGroupIfNeeded(AlluxioURI uri) throws Exception {
    FuseContext fc = mFuseFileSystem.getContext();
    if (!mIsUserGroupTranslation) {
        return;
    }
    long uid = fc.uid.get();
    long gid = fc.gid.get();
    if (uid == AlluxioFuseUtils.ID_NOT_SET_VALUE || uid == AlluxioFuseUtils.ID_NOT_SET_VALUE_UNSIGNED || gid == AlluxioFuseUtils.ID_NOT_SET_VALUE || gid == AlluxioFuseUtils.ID_NOT_SET_VALUE_UNSIGNED) {
        // cannot get valid uid or gid
        return;
    }
    if (uid == AlluxioFuseUtils.DEFAULT_UID && gid == AlluxioFuseUtils.DEFAULT_GID) {
        // no need to set attribute
        return;
    }
    String groupName = gid != AlluxioFuseUtils.DEFAULT_GID ? mGroupnameCache.get(gid) : AlluxioFuseUtils.DEFAULT_GROUP_NAME;
    String userName = uid != AlluxioFuseUtils.DEFAULT_UID ? mUsernameCache.get(uid) : AlluxioFuseUtils.DEFAULT_USER_NAME;
    if (userName.isEmpty() || groupName.isEmpty()) {
        // cannot get valid user name and group name
        return;
    }
    SetAttributePOptions attributeOptions = SetAttributePOptions.newBuilder().setGroup(groupName).setOwner(userName).build();
    LOG.debug("Set attributes of path {} to {}", uri, attributeOptions);
    mFileSystem.setAttribute(uri, attributeOptions);
}
Also used : FuseContext(alluxio.jnifuse.struct.FuseContext) SetAttributePOptions(alluxio.grpc.SetAttributePOptions)

Example 30 with SetAttributePOptions

use of alluxio.grpc.SetAttributePOptions in project alluxio by Alluxio.

the class CustomAuthPolicy method setUserGroupIfNeeded.

@Override
public void setUserGroupIfNeeded(AlluxioURI uri) throws Exception {
    if (StringUtils.isEmpty(mUname) || StringUtils.isEmpty(mGname)) {
        return;
    }
    SetAttributePOptions attributeOptions = SetAttributePOptions.newBuilder().setGroup(mGname).setOwner(mUname).build();
    mFileSystem.setAttribute(uri, attributeOptions);
    LOG.debug("Set attributes of path {} to {}", uri, attributeOptions);
}
Also used : SetAttributePOptions(alluxio.grpc.SetAttributePOptions)

Aggregations

SetAttributePOptions (alluxio.grpc.SetAttributePOptions)31 AlluxioURI (alluxio.AlluxioURI)20 Test (org.junit.Test)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 Mode (alluxio.security.authorization.Mode)6 URIStatus (alluxio.client.file.URIStatus)3 ConfigurationRule (alluxio.ConfigurationRule)2 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)2 Closeable (java.io.Closeable)2 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 InvalidPathException (java.nio.file.InvalidPathException)2 FuseContext (ru.serce.jnrfuse.struct.FuseContext)2 FileOutStream (alluxio.client.file.FileOutStream)1 FileSystem (alluxio.client.file.FileSystem)1 AlluxioException (alluxio.exception.AlluxioException)1 CreateFilePOptions (alluxio.grpc.CreateFilePOptions)1 GetStatusPOptions (alluxio.grpc.GetStatusPOptions)1 FuseContext (alluxio.jnifuse.struct.FuseContext)1 JobIntegrationTest (alluxio.job.JobIntegrationTest)1 ListAllMyBucketsResult (alluxio.proxy.s3.ListAllMyBucketsResult)1