From 57866b366f46fe500884a16b6f56e2bd8998574d Mon Sep 17 00:00:00 2001 From: Bharat Viswanadham Date: Thu, 15 Nov 2018 14:21:42 -0800 Subject: [PATCH] HDDS-821. Handle empty x-amz-storage-class header in Ozone S3 gateway. Contributed by Elek Marton. --- .../ozone/s3/endpoint/ObjectEndpoint.java | 2 +- ...{TestPutObject.java => TestObjectPut.java} | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) rename hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/{TestPutObject.java => TestObjectPut.java} (90%) diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java index 7000a3a38ae..149add52837 100644 --- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java +++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java @@ -105,7 +105,7 @@ public class ObjectEndpoint extends EndpointBase { ReplicationType replicationType; ReplicationFactor replicationFactor; boolean storageTypeDefault; - if (storageType == null) { + if (storageType == null || storageType.equals("")) { replicationType = S3StorageType.getDefault().getType(); replicationFactor = S3StorageType.getDefault().getFactor(); storageTypeDefault = true; diff --git a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestPutObject.java b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectPut.java similarity index 90% rename from hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestPutObject.java rename to hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectPut.java index eb058615fa5..d60ddd28bed 100644 --- a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestPutObject.java +++ b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectPut.java @@ -26,8 +26,10 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.charset.Charset; +import org.apache.hadoop.hdds.client.ReplicationType; import org.apache.hadoop.ozone.client.ObjectStore; import org.apache.hadoop.ozone.client.OzoneClientStub; +import org.apache.hadoop.ozone.client.OzoneKeyDetails; import org.apache.hadoop.ozone.client.io.OzoneInputStream; import org.apache.hadoop.ozone.s3.exception.OS3Exception; @@ -47,7 +49,7 @@ import static org.mockito.Mockito.when; /** * Test put object. */ -public class TestPutObject { +public class TestObjectPut { public static final String CONTENT = "0123456789"; private String userName = "ozone"; private String bucketName = "b1"; @@ -240,6 +242,27 @@ public class TestPutObject { ex.getErrorMessage()); assertEquals("random", ex.getResource()); } + } + @Test + public void testEmptyStorageType() throws IOException, OS3Exception { + HttpHeaders headers = Mockito.mock(HttpHeaders.class); + ByteArrayInputStream body = new ByteArrayInputStream(CONTENT.getBytes()); + objectEndpoint.setHeaders(headers); + keyName = "sourceKey"; + when(headers.getHeaderString(STORAGE_CLASS_HEADER)).thenReturn(""); + + Response response = + objectEndpoint.put(bucketName, keyName, CONTENT.length(), body); + + String volumeName = clientStub.getObjectStore() + .getOzoneVolumeName(bucketName); + + OzoneKeyDetails key = + clientStub.getObjectStore().getVolume(volumeName).getBucket(bucketName) + .getKey(keyName); + + //default type is set + Assert.assertEquals(ReplicationType.RATIS, key.getReplicationType()); } } \ No newline at end of file