sadanand48 commented on code in PR #6949:
URL: https://github.com/apache/ozone/pull/6949#discussion_r1680611621


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/helpers/OMAuditLogger.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.helpers;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.hadoop.ozone.audit.AuditLogger;
+import org.apache.hadoop.ozone.audit.AuditMessage;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.request.OMClientRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.ratis.server.protocol.TermIndex;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type;
+
+/**
+ * This class is used for OM Audit logs.
+ */
+public final class OMAuditLogger {
+  private OMAuditLogger() {
+  }
+
+  private static final Map<Type, OMAction> CMD_AUDIT_ACTION_MAP = new 
HashMap<>();
+  private static final Logger LOG = 
LoggerFactory.getLogger(OMAuditLogger.class);
+
+  static {
+    init();
+  }
+
+  private static void init() {
+    CMD_AUDIT_ACTION_MAP.put(Type.CreateVolume, OMAction.CREATE_VOLUME);
+    CMD_AUDIT_ACTION_MAP.put(Type.DeleteVolume, OMAction.DELETE_VOLUME);
+    CMD_AUDIT_ACTION_MAP.put(Type.CreateBucket, OMAction.CREATE_BUCKET);
+    CMD_AUDIT_ACTION_MAP.put(Type.DeleteBucket, OMAction.DELETE_BUCKET);
+    CMD_AUDIT_ACTION_MAP.put(Type.AddAcl, OMAction.ADD_ACL);
+    CMD_AUDIT_ACTION_MAP.put(Type.RemoveAcl, OMAction.REMOVE_ACL);
+    CMD_AUDIT_ACTION_MAP.put(Type.SetAcl, OMAction.SET_ACL);
+    CMD_AUDIT_ACTION_MAP.put(Type.GetDelegationToken, 
OMAction.GET_DELEGATION_TOKEN);
+    CMD_AUDIT_ACTION_MAP.put(Type.CancelDelegationToken, 
OMAction.CANCEL_DELEGATION_TOKEN);
+    CMD_AUDIT_ACTION_MAP.put(Type.RenewDelegationToken, 
OMAction.RENEW_DELEGATION_TOKEN);
+    CMD_AUDIT_ACTION_MAP.put(Type.GetS3Secret, OMAction.GET_S3_SECRET);
+    CMD_AUDIT_ACTION_MAP.put(Type.SetS3Secret, OMAction.SET_S3_SECRET);
+    CMD_AUDIT_ACTION_MAP.put(Type.RevokeS3Secret, OMAction.REVOKE_S3_SECRET);
+    CMD_AUDIT_ACTION_MAP.put(Type.CreateTenant, OMAction.CREATE_TENANT);
+    CMD_AUDIT_ACTION_MAP.put(Type.DeleteTenant, OMAction.DELETE_TENANT);
+    CMD_AUDIT_ACTION_MAP.put(Type.TenantAssignUserAccessId, 
OMAction.TENANT_ASSIGN_USER_ACCESSID);
+    CMD_AUDIT_ACTION_MAP.put(Type.TenantRevokeUserAccessId, 
OMAction.TENANT_REVOKE_USER_ACCESSID);
+    CMD_AUDIT_ACTION_MAP.put(Type.TenantRevokeAdmin, 
OMAction.TENANT_REVOKE_ADMIN);
+    CMD_AUDIT_ACTION_MAP.put(Type.CreateSnapshot, OMAction.CREATE_SNAPSHOT);
+    CMD_AUDIT_ACTION_MAP.put(Type.DeleteSnapshot, OMAction.DELETE_SNAPSHOT);
+    CMD_AUDIT_ACTION_MAP.put(Type.RenameSnapshot, OMAction.RENAME_SNAPSHOT);
+    CMD_AUDIT_ACTION_MAP.put(Type.RecoverLease, OMAction.RECOVER_LEASE);
+    CMD_AUDIT_ACTION_MAP.put(Type.CreateDirectory, OMAction.CREATE_DIRECTORY);
+    CMD_AUDIT_ACTION_MAP.put(Type.CreateFile, OMAction.CREATE_FILE);
+    CMD_AUDIT_ACTION_MAP.put(Type.CreateKey, OMAction.ALLOCATE_KEY);
+    CMD_AUDIT_ACTION_MAP.put(Type.AllocateBlock, OMAction.ALLOCATE_BLOCK);
+    CMD_AUDIT_ACTION_MAP.put(Type.CommitKey, OMAction.COMMIT_KEY);
+    CMD_AUDIT_ACTION_MAP.put(Type.DeleteKey, OMAction.DELETE_KEY);
+    CMD_AUDIT_ACTION_MAP.put(Type.DeleteKeys, OMAction.DELETE_KEYS);
+    CMD_AUDIT_ACTION_MAP.put(Type.RenameKey, OMAction.RENAME_KEY);
+    CMD_AUDIT_ACTION_MAP.put(Type.RenameKeys, OMAction.RENAME_KEYS);
+    CMD_AUDIT_ACTION_MAP.put(Type.InitiateMultiPartUpload, 
OMAction.INITIATE_MULTIPART_UPLOAD);
+    CMD_AUDIT_ACTION_MAP.put(Type.CommitMultiPartUpload, 
OMAction.COMMIT_MULTIPART_UPLOAD_PARTKEY);
+    CMD_AUDIT_ACTION_MAP.put(Type.AbortMultiPartUpload, 
OMAction.ABORT_MULTIPART_UPLOAD);
+    CMD_AUDIT_ACTION_MAP.put(Type.CompleteMultiPartUpload, 
OMAction.COMPLETE_MULTIPART_UPLOAD);
+    CMD_AUDIT_ACTION_MAP.put(Type.SetTimes, OMAction.SET_TIMES);
+    CMD_AUDIT_ACTION_MAP.put(Type.AbortExpiredMultiPartUploads, 
OMAction.ABORT_EXPIRED_MULTIPART_UPLOAD);
+    CMD_AUDIT_ACTION_MAP.put(Type.SetVolumeProperty, OMAction.SET_OWNER);
+    CMD_AUDIT_ACTION_MAP.put(Type.SetBucketProperty, OMAction.UPDATE_BUCKET);
+  }
+
+  private static OMAction getAction(OzoneManagerProtocolProtos.OMRequest 
request) {
+    Type cmdType = request.getCmdType();
+    OMAction omAction = CMD_AUDIT_ACTION_MAP.get(cmdType);
+    if (null != omAction) {
+      if (cmdType.equals(Type.SetVolumeProperty)) {
+        boolean hasQuota = 
request.getSetVolumePropertyRequest().hasQuotaInBytes();
+        if (hasQuota) {
+          return OMAction.SET_QUOTA;
+        }
+      }
+      if (cmdType.equals(Type.SetVolumeProperty)) {

Review Comment:
   ```suggestion
         if (cmdType.equals(Type.SetBucketProperty)) {
   ```
   We can add another condition for set volume owner too



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