Search in sources :

Example 11 with SetAttributePOptions

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

the class ChmodCommand method chmod.

/**
 * Changes the permissions of directory or file with the path specified in args.
 *
 * @param path The {@link AlluxioURI} path as the input of the command
 * @param modeStr The new permission to be updated to the file or directory
 * @param recursive Whether change the permission recursively
 */
private void chmod(AlluxioURI path, String modeStr, boolean recursive) throws AlluxioException, IOException {
    Mode mode = ModeParser.parse(modeStr);
    SetAttributePOptions options = SetAttributePOptions.newBuilder().setMode(mode.toProto()).setRecursive(recursive).build();
    mFileSystem.setAttribute(path, options);
    System.out.println("Changed permission of " + path + " to " + Integer.toOctalString(mode.toShort()));
}
Also used : SetAttributePOptions(alluxio.grpc.SetAttributePOptions) Mode(alluxio.security.authorization.Mode)

Example 12 with SetAttributePOptions

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

the class BaseFileSystemTest method setAttributeSyncMetadataInterval.

/**
 * Tests that the metadata sync interval is included on setAttributePOptions by default.
 */
@Test
public void setAttributeSyncMetadataInterval() throws Exception {
    AlluxioURI file = new AlluxioURI("/file");
    SetAttributePOptions opt = FileSystemOptions.setAttributeClientDefaults(mFileContext.getPathConf(file));
    // Check that metadata sync interval from configuration is used when options are omitted
    mFileSystem.setAttribute(file);
    verify(mFileSystemMasterClient).setAttribute(file, opt);
}
Also used : SetAttributePOptions(alluxio.grpc.SetAttributePOptions) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with SetAttributePOptions

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

the class BaseFileSystemTest method setStateException.

/**
 * Ensures that an exception is propagated successfully when setting the state.
 */
@Test
public void setStateException() throws Exception {
    AlluxioURI file = new AlluxioURI("/file");
    SetAttributePOptions setAttributeOptions = FileSystemOptions.setAttributeClientDefaults(mFileContext.getPathConf(file));
    doThrow(EXCEPTION).when(mFileSystemMasterClient).setAttribute(file, setAttributeOptions);
    try {
        mFileSystem.setAttribute(file, setAttributeOptions);
        fail(SHOULD_HAVE_PROPAGATED_MESSAGE);
    } catch (Exception e) {
        assertSame(EXCEPTION, e);
    }
}
Also used : SetAttributePOptions(alluxio.grpc.SetAttributePOptions) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with SetAttributePOptions

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

the class BaseFileSystemTest method setAttribute.

/**
 * Tests for the {@link BaseFileSystem#setAttribute(AlluxioURI, SetAttributePOptions)} method.
 */
@Test
public void setAttribute() throws Exception {
    AlluxioURI file = new AlluxioURI("/file");
    SetAttributePOptions setAttributeOptions = FileSystemOptions.setAttributeClientDefaults(mFileContext.getPathConf(file));
    mFileSystem.setAttribute(file, setAttributeOptions);
    verify(mFileSystemMasterClient).setAttribute(file, setAttributeOptions);
}
Also used : SetAttributePOptions(alluxio.grpc.SetAttributePOptions) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with SetAttributePOptions

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

the class FileSystemCommandUtils method setTtl.

/**
 * Sets a new TTL value or unsets an existing TTL value for file at path.
 *
 * @param fs the file system for Alluxio
 * @param path the file path
 * @param ttlMs the TTL (time to live) value to use; it identifies duration (in milliseconds) the
 *        created file should be kept around before it is automatically deleted, irrespective of
 *        whether the file is pinned; {@link Constants#NO_TTL} means to unset the TTL value
 * @param ttlAction Action to perform on Ttl expiry
 */
public static void setTtl(FileSystem fs, AlluxioURI path, long ttlMs, TtlAction ttlAction) throws AlluxioException, IOException {
    SetAttributePOptions options = SetAttributePOptions.newBuilder().setRecursive(true).setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(ttlMs).setTtlAction(ttlAction).build()).build();
    fs.setAttribute(path, options);
}
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