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
5 changes: 5 additions & 0 deletions hadoop-hdds/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>snakeyaml</artifactId>
<version>1.16</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson2.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
package org.apache.hadoop.ozone.web.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import java.io.IOException;
import java.util.List;
Expand All @@ -34,10 +35,14 @@ public final class JsonUtils {
// Reuse ObjectMapper instance for improving performance.
// ObjectMapper is thread safe as long as we always configure instance
// before use.
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final ObjectReader READER = MAPPER.readerFor(Object.class);
private static final ObjectWriter WRITTER =
MAPPER.writerWithDefaultPrettyPrinter();
private static final ObjectMapper MAPPER;
private static final ObjectWriter WRITTER;
static {
MAPPER = new ObjectMapper()
.registerModule(new JavaTimeModule())
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
WRITTER = MAPPER.writerWithDefaultPrettyPrinter();
}

private JsonUtils() {
// Never constructed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.hadoop.ozone.security.acl.OzoneObjInfo;

import java.io.IOException;
import java.time.Instant;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -93,7 +94,7 @@ public class OzoneBucket extends WithMetadata {
/**
* Creation time of the bucket.
*/
private long creationTime;
private Instant creationTime;

/**
* Bucket Encryption key name if bucket encryption is enabled.
Expand Down Expand Up @@ -140,7 +141,7 @@ public OzoneBucket(Configuration conf, ClientProtocol proxy,
this.storageType = storageType;
this.versioning = versioning;
this.listCacheSize = HddsClientUtils.getListCacheSize(conf);
this.creationTime = creationTime;
this.creationTime = Instant.ofEpochMilli(creationTime);
this.metadata = metadata;
this.encryptionKeyName = encryptionKeyName;
}
Expand All @@ -163,7 +164,7 @@ public OzoneBucket(Configuration conf, ClientProtocol proxy,
this.storageType = storageType;
this.versioning = versioning;
this.listCacheSize = HddsClientUtils.getListCacheSize(conf);
this.creationTime = creationTime;
this.creationTime = Instant.ofEpochMilli(creationTime);
this.metadata = metadata;
}

Expand All @@ -180,7 +181,7 @@ public OzoneBucket(Configuration conf, ClientProtocol proxy,
this.defaultReplicationType = defaultReplicationType;
this.storageType = storageType;
this.versioning = versioning;
this.creationTime = creationTime;
this.creationTime = Instant.ofEpochMilli(creationTime);
this.ozoneObj = OzoneObjInfo.Builder.newBuilder()
.setBucketName(name)
.setVolumeName(volumeName)
Expand Down Expand Up @@ -240,7 +241,7 @@ public Boolean getVersioning() {
*
* @return creation time of the bucket
*/
public long getCreationTime() {
public Instant getCreationTime() {
return creationTime;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import org.apache.hadoop.hdds.client.ReplicationType;

import java.time.Instant;

/**
* A class that encapsulates OzoneKey.
*/
Expand All @@ -44,11 +46,11 @@ public class OzoneKey {
/**
* Creation time of the key.
*/
private long creationTime;
private Instant creationTime;
/**
* Modification time of the key.
*/
private long modificationTime;
private Instant modificationTime;

private ReplicationType replicationType;

Expand All @@ -67,8 +69,8 @@ public OzoneKey(String volumeName, String bucketName,
this.bucketName = bucketName;
this.name = keyName;
this.dataSize = size;
this.creationTime = creationTime;
this.modificationTime = modificationTime;
this.creationTime = Instant.ofEpochMilli(creationTime);
this.modificationTime = Instant.ofEpochMilli(modificationTime);
this.replicationType = type;
this.replicationFactor = replicationFactor;
}
Expand Down Expand Up @@ -114,7 +116,7 @@ public long getDataSize() {
*
* @return creation time
*/
public long getCreationTime() {
public Instant getCreationTime() {
return creationTime;
}

Expand All @@ -123,7 +125,7 @@ public long getCreationTime() {
*
* @return modification time
*/
public long getModificationTime() {
public Instant getModificationTime() {
return modificationTime;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.hadoop.ozone.client;

import java.io.IOException;
import java.time.Instant;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -66,7 +67,7 @@ public class OzoneVolume extends WithMetadata {
/**
* Creation time of the volume.
*/
private long creationTime;
private Instant creationTime;
/**
* Volume ACLs.
*/
Expand Down Expand Up @@ -97,7 +98,7 @@ public OzoneVolume(Configuration conf, ClientProtocol proxy, String name,
this.admin = admin;
this.owner = owner;
this.quotaInBytes = quotaInBytes;
this.creationTime = creationTime;
this.creationTime = Instant.ofEpochMilli(creationTime);
this.acls = acls;
this.listCacheSize = HddsClientUtils.getListCacheSize(conf);
this.metadata = metadata;
Expand All @@ -120,7 +121,7 @@ protected OzoneVolume(String name, String admin, String owner,
this.admin = admin;
this.owner = owner;
this.quotaInBytes = quotaInBytes;
this.creationTime = creationTime;
this.creationTime = Instant.ofEpochMilli(creationTime);
this.acls = acls;
this.metadata = new HashMap<>();
}
Expand Down Expand Up @@ -166,7 +167,7 @@ public long getQuota() {
*
* @return creation time.
*/
public long getCreationTime() {
public Instant getCreationTime() {
return creationTime;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Time;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
Expand All @@ -58,6 +57,7 @@
import java.io.File;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -162,7 +162,7 @@ public static void shutdown() throws IOException {
public void testPutKeyWithEncryption() throws Exception {
String volumeName = UUID.randomUUID().toString();
String bucketName = UUID.randomUUID().toString();
long currentTime = Time.now();
Instant testStartTime = Instant.now();

String value = "sample value";
store.createVolume(volumeName);
Expand Down Expand Up @@ -196,8 +196,8 @@ public void testPutKeyWithEncryption() throws Exception {
keyName, ReplicationType.STAND_ALONE,
ReplicationFactor.ONE));
Assert.assertEquals(value, new String(fileContent, "UTF-8"));
Assert.assertTrue(key.getCreationTime() >= currentTime);
Assert.assertTrue(key.getModificationTime() >= currentTime);
Assert.assertTrue(key.getCreationTime().isAfter(testStartTime));
Assert.assertTrue(key.getModificationTime().isAfter(testStartTime));
}
}

Expand All @@ -213,7 +213,7 @@ public void testKeyWithEncryptionAndGdpr() throws Exception {
//Step 1
String volumeName = UUID.randomUUID().toString();
String bucketName = UUID.randomUUID().toString();
long currentTime = Time.now();
Instant testStartTime = Instant.now();

String value = "sample value";
store.createVolume(volumeName);
Expand Down Expand Up @@ -254,8 +254,8 @@ public void testKeyWithEncryptionAndGdpr() throws Exception {
keyName, ReplicationType.STAND_ALONE,
ReplicationFactor.ONE));
Assert.assertEquals(value, new String(fileContent, "UTF-8"));
Assert.assertTrue(key.getCreationTime() >= currentTime);
Assert.assertTrue(key.getModificationTime() >= currentTime);
Assert.assertTrue(key.getCreationTime().isAfter(testStartTime));
Assert.assertTrue(key.getModificationTime().isAfter(testStartTime));
Assert.assertEquals("true", key.getMetadata().get(OzoneConsts.GDPR_FLAG));
//As TDE is enabled, the TDE encryption details should not be null.
Assert.assertNotNull(key.getFileEncryptionInfo());
Expand Down
Loading