Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
6f61f55
HDDS-12870. Add maxKey validation for S3 listObjects function
Jimmyweng006 Apr 20, 2025
365c67b
HDDS-12870. Unit test for maxKey validation of S3 listObjects function
Jimmyweng006 Apr 20, 2025
7bd5677
HDDS-12870. Integration test for maxKey validation of S3 listObjects …
Jimmyweng006 Apr 20, 2025
19f7ba5
HDDS-12870. Fix checkstyle and add Apache License header
Jimmyweng006 Apr 20, 2025
f283cc0
HDDS-12870. Add smoke test for maxKey validation in S3 listObjects fu…
Jimmyweng006 Apr 26, 2025
5035f36
HDDS-12870. Simplify new exception syntax in validateMaxKeys
Jimmyweng006 Apr 26, 2025
7611798
HDDS-12870. Add maxkeys_validation robot test into compatbility_check…
Jimmyweng006 Apr 26, 2025
228bacd
Revert "HDDS-12870. Fix checkstyle and add Apache License header"
Jimmyweng006 Apr 26, 2025
a4e074d
Revert "HDDS-12870. Integration test for maxKey validation of S3 list…
Jimmyweng006 Apr 26, 2025
beffb26
HDDS-12870. Fix for check style
Jimmyweng006 Apr 26, 2025
c8d7db3
HDDS-12870. Make maxKeysLimit configurable
Jimmyweng006 Apr 27, 2025
7e2d5d4
HDDS-12870. Add robot tests for testing max-keys is lower or higher t…
Jimmyweng006 Apr 27, 2025
ab8092b
HDDS-12870. Set default maxKeysLimit to avoid uninitialized value in …
Jimmyweng006 Apr 27, 2025
edcb530
HDDS-12870. Check Contents length using jq with temp file to avoid JS…
Jimmyweng006 May 3, 2025
93f6cb8
HDDS-12870. Make robot test name more general
Jimmyweng006 May 10, 2025
ff1408f
Merge remote-tracking branch 'origin/master' into HDDS-12870
Jimmyweng006 May 10, 2025
aaf2783
HDDS-12870. Add unit test to verify max-keys limit is configurable an…
Jimmyweng006 May 18, 2025
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 @@ -29,6 +29,7 @@
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.newError;
import static org.apache.hadoop.ozone.s3.util.S3Consts.ENCODING_TYPE;

import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
Expand Down Expand Up @@ -766,6 +767,16 @@ private void addKey(ListObjectResponse response, OzoneKey next) {
response.addKey(keyMetadata);
}

@VisibleForTesting
public void setOzoneConfiguration(OzoneConfiguration config) {
this.ozoneConfiguration = config;
}

@VisibleForTesting
public OzoneConfiguration getOzoneConfiguration() {
return this.ozoneConfiguration;
}

@Override
@PostConstruct
public void init() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.ozone.s3.endpoint;

/**
* Builder for BucketEndpoint in tests.
*/
public class BucketEndpointBuilder extends
EndpointBuilder<BucketEndpoint> {

public BucketEndpointBuilder() {
super(BucketEndpoint::new);
}

@Override
public BucketEndpoint build() {
BucketEndpoint endpoint = super.build();
endpoint.setOzoneConfiguration(getConfig());

return endpoint;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static EndpointBuilder<RootEndpoint> newRootEndpointBuilder() {
}

public static EndpointBuilder<BucketEndpoint> newBucketEndpointBuilder() {
return new EndpointBuilder<>(BucketEndpoint::new);
return new BucketEndpointBuilder();
}

public static EndpointBuilder<ObjectEndpoint> newObjectEndpointBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.hadoop.ozone.s3.endpoint;

import static org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_LIST_MAX_KEYS_LIMIT;
import static org.apache.hadoop.ozone.s3.util.S3Consts.ENCODING_TYPE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -26,6 +27,8 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.util.stream.IntStream;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.ozone.client.OzoneBucket;
import org.apache.hadoop.ozone.client.OzoneClient;
import org.apache.hadoop.ozone.client.OzoneClientStub;
Expand Down Expand Up @@ -541,6 +544,39 @@ public void testListObjectsWithInvalidMaxKeys() throws Exception {
assertEquals(S3ErrorTable.INVALID_ARGUMENT.getCode(), e2.getCode());
}

@Test
public void testListObjectsRespectsConfiguredMaxKeysLimit() throws Exception {
// Arrange: Create a bucket with 1001 keys
String[] keys = IntStream.range(0, 1001).mapToObj(i -> "file" + i).toArray(String[]::new);
OzoneClient client = createClientWithKeys(keys);

// Arrange: Set the max-keys limit in the configuration
OzoneConfiguration config = new OzoneConfiguration();
final String configuredMaxKeysLimit = "900";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok, but my original thought is just want this to be a very low value, like 10, so we don't need to create too much key in test.

config.set(OZONE_S3G_LIST_MAX_KEYS_LIMIT, configuredMaxKeysLimit);

// Arrange: Build and initialize the BucketEndpoint with the config
BucketEndpoint bucketEndpoint = EndpointBuilder.newBucketEndpointBuilder()
.setClient(client)
.setConfig(config)
.build();
bucketEndpoint.init();

// Assert: Ensure the config value is correctly set in the endpoint
assertEquals(configuredMaxKeysLimit,
bucketEndpoint.getOzoneConfiguration().get(OZONE_S3G_LIST_MAX_KEYS_LIMIT));

// Act: Request more keys than the configured max-keys limit
final int requestedMaxKeys = Integer.parseInt(configuredMaxKeysLimit) + 1;
ListObjectResponse response = (ListObjectResponse)
bucketEndpoint.get("b1", null, null, null, requestedMaxKeys,
null, null, null, null, null, null, null,
1000, null).getEntity();

// Assert: The number of returned keys should be capped at the configured limit
assertEquals(Integer.parseInt(configuredMaxKeysLimit), response.getContents().size());
}

private void assertEncodingTypeObject(
String exceptName, String exceptEncodingType, EncodingTypeObject object) {
assertEquals(exceptName, object.getName());
Expand Down