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 ad8395fce [Improve] An exception occurs when the job name contains 
Spaces (#4172)
ad8395fce is described below

commit ad8395fce97eb26105473ddcb3473d530424d60f
Author: Zhilin Li <[email protected]>
AuthorDate: Mon Jan 20 18:30:49 2025 +0800

    [Improve] An exception occurs when the job name contains Spaces (#4172)
    
    * [Improve] An exception occurs when the job name contains Spaces
    
    * Update app.ts
    
    
    ---------
    
    Co-authored-by: benjobs <[email protected]>
---
 .../console/base/exception/ApiAlertException.java         | 15 +++++++++++++++
 .../impl/FlinkApplicationManageServiceImpl.java           | 13 ++++++++-----
 .../src/locales/lang/en/flink/app.ts                      |  4 ++--
 3 files changed, 25 insertions(+), 7 deletions(-)

diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApiAlertException.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApiAlertException.java
index cd866a908..28fb07f5d 100644
--- 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApiAlertException.java
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApiAlertException.java
@@ -78,4 +78,19 @@ public class ApiAlertException extends AbstractApiException {
             throw new ApiAlertException(String.format(errorMsgFmt, args));
         }
     }
+
+    /**
+     * Validates a given condition and throws an ApiAlertException if the 
condition is false.
+     * This method is used to enforce business rules and ensure the validity 
of input parameters or states.
+     *
+     * @param condition the boolean condition to be validated. If false, an 
exception is thrown.
+     * @param message   the error message template, which supports 
placeholders for arguments.
+     * @param args      optional arguments to format the error message. These 
are inserted into the
+     *                  placeholders in the message using {@link 
String#format(String, Object...)}.
+     * @throws ApiAlertException if the condition evaluates to false. The 
formatted error message
+     *                           will be used as the exception message.
+     */
+    public static void validateCondition(boolean condition, String message, 
Object... args) {
+        ApiAlertException.throwIfFalse(condition, String.format(message, 
args));
+    }
 }
diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/application/impl/FlinkApplicationManageServiceImpl.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/application/impl/FlinkApplicationManageServiceImpl.java
index a4ed4dbdf..359e64f2a 100644
--- 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/application/impl/FlinkApplicationManageServiceImpl.java
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/application/impl/FlinkApplicationManageServiceImpl.java
@@ -93,6 +93,8 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.stream.Collectors;
 
+import static 
org.apache.streampark.console.base.exception.ApiAlertException.validateCondition;
+
 @Slf4j
 @Service
 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, 
rollbackFor = Exception.class)
@@ -341,11 +343,12 @@ public class FlinkApplicationManageServiceImpl extends 
ServiceImpl<FlinkApplicat
         appParam.setCreateTime(date);
         appParam.setModifyTime(date);
         appParam.setDefaultModeIngress(settingService.getIngressModeDefault());
-
-        boolean success = validateQueueIfNeeded(appParam);
-        ApiAlertException.throwIfFalse(
-            success,
-            String.format(ERROR_APP_QUEUE_HINT, appParam.getYarnQueue(), 
appParam.getTeamId()));
+        String jobName = appParam.getJobName();
+        // validate job application
+        validateCondition(!jobName.contains(" "),
+            "The added job name `%s` is an invalid character and cannot 
contain Spaces", jobName);
+        validateCondition(validateQueueIfNeeded(appParam), 
ERROR_APP_QUEUE_HINT, appParam.getYarnQueue(),
+            appParam.getTeamId());
 
         appParam.doSetHotParams();
         if (appParam.isResourceFromUpload()) {
diff --git 
a/streampark-console/streampark-console-webapp/src/locales/lang/en/flink/app.ts 
b/streampark-console/streampark-console-webapp/src/locales/lang/en/flink/app.ts
index 79fa2669f..ab0bc56b8 100644
--- 
a/streampark-console/streampark-console-webapp/src/locales/lang/en/flink/app.ts
+++ 
b/streampark-console/streampark-console-webapp/src/locales/lang/en/flink/app.ts
@@ -281,7 +281,7 @@ export default {
     appNameValid: 'The job name is invalid',
     appNameRole: 'The job name must follow these rules: ',
     appNameNotValid:
-      'The job name is invalid, must be (Chinese or English or "-" or "_"), 
two consecutive spaces cannot appear.Please check',
+      'The job name is invalid, must be (Chinese or English or "-" or "_"), 
Spaces are not allowed. Please check',
     K8sSessionClusterIdRole: 'The Kubernetes clusterId must follow the 
following rules:',
     appNameK8sClusterIdRole:
       'The current deployment mode is kubernetes application mode, and the job 
name will be used as the clusterId in kubernetes. Therefore, the job name must 
follow the following rules:',
@@ -289,7 +289,7 @@ export default {
     appNameK8sClusterIdRoleRegexp:
       'must only contain lowercase alphanumeric characters and "-",The 
required format is [a-z]([-a-z0-9]*[a-z0-9])',
     appNameRoleContent:
-      'must be (Chinese or English or "-" or "_"), two consecutive spaces 
cannot appear.Please check',
+      'must be (Chinese or English or "-" or "_"), Spaces are not allowed. 
Please check',
     flinkClusterIsRequiredMessage: 'Flink Cluster is required',
     flinkSqlIsRequiredMessage: 'Flink SQL is required',
     tagsPlaceholder: 'Please enter tags,if more than one, separate them with 
commas(,)',

Reply via email to