Skip to content

[Improvement-18286][ApiServer] Remove the default workerGroup from the frontend and add backend validation for workerGroup#18293

Open
njnu-seafish wants to merge 40 commits into
apache:devfrom
njnu-seafish:Improvement-18286
Open

[Improvement-18286][ApiServer] Remove the default workerGroup from the frontend and add backend validation for workerGroup#18293
njnu-seafish wants to merge 40 commits into
apache:devfrom
njnu-seafish:Improvement-18286

Conversation

@njnu-seafish

Copy link
Copy Markdown
Contributor

Was this PR generated or assisted by AI?

Yes, Modify the frontend code using AI, then test and verify locally.

Purpose of the pull request

close #18286

Brief change log

Remove the default workerGroup from the frontend and add backend validation for workerGroup

Verify this pull request

This pull request is code cleanup without any test coverage.

(or)

This pull request is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(or)

Pull Request Notice

Pull Request Notice

If your pull request contains incompatible change, you should also add it to docs/docs/en/guide/upgrade/incompatible.md

@ruanwenjun ruanwenjun added this to the 3.4.2 milestone May 26, 2026
* @param workerGroups worker group names to validate
* @throws ServiceException if any worker group is not assigned
*/
void validateWorkerGroupsAssignedToProject(Long projectCode, List<String> workerGroups);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated with WorkerGroupValidator

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated with WorkerGroupValidator

Okay, I will unify the logic.

