This is an automated email from the ASF dual-hosted git repository.

benjobs pushed a commit to branch dev-2.1.5
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git


The following commit(s) were added to refs/heads/dev-2.1.5 by this push:
     new dc6648658 Optimize the user experience of the Flink web page proxy. 
(#4012)
dc6648658 is described below

commit dc6648658d9300f5afe73ad4db1a7597621dd3d0
Author: Darcy <[email protected]>
AuthorDate: Sat Aug 31 23:43:28 2024 +0800

    Optimize the user experience of the Flink web page proxy. (#4012)
    
    * feature: optimize flink proxy
    
    * fix: add log for proxy failed
---
 .../streampark/console/core/bean/AppControl.java   |  3 ++
 .../console/core/controller/ProxyController.java   | 39 ++++++++++++----------
 .../core/service/impl/ApplicationServiceImpl.java  | 25 ++++++++------
 .../core/service/impl/ProxyServiceImpl.java        | 23 +++++++++----
 .../src/views/flink/app/Detail.vue                 |  2 +-
 .../src/views/flink/app/View.vue                   | 10 ++----
 6 files changed, 58 insertions(+), 44 deletions(-)

diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/bean/AppControl.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/bean/AppControl.java
index f899ac653..bf25db157 100644
--- 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/bean/AppControl.java
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/bean/AppControl.java
@@ -34,4 +34,7 @@ public class AppControl {
 
   /** allow to build the application */
   private boolean allowBuild;
+
+  /** allow to view application web ui */
+  private boolean allowView;
 }
diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/ProxyController.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/ProxyController.java
index baf178b2e..f36155604 100644
--- 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/ProxyController.java
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/ProxyController.java
@@ -40,31 +40,34 @@ public class ProxyController {
 
   @Autowired private ProxyService proxyService;
 
-  @GetMapping("flink/{id}/**")
-  @RequiresPermissions("app:view")
-  public ResponseEntity<?> proxyFlink(HttpServletRequest request, 
@PathVariable("id") Long id)
-      throws Exception {
-    return proxyService.proxyFlink(request, id);
-  }
-
-  @GetMapping("cluster/{id}/**")
-  @RequiresPermissions("app:view")
-  public ResponseEntity<?> proxyCluster(HttpServletRequest request, 
@PathVariable("id") Long id)
+  @GetMapping("{type}/{id}/assets/**")
+  public ResponseEntity<?> proxyFlinkAssets(
+      HttpServletRequest request, @PathVariable("type") String type, 
@PathVariable("id") Long id)
       throws Exception {
-    return proxyService.proxyCluster(request, id);
+    return proxy(type, request, id);
   }
 
-  @GetMapping("history/{id}/**")
+  @GetMapping("{type}/{id}/**")
   @RequiresPermissions("app:view")
-  public ResponseEntity<?> proxyHistory(HttpServletRequest request, 
@PathVariable("id") Long id)
+  public ResponseEntity<?> proxyFlink(
+      HttpServletRequest request, @PathVariable("type") String type, 
@PathVariable("id") Long id)
       throws Exception {
-    return proxyService.proxyHistory(request, id);
+    return proxy(type, request, id);
   }
 
-  @GetMapping("yarn/{id}/**")
-  @RequiresPermissions("app:view")
-  public ResponseEntity<?> proxyYarn(HttpServletRequest request, 
@PathVariable("id") Long logId)
+  private ResponseEntity<?> proxy(String type, HttpServletRequest request, 
Long id)
       throws Exception {
-    return proxyService.proxyYarn(request, logId);
+    switch (type) {
+      case "flink":
+        return proxyService.proxyFlink(request, id);
+      case "cluster":
+        return proxyService.proxyCluster(request, id);
+      case "history":
+        return proxyService.proxyHistory(request, id);
+      case "yarn":
+        return proxyService.proxyYarn(request, id);
+      default:
+        return ResponseEntity.notFound().build();
+    }
   }
 }
diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationServiceImpl.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationServiceImpl.java
index 8686a68d1..628ef2c7d 100644
--- 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationServiceImpl.java
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationServiceImpl.java
@@ -558,16 +558,7 @@ public class ApplicationServiceImpl extends 
ServiceImpl<ApplicationMapper, Appli
           }
 
           // 4) appControl
-          AppControl appControl =
-              new AppControl()
-                  .setAllowBuild(
-                      record.getBuildStatus() == null
-                          || 
!PipelineStatus.running.getCode().equals(record.getBuildStatus()))
-                  .setAllowStart(
-                      !record.shouldBeTrack()
-                          && 
PipelineStatus.success.getCode().equals(record.getBuildStatus()))
-                  .setAllowStop(record.isRunning());
-          record.setAppControl(appControl);
+          record.setAppControl(buildAppControl(record));
         });
 
     return page;
@@ -1264,9 +1255,23 @@ public class ApplicationServiceImpl extends 
ServiceImpl<ApplicationMapper, Appli
       }
     }
     application.setByHotParams();
+    application.setAppControl(buildAppControl(application));
     return application;
   }
 
