Skip to content

Commit

Permalink
[Improve] An exception occurs when the job name contains Spaces (#4172)
Browse files Browse the repository at this point in the history
* [Improve] An exception occurs when the job name contains Spaces

* Update app.ts


---------

Co-authored-by: benjobs <[email protected]>
  • Loading branch information
zhilinli123 and wolfboys authored Jan 20, 2025
1 parent 5b1a1b4 commit ad8395f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,19 @@ public static void throwIfTrue(boolean expression, String errorMsgFmt, Object...
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
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)
Expand Down Expand Up @@ -341,11 +343,12 @@ public boolean create(FlinkApplication appParam) {
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ 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:',
appNameK8sClusterIdRoleLength: 'must be no more than 45 characters',
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(,)',
Expand Down

0 comments on commit ad8395f

Please sign in to comment.