Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ALLUXIO-2393] Remove the Permission class. #4717

Merged
merged 6 commits into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import alluxio.exception.PreconditionMessage;
import alluxio.metrics.MetricsSystem;
import alluxio.resource.CloseableResource;
import alluxio.security.authorization.Permission;
import alluxio.underfs.UnderFileSystem;
import alluxio.underfs.options.CreateOptions;

Expand Down Expand Up @@ -139,9 +138,9 @@ public FileOutStream(AlluxioURI path, OutStreamOptions options, FileSystemContex
mUfsPath = options.getUfsPath();
if (mUfsDelegation) {
mFileSystemWorkerClient = mCloser.register(mContext.createFileSystemWorkerClient());
Permission perm = options.getPermission();
mUfsFileId = mFileSystemWorkerClient.createUfsFile(new AlluxioURI(mUfsPath),
CreateUfsFileOptions.defaults().setPermission(perm));
CreateUfsFileOptions.defaults().setOwner(options.getOwner())
.setGroup(options.getGroup()).setMode(options.getMode()));
mUnderStorageOutputStream = mCloser.register(mUnderOutStreamFactory
.create(mContext, mFileSystemWorkerClient.getWorkerDataServerAddress(), mUfsFileId));
} else {
Expand All @@ -150,7 +149,8 @@ public FileOutStream(AlluxioURI path, OutStreamOptions options, FileSystemContex
// Parent directory creation in ufs is not required as FileSystemMaster will create any
// required directories as part of inode creation if sync persist = true
CreateOptions createOptions =
CreateOptions.defaults().setPermission(options.getPermission());
CreateOptions.defaults().setOwner(options.getOwner()).setGroup(options.getGroup())
.setMode(options.getMode());
mUnderStorageOutputStream = mCloser.register(ufs.create(mUfsPath, createOptions));

// Set delegation related vars to null as we are not using worker delegation for ufs ops
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import alluxio.collections.Pair;
import alluxio.exception.AlluxioException;
import alluxio.exception.ExceptionMessage;
import alluxio.security.authorization.Permission;
import alluxio.security.authorization.Mode;
import alluxio.underfs.UnderFileSystem;
import alluxio.underfs.options.MkdirsOptions;

Expand Down Expand Up @@ -59,10 +59,10 @@ public static void prepareFilePath(AlluxioURI alluxioPath, String ufsPath,
if (curDirStatus.isMountPoint()) {
throw new IOException(ExceptionMessage.UFS_PATH_DOES_NOT_EXIST.getMessage(curUfsPath));
}
Permission perm = new Permission(curDirStatus.getOwner(), curDirStatus.getGroup(),
(short) curDirStatus.getMode());
ufsDirsToMakeWithOptions.push(new Pair<>(curUfsPath.toString(),
MkdirsOptions.defaults().setCreateParent(false).setPermission(perm)));
MkdirsOptions.defaults().setCreateParent(false).setOwner(curDirStatus.getOwner())
.setGroup(curDirStatus.getGroup())
.setMode(new Mode((short) curDirStatus.getMode()))));
curAlluxioPath = curAlluxioPath.getParent();
curUfsPath = curUfsPath.getParent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

import alluxio.Constants;
import alluxio.annotation.PublicApi;
import alluxio.security.authorization.Permission;
import alluxio.security.authorization.Mode;
import alluxio.thrift.CompleteUfsFileTOptions;
import alluxio.util.SecurityUtils;

import com.google.common.base.Objects;

Expand All @@ -29,8 +30,9 @@
@PublicApi
@NotThreadSafe
public final class CompleteUfsFileOptions {
/** The ufs file permission, including owner, group and mode. */
private Permission mPermission;
private String mOwner;
private String mGroup;
private Mode mMode;

/**
* Creates a default {@link CompleteUfsFileOptions} with owner, group from login module and
Expand All @@ -44,26 +46,58 @@ public static CompleteUfsFileOptions defaults() throws IOException {
}

private CompleteUfsFileOptions() throws IOException {
mPermission = Permission.defaults();
// Set owner and group from user login module, apply default file UMask.
mPermission.setOwnerFromLoginModule().applyFileUMask();
mOwner = SecurityUtils.getOwnerFromLoginModule();
mGroup = SecurityUtils.getGroupFromLoginModule();
mMode = Mode.defaults().applyFileUMask();
// TODO(chaomin): set permission based on the alluxio file. Not needed for now since the
// file is always created with default permission.
}

/**
* @return the permission of the UFS file
* @return the owner
*/
public Permission getPermission() {
return mPermission;
public String getOwner() {
return mOwner;
}

/**
* @param permission the permission to be set
* @return the updated options object
* @return the group
*/
public CompleteUfsFileOptions setPermission(Permission permission) {
mPermission = permission;
public String getGroup() {
return mGroup;
}

/**
* @return the mode
*/
public Mode getMode() {
return mMode;
}

/**
* @param owner the owner to set
* @return the updated object
*/
public CompleteUfsFileOptions setOwner(String owner) {
mOwner = owner;
return this;
}

/**
* @param group the group to set
* @return the updated object
*/
public CompleteUfsFileOptions setGroup(String group) {
mGroup = group;
return this;
}

/**
* @param mode the mode to set
* @return the updated object
*/
public CompleteUfsFileOptions setMode(Mode mode) {
mMode = mode;
return this;
}

Expand All @@ -76,18 +110,22 @@ public boolean equals(Object o) {
return false;
}
CompleteUfsFileOptions that = (CompleteUfsFileOptions) o;
return Objects.equal(mPermission, that.mPermission);
return Objects.equal(mOwner, that.mOwner)
&& Objects.equal(mGroup, that.mGroup)
&& Objects.equal(mMode, that.mMode);
}

@Override
public int hashCode() {
return Objects.hashCode(mPermission);
return Objects.hashCode(mOwner, mGroup, mMode);
}

@Override
public String toString() {
return Objects.toStringHelper(this)
.add("permission", mPermission)
.add("owner", mOwner)
.add("group", mGroup)
.add("mode", mMode)
.toString();
}

Expand All @@ -96,15 +134,14 @@ public String toString() {
*/
public CompleteUfsFileTOptions toThrift() {
CompleteUfsFileTOptions options = new CompleteUfsFileTOptions();
if (!mPermission.getOwner().isEmpty()) {
options.setOwner(mPermission.getOwner());
if (!mOwner.isEmpty()) {
options.setOwner(mOwner);
}
if (!mPermission.getGroup().isEmpty()) {
options.setGroup(mPermission.getGroup());
if (!mGroup.isEmpty()) {
options.setGroup(mGroup);
}
short mode = mPermission.getMode().toShort();
if (mode != Constants.INVALID_MODE) {
options.setMode(mode);
if (mMode != null && mMode.toShort() != Constants.INVALID_MODE) {
options.setMode(mMode.toShort());
}
return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@JsonInclude(Include.NON_EMPTY)
public final class CreateDirectoryOptions {
private boolean mAllowExists;
private Mode mMode; // null if creating the dir using system default mode
private Mode mMode;
private long mTtl;
private TtlAction mTtlAction;
private boolean mRecursive;
Expand All @@ -51,7 +51,7 @@ public static CreateDirectoryOptions defaults() {
private CreateDirectoryOptions() {
mRecursive = false;
mAllowExists = false;
mMode = null;
mMode = Mode.defaults().applyDirectoryUMask();
mTtl = Constants.NO_TTL;
mTtlAction = TtlAction.DELETE;
mWriteType =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class CreateFileOptions {
private long mBlockSizeBytes;
private long mTtl;
private TtlAction mTtlAction;
private Mode mMode; // null if creating the file using system default mode
private Mode mMode;
private int mWriteTier;
private WriteType mWriteType;

Expand All @@ -70,7 +70,7 @@ private CreateFileOptions() {
mWriteType = Configuration.getEnum(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, WriteType.class);
mTtl = Constants.NO_TTL;
mTtlAction = TtlAction.DELETE;
mMode = null;
mMode = Mode.defaults().applyFileUMask();
}

/**
Expand Down Expand Up @@ -289,7 +289,7 @@ public String toString() {
public CreateFileTOptions toThrift() {
CreateFileTOptions options = new CreateFileTOptions();
options.setBlockSizeBytes(mBlockSizeBytes);
options.setPersisted(mWriteType.getUnderStorageType().isSyncPersist());
options.setPersisted(mWriteType.isThrough());
options.setRecursive(mRecursive);
options.setTtl(mTtl);
options.setTtlAction(ThriftUtils.toThrift(mTtlAction));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

import alluxio.Constants;
import alluxio.annotation.PublicApi;
import alluxio.security.authorization.Permission;
import alluxio.security.authorization.Mode;
import alluxio.thrift.CreateUfsFileTOptions;
import alluxio.util.SecurityUtils;

import com.google.common.base.Objects;

Expand All @@ -29,8 +30,9 @@
@PublicApi
@NotThreadSafe
public final class CreateUfsFileOptions {
/** The ufs file permission, including owner, group and mode. */
private Permission mPermission;
private String mOwner;
private String mGroup;
private Mode mMode;

/**
* Creates a default {@link CreateUfsFileOptions} with owner, group from login module and
Expand All @@ -44,26 +46,58 @@ public static CreateUfsFileOptions defaults() throws IOException {
}

private CreateUfsFileOptions() throws IOException {
mPermission = Permission.defaults();
// Set owner and group from user login module, apply default file UMask.
mPermission.setOwnerFromLoginModule().applyFileUMask();
mOwner = SecurityUtils.getOwnerFromLoginModule();
mGroup = SecurityUtils.getGroupFromLoginModule();
mMode = Mode.defaults().applyFileUMask();
// TODO(chaomin): set permission based on the alluxio file. Not needed for now since the
// file is always created with default permission.
}

/**
* @return the permission of the UFS file
* @return the owner
*/
public Permission getPermission() {
return mPermission;
public String getOwner() {
return mOwner;
}

/**
* @param permission the permission to be set
* @return the updated options object
/**
* @return the group
*/
public String getGroup() {
return mGroup;
}

/**
* @return the mode
*/
public Mode getMode() {
return mMode;
}

/**
* @param owner the owner to set
* @return the updated object
*/
public CreateUfsFileOptions setOwner(String owner) {
mOwner = owner;
return this;
}

/**
* @param group the group to set
* @return the updated object
*/
public CreateUfsFileOptions setGroup(String group) {
mGroup = group;
return this;
}

/**
* @param mode the mode to set
* @return the updated object
*/
public CreateUfsFileOptions setPermission(Permission permission) {
mPermission = permission;
public CreateUfsFileOptions setMode(Mode mode) {
mMode = mode;
return this;
}

Expand All @@ -76,18 +110,22 @@ public boolean equals(Object o) {
return false;
}
CreateUfsFileOptions that = (CreateUfsFileOptions) o;
return Objects.equal(mPermission, that.mPermission);
return Objects.equal(mOwner, that.mOwner)
&& Objects.equal(mGroup, that.mGroup)
&& Objects.equal(mMode, that.mMode);
}

@Override
public int hashCode() {
return Objects.hashCode(mPermission);
return Objects.hashCode(mOwner, mGroup, mMode);
}

@Override
public String toString() {
return Objects.toStringHelper(this)
.add("permission", mPermission)
.add("owner", mOwner)
.add("group", mGroup)
.add("mode", mMode)
.toString();
}

Expand All @@ -96,15 +134,14 @@ public String toString() {
*/
public CreateUfsFileTOptions toThrift() {
CreateUfsFileTOptions options = new CreateUfsFileTOptions();
if (!mPermission.getOwner().isEmpty()) {
options.setOwner(mPermission.getOwner());
if (!mOwner.isEmpty()) {
options.setOwner(mOwner);
}
if (!mPermission.getGroup().isEmpty()) {
options.setGroup(mPermission.getGroup());
if (!mGroup.isEmpty()) {
options.setGroup(mGroup);
}
short mode = mPermission.getMode().toShort();
if (mode != Constants.INVALID_MODE) {
options.setMode(mode);
if (mMode != null && mMode.toShort() != Constants.INVALID_MODE) {
options.setMode(mMode.toShort());
}
return options;
}
Expand Down
Loading