+  private AppControl buildAppControl(Application app) {
+    return new AppControl()
+        .setAllowBuild(
+            app.getBuildStatus() == null
+                || 
!PipelineStatus.running.getCode().equals(app.getBuildStatus()))
+        .setAllowStart(
+            !app.shouldBeTrack() && 
PipelineStatus.success.getCode().equals(app.getBuildStatus()))
+        .setAllowStop(app.isRunning())
+        .setAllowView(
+            (!FlinkAppState.isEndState(app.getState()))
+                || OptionState.SAVEPOINTING.getValue() == 
app.getOptionState());
+  }
+
   @Override
   public String getMain(Application application) {
     File jarFile;
diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProxyServiceImpl.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProxyServiceImpl.java
index bcbd57ceb..5268bb80c 100644
--- 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProxyServiceImpl.java
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProxyServiceImpl.java
@@ -46,6 +46,7 @@ import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.web.client.RestTemplateBuilder;
 import org.springframework.http.HttpEntity;
@@ -57,6 +58,7 @@ import org.springframework.http.client.ClientHttpResponse;
 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.DefaultResponseErrorHandler;
+import org.springframework.web.client.RestClientException;
 import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Nonnull;
@@ -68,6 +70,7 @@ import java.net.URI;
 import java.security.PrivilegedExceptionAction;
 import java.util.Enumeration;
 
+@Slf4j
 @Service
 public class ProxyServiceImpl implements ProxyService {
 
@@ -237,9 +240,7 @@ public class ProxyServiceImpl implements ProxyService {
   }
 
   private ResponseEntity<?> proxyRequest(HttpServletRequest request, String 
url) throws Exception {
-    HttpEntity<?> requestEntity = getRequestEntity(request, url);
-    return proxyRestTemplate.exchange(
-        url, HttpMethod.valueOf(request.getMethod()), requestEntity, 
byte[].class);
+    return proxy(request, url, getRequestEntity(request, url));
   }
 
   private ResponseEntity<?> proxyYarnRequest(HttpServletRequest request, 
String url)
@@ -249,15 +250,23 @@ public class ProxyServiceImpl implements ProxyService {
       HttpEntity<?> requestEntity = getRequestEntity(request, url);
       setRestTemplateCredentials(ugi.getShortUserName());
       return ugi.doAs(
-          (PrivilegedExceptionAction<ResponseEntity<?>>)
-              () ->
-                  proxyRestTemplate.exchange(
-                      url, HttpMethod.valueOf(request.getMethod()), 
requestEntity, byte[].class));
+          (PrivilegedExceptionAction<ResponseEntity<?>>) () -> proxy(request, 
url, requestEntity));
     } else {
       return proxyRequest(request, url);
     }
   }
 
+  private ResponseEntity<?> proxy(
+      HttpServletRequest request, String url, HttpEntity<?> requestEntity) {
+    try {
+      return proxyRestTemplate.exchange(
+          url, HttpMethod.valueOf(request.getMethod()), requestEntity, 
byte[].class);
+    } catch (RestClientException e) {
+      log.error("Proxy url: {} failed. ", url, e);
+      return new ResponseEntity<>(HttpStatus.BAD_GATEWAY);
+    }
+  }
+
   private String getRequestURL(HttpServletRequest request, String 
replaceString) {
     String url =
         request.getRequestURI()
diff --git 
a/streampark-console/streampark-console-webapp/src/views/flink/app/Detail.vue 
b/streampark-console/streampark-console-webapp/src/views/flink/app/Detail.vue
index 46d119e1e..6ea8d4548 100644
--- 
a/streampark-console/streampark-console-webapp/src/views/flink/app/Detail.vue
+++ 
b/streampark-console/streampark-console-webapp/src/views/flink/app/Detail.vue
@@ -182,7 +182,7 @@
   });
 
   const appNotRunning = computed(
-    () => app.state !== AppStateEnum.RUNNING || (yarn.value === null && 
app.flinkRestUrl === null),
+    () => app['appControl']['allowView'] === false || (yarn.value === null && 
app.flinkRestUrl === null),
   );
 </script>
 <template>
diff --git 
a/streampark-console/streampark-console-webapp/src/views/flink/app/View.vue 
b/streampark-console/streampark-console-webapp/src/views/flink/app/View.vue
index 6c6c7708d..b06c8fb77 100644
--- a/streampark-console/streampark-console-webapp/src/views/flink/app/View.vue
+++ b/streampark-console/streampark-console-webapp/src/views/flink/app/View.vue
@@ -195,11 +195,7 @@
 
   /* view */
   async function handleJobView(app: AppListRecord) {
-    // Task is running, restarting, in savePoint
-    if (
-      [AppStateEnum.RESTARTING, AppStateEnum.RUNNING].includes(app.state) ||
-      app['optionState'] === OptionStateEnum.SAVEPOINTING
-    ) {
+    if (app['appControl']['allowView'] === true) {
       await handleView(app);
     }
   }
@@ -258,9 +254,7 @@
           <span
             class="link"
             :class="{
-              'cursor-pointer':
-                [AppStateEnum.RESTARTING, 
AppStateEnum.RUNNING].includes(record.state) ||
-                record['optionState'] === OptionStateEnum.SAVEPOINTING,
+              'cursor-pointer': record['appControl']['allowView'] === true,
             }"
             @click="handleJobView(record)"
           >

Reply via email to