You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by "healchow (via GitHub)" <gi...@apache.org> on 2023/02/10 02:29:09 UTC
[GitHub] [inlong] healchow commented on a diff in pull request #7348: [INLONG-7337][Manager] Fix test pulsar connection error
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.
--
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: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org