Gargi-jais11 commented on code in PR #10930:
URL: https://github.com/apache/ozone/pull/10930#discussion_r3709535898


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectAttributesHandler.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * 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;
+
+import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.ACCESS_DENIED;
+import static 
org.apache.hadoop.ozone.s3.exception.S3ErrorTable.INVALID_ARGUMENT;
+import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.NO_SUCH_KEY;
+import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.newError;
+import static 
org.apache.hadoop.ozone.s3.util.S3Consts.OBJECT_ATTRIBUTES_HEADER;
+import static org.apache.hadoop.ozone.s3.util.S3Consts.QueryParams;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.S3GAction;
+import org.apache.hadoop.ozone.client.OzoneKey;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes;
+import org.apache.hadoop.ozone.s3.endpoint.ObjectEndpoint.ObjectRequestContext;
+import org.apache.hadoop.ozone.s3.exception.OS3Exception;
+import org.apache.hadoop.ozone.s3.util.S3StorageType;
+
+/**
+ * Handles the GetObjectAttributes S3 API ({@code GET 
/{bucket}/{key}?attributes}).
+ *
+ * <p>Returns selected metadata about an object without transferring the 
object body.
+ * Supported attributes: {@code ETag}, {@code ObjectSize}, {@code 
StorageClass}, {@code ObjectParts}.
+ *
+ * <p>The {@code Checksum} attribute is not yet supported because Ozone does 
not store
+ * non-MD5 checksum algorithms in key metadata. Object versioning ({@code 
versionId}) and
+ * SSE-C encryption headers are also not supported and are silently ignored.
+ *
+ * <p>See 
https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectAttributes.html
+ */
+class ObjectAttributesHandler extends ObjectOperationHandler {
+
+  /** Valid values for the x-amz-object-attributes request header. */
+  static final String ATTR_ETAG = "ETag";
+  static final String ATTR_CHECKSUM = "Checksum";
+  static final String ATTR_OBJECT_PARTS = "ObjectParts";
+  static final String ATTR_STORAGE_CLASS = "StorageClass";
+  static final String ATTR_OBJECT_SIZE = "ObjectSize";
+
+  private static final Set<String> KNOWN_ATTRIBUTES = new 
HashSet<>(Arrays.asList(
+      ATTR_ETAG, ATTR_CHECKSUM, ATTR_OBJECT_PARTS, ATTR_STORAGE_CLASS, 
ATTR_OBJECT_SIZE));
+
+  @Override
+  Response handleGetRequest(ObjectRequestContext context, String keyPath)
+      throws IOException, OS3Exception {
+
+    if (queryParams().get(QueryParams.ATTRIBUTES) == null) {
+      return null;
+    }
+
+    context.setAction(S3GAction.GET_OBJECT_ATTRIBUTES);
+
+    try {
+      Set<String> requestedAttributes = parseAttributesHeader(keyPath);
+      String bucketName = context.getBucketName();
+
+      OzoneKey key;
+      try {
+        key = getClientProtocol().headS3Object(bucketName, keyPath);
+        isFile(keyPath, key);
+      } catch (OMException ex) {
+        if (ex.getResult() == ResultCodes.KEY_NOT_FOUND) {
+          throw newError(NO_SUCH_KEY, keyPath, ex);
+        } else if (isAccessDenied(ex)) {
+          throw newError(ACCESS_DENIED, bucketName + "/" + keyPath, ex);

Review Comment:
   seems that I missed updating failure metrics. Thanks for pointing it out.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to