Comment on lines +395 to +407
private void validateTaskWorkerGroups(long projectCode, List<TaskDefinitionLog> taskDefinitionLogs) {
if (CollectionUtils.isEmpty(taskDefinitionLogs)) {
return;
}

List<String> workerGroups = taskDefinitionLogs.stream()
.map(TaskDefinitionLog::getWorkerGroup)
.filter(StringUtils::isNotEmpty)
.distinct()
.collect(Collectors.toList());

projectWorkerGroupRelationService.validateWorkerGroupsAssignedToProject(projectCode, workerGroups);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of code should put into WorkerGroupValidator

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of code should put into WorkerGroupValidator

Okay, I will unify the logic.

@SbloodyS SbloodyS changed the title [Improvement-18286][ApiServer]Remove the default workerGroup from the frontend and add backend validation for workerGroup [Improvement-18286][ApiServer] Remove the default workerGroup from the frontend and add backend validation for workerGroup May 26, 2026
.selectOne(new QueryWrapper<ProjectPreference>().lambda().eq(ProjectPreference::getProjectCode,
projectCode));

// Validate workerGroup is assigned to project

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Validate workerGroup is assigned to project

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

}
}
} catch (Exception e) {
log.warn("Failed to parse preferences JSON: {}", preferences, e);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw ServiceException here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw ServiceException here.

ok

}
}
} catch (Exception e) {
log.warn("Failed to parse preferences JSON: {}", preferences, e);

if (StringUtils.isNotBlank(workerGroup)
&& !projectWorkerGroupRelationService.isWorkerGroupAssignedToProject(projectCode, workerGroup)) {
log.warn("Worker group {} is not assigned to project {}", workerGroup, projectCode);

@SbloodyS SbloodyS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI failed. Please check it. @njnu-seafish

@github-actions github-actions Bot added the e2e e2e test label Jun 2, 2026
@njnu-seafish
njnu-seafish requested a review from SbloodyS June 2, 2026 06:39
@SbloodyS SbloodyS modified the milestones: 3.4.2, 3.5.0 Jun 3, 2026
@njnu-seafish
njnu-seafish requested a review from SbloodyS June 22, 2026 03:13
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 60%)

See analysis details on SonarQube Cloud

@SbloodyS

Copy link
Copy Markdown
Member

The backend still accepts an invalid default worker group.

ProjectWorkerGroupRelationServiceImpl.isWorkerGroupAssignedToProject() returns true whenever WorkerGroupUtils.isWorkerGroupEmpty(workerGroup) is true. However, that helper treats both an empty value and the literal "default" as empty. In addition, WorkerGroupValidator skips validation entirely for blank values.

As a result, an API client can still submit either an empty worker group or "default" even when the project has not been assigned that group and no default workers exist. This is exactly the invalid configuration described in #18286, so removing the frontend default does not fully fix the problem.

There is also inconsistent behavior between the two validation paths:

  • Single-value validation always accepts "default".
  • Batch validation treats "default" as an ordinary group and may reject it.

Please resolve the effective worker group first and validate it against the project's assigned/existing worker groups, or explicitly reject empty/"default" values when no valid default group is available. Both validation paths should follow the same semantics.

Please also add a service-level test using the real ProjectWorkerGroupRelationServiceImpl behavior for a project that is assigned only g_suyc: g_suyc should pass, while empty and "default" should fail. Mocking isWorkerGroupAssignedToProject() directly will not catch this regression.

@njnu-seafish

Copy link
Copy Markdown
Contributor Author

The backend still accepts an invalid default worker group.

ProjectWorkerGroupRelationServiceImpl.isWorkerGroupAssignedToProject() returns true whenever WorkerGroupUtils.isWorkerGroupEmpty(workerGroup) is true. However, that helper treats both an empty value and the literal "default" as empty. In addition, WorkerGroupValidator skips validation entirely for blank values.

As a result, an API client can still submit either an empty worker group or "default" even when the project has not been assigned that group and no default workers exist. This is exactly the invalid configuration described in #18286, so removing the frontend default does not fully fix the problem.

There is also inconsistent behavior between the two validation paths:

  • Single-value validation always accepts "default".
  • Batch validation treats "default" as an ordinary group and may reject it.

Please resolve the effective worker group first and validate it against the project's assigned/existing worker groups, or explicitly reject empty/"default" values when no valid default group is available. Both validation paths should follow the same semantics.

Please also add a service-level test using the real ProjectWorkerGroupRelationServiceImpl behavior for a project that is assigned only g_suyc: g_suyc should pass, while empty and "default" should fail. Mocking isWorkerGroupAssignedToProject() directly will not catch this regression.

ok, add some logics.

1, Modified ProjectWorkerGroupRelationServiceImpl.isWorkerGroupAssignedToProject() to:

  • Return false for empty/null worker group values
  • Treat "default" as an ordinary group name that must be explicitly assigned

2, Modified WorkerGroupValidator (both single and batch validation) to:

  • Reject empty/null/blank values with ServiceException
  • Treat "default" as an ordinary group name

3, Added service-level tests using real ProjectWorkerGroupRelationServiceImpl behavior
to verify g_suyc passes while empty and "default" fail when project only has g_suyc assigned

@test
public void testIsWorkerGroupAssignedToProject() {
Mockito.when(projectDao.queryByCode(projectCode)).thenReturn(getProject());
Mockito.when(projectWorkerGroupDao.queryAssignedWorkerGroupNamesByProjectCode(projectCode))
.thenReturn(Sets.newHashSet("g_suyc")); // 项目只分配了 g_suyc
Mockito.when(taskDefinitionDao.queryAllTaskDefinitionWorkerGroups(projectCode))
.thenReturn(new ArrayList<>());
Mockito.when(scheduleDao.querySchedulerListByProjectName(Mockito.any()))
.thenReturn(Lists.newArrayList());
Assertions.assertTrue(projectWorkerGroupRelationService.isWorkerGroupAssignedToProject(projectCode, "g_suyc")); // ✅ g_suyc 通过
Assertions.assertFalse(projectWorkerGroupRelationService.isWorkerGroupAssignedToProject(projectCode, "")); // ❌ 空值拒绝
Assertions.assertFalse(projectWorkerGroupRelationService.isWorkerGroupAssignedToProject(projectCode, "default")); // ❌ "default" 拒绝
Assertions.assertFalse(projectWorkerGroupRelationService.isWorkerGroupAssignedToProject(projectCode, null)); // ❌ null 拒绝
Assertions.assertFalse(projectWorkerGroupRelationService.isWorkerGroupAssignedToProject(projectCode, "unassigned_group")); // ❌ 未分配组拒绝
}

4, Updated WorkerGroupValidatorTest to match new behavior with additional edge case tests

@SbloodyS

Copy link
Copy Markdown
Member

Did you forget to submit the code? I didn't see any commit. @njnu-seafish

@njnu-seafish

Copy link
Copy Markdown
Contributor Author

Did you forget to submit the code? I didn't see any commit. @njnu-seafish

Sorry about that, I got held up with some work stuff. Just submitted it, haha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend e2e e2e test improvement make more easy to user or prompt friendly test UI ui and front end related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement][ApiServer] Use real existing workerGroups more accurately instead of defaulting to 'default', to avoid ambiguity.

4 participants