Search in sources :

Example 1 with SetAttributeOptions

use of alluxio.client.file.options.SetAttributeOptions in project alluxio by Alluxio.

the class ChgrpCommand method chgrp.

/**
   * Changes the group for the directory or file with the path specified in args.
   *
   * @param path The {@link AlluxioURI} path as the input of the command
   * @param group The group to be updated to the file or directory
   * @param recursive Whether change the group recursively
   * @throws AlluxioException when Alluxio exception occurs
   * @throws IOException when non-Alluxio exception occurs
   */
private void chgrp(AlluxioURI path, String group, boolean recursive) throws AlluxioException, IOException {
    SetAttributeOptions options = SetAttributeOptions.defaults().setGroup(group).setRecursive(recursive);
    mFileSystem.setAttribute(path, options);
    System.out.println("Changed group of " + path + " to " + group);
}
Also used : SetAttributeOptions(alluxio.client.file.options.SetAttributeOptions)

Example 2 with SetAttributeOptions

use of alluxio.client.file.options.SetAttributeOptions in project alluxio by Alluxio.

the class CommandUtils method setPinned.

/**
   * Sets pin state for the input path.
   *
   * @param fs The {@link FileSystem} client
   * @param path The {@link AlluxioURI} path as the input of the command
   * @param pinned the state to be set
   * @throws AlluxioException when an Alluxio exception occurs
   * @throws IOException when a non-Alluxio exception occurs
   */
public static void setPinned(FileSystem fs, AlluxioURI path, boolean pinned) throws AlluxioException, IOException {
    SetAttributeOptions options = SetAttributeOptions.defaults().setPinned(pinned);
    fs.setAttribute(path, options);
}
Also used : SetAttributeOptions(alluxio.client.file.options.SetAttributeOptions)

Example 3 with SetAttributeOptions

use of alluxio.client.file.options.SetAttributeOptions in project alluxio by Alluxio.

the class CommandUtils 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
   * @throws AlluxioException when an Alluxio exception occurs
   * @throws IOException when a non-Alluxio exception occurs
   */
public static void setTtl(FileSystem fs, AlluxioURI path, long ttlMs, TtlAction ttlAction) throws AlluxioException, IOException {
    SetAttributeOptions options = SetAttributeOptions.defaults().setRecursive(true).setTtl(ttlMs).setTtlAction(ttlAction);
    fs.setAttribute(path, options);
}
Also used : SetAttributeOptions(alluxio.client.file.options.SetAttributeOptions)

Example 4 with SetAttributeOptions

use of alluxio.client.file.options.SetAttributeOptions in project alluxio by Alluxio.

the class AbstractFileSystem method setOwner.

/**
   * Changes owner or group of a path (i.e. a file or a directory). If username is null, the
   * original username remains unchanged. Same as groupname. If username and groupname are non-null,
   * both of them will be changed.
   *
   * @param path path to set owner or group
   * @param username username to be set
   * @param groupname groupname to be set
   * @throws IOException if changing owner or group of the path failed
   */
@Override
public void setOwner(Path path, final String username, final String groupname) throws IOException {
    LOG.debug("setOwner({},{},{})", path, username, groupname);
    AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
    SetAttributeOptions options = SetAttributeOptions.defaults();
    boolean ownerOrGroupChanged = false;
    if (username != null && !username.isEmpty()) {
        options.setOwner(username).setRecursive(false);
        ownerOrGroupChanged = true;
    }
    if (groupname != null && !groupname.isEmpty()) {
        options.setGroup(groupname).setRecursive(false);
        ownerOrGroupChanged = true;
    }
    if (ownerOrGroupChanged) {
        try {
            mFileSystem.setAttribute(uri, options);
        } catch (AlluxioException e) {
            throw new IOException(e);
        }
    }
}
Also used : SetAttributeOptions(alluxio.client.file.options.SetAttributeOptions) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 5 with SetAttributeOptions

use of alluxio.client.file.options.SetAttributeOptions in project alluxio by Alluxio.

the class AbstractFileSystem method setPermission.

/**
   * Changes permission of a path.
   *
   * @param path path to set permission
   * @param permission permission set to path
   * @throws IOException if the path failed to be changed permission
   */
@Override
public void setPermission(Path path, FsPermission permission) throws IOException {
    LOG.debug("setMode({},{})", path, permission.toString());
    AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
    SetAttributeOptions options = SetAttributeOptions.defaults().setMode(new Mode(permission.toShort())).setRecursive(false);
    try {
        mFileSystem.setAttribute(uri, options);
    } catch (AlluxioException e) {
        throw new IOException(e);
    }
}
Also used : SetAttributeOptions(alluxio.client.file.options.SetAttributeOptions) Mode(alluxio.security.authorization.Mode) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Aggregations

SetAttributeOptions (alluxio.client.file.options.SetAttributeOptions)10 AlluxioURI (alluxio.AlluxioURI)5 Test (org.junit.Test)3 AlluxioException (alluxio.exception.AlluxioException)2 Mode (alluxio.security.authorization.Mode)2 IOException (java.io.IOException)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 URIStatus (alluxio.client.file.URIStatus)1 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)1