njnu-seafish commented on code in PR #18293:
URL:
https://github.com/apache/dolphinscheduler/pull/18293#discussion_r3308028850
##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java:
##########
@@ -67,6 +78,33 @@ public Result updateProjectPreference(User loginUser, long
projectCode, String p
.selectOne(new
QueryWrapper<ProjectPreference>().lambda().eq(ProjectPreference::getProjectCode,
projectCode));
+ // Validate workerGroup is assigned to project
+ if (StringUtils.isNotEmpty(preferences)) {
+ try {
+ Map<String, Object> preferenceMap =
+ JSONUtils.parseObject(preferences, new
TypeReference<Map<String, Object>>() {
+ });
+ if (preferenceMap != null) {
+ Object workerGroupObj = preferenceMap.get("workerGroup");
+ if (workerGroupObj != null) {
+ String workerGroup = String.valueOf(workerGroupObj);
+ WorkerGroupValidationContext workerGroupContext =
WorkerGroupValidationContext.builder()
+ .workerGroup(workerGroup)
+ .projectCode(projectCode)
+ .build();
+ try {
+ workerGroupValidator.validate(workerGroupContext);
+ } catch (ServiceException e) {
+ putMsg(result,
Status.WORKER_GROUP_NOT_ASSIGNED_TO_PROJECT, workerGroup);
+ return result;
+ }
+ }
+ }
+ } catch (Exception e) {
+ log.warn("Failed to parse preferences JSON: {}", preferences,
e);
Review Comment:
> throw `ServiceException` here.
ok
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]