Skip to content
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 @@ -280,6 +280,7 @@ private OzoneConsts() {
public static final String RESOURCE_TYPE = "resourceType";
public static final String IS_VERSION_ENABLED = "isVersionEnabled";
public static final String CREATION_TIME = "creationTime";
public static final String MODIFICATION_TIME = "modificationTime";
public static final String DATA_SIZE = "dataSize";
public static final String REPLICATION_TYPE = "replicationType";
public static final String REPLICATION_FACTOR = "replicationFactor";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.hadoop.ozone.om.helpers.WithMetadata;
import org.apache.hadoop.ozone.security.acl.OzoneObj;
import org.apache.hadoop.ozone.security.acl.OzoneObjInfo;
import org.apache.hadoop.util.Time;

import java.io.IOException;
import java.time.Instant;
Expand Down Expand Up @@ -96,6 +97,11 @@ public class OzoneBucket extends WithMetadata {
*/
private Instant creationTime;

/**
* Modification time of the bucket.
*/
private Instant modificationTime;

/**
* Bucket Encryption key name if bucket encryption is enabled.
*/
Expand Down Expand Up @@ -144,6 +150,21 @@ public OzoneBucket(ConfigurationSource conf, ClientProtocol proxy,
this.creationTime = Instant.ofEpochMilli(creationTime);
this.metadata = metadata;
this.encryptionKeyName = encryptionKeyName;
modificationTime = Instant.now();
if (modificationTime.isBefore(this.creationTime)) {
modificationTime = Instant.ofEpochSecond(
this.creationTime.getEpochSecond(), this.creationTime.getNano());
}
}

@SuppressWarnings("parameternumber")
public OzoneBucket(ConfigurationSource conf, ClientProtocol proxy,
String volumeName, String bucketName, StorageType storageType,
Boolean versioning, long creationTime, long modificationTime,
Map<String, String> metadata, String encryptionKeyName) {
this(conf, proxy, volumeName, bucketName, storageType, versioning,
creationTime, metadata, encryptionKeyName);
this.modificationTime = Instant.ofEpochMilli(modificationTime);
}

/**
Expand All @@ -166,6 +187,24 @@ public OzoneBucket(ConfigurationSource conf, ClientProtocol proxy,
this.listCacheSize = HddsClientUtils.getListCacheSize(conf);
this.creationTime = Instant.ofEpochMilli(creationTime);
this.metadata = metadata;
modificationTime = Instant.now();
if (modificationTime.isBefore(this.creationTime)) {
modificationTime = Instant.ofEpochSecond(
this.creationTime.getEpochSecond(), this.creationTime.getNano());
}
}

/**
* @param modificationTime modification time of the bucket.
*/
@SuppressWarnings("parameternumber")
public OzoneBucket(ConfigurationSource conf, ClientProtocol proxy,
String volumeName, String bucketName, StorageType storageType,
Boolean versioning, long creationTime, long modificationTime,
Map<String, String> metadata) {
this(conf, proxy, volumeName, bucketName, storageType, versioning,
creationTime, metadata);
this.modificationTime = Instant.ofEpochMilli(modificationTime);
}

@VisibleForTesting
Expand All @@ -187,9 +226,14 @@ public OzoneBucket(ConfigurationSource conf, ClientProtocol proxy,
.setVolumeName(volumeName)
.setResType(OzoneObj.ResourceType.BUCKET)
.setStoreType(OzoneObj.StoreType.OZONE).build();
long modifiedTime = Time.now();
if (modifiedTime < creationTime) {
this.modificationTime = Instant.ofEpochMilli(creationTime);
} else {
this.modificationTime = Instant.ofEpochMilli(modifiedTime);
}
}


/**
* Returns Volume Name.
*
Expand Down Expand Up @@ -245,6 +289,15 @@ public Instant getCreationTime() {
return creationTime;
}

/**
* Returns modification time of the Bucket.
*
* @return modification time of the bucket
*/
public Instant getModificationTime() {
return modificationTime;
}

/**
* Return the bucket encryption key name.
* @return the bucket encryption key name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public class OzoneVolume extends WithMetadata {
* Creation time of the volume.
*/
private Instant creationTime;
/**
* Modification time of the volume.
*/
private Instant modificationTime;
/**
* Volume ACLs.
*/
Expand All @@ -89,10 +93,8 @@ public class OzoneVolume extends WithMetadata {
*/
@SuppressWarnings("parameternumber")
public OzoneVolume(ConfigurationSource conf, ClientProtocol proxy,
String name,
String admin, String owner, long quotaInBytes,
long creationTime, List<OzoneAcl> acls,
Map<String, String> metadata) {
String name, String admin, String owner, long quotaInBytes,
long creationTime, List<OzoneAcl> acls, Map<String, String> metadata) {
Preconditions.checkNotNull(proxy, "Client proxy is not set.");
this.proxy = proxy;
this.name = name;
Expand All @@ -103,21 +105,50 @@ public OzoneVolume(ConfigurationSource conf, ClientProtocol proxy,
this.acls = acls;
this.listCacheSize = HddsClientUtils.getListCacheSize(conf);
this.metadata = metadata;
modificationTime = Instant.now();
if (modificationTime.isBefore(this.creationTime)) {
modificationTime = Instant.ofEpochSecond(
this.creationTime.getEpochSecond(), this.creationTime.getNano());
}
}

/**
* @param modificationTime modification time of the volume.
*/
@SuppressWarnings("parameternumber")
public OzoneVolume(ConfigurationSource conf, ClientProtocol proxy,
String name, String admin, String owner, long quotaInBytes,
long creationTime, long modificationTime, List<OzoneAcl> acls,
Map<String, String> metadata) {
this(conf, proxy, name, admin, owner, quotaInBytes,
creationTime, acls, metadata);
this.modificationTime = Instant.ofEpochMilli(modificationTime);
}

@SuppressWarnings("parameternumber")
public OzoneVolume(ConfigurationSource conf, ClientProtocol proxy,
String name,
String admin, String owner, long quotaInBytes,
String name, String admin, String owner, long quotaInBytes,
long creationTime, List<OzoneAcl> acls) {
this(conf, proxy, name, admin, owner, quotaInBytes, creationTime, acls,
new HashMap<>());
modificationTime = Instant.now();
if (modificationTime.isBefore(this.creationTime)) {
modificationTime = Instant.ofEpochSecond(
this.creationTime.getEpochSecond(), this.creationTime.getNano());
}
}

@SuppressWarnings("parameternumber")
public OzoneVolume(ConfigurationSource conf, ClientProtocol proxy,
String name, String admin, String owner, long quotaInBytes,
long creationTime, long modificationTime, List<OzoneAcl> acls) {
this(conf, proxy, name, admin, owner, quotaInBytes, creationTime, acls);
this.modificationTime = Instant.ofEpochMilli(modificationTime);
}

@VisibleForTesting
protected OzoneVolume(String name, String admin, String owner,
long quotaInBytes,
long creationTime, List<OzoneAcl> acls) {
long quotaInBytes, long creationTime, List<OzoneAcl> acls) {
this.proxy = null;
this.name = name;
this.admin = admin;
Expand All @@ -126,6 +157,19 @@ protected OzoneVolume(String name, String admin, String owner,
this.creationTime = Instant.ofEpochMilli(creationTime);
this.acls = acls;
this.metadata = new HashMap<>();
modificationTime = Instant.now();
if (modificationTime.isBefore(this.creationTime)) {
modificationTime = Instant.ofEpochSecond(
this.creationTime.getEpochSecond(), this.creationTime.getNano());
}
}

@VisibleForTesting
protected OzoneVolume(String name, String admin, String owner,
long quotaInBytes, long creationTime, long modificationTime,
List<OzoneAcl> acls) {
this(name, admin, owner, quotaInBytes, creationTime, acls);
this.modificationTime = Instant.ofEpochMilli(modificationTime);
}

/**
Expand Down Expand Up @@ -173,6 +217,15 @@ public Instant getCreationTime() {
return creationTime;
}

/**
* Returns modification time of the volume.
*
* @return modification time.
*/
public Instant getModificationTime() {
return modificationTime;
}

/**
* Returns OzoneAcl list associated with the Volume.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ public OzoneVolume getVolumeDetails(String volumeName)
volume.getOwnerName(),
volume.getQuotaInBytes(),
volume.getCreationTime(),
volume.getModificationTime(),
volume.getAclMap().ozoneAclGetProtobuf().stream().
map(OzoneAcl::fromProtobuf).collect(Collectors.toList()),
volume.getMetadata());
Expand Down Expand Up @@ -377,6 +378,7 @@ public List<OzoneVolume> listVolumes(String volumePrefix, String prevVolume,
volume.getOwnerName(),
volume.getQuotaInBytes(),
volume.getCreationTime(),
volume.getModificationTime(),
volume.getAclMap().ozoneAclGetProtobuf().stream().
map(OzoneAcl::fromProtobuf).collect(Collectors.toList())))
.collect(Collectors.toList());
Expand All @@ -397,6 +399,7 @@ public List<OzoneVolume> listVolumes(String user, String volumePrefix,
volume.getOwnerName(),
volume.getQuotaInBytes(),
volume.getCreationTime(),
volume.getModificationTime(),
volume.getAclMap().ozoneAclGetProtobuf().stream().
map(OzoneAcl::fromProtobuf).collect(Collectors.toList()),
volume.getMetadata()))
Expand Down Expand Up @@ -604,6 +607,7 @@ public OzoneBucket getBucketDetails(
bucketInfo.getStorageType(),
bucketInfo.getIsVersionEnabled(),
bucketInfo.getCreationTime(),
bucketInfo.getModificationTime(),
bucketInfo.getMetadata(),
bucketInfo.getEncryptionKeyInfo() != null ? bucketInfo
.getEncryptionKeyInfo().getKeyName() : null);
Expand All @@ -624,6 +628,7 @@ public List<OzoneBucket> listBuckets(String volumeName, String bucketPrefix,
bucket.getStorageType(),
bucket.getIsVersionEnabled(),
bucket.getCreationTime(),
bucket.getModificationTime(),
bucket.getMetadata(),
bucket.getEncryptionKeyInfo() != null ? bucket
.getEncryptionKeyInfo().getKeyName() : null))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public final class OmBucketInfo extends WithObjectID implements Auditable {
* Creation time of bucket.
*/
private final long creationTime;
/**
* modification time of bucket.
*/
private long modificationTime;

/**
* Bucket encryption key info if encryption is enabled.
Expand All @@ -80,6 +84,7 @@ public final class OmBucketInfo extends WithObjectID implements Auditable {
* @param isVersionEnabled - Bucket version flag.
* @param storageType - Storage type to be used.
* @param creationTime - Bucket creation time.
* @param modificationTime - Bucket modification time.
* @param metadata - metadata.
* @param bekInfo - bucket encryption key info.
*/
Expand All @@ -90,6 +95,7 @@ private OmBucketInfo(String volumeName,
boolean isVersionEnabled,
StorageType storageType,
long creationTime,
long modificationTime,
long objectID,
long updateID,
Map<String, String> metadata,
Expand All @@ -100,6 +106,7 @@ private OmBucketInfo(String volumeName,
this.isVersionEnabled = isVersionEnabled;
this.storageType = storageType;
this.creationTime = creationTime;
this.modificationTime = modificationTime;
this.objectID = objectID;
this.updateID = updateID;
this.metadata = metadata;
Expand Down Expand Up @@ -184,6 +191,15 @@ public long getCreationTime() {
return creationTime;
}

/**
* Returns modification time.
* @return long
*/
public long getModificationTime() {
return modificationTime;
}


/**
* Returns bucket encryption key info.
* @return bucket encryption key info
Expand Down Expand Up @@ -217,6 +233,8 @@ public Map<String, String> toAuditMap() {
auditMap.put(OzoneConsts.CREATION_TIME, String.valueOf(this.creationTime));
auditMap.put(OzoneConsts.BUCKET_ENCRYPTION_KEY,
(bekInfo != null) ? bekInfo.getKeyName() : null);
auditMap.put(OzoneConsts.MODIFICATION_TIME,
String.valueOf(this.modificationTime));
return auditMap;
}

Expand All @@ -230,6 +248,7 @@ public OmBucketInfo copyObject() {
.setStorageType(storageType)
.setIsVersionEnabled(isVersionEnabled)
.setCreationTime(creationTime)
.setModificationTime(modificationTime)
.setObjectID(objectID)
.setUpdateID(updateID)
.setBucketEncryptionKey(bekInfo != null ?
Expand Down Expand Up @@ -257,6 +276,7 @@ public static class Builder {
private Boolean isVersionEnabled;
private StorageType storageType;
private long creationTime;
private long modificationTime;
private long objectID;
private long updateID;
private Map<String, String> metadata;
Expand Down Expand Up @@ -309,6 +329,11 @@ public Builder setCreationTime(long createdOn) {
return this;
}

public Builder setModificationTime(long modifiedOn) {
this.modificationTime = modifiedOn;
return this;
}

public Builder setObjectID(long obId) {
this.objectID = obId;
return this;
Expand Down Expand Up @@ -349,7 +374,8 @@ public OmBucketInfo build() {
Preconditions.checkNotNull(storageType);

return new OmBucketInfo(volumeName, bucketName, acls, isVersionEnabled,
storageType, creationTime, objectID, updateID, metadata, bekInfo);
storageType, creationTime, modificationTime, objectID, updateID,
metadata, bekInfo);
}
}

Expand All @@ -364,6 +390,7 @@ public BucketInfo getProtobuf() {
.setIsVersionEnabled(isVersionEnabled)
.setStorageType(storageType.toProto())
.setCreationTime(creationTime)
.setModificationTime(modificationTime)
.setObjectID(objectID)
.setUpdateID(updateID)
.addAllMetadata(KeyValueUtil.toProtobuf(metadata));
Expand All @@ -386,7 +413,8 @@ public static OmBucketInfo getFromProtobuf(BucketInfo bucketInfo) {
OzoneAcl::fromProtobuf).collect(Collectors.toList()))
.setIsVersionEnabled(bucketInfo.getIsVersionEnabled())
.setStorageType(StorageType.valueOf(bucketInfo.getStorageType()))
.setCreationTime(bucketInfo.getCreationTime());
.setCreationTime(bucketInfo.getCreationTime())
.setModificationTime(bucketInfo.getModificationTime());
if (bucketInfo.hasObjectID()) {
obib.setObjectID(bucketInfo.getObjectID());
}
Expand Down Expand Up @@ -424,6 +452,7 @@ public boolean equals(Object o) {
}
OmBucketInfo that = (OmBucketInfo) o;
return creationTime == that.creationTime &&
modificationTime == that.modificationTime &&
volumeName.equals(that.volumeName) &&
bucketName.equals(that.bucketName) &&
Objects.equals(acls, that.acls) &&
Expand Down
Loading