F64116045 commented on code in PR #12215:
URL: https://github.com/apache/ozone/pull/12215#discussion_r4812118097


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/bucket/OMBucketSetObjectLockConfigRequest.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.om.request.bucket;
+
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.BUCKET_NOT_FOUND;
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.INVALID_REQUEST;
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.PERMISSION_DENIED;
+import static 
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.LeveledResource.BUCKET_LOCK;
+import static 
org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType.WRITE;
+import static 
org.apache.hadoop.ozone.security.acl.OzoneObj.ResourceType.BUCKET;
+import static org.apache.hadoop.ozone.security.acl.OzoneObj.StoreType.OZONE;
+
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OmUtils;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.OzoneManagerUtils;
+import org.apache.hadoop.ozone.om.ResolvedBucket;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.execution.flowcontrol.ExecutionContext;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+import org.apache.hadoop.ozone.om.helpers.BucketRetention;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.RetentionUtil;
+import org.apache.hadoop.ozone.om.request.OMClientRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.bucket.OMBucketSetPropertyResponse;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetBucketObjectLockConfigRequest;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetBucketObjectLockConfigResponse;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.util.Time;
+
+/**
+ * Enables Object Lock and replaces the default retention on an OBS bucket.
+ */
+public class OMBucketSetObjectLockConfigRequest extends OMClientRequest {
+
+  public OMBucketSetObjectLockConfigRequest(OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
+    final OMRequest omRequest = super.preExecute(ozoneManager);
+    if (!omRequest.hasSetBucketObjectLockConfigRequest()) {
+      throw new OMException("Missing bucket Object Lock configuration 
request", INVALID_REQUEST);
+    }
+    SetBucketObjectLockConfigRequest request = 
omRequest.getSetBucketObjectLockConfigRequest();
+    if (!request.getObjectLockEnabled()) {
+      throw new OMException("Object Lock cannot be disabled", INVALID_REQUEST);
+    }
+    OmUtils.validateVolumeName(request.getVolumeName(), 
ozoneManager.isStrictS3());
+    OmUtils.validateBucketName(request.getBucketName(), 
ozoneManager.isStrictS3());
+
+    long modificationTime = Time.now();
+    if (request.hasDefaultRetention()) {
+      try {
+        BucketRetention retention = 
BucketRetention.fromProto(request.getDefaultRetention());
+        RetentionUtil.validateBucketRetention(retention, modificationTime);
+      } catch (IllegalArgumentException e) {
+        throw new OMException(e.getMessage(), e, INVALID_REQUEST);
+      }
+    }
+
+    ResolvedBucket resolved = 
ozoneManager.resolveBucketLink(Pair.of(request.getVolumeName(), 
request.getBucketName()),
+        this);
+    OMMetadataManager metadata = ozoneManager.getMetadataManager();
+    OmBucketInfo bucket = OzoneManagerUtils.getBucketInfo(metadata, 
resolved.realVolume(), resolved.realBucket());
+    validateBucketLayout(bucket);
+    if (ozoneManager.getAclsEnabled()) {
+      checkBucketAccess(ozoneManager, bucket);
+    }
+
+    return omRequest.toBuilder()
+        .setSetBucketObjectLockConfigRequest(request.toBuilder()
+            .setVolumeName(bucket.getVolumeName())
+            .setBucketName(bucket.getBucketName())
+            .setBucketObjectId(bucket.getObjectID())
+            .setModificationTime(modificationTime))
+        .build();
+  }
+
+  @Override
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, 
ExecutionContext context) {

Review Comment:
   I think we should check the owner of the bucket named in the request because 
that matches Lifecycle. In this example, alice should match.
   
   I also moved the check to S3G so both APIs handle this S3 header in the same 
place and we can drop expectedBucketOwner as 
https://github.com/apache/ozone/pull/12215#discussion_r4783442880 suggested 
   
   addressed in 
[16f9fa3e76](https://github.com/apache/ozone/commit/16f9fa3e76a5e882bf101e52d1ef8ae435de6d1a).



-- 
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