/** * 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 */ public static void setPinned(FileSystem fs, AlluxioURI path, boolean pinned) throws AlluxioException, IOException { SetAttributePOptions options = SetAttributePOptions.newBuilder().setPinned(pinned).build(); fs.setAttribute(path, options); } }
/** * 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); }
/** * Changes the owner for the path specified in args. * * @param path The {@link AlluxioURI} path as the input of the command * @param owner The owner to be updated to the file or directory * @param recursive Whether change the owner recursively */ private void chown(AlluxioURI path, String owner, boolean recursive) throws AlluxioException, IOException { SetAttributePOptions options = SetAttributePOptions.newBuilder().setOwner(owner).setRecursive(recursive).build(); mFileSystem.setAttribute(path, options); System.out.println("Changed owner of " + path + " to " + owner); }
/** * 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 + "."); }
@Override public void apply(FileSystem fs) throws Exception { fs.createDirectory(DIR); Utils.createFile(fs, INNER_FILE); fs.setAttribute(INNER_FILE, SetAttributePOptions.newBuilder().setPersisted(true).build()); }
} else if (userName.isEmpty()) { LOG.info("Change group of file {} to {}", path, groupName); mFileSystem.setAttribute(uri, optionsBuilder.build()); } else { LOG.info("Change owner of file {} to {}", path, groupName); mFileSystem.setAttribute(uri, optionsBuilder.build());
/** * Changes the mode of an Alluxio file. * * @param path the path of the file * @param mode the mode to change to * @return 0 on success, a negative value on error */ @Override public int chmod(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; }
mFileSystem.setAttribute(uri, optionsBuilder.build()); } catch (AlluxioException e) { throw new IOException(e);
/** * Changes the replication level of directory or file with the path specified in args. * * @param path The {@link AlluxioURI} path as the input of the command * @param replicationMax the max replicas, null if not to set * @param replicationMin the min replicas, null if not to set * @param recursive Whether change the permission recursively * @throws AlluxioException when Alluxio exception occurs * @throws IOException when non-Alluxio exception occurs */ private void setReplication(AlluxioURI path, Integer replicationMax, Integer replicationMin, boolean recursive) throws AlluxioException, IOException { SetAttributePOptions.Builder optionsBuilder = SetAttributePOptions.newBuilder().setRecursive(recursive); String message = "Changed the replication level of " + path + "\n"; if (replicationMax != null) { optionsBuilder.setReplicationMax(replicationMax); message += "replicationMax was set to " + replicationMax + "\n"; } if (replicationMin != null) { optionsBuilder.setReplicationMin(replicationMin); message += "replicationMin was set to " + replicationMin + "\n"; } mFileSystem.setAttribute(path, optionsBuilder.build()); System.out.println(message); }
/** * 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) .setTtl(ttlMs).setTtlAction(ttlAction).build(); fs.setAttribute(path, options); }
@Override public boolean setReplication(Path path, short replication) throws IOException { AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); try { if (!mFileSystem.exists(uri) || mFileSystem.getStatus(uri).isFolder()) { return false; } mFileSystem.setAttribute(uri, (SetAttributePOptions) SetAttributePOptions.newBuilder() .setReplicationMin(replication).build()); return true; } catch (AlluxioException e) { throw new IOException(e); } }
/** * 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())); }
/** * Changes permission of a path. * * @param path path to set permission * @param permission permission set to path */ @Override public void setPermission(Path path, FsPermission permission) throws IOException { LOG.debug("setMode({},{})", path, permission.toString()); AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); SetAttributePOptions options = SetAttributePOptions.newBuilder() .setMode(new Mode(permission.toShort()).toProto()).setRecursive(false).build(); try { mFileSystem.setAttribute(uri, options); } catch (AlluxioException e) { throw new IOException(e); } }
/** * Tests for the {@link BaseFileSystem#setAttribute(AlluxioURI, SetAttributePOptions)} method. */ @Test public void setAttribute() throws Exception { AlluxioURI file = new AlluxioURI("/file"); SetAttributePOptions setAttributeOptions = SetAttributePOptions.getDefaultInstance(); mFileSystem.setAttribute(file, setAttributeOptions); verify(mFileSystemMasterClient).setAttribute(file, setAttributeOptions); }
/** * Ensures that an exception is propagated successfully when setting the state. */ @Test public void setStateException() throws Exception { AlluxioURI file = new AlluxioURI("/file"); SetAttributePOptions setAttributeOptions = SetAttributePOptions.getDefaultInstance(); doThrow(EXCEPTION).when(mFileSystemMasterClient) .setAttribute(file, setAttributeOptions); try { mFileSystem.setAttribute(file, setAttributeOptions); fail(SHOULD_HAVE_PROPAGATED_MESSAGE); } catch (Exception e) { assertSame(EXCEPTION, e); } }
mFileSystem.setAttribute(uri, options); } catch (AlluxioException e) { throw new IOException(e);
/** * Changes permission of a path. * * @param path path to set permission * @param permission permission set to path */ @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); } }
mFileSystem.setAttribute(tPath, options);
/** * 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 */ public void setPermission(Path path, FsPermission permission) throws IOException { AlluxioURI tPath = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); Path hdfsPath = HadoopUtils.getHDFSPath(tPath, mUnderFSAddress); LOG.info("setPermission({},{}) HDFS Path: {} Alluxio Path: {}{}", path, permission.toString(), hdfsPath, mAlluxioHeader, tPath); try { SetAttributeOptions options = SetAttributeOptions.defaults().setPermission(permission.toShort()).setRecursive(false); mFileSystem.setAttribute(tPath, options); } catch (AlluxioException e) { throw new IOException(e); } }
fs.setAttribute(uri, SetAttributeOptions.defaults().setPersisted(true)); return ret;