You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampark.apache.org by be...@apache.org on 2023/09/27 14:06:30 UTC

[incubator-streampark] branch dev updated: [Refactor] Refactor exception handling with ApiAlertException (#3198)

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

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


The following commit(s) were added to refs/heads/dev by this push:
     new e45000129 [Refactor] Refactor exception handling with ApiAlertException (#3198)
e45000129 is described below

commit e45000129c7704bf309f475d64e2a451808e33f0
Author: gongzhongqiang <76...@qq.com>
AuthorDate: Wed Sep 27 22:06:25 2023 +0800

    [Refactor] Refactor exception handling with ApiAlertException (#3198)
    
    * [Refactor] Refactor exception handling with ApiAlertException
---
 .../impl/ApplicationActionServiceImpl.java         | 10 ++-
 .../impl/ApplicationInfoServiceImpl.java           | 75 +++++++++++-----------
 .../core/service/impl/AppBuildPipeServiceImpl.java |  8 +--
 .../service/impl/ApplicationConfigServiceImpl.java |  8 +--
 .../core/service/impl/CommonServiceImpl.java       | 17 ++---
 .../core/service/impl/FlinkGateWayServiceImpl.java |  6 +-
 .../core/service/impl/ProjectServiceImpl.java      | 18 +++---
 .../core/service/impl/SavePointServiceImpl.java    |  1 -
 .../core/service/impl/VariableServiceImpl.java     | 29 ++++-----
 .../console/system/controller/SsoController.java   | 23 ++++---
 .../system/security/impl/AuthenticatorImpl.java    | 45 +++++++------
 .../console/system/security/impl/LdapService.java  |  7 +-
 .../system/service/impl/MenuServiceImpl.java       |  3 -
 .../system/service/impl/TeamServiceImpl.java       | 36 +++++------
 .../system/service/impl/UserServiceImpl.java       | 16 ++---
 15 files changed, 145 insertions(+), 157 deletions(-)

diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/application/impl/ApplicationActionServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/application/impl/ApplicationActionServiceImpl.java
index 223264317..6bc26585d 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/application/impl/ApplicationActionServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/application/impl/ApplicationActionServiceImpl.java
@@ -378,17 +378,15 @@ public class ApplicationActionServiceImpl extends ServiceImpl<ApplicationMapper,
     // 1) check application
     final Application application = getById(appParam.getId());
     Utils.notNull(application);
-    if (!application.isCanBeStart()) {
-      throw new ApiAlertException("[StreamPark] The application cannot be started repeatedly.");
-    }
+    ApiAlertException.throwIfTrue(
+        !application.isCanBeStart(), "[StreamPark] The application cannot be started repeatedly.");
 
     AppBuildPipeline buildPipeline = appBuildPipeService.getById(application.getId());
     Utils.notNull(buildPipeline);
 
     FlinkEnv flinkEnv = flinkEnvService.getByIdOrDefault(application.getVersionId());
-    if (flinkEnv == null) {
-      throw new ApiAlertException("[StreamPark] can no found flink version");
-    }
+
+    ApiAlertException.throwIfNull(flinkEnv, "[StreamPark] can no found flink version");
 
     // if manually started, clear the restart flag
     if (!auto) {
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/application/impl/ApplicationInfoServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/application/impl/ApplicationInfoServiceImpl.java
index ee6f21bb1..42e009e34 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/application/impl/ApplicationInfoServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/application/impl/ApplicationInfoServiceImpl.java
@@ -322,44 +322,43 @@ public class ApplicationInfoServiceImpl extends ServiceImpl<ApplicationMapper, A
     Application application = getById(id);
     ApiAlertException.throwIfNull(
         application, String.format("The application id=%s can't be found.", id));
-    if (FlinkExecutionMode.isKubernetesMode(application.getFlinkExecutionMode())) {
-      CompletableFuture<String> future =
-          CompletableFuture.supplyAsync(
-              () ->
-                  KubernetesDeploymentHelper.watchDeploymentLog(
-                      application.getK8sNamespace(),
-                      application.getJobName(),
-                      application.getJobId()));
-
-      return future
-          .exceptionally(
-              e -> {
-                String errorLog =
-                    String.format(
-                        "%s/%s_err.log",
-                        WebUtils.getAppTempDir().getAbsolutePath(), application.getJobId());
-                File file = new File(errorLog);
-                if (file.exists() && file.isFile()) {
-                  return file.getAbsolutePath();
-                }
-                return null;
-              })
-          .thenApply(
-              path -> {
-                if (!future.isDone()) {
-                  future.cancel(true);
-                }
-                if (org.apache.streampark.common.util.FileUtils.exists(path)) {
-                  return org.apache.streampark.common.util.FileUtils.tailOf(path, offset, limit);
-                }
-                return null;
-              })
-          .toCompletableFuture()
-          .get(5, TimeUnit.SECONDS);
-    } else {
-      throw new ApiAlertException(
-          "Job executionMode must be kubernetes-session|kubernetes-application.");
-    }
+    ApiAlertException.throwIfFalse(
+        FlinkExecutionMode.isKubernetesMode(application.getFlinkExecutionMode()),
+        "Job executionMode must be kubernetes-session|kubernetes-application.");
+
+    CompletableFuture<String> future =
+        CompletableFuture.supplyAsync(
+            () ->
+                KubernetesDeploymentHelper.watchDeploymentLog(
+                    application.getK8sNamespace(),
+                    application.getJobName(),
+                    application.getJobId()));
+
+    return future
+        .exceptionally(
+            e -> {
+              String errorLog =
+                  String.format(
+                      "%s/%s_err.log",
+                      WebUtils.getAppTempDir().getAbsolutePath(), application.getJobId());
+              File file = new File(errorLog);
+              if (file.exists() && file.isFile()) {
+                return file.getAbsolutePath();
+              }
+              return null;
+            })
+        .thenApply(
+            path -> {
+              if (!future.isDone()) {
+                future.cancel(true);
+              }
+              if (org.apache.streampark.common.util.FileUtils.exists(path)) {
+                return org.apache.streampark.common.util.FileUtils.tailOf(path, offset, limit);
+              }
+              return null;
+            })
+        .toCompletableFuture()
+        .get(5, TimeUnit.SECONDS);
   }
 
   @Override
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/AppBuildPipeServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/AppBuildPipeServiceImpl.java
index d80b36d85..606201714 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/AppBuildPipeServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/AppBuildPipeServiceImpl.java
@@ -404,7 +404,6 @@ public class AppBuildPipeServiceImpl
    *
    * @param appId application id
    * @param forceBuild forced start pipeline or not
-   * @return
    */
   private void checkBuildEnv(Long appId, boolean forceBuild) {
     Application app = applicationManageService.getById(appId);
@@ -421,10 +420,9 @@ public class AppBuildPipeServiceImpl
         envOk, "Check flink env failed, please check the flink version of this job");
 
     // 3) Whether the application can currently start a new building progress
-    if (!forceBuild && !allowToBuildNow(appId)) {
-      throw new ApiAlertException(
-          "The job is invalid, or the job cannot be built while it is running");
-    }
+    ApiAlertException.throwIfTrue(
+        !forceBuild && !allowToBuildNow(appId),
+        "The job is invalid, or the job cannot be built while it is running");
   }
 
   /** create building pipeline instance */
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationConfigServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationConfigServiceImpl.java
index f24fd38fb..2428b409b 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationConfigServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationConfigServiceImpl.java
@@ -73,10 +73,10 @@ public class ApplicationConfigServiceImpl
 
     if (application.getFormat() != null) {
       ConfigFileTypeEnum fileType = ConfigFileTypeEnum.of(application.getFormat());
-      if (fileType == null || ConfigFileTypeEnum.UNKNOWN == fileType) {
-        throw new ApiAlertException(
-            "application' config error. must be (.properties|.yaml|.yml |.conf)");
-      }
+      ApiAlertException.throwIfTrue(
+          fileType == null || ConfigFileTypeEnum.UNKNOWN == fileType,
+          "application' config error. must be (.properties|.yaml|.yml |.conf)");
+
       applicationConfig.setFormat(fileType.getValue());
     }
 
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/CommonServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/CommonServiceImpl.java
index 005688cd2..0ef911c9a 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/CommonServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/CommonServiceImpl.java
@@ -69,14 +69,15 @@ public class CommonServiceImpl implements CommonService {
                       x.matches(
                           "streampark-flink-sqlclient_" + flinkEnv.getScalaVersion() + "-.*\\.jar"))
               .collect(Collectors.toList());
-      if (jars.isEmpty()) {
-        throw new ApiAlertException(
-            "[StreamPark] can't found streampark-flink-sqlclient jar in " + localClient);
-      }
-      if (jars.size() > 1) {
-        throw new ApiAlertException(
-            "[StreamPark] found multiple streampark-flink-sqlclient jar in " + localClient);
-      }
+
+      ApiAlertException.throwIfTrue(
+          jars.isEmpty(),
+          "[StreamPark] can't found streampark-flink-sqlclient jar in " + localClient);
+
+      ApiAlertException.throwIfTrue(
+          jars.size() > 1,
+          "[StreamPark] found multiple streampark-flink-sqlclient jar in " + localClient);
+
       sqlClientJar = jars.get(0);
     }
     return sqlClientJar;
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkGateWayServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkGateWayServiceImpl.java
index f14280b84..22577589a 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkGateWayServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkGateWayServiceImpl.java
@@ -45,9 +45,9 @@ public class FlinkGateWayServiceImpl extends ServiceImpl<FlinkGateWayMapper, Fli
 
   private void preHandleGatewayInfo(FlinkGateWay flinkGateWay) {
     // validate gateway name
-    if (existsByGatewayName(flinkGateWay.getGatewayName())) {
-      throw new ApiAlertException("gateway name already exists");
-    }
+    ApiAlertException.throwIfTrue(
+        existsByGatewayName(flinkGateWay.getGatewayName()), "gateway name already exists");
+
     // validate gateway address and set gateway type
     flinkGateWay.setGatewayType(getGatewayVersion(flinkGateWay.getAddress()));
   }
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java
index ab1620115..307d76fba 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java
@@ -100,16 +100,16 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project>
         new LambdaQueryWrapper<Project>().eq(Project::getName, project.getName());
     long count = count(queryWrapper);
     RestResponse response = RestResponse.success();
-    if (count == 0) {
-      project.setCreateTime(new Date());
-      boolean status = save(project);
-      if (status) {
-        return response.message("Add project successfully").data(true);
-      } else {
-        return response.message("Add project failed").data(false);
-      }
+
+    ApiAlertException.throwIfTrue(count > 0, "project name already exists, add project failed");
+
+    project.setCreateTime(new Date());
+    boolean status = save(project);
+
+    if (status) {
+      return response.message("Add project successfully").data(true);
     } else {
-      throw new ApiAlertException("project name already exists,add project failed");
+      return response.message("Add project failed").data(false);
     }
   }
 
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SavePointServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SavePointServiceImpl.java
index 5bf47c286..fdfe3a9a6 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SavePointServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SavePointServiceImpl.java
@@ -196,7 +196,6 @@ public class SavePointServiceImpl extends ServiceImpl<SavePointMapper, SavePoint
   }
 
   @Override
