Search in sources :

Example 21 with SetAttributePOptions

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;
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) FileOutStream(alluxio.client.file.FileOutStream) InvalidPathException(java.nio.file.InvalidPathException) FuseContext(ru.serce.jnrfuse.struct.FuseContext) SetAttributePOptions(alluxio.grpc.SetAttributePOptions) AlluxioURI(alluxio.AlluxioURI)

Example 22 with SetAttributePOptions

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());
    }
}
Also used : SetAttributePOptions(alluxio.grpc.SetAttributePOptions) Closeable(java.io.Closeable) ConfigurationRule(alluxio.ConfigurationRule) Test(org.junit.Test)

Example 23 with SetAttributePOptions

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

Example 24 with SetAttributePOptions

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

Example 25 with SetAttributePOptions

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);
}
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)

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