Skip to content
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
202fc8f
HDDS-6440. Handle custom metadata (x-amz-meta) through S3 API.
Mar 15, 2022
67a99da
HDDS-6440. Handle custom metadata (x-amz-meta) through S3 API. 2
Mar 15, 2022
03be08e
Unit test fix.
Mar 15, 2022
87280e6
Update hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/clie…
avijayanhwx Mar 22, 2022
f63ca57
Merge remote-tracking branch 'upstream/master' into HDDS-6440-master
Mar 23, 2022
996afde
Merge branch 'HDDS-6440-master' of github.com:avijayanhwx/hadoop-ozon…
Mar 23, 2022
44180c1
Max size of 2KB
Mar 29, 2022
c1c0454
Merge remote-tracking branch 'upstream/master' into HDDS-6440-master
Mar 29, 2022
af9ee6c
Remove deprecated constructor.
Mar 29, 2022
1e03a4f
Merge remote-tracking branch 'upstream/master' into HDDS-6440-master
Apr 6, 2022
1b12aad
Merge remote-tracking branch 'upstream/master' into HDDS-6440-master
Apr 11, 2022
1bbfac7
sync with master branch
Aug 29, 2022
43efa39
fix checkstyle error
Aug 29, 2022
73257bd
remove gdprEnabled metadata from client request
Aug 30, 2022
8d68c21
fix checkstyle error
Aug 31, 2022
da17c8a
comment out some unit test
Aug 31, 2022
9db93fa
comment out updating creation time and modification time of key on cl…
Aug 31, 2022
50b7946
update unit test
Aug 31, 2022
32a9ad5
pick gdpr related string from OzoneConst; update s3 request metadata'…
Aug 31, 2022
256951e
fix checkstyle error
Aug 31, 2022
83626aa
fix OzoneKey creation time and modification time error
Aug 31, 2022
ff1603b
fix EndpointBase missing import
Aug 31, 2022
b420b0d
fix OzoneKey unit test
Aug 31, 2022
e1db11e
remove unused variable from OzoneKey
Aug 31, 2022
7febc6a
fix compiling error
Sep 1, 2022
84e5abf
pass metadata to copyObject method
Sep 1, 2022
8acd6c6
pass metadata to copyObject and put method of ObjectEndpoint class
Sep 1, 2022
35c4773
add Freon tests for s3 api with request of invalid size of metadata a…
Sep 1, 2022
0852059
Update s3 api Freon test result message
Sep 1, 2022
07f84a5
Fix checkstyle error; fix updated variable name
Sep 1, 2022
02fb612
Update s3 api robot test
Sep 1, 2022
fe93b51
Update s3 api robot test
Sep 2, 2022
ff9ba65
Update s3 api robot test
Sep 2, 2022
7bd79b6
Fix s3 robot test
Sep 6, 2022
aafd1c6
Update s3 robot test case where request with custom metadata size ove…
Sep 7, 2022
4f4357b
Fix checkstyle error
Sep 8, 2022
e1f911a
Remove debug log;remove unused import library
Sep 8, 2022
8ea42b1
Fix checkstyle error
Sep 9, 2022
0025afe
Remove additional line
Sep 9, 2022
13bd6ca
Add unit test
Sep 22, 2022
867fa27
Add setter for metadata attribute of OzoneKey class
Sep 23, 2022
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 @@ -391,6 +391,8 @@ private OzoneConsts() {

public static final int S3_SECRET_KEY_MIN_LENGTH = 8;

public static final int S3_REQUEST_HEADER_METADATA_SIZE_LIMIT_KB = 2;

//GDPR
public static final String GDPR_FLAG = "gdprEnabled";
public static final String GDPR_ALGORITHM_NAME = "AES";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.apache.hadoop.hdds.client.ReplicationType;

import java.time.Instant;
import java.util.Map;
import java.util.HashMap;

/**
* A class that encapsulates OzoneKey.
Expand Down Expand Up @@ -57,6 +59,7 @@ public class OzoneKey {

private ReplicationConfig replicationConfig;

private Map<String, String> metadata = new HashMap<>();
/**
* Constructs OzoneKey from OmKeyInfo.
*
Expand All @@ -67,14 +70,9 @@ public OzoneKey(String volumeName, String bucketName,
String keyName, long size, long creationTime,
long modificationTime, ReplicationType type,
int replicationFactor) {
this.volumeName = volumeName;
this.bucketName = bucketName;
this.name = keyName;
this.dataSize = size;
this.creationTime = Instant.ofEpochMilli(creationTime);
this.modificationTime = Instant.ofEpochMilli(modificationTime);
this.replicationConfig = ReplicationConfig.fromTypeAndFactor(type,
ReplicationFactor.valueOf(replicationFactor));
this(volumeName, bucketName, keyName, size, creationTime, modificationTime,
ReplicationConfig.fromTypeAndFactor(type,
Copy link
Contributor

Choose a reason for hiding this comment

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

Setting the instance this(creationTime, modificationTime ) can remain initialized with Instant.ofEpochMilli(creationTime) and Instant.ofEpochMilli(modificationTime) respectively.

Copy link
Contributor

Choose a reason for hiding this comment

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

@neils-dev can you please explain, I am not sure I understood your comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure @kerneltime, the intialization for the creationTime, modification can retain its previous initialization prior to the change:
previous:

this.creationTime = Instant.ofEpochMilli(creationTime);
    this.modificationTime = Instant.ofEpochMilli(modificationTime);

now:
line 73,
this(volumeName, bucketName, keyName, size, Instant.ofEpochMilli(creationTime), Instant.ofEpochMilli(modificationTime), ...)

Copy link
Contributor

Choose a reason for hiding this comment

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

The constructor called internally does the same, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes!

ReplicationFactor.valueOf(replicationFactor)));
}

/**
Expand All @@ -94,6 +92,16 @@ public OzoneKey(String volumeName, String bucketName,
this.replicationConfig = replicationConfig;
}

@SuppressWarnings("parameternumber")
public OzoneKey(String volumeName, String bucketName,
String keyName, long size, long creationTime,
long modificationTime, ReplicationConfig replicationConfig,
Map<String, String> metadata) {
this(volumeName, bucketName, keyName, size, creationTime,
modificationTime, replicationConfig);
this.metadata.putAll(metadata);
}

/**
* Returns Volume Name associated with the Key.
*
Expand Down Expand Up @@ -154,6 +162,10 @@ public Instant getModificationTime() {
* @return replicationType
*/

public Map<String, String> getMetadata() {
return metadata;
}

@Deprecated
@JsonIgnore
public ReplicationType getReplicationType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public class OzoneKeyDetails extends OzoneKey {
*/
private List<OzoneKeyLocation> ozoneKeyLocations;

private Map<String, String> metadata;

private FileEncryptionInfo feInfo;

private SupplierWithIOException<OzoneInputStream> contentSupplier;
Expand All @@ -58,8 +56,8 @@ public OzoneKeyDetails(String volumeName, String bucketName, String keyName,
super(volumeName, bucketName, keyName, size, creationTime,
modificationTime, type, replicationFactor);
this.ozoneKeyLocations = ozoneKeyLocations;
this.metadata = metadata;
this.feInfo = feInfo;
this.getMetadata().putAll(metadata);
}


Expand All @@ -75,9 +73,8 @@ public OzoneKeyDetails(String volumeName, String bucketName, String keyName,
FileEncryptionInfo feInfo,
SupplierWithIOException<OzoneInputStream> contentSupplier) {
super(volumeName, bucketName, keyName, size, creationTime,
modificationTime, replicationConfig);
modificationTime, replicationConfig, metadata);
this.ozoneKeyLocations = ozoneKeyLocations;
this.metadata = metadata;
this.feInfo = feInfo;
this.contentSupplier = contentSupplier;
}
Expand All @@ -89,10 +86,6 @@ public List<OzoneKeyLocation> getOzoneKeyLocations() {
return ozoneKeyLocations;
}

public Map<String, String> getMetadata() {
return metadata;
}

public FileEncryptionInfo getFileEncryptionInfo() {
return feInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,8 @@ public OzoneKey headObject(String volumeName, String bucketName,

return new OzoneKey(keyInfo.getVolumeName(), keyInfo.getBucketName(),
keyInfo.getKeyName(), keyInfo.getDataSize(), keyInfo.getCreationTime(),
keyInfo.getModificationTime(), keyInfo.getReplicationConfig());
keyInfo.getModificationTime(), keyInfo.getReplicationConfig(),
keyInfo.getMetadata());

}

Expand Down
5 changes: 5 additions & 0 deletions hadoop-ozone/dist/src/main/smoketest/s3/commonawslib.robot
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ Execute AWSS3APICli and checkrc
${output} = Execute and checkrc aws s3api --endpoint-url ${ENDPOINT_URL} ${command} ${expected_error_code}
[return] ${output}

Execute AWSS3APICli and ignore error
[Arguments] ${command}
${output} = Execute And Ignore Error aws s3api --endpoint-url ${ENDPOINT_URL} ${command}
[return] ${output}

Execute AWSS3Cli
[Arguments] ${command}
${output} = Execute aws s3 --endpoint-url ${ENDPOINT_URL} ${command}
Expand Down
26 changes: 26 additions & 0 deletions hadoop-ozone/dist/src/main/smoketest/s3/objectputget.robot
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,29 @@ Zero byte file

${result} = Execute AWSS3APICli and checkrc get-object --bucket ${BUCKET} --key ${PREFIX}/putobject/key=value/zerobyte --range bytes=0-10000 /tmp/testfile2.result 255
Should contain ${result} InvalidRange

Create file with user defined metadata
Execute echo "Randomtext" > /tmp/testfile2
Execute AWSS3ApiCli put-object --bucket ${BUCKET} --key ${PREFIX}/putobject/custom-metadata/key1 --body /tmp/testfile2 --metadata="custom-key1=custom-value1,custom-key2=custom-value2"

${result} = Execute AWSS3APICli head-object --bucket ${BUCKET} --key ${PREFIX}/putobject/custom-metadata/key1
Should contain ${result} \"custom-key1\": \"custom-value1\"
Should contain ${result} \"custom-key2\": \"custom-value2\"

${result} = Execute ozone sh key info /s3v/${BUCKET}/${PREFIX}/putobject/custom-metadata/key1
Should contain ${result} \"custom-key1\" : \"custom-value1\"
Should contain ${result} \"custom-key2\" : \"custom-value2\"

Create file with user defined metadata with gdpr enabled value in request
Execute echo "Randomtext" > /tmp/testfile2
Execute AWSS3ApiCli put-object --bucket ${BUCKET} --key ${PREFIX}/putobject/custom-metadata/key2 --body /tmp/testfile2 --metadata="gdprEnabled=true,custom-key2=custom-value2"
${result} = Execute AWSS3ApiCli head-object --bucket ${BUCKET} --key ${PREFIX}/putobject/custom-metadata/key2
Should contain ${result} \"custom-key2\": \"custom-value2\"
Should not contain ${result} \"gdprEnabled\": \"true\"


Create file with user defined metadata size larger than 2 KB
Execute echo "Randomtext" > /tmp/testfile2
${custom_metadata_value} = Execute printf 'v%.0s' {1..3000}
${result} = Execute AWSS3APICli and ignore error put-object --bucket ${BUCKET} --key ${PREFIX}/putobject/custom-metadata/key2 --body /tmp/testfile2 --metadata="custom-key1=${custom_metadata_value}"
Should not contain ${result} custom-key1: ${custom_metadata_value}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,24 @@

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.core.Context;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import java.util.HashSet;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.ozone.audit.AuditAction;
import org.apache.hadoop.ozone.audit.AuditEventStatus;
import org.apache.hadoop.ozone.audit.AuditLogger;
Expand All @@ -35,6 +45,7 @@
import org.apache.hadoop.ozone.audit.Auditor;
import org.apache.hadoop.ozone.client.OzoneBucket;
import org.apache.hadoop.ozone.client.OzoneClient;
import org.apache.hadoop.ozone.client.OzoneKey;
import org.apache.hadoop.ozone.client.OzoneVolume;
import org.apache.hadoop.ozone.client.protocol.ClientProtocol;
import org.apache.hadoop.ozone.om.exceptions.OMException;
Expand All @@ -44,12 +55,16 @@
import org.apache.hadoop.ozone.s3.exception.S3ErrorTable;

import com.google.common.annotations.VisibleForTesting;

import org.apache.hadoop.ozone.s3.metrics.S3GatewayMetrics;
import org.apache.hadoop.ozone.s3.util.AuditUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.hadoop.ozone.OzoneConsts.KB;
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.newError;
import static org.apache.hadoop.ozone.s3.util.S3Consts.CUSTOM_METADATA_HEADER_PREFIX;

/**
* Basic helpers for all the REST endpoints.
Expand All @@ -63,6 +78,8 @@ public abstract class EndpointBase implements Auditor {
@Context
private ContainerRequestContext context;

private Set<String> excludeMetadataFields =
new HashSet<>(Arrays.asList(OzoneConsts.GDPR_FLAG));
private static final Logger LOG =
LoggerFactory.getLogger(EndpointBase.class);

Expand Down Expand Up @@ -240,6 +257,57 @@ private Iterator<? extends OzoneBucket> iterateBuckets(
}
}

protected Map<String, String> getCustomMetadataFromHeaders(
MultivaluedMap<String, String> requestHeaders) throws OS3Exception {
Map<String, String> customMetadata = new HashMap<>();
if (requestHeaders == null || requestHeaders.isEmpty()) {
return customMetadata;
}

Set<String> customMetadataKeys = requestHeaders.keySet().stream()
.filter(k -> {
if (k.startsWith(CUSTOM_METADATA_HEADER_PREFIX) &&
!excludeMetadataFields.contains(
k.substring(
CUSTOM_METADATA_HEADER_PREFIX.length()))) {
return true;
}
return false;
})
.collect(Collectors.toSet());

long sizeInBytes = 0;
if (!customMetadataKeys.isEmpty()) {
for (String key : customMetadataKeys) {
String mapKey =
key.substring(CUSTOM_METADATA_HEADER_PREFIX.length());
List<String> values = requestHeaders.get(key);
String value = StringUtils.join(values, ",");
sizeInBytes += mapKey.getBytes(UTF_8).length;
sizeInBytes += value.getBytes(UTF_8).length;

if (sizeInBytes >
OzoneConsts.S3_REQUEST_HEADER_METADATA_SIZE_LIMIT_KB * KB) {
throw new IllegalArgumentException("Illegal user defined metadata." +
" Combined size cannot exceed 2KB.");
}
customMetadata.put(mapKey, value);
}
}
return customMetadata;
}

protected void addCustomMetadataHeaders(
Response.ResponseBuilder responseBuilder, OzoneKey key) {

Map<String, String> metadata = key.getMetadata();
for (Map.Entry<String, String> entry : metadata.entrySet()) {
responseBuilder
.header(CUSTOM_METADATA_HEADER_PREFIX + entry.getKey(),
entry.getValue());
}
}

private AuditMessage.Builder auditMessageBaseBuilder(AuditAction op,
Map<String, String> auditMap) {
AuditMessage.Builder builder = new AuditMessage.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.OptionalLong;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -210,13 +209,17 @@ public Response put(
"Connection", "close").build();
}

// Normal put object
Map<String, String> customMetadata =
getCustomMetadataFromHeaders(headers.getRequestHeaders());

if ("STREAMING-AWS4-HMAC-SHA256-PAYLOAD"
.equals(headers.getHeaderString("x-amz-content-sha256"))) {
body = new SignedChunksInputStream(body);
}

output = getClientProtocol().createKey(volume.getName(), bucketName,
keyPath, length, replicationConfig, new HashMap<>());
keyPath, length, replicationConfig, customMetadata);
IOUtils.copy(body, output);

getMetrics().incCreateKeySuccess();
Expand Down Expand Up @@ -470,6 +473,7 @@ public Response head(
.header("Content-Length", key.getDataSize())
.header("Content-Type", "binary/octet-stream");
addLastModifiedDate(response, key);
addCustomMetadataHeaders(response, key);
getMetrics().incHeadKeySuccess();
AUDIT.logReadSuccess(buildAuditMessageForSuccess(s3GAction,
getAuditParameters()));
Expand Down Expand Up @@ -882,10 +886,12 @@ public void setContext(ContainerRequestContext context) {

void copy(OzoneVolume volume, InputStream src, long srcKeyLen,
String destKey, String destBucket,
ReplicationConfig replication) throws IOException {
try (OzoneOutputStream dest = getClientProtocol().createKey(
ReplicationConfig replication,
Map<String, String> metadata) throws IOException {
try (OzoneOutputStream dest =
getClientProtocol().createKey(
volume.getName(), destBucket, destKey, srcKeyLen,
replication, new HashMap<>())) {
replication, metadata)) {
IOUtils.copy(src, dest);
}
}
Expand Down Expand Up @@ -936,7 +942,8 @@ private CopyObjectResponse copyObject(OzoneVolume volume,

try (OzoneInputStream src = getClientProtocol().getKey(volume.getName(),
sourceBucket, sourceKey)) {
copy(volume, src, sourceKeyLen, destkey, destBucket, replicationConfig);
copy(volume, src, sourceKeyLen, destkey, destBucket, replicationConfig,
sourceKeyDetails.getMetadata());
}

final OzoneKeyDetails destKeyDetails = getClientProtocol().getKeyDetails(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ private S3Consts() {
public static final String S3_XML_NAMESPACE = "http://s3.amazonaws" +
".com/doc/2006-03-01/";

public static final String CUSTOM_METADATA_HEADER_PREFIX = "x-amz-meta-";

}
Loading