-  @Transactional(rollbackFor = Exception.class)
   public Boolean delete(Long id, Application application) throws InternalException {
     SavePoint savePoint = getById(id);
     try {
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/VariableServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/VariableServiceImpl.java
index e4de5d58f..711022888 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/VariableServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/VariableServiceImpl.java
@@ -72,21 +72,20 @@ public class VariableServiceImpl extends ServiceImpl<VariableMapper, Variable>
   @Autowired private CommonService commonService;
 
   @Override
-  @Transactional(rollbackFor = Exception.class)
   public void createVariable(Variable variable) {
-    if (this.findByVariableCode(variable.getTeamId(), variable.getVariableCode()) != null) {
-      throw new ApiAlertException("Sorry, the variable code already exists.");
-    }
+
+    ApiAlertException.throwIfTrue(
+        this.findByVariableCode(variable.getTeamId(), variable.getVariableCode()) != null,
+        "Sorry, the variable code already exists.");
+
     variable.setCreatorId(commonService.getUserId());
     this.save(variable);
   }
 
   @Override
-  @Transactional(rollbackFor = Exception.class)
   public void deleteVariable(Variable variable) {
-    if (isDependByApplications(variable)) {
-      throw new ApiAlertException("Sorry, the variable is actually used.");
-    }
+    ApiAlertException.throwIfTrue(
+        isDependByApplications(variable), "Sorry, the variable is actually used.");
     this.removeById(variable);
   }
 
@@ -120,16 +119,12 @@ public class VariableServiceImpl extends ServiceImpl<VariableMapper, Variable>
   @Override
   public void updateVariable(Variable variable) {
     // region update variable
-    if (variable.getId() == null) {
-      throw new ApiAlertException("Sorry, the variable id cannot be null.");
-    }
+    ApiAlertException.throwIfNull(variable.getId(), "Sorry, the variable id cannot be null.");
     Variable findVariable = this.baseMapper.selectById(variable.getId());
-    if (findVariable == null) {
-      throw new ApiAlertException("Sorry, the variable does not exist.");
-    }
-    if (!findVariable.getVariableCode().equals(variable.getVariableCode())) {
-      throw new ApiAlertException("Sorry, the variable code cannot be updated.");
-    }
+    ApiAlertException.throwIfNull(findVariable, "Sorry, the variable does not exist.");
+    ApiAlertException.throwIfFalse(
+        findVariable.getVariableCode().equals(variable.getVariableCode()),
+        "Sorry, the variable code cannot be updated.");
     this.baseMapper.updateById(variable);
     // endregion
 
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/SsoController.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/SsoController.java
index b12791771..caa46f76e 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/SsoController.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/SsoController.java
@@ -65,25 +65,30 @@ public class SsoController {
   @GetMapping("token")
   @ResponseBody
   public RestResponse token() throws Exception {
-    if (!ssoEnable) {
-      throw new ApiAlertException(
-          "Single Sign On (SSO) is not available, please contact the administrator to enable");
-    }
-    // Based on User Profile from Shiro and build Pac4jPrincipal
+
+    // Check SSO enable status
+    ApiAlertException.throwIfTrue(
+        !ssoEnable,
+        "Single Sign On (SSO) is not available, please contact the administrator to enable");
+
     Subject subject = SecurityUtils.getSubject();
     PrincipalCollection principals = subject.getPrincipals();
     Pac4jPrincipal principal = principals.oneByType(Pac4jPrincipal.class);
+
     List<CommonProfile> profiles = null;
+
     if (principal != null) {
       profiles = principal.getProfiles();
     }
+
     principal = new Pac4jPrincipal(profiles, principalNameAttribute);
-    if (principal.getName() == null) {
-      log.error("Please configure correct principalNameAttribute from UserProfile: " + principal);
-      throw new ApiAlertException("Please configure the correct Principal Name Attribute");
-    }
+
+    // Check Principal name
+    ApiAlertException.throwIfNull(
+        principal.getName(), "Please configure the correct Principal Name Attribute");
 
     User user = authenticator.authenticate(principal.getName(), null, LoginTypeEnum.SSO.toString());
+
     return userService.getLoginUserInfo(user);
   }
 }
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/impl/AuthenticatorImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/impl/AuthenticatorImpl.java
index 55810c7a7..a4e77ec63 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/impl/AuthenticatorImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/impl/AuthenticatorImpl.java
@@ -40,10 +40,10 @@ public class AuthenticatorImpl implements Authenticator {
   @Override
   public User authenticate(String username, String password, String loginType) throws Exception {
     LoginTypeEnum loginTypeEnum = LoginTypeEnum.of(loginType);
-    if (loginTypeEnum == null) {
-      throw new ApiAlertException(
-          String.format("the login type [%s] is not supported.", loginType));
-    }
+
+    ApiAlertException.throwIfNull(
+        loginTypeEnum, String.format("the login type [%s] is not supported.", loginType));
+
     switch (loginTypeEnum) {
       case PASSWORD:
         return passwordAuthenticate(username, password);
@@ -59,17 +59,19 @@ public class AuthenticatorImpl implements Authenticator {
 
   private User passwordAuthenticate(String username, String password) {
     User user = usersService.findByName(username);
-    if (user == null) {
-      throw new ApiAlertException(String.format("user [%s] does not exist", username));
-    }
-    if (user.getLoginType() != LoginTypeEnum.PASSWORD) {
-      throw new ApiAlertException(String.format("user [%s] can not login with PASSWORD", username));
-    }
+
+    ApiAlertException.throwIfNull(user, String.format("User [%s] does not exist", username));
+
+    ApiAlertException.throwIfTrue(
+        user.getLoginType() != LoginTypeEnum.PASSWORD,
+        String.format("user [%s] can not login with PASSWORD", username));
+
     String salt = user.getSalt();
     password = ShaHashUtils.encrypt(salt, password);
-    if (!StringUtils.equals(user.getPassword(), password)) {
-      return null;
-    }
+
+    ApiAlertException.throwIfFalse(
+        StringUtils.equals(user.getPassword(), password), "Incorrect password");
+
     return user;
   }
 
@@ -82,10 +84,10 @@ public class AuthenticatorImpl implements Authenticator {
     User user = usersService.findByName(username);
 
     if (user != null) {
-      if (user.getLoginType() != LoginTypeEnum.LDAP) {
-        throw new ApiAlertException(
-            String.format("user [%s] can only sign in with %s", username, user.getLoginType()));
-      }
+      ApiAlertException.throwIfTrue(
+          user.getLoginType() != LoginTypeEnum.LDAP,
+          String.format("user [%s] can only sign in with %s", username, user.getLoginType()));
+
       return user;
     }
     return this.newUserCreate(LoginTypeEnum.LDAP, username);
@@ -94,13 +96,14 @@ public class AuthenticatorImpl implements Authenticator {
   private User ssoAuthenticate(String username) throws Exception {
     // check if user exist
     User user = usersService.findByName(username);
+
     if (user != null) {
-      if (user.getLoginType() != LoginTypeEnum.SSO) {
-        throw new ApiAlertException(
-            String.format("user [%s] can only sign in with %s", username, user.getLoginType()));
-      }
+      ApiAlertException.throwIfTrue(
+          user.getLoginType() != LoginTypeEnum.SSO,
+          String.format("user [%s] can only sign in with %s", username, user.getLoginType()));
       return user;
     }
+
     return this.newUserCreate(LoginTypeEnum.SSO, username);
   }
 
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/impl/LdapService.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/impl/LdapService.java
index 2eb0043a4..b6a3d9b31 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/impl/LdapService.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/impl/LdapService.java
@@ -73,10 +73,9 @@ public class LdapService {
    * @return user email
    */
   public String ldapLogin(String userId, String userPwd) {
-    if (!enable) {
-      throw new ApiAlertException(
-          "ldap is not enabled, Please check the configuration: ldap.enable");
-    }
+
+    ApiAlertException.throwIfFalse(
+        enable, "ldap is not enabled, Please check the configuration: ldap.enable");
 
     if (ldapEnv == null) {
       ldapEnv = new Properties();
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/MenuServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/MenuServiceImpl.java
index 699d99685..bf059053f 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/MenuServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/MenuServiceImpl.java
@@ -126,7 +126,6 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
   }
 
   @Override
-  @Transactional(rollbackFor = Exception.class)
   public void createMenu(Menu menu) {
     menu.setCreateTime(new Date());
     setMenu(menu);
@@ -134,7 +133,6 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
   }
 
   @Override
-  @Transactional(rollbackFor = Exception.class)
   public void updateMenu(Menu menu) throws Exception {
     menu.setModifyTime(new Date());
     setMenu(menu);
@@ -142,7 +140,6 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
   }
 
   @Override
-  @Transactional(rollbackFor = Exception.class)
   public void deleteMenus(String[] menuIds) throws Exception {
     // Find users associated with these menus/buttons
     this.roleMenuServie.deleteByMenuId(menuIds);
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/TeamServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/TeamServiceImpl.java
index c59a5037d..25e71b018 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/TeamServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/TeamServiceImpl.java
@@ -95,25 +95,23 @@ public class TeamServiceImpl extends ServiceImpl<TeamMapper, Team> implements Te
   public void deleteTeam(Long teamId) {
     log.info("{} Proceed delete team[Id={}]", commonService.getCurrentUser().getUsername(), teamId);
     Team team = this.getById(teamId);
-    // TODO The AssertUtils.checkApiAlert can simplify the exception.
-    if (team == null) {
-      throw new ApiAlertException(String.format("The team[Id=%s] doesn't exists.", teamId));
-    }
-    if (applicationInfoService.existsByTeamId(teamId)) {
-      throw new ApiAlertException(
-          String.format(
-              "Please delete the applications under the team[name=%s] first!", team.getTeamName()));
-    }
-    if (projectService.existsByTeamId(teamId)) {
-      throw new ApiAlertException(
-          String.format(
-              "Please delete the projects under the team[name=%s] first!", team.getTeamName()));
-    }
-    if (variableService.existsByTeamId(teamId)) {
-      throw new ApiAlertException(
-          String.format(
-              "Please delete the variables under the team[name=%s] first!", team.getTeamName()));
-    }
+
+    ApiAlertException.throwIfNull(team, String.format("The team[Id=%s] doesn't exist.", teamId));
+
+    ApiAlertException.throwIfTrue(
+        applicationInfoService.existsByTeamId(teamId),
+        String.format(
+            "Please delete the applications under the team[name=%s] first!", team.getTeamName()));
+
+    ApiAlertException.throwIfTrue(
+        projectService.existsByTeamId(teamId),
+        String.format(
+            "Please delete the projects under the team[name=%s] first!", team.getTeamName()));
+
+    ApiAlertException.throwIfTrue(
+        variableService.existsByTeamId(teamId),
+        String.format(
+            "Please delete the variables under the team[name=%s] first!", team.getTeamName()));
 
     memberService.deleteByTeamId(teamId);
     userService.clearLastTeam(teamId);
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java
index e24eb6686..7a007751f 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java
@@ -103,7 +103,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
   }
 
   @Override
-  @Transactional(rollbackFor = Exception.class)
   public void updateLoginTime(String username) {
     User user = new User();
     user.setLastLoginTime(new Date());
@@ -113,7 +112,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
   }
 
   @Override
-  @Transactional(rollbackFor = Exception.class)
   public void createUser(User user) {
     user.setCreateTime(new Date());
     if (StringUtils.isNoneBlank(user.getPassword())) {
@@ -126,7 +124,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
   }
 
   @Override
-  @Transactional(rollbackFor = Exception.class)
   public RestResponse updateUser(User user) {
     User existsUser = getById(user.getUserId());
     user.setLoginType(null);
@@ -149,7 +146,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
   }
 
   @Override
-  @Transactional(rollbackFor = Exception.class)
   public void updatePassword(User userParam) {
     User user = getById(userParam.getUserId());
     ApiAlertException.throwIfNull(user, "User is null. Update password failed.");
@@ -170,7 +166,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
   }
 
   @Override
-  @Transactional(rollbackFor = Exception.class)
   public String resetPassword(String username) {
     User user = new User();
     String salt = ShaHashUtils.getRandomSalt();
@@ -226,10 +221,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
   public void fillInTeam(User user) {
     if (user.getLastTeamId() == null) {
       List<Team> teams = memberService.findUserTeams(user.getUserId());
-      if (CollectionUtils.isEmpty(teams)) {
-        throw new ApiAlertException(
-            "The current user not belong to any team, please contact the administrator!");
-      } else if (teams.size() == 1) {
+
+      ApiAlertException.throwIfTrue(
+          CollectionUtils.isEmpty(teams),
+          "The current user does not belong to any team, please contact the administrator!");
+
+      if (teams.size() == 1) {
         Team team = teams.get(0);
         user.setLastTeamId(team.getId());
         this.baseMapper.updateById(user);
@@ -271,7 +268,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
   }
 
   @Override
-  @Transactional(rollbackFor = Exception.class)
   public void transferResource(Long userId, Long targetUserId) {
     applicationManageService.changeOwnership(userId, targetUserId);
     resourceService.changeOwnership(userId, targetUserId);