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 @@ -60,6 +60,7 @@
import com.amazonaws.services.s3.transfer.Upload;
import com.amazonaws.services.s3.transfer.model.UploadResult;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.hadoop.hdds.client.OzoneQuota;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.hdds.client.ReplicationFactor;
import org.apache.hadoop.hdds.client.ReplicationType;
Expand Down Expand Up @@ -814,6 +815,28 @@ public void testListPartsNotFound() {
assertEquals("NoSuchUpload", ase.getErrorCode());
}

@Test
public void testQuotaExceeded() throws IOException {
final String bucketName = getBucketName();
final String keyName = getKeyName();

s3Client.createBucket(bucketName);

cluster.newClient().getObjectStore()
.getVolume("s3v")
.getBucket(bucketName)
.setQuota(OzoneQuota.parseQuota("1", "10"));

// Upload some objects to the bucket
AmazonServiceException ase = assertThrows(AmazonServiceException.class,
() -> s3Client.putObject(bucketName, keyName,
RandomStringUtils.randomAlphanumeric(1024)));

assertEquals(ErrorType.Client, ase.getErrorType());
assertEquals(403, ase.getStatusCode());
assertEquals("QuotaExceeded", ase.getErrorCode());
}

private boolean isBucketEmpty(Bucket bucket) {
ObjectListing objectListing = s3Client.listObjects(bucket.getName());
return objectListing.getObjectSummaries().isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ public Response put(
throw os3Exception;
} else if (isAccessDenied(ex)) {
throw newError(S3ErrorTable.ACCESS_DENIED, keyPath, ex);
} else if (ex.getResult() == ResultCodes.QUOTA_EXCEEDED) {
throw newError(S3ErrorTable.QUOTA_EXCEEDED, keyPath, ex);
} else if (ex.getResult() == ResultCodes.BUCKET_NOT_FOUND) {
throw newError(S3ErrorTable.NO_SUCH_BUCKET, bucketName, ex);
} else if (ex.getResult() == ResultCodes.FILE_ALREADY_EXISTS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ private S3ErrorTable() {
"MalformedXML", "The XML you provided was not well-formed or did not " +
"validate against our published schema", HTTP_BAD_REQUEST);

public static final OS3Exception QUOTA_EXCEEDED = new OS3Exception(
"QuotaExceeded", "The quota has been exceeded. " +
"Please review your disk space or namespace usage and adjust accordingly.",
HTTP_FORBIDDEN
);

public static OS3Exception newError(OS3Exception e, String resource) {
return newError(e, resource, null);
}
Expand Down