yihua commented on code in PR #13868:
URL: https://github.com/apache/hudi/pull/13868#discussion_r2334589719


##########
hudi-cli/src/main/java/org/apache/hudi/cli/commands/LockCommand.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.hudi.cli.commands;
+
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.storage.StoragePath;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.shell.standard.ShellComponent;
+import org.springframework.shell.standard.ShellMethod;
+import org.springframework.shell.standard.ShellOption;
+
+import org.apache.hudi.common.util.FileIOUtils;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import static 
org.apache.hudi.client.transaction.lock.audit.StorageLockProviderAuditService.AUDIT_FOLDER_NAME;
+
+/**
+ * CLI commands for managing Hudi table locking and audit functionality.
+ */
+@ShellComponent
+public class LockCommand {
+
+  private static final Logger LOG = LoggerFactory.getLogger(LockCommand.class);
+  private static final String AUDIT_CONFIG_FILE_NAME = "audit_enabled.json";
+  private static final String STORAGE_LOCK_AUDIT_SERVICE_ENABLED_FIELD = 
"STORAGE_LOCK_AUDIT_SERVICE_ENABLED";

Review Comment:
   Similar on reusing 
`AuditServiceFactory.STORAGE_LOCK_AUDIT_SERVICE_ENABLED_FIELD`



##########
hudi-cli/src/main/java/org/apache/hudi/cli/commands/LockCommand.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.hudi.cli.commands;
+
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.storage.StoragePath;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.shell.standard.ShellComponent;
+import org.springframework.shell.standard.ShellMethod;
+import org.springframework.shell.standard.ShellOption;
+
+import org.apache.hudi.common.util.FileIOUtils;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import static 
org.apache.hudi.client.transaction.lock.audit.StorageLockProviderAuditService.AUDIT_FOLDER_NAME;
+
+/**
+ * CLI commands for managing Hudi table locking and audit functionality.
+ */
+@ShellComponent
+public class LockCommand {
+
+  private static final Logger LOG = LoggerFactory.getLogger(LockCommand.class);
+  private static final String AUDIT_CONFIG_FILE_NAME = "audit_enabled.json";
+  private static final String STORAGE_LOCK_AUDIT_SERVICE_ENABLED_FIELD = 
"STORAGE_LOCK_AUDIT_SERVICE_ENABLED";
+  private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+  @ShellMethod(key = "locks audit enable", value = "Enable storage lock audit 
service for the current table")
+  public String enableLockAudit() {
+    
+    if (HoodieCLI.basePath == null) {
+      return "No Hudi table loaded. Please connect to a table first.";
+    }
+
+    try {
+      // Create the audit config file path using .hoodie/.locks structure 
+      String lockFolderPath = String.format("%s%s%s", HoodieCLI.basePath, 
StoragePath.SEPARATOR, HoodieTableMetaClient.LOCKS_FOLDER_NAME);

Review Comment:
   nit: use `getLockFolderPath`?



##########
hudi-cli/src/main/java/org/apache/hudi/cli/commands/LockCommand.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.hudi.cli.commands;
+
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.storage.StoragePath;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.shell.standard.ShellComponent;
+import org.springframework.shell.standard.ShellMethod;
+import org.springframework.shell.standard.ShellOption;
+
+import org.apache.hudi.common.util.FileIOUtils;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import static 
org.apache.hudi.client.transaction.lock.audit.StorageLockProviderAuditService.AUDIT_FOLDER_NAME;
+
+/**
+ * CLI commands for managing Hudi table locking and audit functionality.
+ */
+@ShellComponent
+public class LockCommand {
+
+  private static final Logger LOG = LoggerFactory.getLogger(LockCommand.class);
+  private static final String AUDIT_CONFIG_FILE_NAME = "audit_enabled.json";

Review Comment:
   Could `AuditServiceFactory.AUDIT_CONFIG_FILE_NAME` be reused?



##########
hudi-cli/src/main/java/org/apache/hudi/cli/commands/LockCommand.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.hudi.cli.commands;
+
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.storage.StoragePath;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.shell.standard.ShellComponent;
+import org.springframework.shell.standard.ShellMethod;
+import org.springframework.shell.standard.ShellOption;
+
+import org.apache.hudi.common.util.FileIOUtils;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import static 
org.apache.hudi.client.transaction.lock.audit.StorageLockProviderAuditService.AUDIT_FOLDER_NAME;
+
+/**
+ * CLI commands for managing Hudi table locking and audit functionality.
+ */
+@ShellComponent
+public class LockCommand {
+
+  private static final Logger LOG = LoggerFactory.getLogger(LockCommand.class);
+  private static final String AUDIT_CONFIG_FILE_NAME = "audit_enabled.json";
+  private static final String STORAGE_LOCK_AUDIT_SERVICE_ENABLED_FIELD = 
"STORAGE_LOCK_AUDIT_SERVICE_ENABLED";
+  private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+  @ShellMethod(key = "locks audit enable", value = "Enable storage lock audit 
service for the current table")
+  public String enableLockAudit() {
+    
+    if (HoodieCLI.basePath == null) {
+      return "No Hudi table loaded. Please connect to a table first.";
+    }
+
+    try {
+      // Create the audit config file path using .hoodie/.locks structure 
+      String lockFolderPath = String.format("%s%s%s", HoodieCLI.basePath, 
StoragePath.SEPARATOR, HoodieTableMetaClient.LOCKS_FOLDER_NAME);
+      String auditConfigPath = String.format("%s%s%s", lockFolderPath, 
StoragePath.SEPARATOR, AUDIT_CONFIG_FILE_NAME);

Review Comment:
   Add another method to get audit config path for reuse across 
`AuditServiceFactory` and `LockCommand` classes?



##########
hudi-cli/src/main/java/org/apache/hudi/cli/commands/LockCommand.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.hudi.cli.commands;
+
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.storage.StoragePath;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.shell.standard.ShellComponent;
+import org.springframework.shell.standard.ShellMethod;
+import org.springframework.shell.standard.ShellOption;
+
+import org.apache.hudi.common.util.FileIOUtils;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import static 
org.apache.hudi.client.transaction.lock.audit.StorageLockProviderAuditService.AUDIT_FOLDER_NAME;
+
+/**
+ * CLI commands for managing Hudi table locking and audit functionality.
+ */
+@ShellComponent
+public class LockCommand {
+
+  private static final Logger LOG = LoggerFactory.getLogger(LockCommand.class);
+  private static final String AUDIT_CONFIG_FILE_NAME = "audit_enabled.json";
+  private static final String STORAGE_LOCK_AUDIT_SERVICE_ENABLED_FIELD = 
"STORAGE_LOCK_AUDIT_SERVICE_ENABLED";
+  private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+  @ShellMethod(key = "locks audit enable", value = "Enable storage lock audit 
service for the current table")
+  public String enableLockAudit() {
+    
+    if (HoodieCLI.basePath == null) {
+      return "No Hudi table loaded. Please connect to a table first.";
+    }
+
+    try {
+      // Create the audit config file path using .hoodie/.locks structure 
+      String lockFolderPath = String.format("%s%s%s", HoodieCLI.basePath, 
StoragePath.SEPARATOR, HoodieTableMetaClient.LOCKS_FOLDER_NAME);
+      String auditConfigPath = String.format("%s%s%s", lockFolderPath, 
StoragePath.SEPARATOR, AUDIT_CONFIG_FILE_NAME);
+      
+      // Create the JSON content
+      ObjectNode configJson = OBJECT_MAPPER.createObjectNode();
+      configJson.put(STORAGE_LOCK_AUDIT_SERVICE_ENABLED_FIELD, true);
+      String jsonContent = OBJECT_MAPPER.writeValueAsString(configJson);
+      
+      // Write the config file using HoodieStorage
+      StoragePath configPath = new StoragePath(auditConfigPath);
+      try (OutputStream outputStream = HoodieCLI.storage.create(configPath, 
true)) {
+        outputStream.write(jsonContent.getBytes());
+      }
+      
+      return String.format("Lock audit enabled successfully.\nAudit config 
written to: %s\n"
+          + "Audit files will be stored at: %s%s%s", auditConfigPath, 
lockFolderPath, StoragePath.SEPARATOR, AUDIT_FOLDER_NAME);

Review Comment:
   nit: add another util for constructing the absolute path of the audit folder?



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

Reply via email to