Search in sources :

Example 16 with SetAttributePOptions

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

the class ChownCommand method chown.

/**
 * Changes the owner and group for the path specified in args.
 *
 * @param path the {@link AlluxioURI} path to update
 * @param owner the new owner
 * @param group the new group
 * @param recursive whether to change the owner and group recursively
 */
private void chown(AlluxioURI path, String owner, String group, boolean recursive) throws AlluxioException, IOException {
    SetAttributePOptions options = SetAttributePOptions.newBuilder().setOwner(owner).setGroup(group).setRecursive(recursive).build();
    mFileSystem.setAttribute(path, options);
    System.out.println("Changed owner:group of " + path + " to " + owner + ":" + group + ".");
}
Also used : SetAttributePOptions(alluxio.grpc.SetAttributePOptions)

Example 17 with SetAttributePOptions

use of alluxio.grpc.SetAttributePOptions 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
 */
private void chgrp(AlluxioURI path, String group, boolean recursive) throws AlluxioException, IOException {
    SetAttributePOptions options = SetAttributePOptions.newBuilder().setGroup(group).setRecursive(recursive).build();
    mFileSystem.setAttribute(path, options);
    System.out.println("Changed group of " + path + " to " + group);
}
Also used : SetAttributePOptions(alluxio.grpc.SetAttributePOptions)

Example 18 with SetAttributePOptions

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

the class SetAttributeContext method mergeFrom.

/**
 * Merges and embeds the given {@link SetAttributePOptions} with the corresponding master options.
 *
 * @param optionsBuilder Builder for proto {@link SetAttributePOptions} to merge with defaults
 * @return the instance of {@link SetAttributeContext} with default values for master
 */
public static SetAttributeContext mergeFrom(SetAttributePOptions.Builder optionsBuilder) {
    SetAttributePOptions masterOptions = FileSystemOptions.setAttributeDefaults(ServerConfiguration.global());
    SetAttributePOptions.Builder mergedOptionsBuilder = masterOptions.toBuilder().mergeFrom(optionsBuilder.build());
    return create(mergedOptionsBuilder);
}
Also used : SetAttributePOptions(alluxio.grpc.SetAttributePOptions)

Example 19 with SetAttributePOptions

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

the class AlluxioFuseFileSystem method mkdirInternal.

private int mkdirInternal(String path, @mode_t long mode) {
    final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
    if (turi.getName().length() > MAX_NAME_LENGTH) {
        LOG.error("Failed to create directory {}, directory name is longer than {} characters", path, MAX_NAME_LENGTH);
        return -ErrorCodes.ENAMETOOLONG();
    }
    SetAttributePOptions.Builder attributeOptionsBuilder = SetAttributePOptions.newBuilder();
    FuseContext fc = getContext();
    long uid = fc.uid.get();
    long gid = fc.gid.get();
    try {
        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();
        mFileSystem.createDirectory(turi, CreateDirectoryPOptions.newBuilder().setMode(new alluxio.security.authorization.Mode((short) mode).toProto()).build());
        if (gid != GID || uid != UID) {
            LOG.debug("Set attributes of path {} to {}", path, setAttributePOptions);
            mFileSystem.setAttribute(turi, setAttributePOptions);
        }
    } catch (FileAlreadyExistsException e) {
        LOG.debug("Failed to create directory {}, directory already exists", path);
        return -ErrorCodes.EEXIST();
    } catch (InvalidPathException e) {
        LOG.debug("Failed to create directory {}, path is invalid", path);
        return -ErrorCodes.ENOENT();
    } catch (Throwable t) {
        LOG.error("Failed to create directory {}", path, t);
        return AlluxioFuseUtils.getErrorCode(t);
    }
    return 0;
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) FuseContext(ru.serce.jnrfuse.struct.FuseContext) SetAttributePOptions(alluxio.grpc.SetAttributePOptions) InvalidPathException(java.nio.file.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 20 with SetAttributePOptions

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

the class AlluxioFuseFileSystem method chmodInternal.

private int chmodInternal(String path, @mode_t long mode) {
    AlluxioURI uri = mPathResolverCache.getUnchecked(path);
    SetAttributePOptions options = SetAttributePOptions.newBuilder().setMode(new alluxio.security.authorization.Mode((short) mode).toProto()).build();
    try {
        mFileSystem.setAttribute(uri, options);
    } catch (Throwable t) {
        LOG.error("Failed to change {} to mode {}", path, mode, t);
        return AlluxioFuseUtils.getErrorCode(t);
    }
    return 0;
}
Also used : SetAttributePOptions(alluxio.grpc.SetAttributePOptions) AlluxioURI(alluxio.AlluxioURI)

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