Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -905,6 +905,16 @@ public OzoneMultipartUploadList listMultipartUploads(String prefix)
return proxy.listMultipartUploads(volumeName, getName(), prefix);
}

/**
* Sets/Changes the owner of this Bucket.
* @param userName new owner
* @throws IOException
*/
public void setOwner(String userName) throws IOException{
proxy.setBucketOwner(volumeName, name, userName);
this.owner = userName;
}

/**
* An Iterator to iterate over {@link OzoneKey} list.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,4 +772,14 @@ OzoneKey headObject(String volumeName, String bucketName,
* Clears the S3 Authentication information attached to the thread.
*/
void clearTheadLocalS3Auth();

/**
* Sets the owner of bucket.
* @param volumeName Name of the Volume
* @param bucketName Name of the Bucket
* @param owner to be set for the bucket
* @throws IOException
*/
void setBucketOwner(String volumeName, String bucketName,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's follow setVolumeOwner() and return boolean instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I can add a response for SetBucketPropertyResponse to return boolean in OmClientProtocol.proto

String owner) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1579,4 +1579,17 @@ public S3Auth getThreadLocalS3Auth() {
public void clearTheadLocalS3Auth() {
ozoneManagerClient.clearThreadLocalS3Auth();
}

@Override
public void setBucketOwner(String volumeName, String bucketName,
String owner) throws IOException {
verifyVolumeName(volumeName);
verifyBucketName(bucketName);
Preconditions.checkNotNull(owner);
OmBucketArgs.Builder builder = OmBucketArgs.newBuilder();
builder.setVolumeName(volumeName)
.setBucketName(bucketName)
.setOwnerName(owner);
ozoneManagerClient.setBucketProperty(builder.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public final class OmBucketArgs extends WithMetadata implements Auditable {

private long quotaInBytes;
private long quotaInNamespace;
/**
* Bucket Owner Name.
*/
private String ownerName;

/**
* Private constructor, constructed via builder.
Expand All @@ -61,16 +65,19 @@ public final class OmBucketArgs extends WithMetadata implements Auditable {
* @param quotaInBytes Volume quota in bytes.
* @param quotaInNamespace Volume quota in counts.
*/
@SuppressWarnings("checkstyle:ParameterNumber")
private OmBucketArgs(String volumeName, String bucketName,
Boolean isVersionEnabled, StorageType storageType,
Map<String, String> metadata, long quotaInBytes, long quotaInNamespace) {
Map<String, String> metadata, long quotaInBytes, long quotaInNamespace,
String ownerName) {
this.volumeName = volumeName;
this.bucketName = bucketName;
this.isVersionEnabled = isVersionEnabled;
this.storageType = storageType;
this.metadata = metadata;
this.quotaInBytes = quotaInBytes;
this.quotaInNamespace = quotaInNamespace;
this.ownerName = ownerName;
}

/**
Expand Down Expand Up @@ -121,6 +128,14 @@ public long getQuotaInNamespace() {
return quotaInNamespace;
}

/**
* Returns Bucket Owner Name.
* @return ownerName.
*/
public String getOwnerName() {
return ownerName;
}

/**
* Returns new builder class that builds a OmBucketArgs.
* @return Builder
Expand Down Expand Up @@ -155,7 +170,7 @@ public static class Builder {
private Map<String, String> metadata;
private long quotaInBytes;
private long quotaInNamespace;

private String ownerName;
/**
* Constructs a builder.
*/
Expand Down Expand Up @@ -199,6 +214,11 @@ public Builder setQuotaInNamespace(long quota) {
return this;
}

public Builder setOwnerName(String owner) {
ownerName = owner;
return this;
}

/**
* Constructs the OmBucketArgs.
* @return instance of OmBucketArgs.
Expand All @@ -207,7 +227,7 @@ public OmBucketArgs build() {
Preconditions.checkNotNull(volumeName);
Preconditions.checkNotNull(bucketName);
return new OmBucketArgs(volumeName, bucketName, isVersionEnabled,
storageType, metadata, quotaInBytes, quotaInNamespace);
storageType, metadata, quotaInBytes, quotaInNamespace, ownerName);
}
}

Expand All @@ -230,6 +250,9 @@ public BucketArgs getProtobuf() {
if(quotaInNamespace > 0 || quotaInNamespace == OzoneConsts.QUOTA_RESET) {
builder.setQuotaInNamespace(quotaInNamespace);
}
if(ownerName != null) {
Comment thread
smengcl marked this conversation as resolved.
Outdated
builder.setOwnerName(ownerName);
}
return builder.build();
}

Expand All @@ -247,6 +270,8 @@ public static OmBucketArgs getFromProtobuf(BucketArgs bucketArgs) {
bucketArgs.getStorageType()) : null,
KeyValueUtil.getFromProtobuf(bucketArgs.getMetadataList()),
bucketArgs.getQuotaInBytes(),
bucketArgs.getQuotaInNamespace());
bucketArgs.getQuotaInNamespace(),
bucketArgs.hasOwnerName() ?
bucketArgs.getOwnerName() : null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public final class OmBucketInfo extends WithObjectID implements Auditable {
*/
private BucketLayout bucketLayout;

private final String owner;
private String owner;

/**
* Private constructor, constructed via builder.
Expand Down Expand Up @@ -297,6 +297,14 @@ public String getOwner() {
return owner;
}

public void setModificationTime(long modificationTime) {
this.modificationTime = modificationTime;
}

public void setOwner(String ownerName) {
this.owner = ownerName;
}

/**
* Returns new builder class that builds a OmBucketInfo.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,26 @@ public void testVolumeSetOwner() throws IOException {
proxy.setVolumeOwner(volumeName, ownerName);
}

@Test
public void testBucketSetOwner() throws IOException {
String volumeName = UUID.randomUUID().toString();
String bucketName = UUID.randomUUID().toString();
store.createVolume(volumeName);
store.getVolume(volumeName).createBucket(bucketName);

String oldOwner = store.getVolume(volumeName).getBucket(bucketName)
.getOwner();
String ownerName = "testUser";

ClientProtocol proxy = store.getClientProxy();
proxy.setBucketOwner(volumeName, bucketName, ownerName);
String newOwner = store.getVolume(volumeName).getBucket(bucketName)
.getOwner();

assertEquals(ownerName, newOwner);
assertNotEquals(oldOwner, newOwner);
}
Comment thread
smengcl marked this conversation as resolved.

@Test
public void testSetAndClrQuota() throws Exception {
String volumeName = UUID.randomUUID().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ message BucketArgs {
repeated hadoop.hdds.KeyValue metadata = 7;
optional uint64 quotaInBytes = 8;
optional uint64 quotaInNamespace = 9;
optional string ownerName = 10;
}

message PrefixInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.hadoop.ozone.om.request.OMKeyRequestFactory;
import org.apache.hadoop.ozone.om.request.bucket.OMBucketCreateRequest;
import org.apache.hadoop.ozone.om.request.bucket.OMBucketDeleteRequest;
import org.apache.hadoop.ozone.om.request.bucket.OMBucketSetOwnerRequest;
import org.apache.hadoop.ozone.om.request.bucket.OMBucketSetPropertyRequest;
import org.apache.hadoop.ozone.om.request.OMClientRequest;
import org.apache.hadoop.ozone.om.request.bucket.acl.OMBucketAddAclRequest;
Expand Down Expand Up @@ -141,7 +142,13 @@ public static OMClientRequest createClientRequest(OMRequest omRequest,
case DeleteBucket:
return new OMBucketDeleteRequest(omRequest);
case SetBucketProperty:
return new OMBucketSetPropertyRequest(omRequest);
boolean hasBucketOwner = omRequest.getSetBucketPropertyRequest()
.getBucketArgs().hasOwnerName();
if (hasBucketOwner) {
return new OMBucketSetOwnerRequest(omRequest);
} else {
return new OMBucketSetPropertyRequest(omRequest);
}
case AddAcl:
case RemoveAcl:
case SetAcl:
Expand Down
Loading