You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/04/21 01:51:43 UTC

[GitHub] [iotdb] wangchao316 commented on a diff in pull request #5619: [IOTDB-2959] add permission cache

wangchao316 commented on code in PR #5619:
URL: https://github.com/apache/iotdb/pull/5619#discussion_r854706559


##########
server/src/main/java/org/apache/iotdb/db/auth/authorizer/ClusterAuthorizer.java:
##########
@@ -16,8 +16,94 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.db.auth.authorizer;
 
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.BadNodeUrlException;
+import org.apache.iotdb.confignode.rpc.thrift.TAuthorizerReq;
+import org.apache.iotdb.db.auth.AuthException;
+import org.apache.iotdb.db.client.ConfigNodeClient;
+import org.apache.iotdb.db.mpp.sql.planner.plan.node.metedata.write.AuthorNode;
+import org.apache.iotdb.db.mpp.sql.statement.sys.AuthorStatement;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import com.google.common.util.concurrent.SettableFuture;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Locale;
+
 public class ClusterAuthorizer {
-  // TODO: send rpc to confignode
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(ClusterAuthorizer.class);
+
+  public SettableFuture<Void> operatePermission(AuthorStatement authorStatement) {
+    SettableFuture<Void> future = SettableFuture.create();
+    ConfigNodeClient configNodeClient = null;
+    try {
+      // Construct request using statement
+      TAuthorizerReq req = getTAuthorizerReq(authorStatement);
+      configNodeClient = new ConfigNodeClient();
+      // Send request to some API server
+      TSStatus tsStatus = configNodeClient.operatePermission(req);
+      // Get response or throw exception
+      if (TSStatusCode.SUCCESS_STATUS.getStatusCode() != tsStatus.getCode()) {
+        LOGGER.error(
+            "Failed to execute {} in config node, status is {}.",
+            authorStatement.getAuthorType().toString().toLowerCase(Locale.ROOT),
+            tsStatus);
+        future.setException(new StatementExecutionException(tsStatus));
+      } else {
+        future.set(null);
+      }
+    } catch (IoTDBConnectionException | BadNodeUrlException e) {
+      LOGGER.error("Failed to connect to config node.");
+      future.setException(e);
+    } catch (AuthException e) {
+      LOGGER.error("No such privilege {}.", authorStatement.getAuthorType());
+      future.setException(e);
+    } finally {
+      if (configNodeClient != null) {
+        configNodeClient.close();
+      }
+    }
+    // If the action is executed successfully, return the Future.
+    // If your operation is async, you can return the corresponding future directly.
+    return future;
+  }
+
+  public void queryPermission(AuthorStatement authorStatement) {
+    ConfigNodeClient configNodeClient = null;
+    try {
+      configNodeClient = new ConfigNodeClient();
+      TAuthorizerReq req = getTAuthorizerReq(authorStatement);
+      configNodeClient.queryPermission(req);
+      // TODO: Process the returned data
+    } catch (AuthException e) {
+      LOGGER.error("No such privilege {}.", authorStatement.getAuthorType());
+    } catch (IoTDBConnectionException | BadNodeUrlException e) {
+      LOGGER.error("Failed to connect to config node.");
+    }

Review Comment:
   need configNodeClient  close 



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org