CRZbulabula commented on code in PR #16647:
URL: https://github.com/apache/iotdb/pull/16647#discussion_r2485207101


##########
iotdb-protocol/thrift-confignode/src/main/thrift/confignode.thrift:
##########
@@ -1361,6 +1371,16 @@ service IConfigNodeRPCService {
 
   TAINodeConfigurationResp getAINodeConfiguration(i32 aiNodeId)
 
+    // ====================================================
+    // AI Node Location (no modelId)
+    // ====================================================
+    /**
+     * Return a reachable AINode location when modelId is not provided.
+     * If deviceId is provided, try to pick one that supports the device; 
otherwise
+     * return any healthy/default AINode.
+     */
+    TGetAINodeLocationResp getAINodeLocation(TGetAINodeLocationReq req)

Review Comment:
   ```suggestion
       TGetAINodeLocationResp getAINodeLocation()
   ```
   You don't need any input for this interface.



##########
iotdb-protocol/thrift-confignode/src/main/thrift/confignode.thrift:
##########
@@ -1361,6 +1371,16 @@ service IConfigNodeRPCService {
 
   TAINodeConfigurationResp getAINodeConfiguration(i32 aiNodeId)
 
+    // ====================================================
+    // AI Node Location (no modelId)
+    // ====================================================
+    /**
+     * Return a reachable AINode location when modelId is not provided.
+     * If deviceId is provided, try to pick one that supports the device; 
otherwise
+     * return any healthy/default AINode.

Review Comment:
   ```suggestion
        * Return a reachable AINode location.
   ```



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java:
##########
@@ -648,6 +651,59 @@ public TSStatus operatePermission(final TAuthorizerReq 
req) {
             req.getNewUsername()));
   }
 
+  @Override
+  public TGetAINodeLocationResp getAINodeLocation(final TGetAINodeLocationReq 
req)
+      throws TException {
+    final TGetAINodeLocationResp resp = new TGetAINodeLocationResp();
+    final TSStatus status = new TSStatus();
+    try {
+      final java.util.List<?> registered = 
configManager.getNodeManager().getRegisteredAINodes();

Review Comment:
   ```suggestion
         final List<TAINodeConfiguration> registeredAINodes = 
configManager.getNodeManager().getRegisteredAINodes();
   ```



##########
iotdb-protocol/thrift-confignode/src/main/thrift/confignode.thrift:
##########
@@ -659,6 +659,16 @@ struct TAINodeInfo {
   4: required i32 internalPort
 }
 
+// ----------- New messages -----------
+struct TGetAINodeLocationReq {
+  1: optional string deviceId
+}
+
+struct TGetAINodeLocationResp {
+  1: required common.TSStatus status
+  2: optional common.TEndPoint aiNodeAddress

Review Comment:
   ```suggestion
     2: optional common.TAINodeLocation aiNodeLocation
   ```



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java:
##########
@@ -648,6 +651,59 @@ public TSStatus operatePermission(final TAuthorizerReq 
req) {
             req.getNewUsername()));
   }
 
+  @Override
+  public TGetAINodeLocationResp getAINodeLocation(final TGetAINodeLocationReq 
req)
+      throws TException {
+    final TGetAINodeLocationResp resp = new TGetAINodeLocationResp();
+    final TSStatus status = new TSStatus();
+    try {
+      final java.util.List<?> registered = 
configManager.getNodeManager().getRegisteredAINodes();
+      if (registered == null || registered.isEmpty()) {
+        status.setCode(TSStatusCode.AI_NODE_INTERNAL_ERROR.getStatusCode());
+        status.setMessage("No registered AINode found");
+        resp.setStatus(status);
+        return resp;
+      }
+      final java.util.Optional<TEndPoint> picked = 
pickAnyEndPointFromRegistered(registered);
+      if (picked.isPresent()) {
+        resp.setAiNodeAddress(picked.get());

Review Comment:
   ```suggestion
           resp.setAiNodeAddress(registeredAINodes.get(0).getLocation());
   ```



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java:
##########
@@ -648,6 +651,59 @@ public TSStatus operatePermission(final TAuthorizerReq 
req) {
             req.getNewUsername()));
   }
 
+  @Override
+  public TGetAINodeLocationResp getAINodeLocation(final TGetAINodeLocationReq 
req)
+      throws TException {
+    final TGetAINodeLocationResp resp = new TGetAINodeLocationResp();
+    final TSStatus status = new TSStatus();
+    try {
+      final java.util.List<?> registered = 
configManager.getNodeManager().getRegisteredAINodes();
+      if (registered == null || registered.isEmpty()) {
+        status.setCode(TSStatusCode.AI_NODE_INTERNAL_ERROR.getStatusCode());
+        status.setMessage("No registered AINode found");
+        resp.setStatus(status);
+        return resp;
+      }
+      final java.util.Optional<TEndPoint> picked = 
pickAnyEndPointFromRegistered(registered);
+      if (picked.isPresent()) {
+        resp.setAiNodeAddress(picked.get());
+        status.setCode(TSStatusCode.SUCCESS_STATUS.getStatusCode());
+      } else {
+        status.setCode(TSStatusCode.AI_NODE_INTERNAL_ERROR.getStatusCode());
+        status.setMessage("No valid AINode endpoint extracted from registry");
+      }
+    } catch (Exception e) {
+      status.setCode(TSStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
+      status.setMessage("getAINodeLocation failed: " + e.getMessage());
+    }
+    resp.setStatus(status);
+    return resp;
+  }
+
+  private java.util.Optional<TEndPoint> pickAnyEndPointFromRegistered(

Review Comment:
   Remove this function



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/ainode/AINodeClient.java:
##########
@@ -189,75 +294,44 @@ private ModelInformation parseModelInformation(
   }
 
   public TSStatus deleteModel(String modelId) throws TException {
-    try {
-      return client.deleteModel(new TDeleteModelReq(modelId));
-    } catch (TException e) {
-      logger.warn(
-          "Failed to connect to AINode from ConfigNode when executing {}: {}",
-          Thread.currentThread().getStackTrace()[1].getMethodName(),
-          e.getMessage());
-      throw new TException(MSG_CONNECTION_FAIL);
-    }
+    final TDeleteModelReq req = new TDeleteModelReq(modelId);

Review Comment:
   Use `req` as input parameter for this function.



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java:
##########
@@ -648,6 +651,59 @@ public TSStatus operatePermission(final TAuthorizerReq 
req) {
             req.getNewUsername()));
   }
 
+  @Override
+  public TGetAINodeLocationResp getAINodeLocation(final TGetAINodeLocationReq 
req)
+      throws TException {
+    final TGetAINodeLocationResp resp = new TGetAINodeLocationResp();
+    final TSStatus status = new TSStatus();
+    try {
+      final java.util.List<?> registered = 
configManager.getNodeManager().getRegisteredAINodes();
+      if (registered == null || registered.isEmpty()) {
+        status.setCode(TSStatusCode.AI_NODE_INTERNAL_ERROR.getStatusCode());

Review Comment:
   ```suggestion
           
status.setCode(TSStatusCode.NO_REGISTERED_AI_NODE_ERROR.getStatusCode());
   ```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/client/ConfigNodeClient.java:
##########
@@ -529,6 +531,11 @@ public TAINodeRestartResp restartAINode(TAINodeRestartReq 
req) throws TException
     throw new UnsupportedOperationException(UNSUPPORTED_INVOCATION);
   }
 
+  public TGetAINodeLocationResp getAINodeLocation(final TGetAINodeLocationReq 
req)
+      throws org.apache.thrift.TException {
+    return client.getAINodeLocation(req);

Review Comment:
   Using the same code format as other functions in this class.



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