healchow commented on code in PR #7348:
URL: https://github.com/apache/inlong/pull/7348#discussion_r1102214667


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/PulsarClusterOperator.java:
##########
@@ -110,19 +112,34 @@ public Boolean testConnection(ClusterRequest request) {
                     String.format("Pulsar ServiceUrl=%s should starts with 
%s", serviceUrl, SERVICE_URL_PREFIX));
 
             String hostPortStr = serviceUrl.replaceAll(SERVICE_URL_PREFIX, "");
-            String[] hostPortArr = hostPortStr.split(InlongConstants.COLON);
-            Preconditions.expectTrue(hostPortArr.length >= 2,
-                    String.format("Pulsar ServiceUrl=%s should has ip and 
port, such as '127.0.0.1:6650'", serviceUrl));
-
-            String host = hostPortArr[0];
-            int port = Integer.parseInt(hostPortArr[1]);
-            SocketAddress socketAddress = new InetSocketAddress(host, port);
-            Socket socket = new Socket();
-            socket.connect(socketAddress, 30000);
-            socket.close();
-            LOGGER.debug("Pulsar connection not null - connection success for 
AdminUrl={}, ServiceUrl={}",
-                    pulsarInfo.getAdminUrl(), pulsarInfo.getUrl());
-            return true;
+            boolean successConnect = 
Arrays.stream(hostPortStr.split(InlongConstants.COMMA))
+                    // If there are multiple addresses, as long as one 
succeeds, it's considered successful
+                    .anyMatch(hostPort -> {
+                        String[] hostPortArr = 
hostPort.split(InlongConstants.COLON);
+                        Preconditions.expectTrue(hostPortArr.length >= 2,
+                                String.format("Pulsar ServiceUrl=%s should has 
ip and port, such as '127.0.0.1:6650'",
+                                        serviceUrl));
+
+                        String host = hostPortArr[0];
+                        int port = Integer.parseInt(hostPortArr[1]);
+
+                        try (Socket socket = new Socket()) {
+                            SocketAddress socketAddress = new 
InetSocketAddress(host, port);
+                            socket.connect(socketAddress, 30000);
+                            return true;
+                        } catch (IOException e) {
+                            String errMsg = String.format("Pulsar connection 
failed for AdminUrl=%s, ServiceUrl=%s",
+                                    pulsarInfo.getAdminUrl(), hostPort);
+                            LOGGER.error(errMsg, e);
+                            return false;
+                        }
+                    });
+
+            if (successConnect) {
+                return true;
+            } else {
+                throw new BusinessException("Pulsar connection failed for 
serviceUrl");
+            }
         } catch (Exception e) {

Review Comment:
   This catch seems unnecessary.
   The exception inside has been caught, and then an exception is thrown, and a 
repeated encapsulation will be done outside.



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