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 @@ -290,8 +290,7 @@ protected Map<String, String> getCustomMetadataFromHeaders(

if (sizeInBytes >
OzoneConsts.S3_REQUEST_HEADER_METADATA_SIZE_LIMIT_KB * KB) {
throw new IllegalArgumentException("Illegal user defined metadata." +
" Combined size cannot exceed 2KB.");
throw newError(S3ErrorTable.METADATA_TOO_LARGE, key);
}
customMetadata.put(mapKey, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static java.net.HttpURLConnection.HTTP_PRECON_FAILED;
import static java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED;
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
import static org.apache.hadoop.ozone.OzoneConsts.S3_REQUEST_HEADER_METADATA_SIZE_LIMIT_KB;
import static org.apache.hadoop.ozone.s3.util.S3Consts.RANGE_NOT_SATISFIABLE;

/**
Expand Down Expand Up @@ -126,6 +127,11 @@ private S3ErrorTable() {
public static final OS3Exception NO_OVERWRITE = new OS3Exception(
"Conflict", "Cannot overwrite file with directory", HTTP_CONFLICT);

public static final OS3Exception METADATA_TOO_LARGE = new OS3Exception(
"MetadataTooLarge", "Illegal user defined metadata. Combined size " +
"exceeds the maximum allowed metadata size of " +
S3_REQUEST_HEADER_METADATA_SIZE_LIMIT_KB + "KB", HTTP_BAD_REQUEST);

public static OS3Exception newError(OS3Exception e, String resource) {
return newError(e, resource, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.hadoop.ozone.s3.exception.OS3Exception;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;

import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
Expand Down Expand Up @@ -95,12 +94,13 @@ public void testCustomMetadataHeadersSizeOverbig() {
public void init() { }
};

Exception exception = Assertions.assertThrows(
IllegalArgumentException.class,
() -> endpointBase.getCustomMetadataFromHeaders(s3requestHeaders));
Assert.assertEquals(
"Illegal user defined metadata. Combined size cannot exceed 2KB.",
exception.getMessage());
try {
endpointBase.getCustomMetadataFromHeaders(s3requestHeaders);
Assert.fail("getCustomMetadataFromHeaders should fail. " +
"Expected OS3Exception not thrown");
} catch (OS3Exception ex) {
Assert.assertTrue(ex.getCode().contains("MetadataTooLarge"));
}
Comment thread
Tejaskriya marked this conversation as resolved.
}

}