You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@streampark.apache.org by GitBox <gi...@apache.org> on 2022/11/28 11:47:20 UTC

[GitHub] [incubator-streampark] 1996fanrui commented on a diff in pull request #2100: [Bug] flink cluster management bug fixed

1996fanrui commented on code in PR #2100:
URL: https://github.com/apache/incubator-streampark/pull/2100#discussion_r1033441186


##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/entity/FlinkCluster.java:
##########
@@ -138,23 +144,34 @@ public URI getActiveAddress() {
         return null;
     }
 
-    public boolean verifyConnection() {
-        if (address == null) {
-            return false;
-        }
-        String[] array = address.split(",");
-        for (String url : array) {
-            try {
-                new URI(url);
-            } catch (Exception ignored) {
+    public boolean verifyClusterConnection() {
+        if (ExecutionMode.REMOTE.equals(this.getExecutionModeEnum()) ||
+            ExecutionMode.YARN_SESSION.equals(this.getExecutionModeEnum())) {
+            if (address == null) {
                 return false;
             }
-            try {
-                HttpClientUtils.httpGetRequest(url, RequestConfig.custom().setConnectTimeout(2000).build());
-                return true;
-            } catch (Exception ignored) {
-                //
+            String[] array = address.split(",");
+            for (String url : array) {
+                try {
+                    new URI(url);
+                } catch (Exception ignored) {
+                    return false;
+                }
+                try {
+                    String restUrl;
+                    if (ExecutionMode.REMOTE.equals(this.getExecutionModeEnum())) {
+                        restUrl = url + "/overview";
+                    } else {
+                        restUrl = url + "/proxy/" + this.clusterId + "/overview";
+                    }
+                    String result = HttpClientUtils.httpGetRequest(restUrl, RequestConfig.custom().setConnectTimeout(2000).build());
+                    JacksonUtils.read(result, Overview.class);
+                    return true;
+                } catch (Exception ignored) {
+                    //
+                }

Review Comment:
   Can 2 `try ... catch` be simplified to one? 



##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/entity/FlinkCluster.java:
##########
@@ -138,23 +144,34 @@ public URI getActiveAddress() {
         return null;
     }
 
-    public boolean verifyConnection() {
-        if (address == null) {
-            return false;
-        }
-        String[] array = address.split(",");
-        for (String url : array) {
-            try {
-                new URI(url);
-            } catch (Exception ignored) {
+    public boolean verifyClusterConnection() {
+        if (ExecutionMode.REMOTE.equals(this.getExecutionModeEnum()) ||
+            ExecutionMode.YARN_SESSION.equals(this.getExecutionModeEnum())) {
+            if (address == null) {
                 return false;
             }
-            try {
-                HttpClientUtils.httpGetRequest(url, RequestConfig.custom().setConnectTimeout(2000).build());
-                return true;
-            } catch (Exception ignored) {
-                //
+            String[] array = address.split(",");
+            for (String url : array) {

Review Comment:
   Same question: Isn't the address JM url? 
   
   If the address is JM url, why is it a list?



##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/entity/FlinkCluster.java:
##########
@@ -138,23 +144,34 @@ public URI getActiveAddress() {
         return null;
     }
 
-    public boolean verifyConnection() {
-        if (address == null) {
-            return false;
-        }
-        String[] array = address.split(",");
-        for (String url : array) {
-            try {
-                new URI(url);
-            } catch (Exception ignored) {
+    public boolean verifyClusterConnection() {
+        if (ExecutionMode.REMOTE.equals(this.getExecutionModeEnum()) ||
+            ExecutionMode.YARN_SESSION.equals(this.getExecutionModeEnum())) {
+            if (address == null) {
                 return false;
             }
-            try {
-                HttpClientUtils.httpGetRequest(url, RequestConfig.custom().setConnectTimeout(2000).build());
-                return true;
-            } catch (Exception ignored) {
-                //
+            String[] array = address.split(",");
+            for (String url : array) {
+                try {
+                    new URI(url);
+                } catch (Exception ignored) {
+                    return false;
+                }
+                try {
+                    String restUrl;
+                    if (ExecutionMode.REMOTE.equals(this.getExecutionModeEnum())) {
+                        restUrl = url + "/overview";
+                    } else {
+                        restUrl = url + "/proxy/" + this.clusterId + "/overview";
+                    }
+                    String result = HttpClientUtils.httpGetRequest(restUrl, RequestConfig.custom().setConnectTimeout(2000).build());
+                    JacksonUtils.read(result, Overview.class);
+                    return true;
+                } catch (Exception ignored) {
+                    //
+                }
             }
+            return false;
         }
         return false;

Review Comment:
   Can 3 `return false` be simplified to one?



-- 
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: issues-unsubscribe@streampark.apache.org

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