SbloodyS commented on code in PR #18293:
URL: 
https://github.com/apache/dolphinscheduler/pull/18293#discussion_r3302086148


##########
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");

Review Comment:
   Using entity instead of hard coding.



##########
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

Review Comment:
   ```suggestion
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java:
##########
@@ -570,6 +582,12 @@ private Schedule updateSchedule(Schedule schedule, 
WorkflowDefinition workflowDe
             schedule.setFailureStrategy(failureStrategy);
         }
 
+        // Validate workerGroup

Review Comment:
   ```suggestion
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/validator/workflow/TriggerWorkflowDTOValidator.java:
##########
@@ -56,5 +62,12 @@ public void validate(final TriggerWorkflowDTO 
triggerWorkflowDTO) {
         tenantExistValidator.validate(triggerWorkflowDTO.getTenantCode());
 
         
startParamListValidator.validate(triggerWorkflowDTO.getStartParamList());
+
+        // Validate workerGroup using WorkerGroupValidator

Review Comment:
   ```suggestion
   ```



##########
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.



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java:
##########
@@ -182,6 +187,13 @@ public Schedule insertSchedule(User loginUser,
         scheduleObj.setUserName(loginUser.getUserName());
         scheduleObj.setReleaseState(ReleaseState.OFFLINE);
         scheduleObj.setWorkflowInstancePriority(workflowInstancePriority);
+
+        // Validate workerGroup

Review Comment:
   ```suggestion
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/validator/WorkerGroupValidationContext.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.validator;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * Validation context for workerGroup validation
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class WorkerGroupValidationContext {
+
+    /**
+     * The workerGroup to validate
+     */
+    private String workerGroup;
+
+    /**
+     * The project code to check against
+     */
+    private long projectCode;

Review Comment:
   Remove all unnessnary comment.



-- 
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]

Reply via email to