From fe1f40c35e8999b4a20f20142994414976f021d2 Mon Sep 17 00:00:00 2001 From: Yanjun Qiu <153984347+qiuyanjun888@users.noreply.github.com> Date: Sun, 14 Jun 2026 21:00:35 +0800 Subject: [PATCH 1/6] [Improvement-17928][API] Add worker group id to environment relation --- .../service/impl/EnvironmentServiceImpl.java | 15 +++++ .../service/impl/WorkerGroupServiceImpl.java | 4 +- .../api/service/WorkerGroupServiceTest.java | 63 +++++++++++++++++++ .../service/impl/EnvironmentServiceTest.java | 54 ++++++++++++++++ .../EnvironmentWorkerGroupRelation.java | 5 ++ .../EnvironmentWorkerGroupRelationMapper.xml | 2 +- .../resources/sql/dolphinscheduler_h2.sql | 1 + .../resources/sql/dolphinscheduler_mysql.sql | 3 +- .../sql/dolphinscheduler_postgresql.sql | 1 + .../mysql/dolphinscheduler_ddl.sql | 10 ++- .../postgresql/dolphinscheduler_ddl.sql | 8 +++ ...ironmentWorkerGroupRelationMapperTest.java | 2 + 12 files changed, 164 insertions(+), 4 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceImpl.java index 96b04c19b950..d82fde7d57fa 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceImpl.java @@ -35,9 +35,11 @@ import org.apache.dolphinscheduler.dao.entity.EnvironmentWorkerGroupRelation; import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.User; +import org.apache.dolphinscheduler.dao.entity.WorkerGroup; import org.apache.dolphinscheduler.dao.mapper.EnvironmentMapper; import org.apache.dolphinscheduler.dao.mapper.EnvironmentWorkerGroupRelationMapper; import org.apache.dolphinscheduler.dao.repository.TaskDefinitionDao; +import org.apache.dolphinscheduler.dao.repository.WorkerGroupDao; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.SetUtils; @@ -82,6 +84,9 @@ public class EnvironmentServiceImpl extends BaseServiceImpl implements Environme @Autowired private TaskDefinitionDao taskDefinitionDao; + @Autowired + private WorkerGroupDao workerGroupDao; + /** * create environment * @@ -129,6 +134,7 @@ public Long createEnvironment(User loginUser, if (!StringUtils.isEmpty(workerGroup)) { EnvironmentWorkerGroupRelation relation = new EnvironmentWorkerGroupRelation(); relation.setEnvironmentCode(env.getCode()); + relation.setWorkerGroupId(getWorkerGroupId(workerGroup)); relation.setWorkerGroup(workerGroup); relation.setOperator(loginUser.getId()); relation.setCreateTime(new Date()); @@ -374,6 +380,7 @@ public Environment updateEnvironmentByCode(User loginUser, Long code, String nam if (StringUtils.isNotEmpty(key)) { EnvironmentWorkerGroupRelation relation = new EnvironmentWorkerGroupRelation(); relation.setEnvironmentCode(code); + relation.setWorkerGroupId(getWorkerGroupId(key)); relation.setWorkerGroup(key); relation.setUpdateTime(new Date()); relation.setCreateTime(new Date()); @@ -418,6 +425,14 @@ private void checkUsedEnvironmentWorkerGroupRelation(Set deleteKeySet, } } + private Integer getWorkerGroupId(String workerGroupName) { + List workerGroups = workerGroupDao.queryWorkerGroupByName(workerGroupName); + if (CollectionUtils.isEmpty(workerGroups)) { + return null; + } + return workerGroups.get(0).getId(); + } + protected void checkParams(String name, String config, String workerGroups) { if (StringUtils.isEmpty(name)) { throw new ServiceException(Status.ENVIRONMENT_NAME_IS_NULL); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java index ea7cc151cccd..95dc2f4e82eb 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java @@ -182,7 +182,9 @@ private void checkWorkerGroupDependencies(WorkerGroup workerGroup) { // check if the worker group has any dependent environments List environmentWorkerGroupRelations = environmentWorkerGroupRelationMapper.selectList(new QueryWrapper() - .lambda().eq(EnvironmentWorkerGroupRelation::getWorkerGroup, workerGroup.getName())); + .eq("worker_group_id", workerGroup.getId()) + .or(queryWrapper -> queryWrapper.isNull("worker_group_id") + .eq("worker_group", workerGroup.getName()))); if (CollectionUtils.isNotEmpty(environmentWorkerGroupRelations)) { throw new ServiceException(Status.WORKER_GROUP_DEPENDENT_ENVIRONMENT_EXISTS, diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java index e2ba1b7e6a86..960e3f6ea80f 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java @@ -32,6 +32,7 @@ import org.apache.dolphinscheduler.common.enums.AuthorizationType; import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus; +import org.apache.dolphinscheduler.dao.entity.EnvironmentWorkerGroupRelation; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.WorkerGroup; import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; @@ -44,6 +45,7 @@ import org.apache.dolphinscheduler.registry.api.enums.RegistryNodeType; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -63,6 +65,8 @@ import org.slf4j.LoggerFactory; import org.springframework.dao.DuplicateKeyException; +import com.baomidou.mybatisplus.core.conditions.Wrapper; + @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) public class WorkerGroupServiceTest { @@ -260,6 +264,65 @@ public void giveValidParams_whenDeleteWorkerGroupById_expectSuccess() { assertDoesNotThrow(() -> workerGroupService.deleteWorkerGroupById(loginUser, 1)); } + @Test + public void giveEnvironmentRelationMatchedByWorkerGroupId_whenDeleteWorkerGroupById_expectEnvironmentDependency() { + User loginUser = getLoginUser(); + when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, 1, + WORKER_GROUP_DELETE, baseServiceLogger)).thenReturn(true); + when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, + baseServiceLogger)).thenReturn(true); + WorkerGroup workerGroup = getWorkerGroup(1); + when(workerGroupDao.queryById(1)).thenReturn(workerGroup); + when(workflowInstanceDao.queryByWorkerGroupNameAndStatus(workerGroup.getName(), + WorkflowExecutionStatus.NOT_TERMINAL_STATES)).thenReturn(null); + when(taskDefinitionDao.queryByWorkerGroup(Mockito.any())).thenReturn(null); + when(scheduleDao.queryScheduleByWorkerGroup(Mockito.any())).thenReturn(null); + + EnvironmentWorkerGroupRelation relation = new EnvironmentWorkerGroupRelation(); + relation.setWorkerGroupId(workerGroup.getId()); + relation.setWorkerGroup("stale-" + workerGroup.getName()); + when(environmentWorkerGroupRelationMapper.selectList(Mockito.any())).thenAnswer(invocation -> { + Wrapper wrapper = invocation.getArgument(0); + String sqlSegment = wrapper.getSqlSegment(); + if (sqlSegment.contains("worker_group_id") && sqlSegment.contains("worker_group")) { + return Collections.singletonList(relation); + } + return Collections.emptyList(); + }); + + assertThrowsServiceException(Status.WORKER_GROUP_DEPENDENT_ENVIRONMENT_EXISTS, + () -> workerGroupService.deleteWorkerGroupById(loginUser, 1)); + } + + @Test + public void giveEnvironmentRelationMatchedOnlyByLegacyNameWithDifferentWorkerGroupId_whenDeleteWorkerGroupById_expectSuccess() { + User loginUser = getLoginUser(); + when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, 1, + WORKER_GROUP_DELETE, baseServiceLogger)).thenReturn(true); + when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, + baseServiceLogger)).thenReturn(true); + WorkerGroup workerGroup = getWorkerGroup(1); + when(workerGroupDao.queryById(1)).thenReturn(workerGroup); + when(workflowInstanceDao.queryByWorkerGroupNameAndStatus(workerGroup.getName(), + WorkflowExecutionStatus.NOT_TERMINAL_STATES)).thenReturn(null); + when(taskDefinitionDao.queryByWorkerGroup(Mockito.any())).thenReturn(null); + when(scheduleDao.queryScheduleByWorkerGroup(Mockito.any())).thenReturn(null); + + EnvironmentWorkerGroupRelation relation = new EnvironmentWorkerGroupRelation(); + relation.setWorkerGroupId(2); + relation.setWorkerGroup(workerGroup.getName()); + when(environmentWorkerGroupRelationMapper.selectList(Mockito.any())).thenAnswer(invocation -> { + Wrapper wrapper = invocation.getArgument(0); + String sqlSegment = wrapper.getSqlSegment(); + if (sqlSegment.contains("worker_group") && !sqlSegment.contains("worker_group_id IS NULL")) { + return Collections.singletonList(relation); + } + return Collections.emptyList(); + }); + + assertDoesNotThrow(() -> workerGroupService.deleteWorkerGroupById(loginUser, 1)); + } + @Test public void testQueryAllGroupWithDefault() { List workerGroups = workerGroupService.queryAllGroup(getLoginUser()); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceTest.java index e7cd2a7b433e..ff17317af9a0 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceTest.java @@ -39,9 +39,11 @@ import org.apache.dolphinscheduler.dao.entity.Environment; import org.apache.dolphinscheduler.dao.entity.EnvironmentWorkerGroupRelation; import org.apache.dolphinscheduler.dao.entity.User; +import org.apache.dolphinscheduler.dao.entity.WorkerGroup; import org.apache.dolphinscheduler.dao.mapper.EnvironmentMapper; import org.apache.dolphinscheduler.dao.mapper.EnvironmentWorkerGroupRelationMapper; import org.apache.dolphinscheduler.dao.repository.TaskDefinitionDao; +import org.apache.dolphinscheduler.dao.repository.WorkerGroupDao; import org.apache.commons.collections4.CollectionUtils; @@ -55,6 +57,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockedStatic; @@ -88,6 +91,9 @@ public class EnvironmentServiceTest { @Mock private TaskDefinitionDao taskDefinitionDao; + @Mock + private WorkerGroupDao workerGroupDao; + @Mock private ResourcePermissionCheckService resourcePermissionCheckService; @@ -140,6 +146,26 @@ public void testCreateEnvironment() { } } + @Test + public void testCreateEnvironmentWithWorkerGroupId() { + User adminUser = getAdminUser(); + when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ENVIRONMENT, + adminUser.getId(), ENVIRONMENT_CREATE, baseServiceLogger)).thenReturn(true); + when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ENVIRONMENT, null, + 0, baseServiceLogger)).thenReturn(true); + WorkerGroup workerGroup = getWorkerGroup(1, "default"); + when(environmentMapper.insert(any(Environment.class))).thenReturn(1); + when(workerGroupDao.queryWorkerGroupByName("default")).thenReturn(Collections.singletonList(workerGroup)); + when(relationMapper.insert(any(EnvironmentWorkerGroupRelation.class))).thenReturn(1); + + environmentService.createEnvironment(adminUser, "testName", "test", "test", workerGroups); + + ArgumentCaptor relationCaptor = + ArgumentCaptor.forClass(EnvironmentWorkerGroupRelation.class); + Mockito.verify(relationMapper).insert(relationCaptor.capture()); + assertEquals(workerGroup.getId(), relationCaptor.getValue().getWorkerGroupId()); + } + @Test public void testCheckParams() { assertThrowsServiceException(Status.ENVIRONMENT_WORKER_GROUPS_IS_INVALID, @@ -193,6 +219,27 @@ public void testUpdateEnvironmentByCode() { "")); } + @Test + public void testUpdateEnvironmentByCodeWithWorkerGroupId() { + User adminUser = getAdminUser(); + when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ENVIRONMENT, + adminUser.getId(), ENVIRONMENT_UPDATE, baseServiceLogger)).thenReturn(true); + when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ENVIRONMENT, null, + 0, baseServiceLogger)).thenReturn(true); + WorkerGroup workerGroup = getWorkerGroup(1, "default"); + when(environmentMapper.update(any(Environment.class), any(Wrapper.class))).thenReturn(1); + when(relationMapper.queryByEnvironmentCode(1L)).thenReturn(Collections.emptyList()); + when(workerGroupDao.queryWorkerGroupByName("default")).thenReturn(Collections.singletonList(workerGroup)); + when(relationMapper.insert(any(EnvironmentWorkerGroupRelation.class))).thenReturn(1); + + environmentService.updateEnvironmentByCode(adminUser, 1L, "testName", "test", "test", workerGroups); + + ArgumentCaptor relationCaptor = + ArgumentCaptor.forClass(EnvironmentWorkerGroupRelation.class); + Mockito.verify(relationMapper).insert(relationCaptor.capture()); + assertEquals(workerGroup.getId(), relationCaptor.getValue().getWorkerGroupId()); + } + @Test public void testQueryAllEnvironmentList() { when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.ENVIRONMENT, @@ -325,6 +372,13 @@ private EnvironmentWorkerGroupRelation getEnvironmentWorkerGroup() { return relation; } + private WorkerGroup getWorkerGroup(int id, String name) { + WorkerGroup workerGroup = new WorkerGroup(); + workerGroup.setId(id); + workerGroup.setName(name); + return workerGroup; + } + /** * create an environment description */ diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/EnvironmentWorkerGroupRelation.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/EnvironmentWorkerGroupRelation.java index 243edbc67ea3..9bcb2e0427bc 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/EnvironmentWorkerGroupRelation.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/EnvironmentWorkerGroupRelation.java @@ -37,6 +37,11 @@ public class EnvironmentWorkerGroupRelation { /** * worker group id */ + private Integer workerGroupId; + + /** + * worker group name + */ private String workerGroup; /** diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/EnvironmentWorkerGroupRelationMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/EnvironmentWorkerGroupRelationMapper.xml index 7ea959d6014c..19b2780cc9d4 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/EnvironmentWorkerGroupRelationMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/EnvironmentWorkerGroupRelationMapper.xml @@ -19,7 +19,7 @@ - id, environment_code, worker_group, operator, create_time, update_time + id, environment_code, worker_group_id, worker_group, operator, create_time, update_time + update t_ds_worker_group diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql index 94bfe58a645e..847d23a36abb 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql @@ -1158,7 +1158,7 @@ CREATE TABLE t_ds_environment_worker_group_relation ( id int NOT NULL AUTO_INCREMENT, environment_code bigint(20) NOT NULL, - worker_group_id int DEFAULT NULL, + worker_group_id int NOT NULL, worker_group varchar(255) NOT NULL, operator int DEFAULT NULL, create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql index cf4eb8abac18..7a81fdd360a8 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql @@ -1149,7 +1149,7 @@ DROP TABLE IF EXISTS `t_ds_environment_worker_group_relation`; CREATE TABLE `t_ds_environment_worker_group_relation` ( `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'id', `environment_code` bigint(20) NOT NULL COMMENT 'environment code', - `worker_group_id` int(11) DEFAULT NULL COMMENT 'worker group id', + `worker_group_id` int(11) NOT NULL COMMENT 'worker group id', `worker_group` varchar(255) NOT NULL COMMENT 'worker group name', `operator` int(11) DEFAULT NULL COMMENT 'operator user id', `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP, diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql index dcbcabb2302b..81246ace7a37 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql @@ -1160,7 +1160,7 @@ DROP TABLE IF EXISTS t_ds_environment_worker_group_relation; CREATE TABLE t_ds_environment_worker_group_relation ( id serial NOT NULL, environment_code bigint NOT NULL, - worker_group_id int DEFAULT NULL, + worker_group_id int NOT NULL, worker_group varchar(255) NOT NULL, operator int DEFAULT NULL, create_time timestamp DEFAULT NULL, diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/mysql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/mysql/dolphinscheduler_ddl.sql index aa32686cc64d..e0556e265d70 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/mysql/dolphinscheduler_ddl.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/mysql/dolphinscheduler_ddl.sql @@ -17,6 +17,3 @@ ALTER TABLE `t_ds_serial_command` MODIFY COLUMN `workflow_definition_code` BIGINT(20) NOT NULL COMMENT 'workflow definition code'; - -ALTER TABLE `t_ds_environment_worker_group_relation` -ADD COLUMN `worker_group_id` int(11) DEFAULT NULL COMMENT 'worker group id'; \ No newline at end of file diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/mysql/dolphinscheduler_dml.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/mysql/dolphinscheduler_dml.sql index 3bf30f200474..4a14f326b985 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/mysql/dolphinscheduler_dml.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/mysql/dolphinscheduler_dml.sql @@ -14,8 +14,3 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -UPDATE `t_ds_environment_worker_group_relation` ewgr -INNER JOIN `t_ds_worker_group` wg ON ewgr.`worker_group` = wg.`name` -SET ewgr.`worker_group_id` = wg.`id` -WHERE ewgr.`worker_group_id` IS NULL; diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/postgresql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/postgresql/dolphinscheduler_ddl.sql index 72da545c5688..d25618977331 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/postgresql/dolphinscheduler_ddl.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/postgresql/dolphinscheduler_ddl.sql @@ -18,5 +18,3 @@ CREATE SEQUENCE IF NOT EXISTS t_ds_task_instance_context_id_seq; ALTER TABLE t_ds_task_instance_context ALTER COLUMN id SET DEFAULT nextval('t_ds_task_instance_context_id_seq'::regclass); - -ALTER TABLE t_ds_environment_worker_group_relation ADD COLUMN IF NOT EXISTS worker_group_id int DEFAULT NULL; diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/postgresql/dolphinscheduler_dml.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/postgresql/dolphinscheduler_dml.sql index f4cbab76495e..4a14f326b985 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/postgresql/dolphinscheduler_dml.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/postgresql/dolphinscheduler_dml.sql @@ -14,9 +14,3 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -UPDATE t_ds_environment_worker_group_relation ewgr -SET worker_group_id = wg.id -FROM t_ds_worker_group wg -WHERE ewgr.worker_group_id IS NULL - AND ewgr.worker_group = wg.name; diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/mysql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/mysql/dolphinscheduler_ddl.sql new file mode 100644 index 000000000000..75c3f0f913a8 --- /dev/null +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/mysql/dolphinscheduler_ddl.sql @@ -0,0 +1,19 @@ +/* + * 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. +*/ + +ALTER TABLE `t_ds_environment_worker_group_relation` +ADD COLUMN `worker_group_id` int(11) DEFAULT NULL COMMENT 'worker group id'; diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/mysql/dolphinscheduler_dml.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/mysql/dolphinscheduler_dml.sql new file mode 100644 index 000000000000..5daf53fcebe5 --- /dev/null +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/mysql/dolphinscheduler_dml.sql @@ -0,0 +1,24 @@ +/* + * 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. +*/ + +UPDATE `t_ds_environment_worker_group_relation` ewgr +INNER JOIN `t_ds_worker_group` wg ON ewgr.`worker_group` = wg.`name` +SET ewgr.`worker_group_id` = wg.`id` +WHERE ewgr.`worker_group_id` IS NULL; + +ALTER TABLE `t_ds_environment_worker_group_relation` +MODIFY COLUMN `worker_group_id` int(11) NOT NULL COMMENT 'worker group id'; diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/postgresql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/postgresql/dolphinscheduler_ddl.sql new file mode 100644 index 000000000000..65fecfdd5ddc --- /dev/null +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/postgresql/dolphinscheduler_ddl.sql @@ -0,0 +1,19 @@ +/* + * 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. +*/ + +ALTER TABLE t_ds_environment_worker_group_relation +ADD COLUMN IF NOT EXISTS worker_group_id int DEFAULT NULL; diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/postgresql/dolphinscheduler_dml.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/postgresql/dolphinscheduler_dml.sql new file mode 100644 index 000000000000..919d4331a0c1 --- /dev/null +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/postgresql/dolphinscheduler_dml.sql @@ -0,0 +1,25 @@ +/* + * 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. +*/ + +UPDATE t_ds_environment_worker_group_relation ewgr +SET worker_group_id = wg.id +FROM t_ds_worker_group wg +WHERE ewgr.worker_group_id IS NULL + AND ewgr.worker_group = wg.name; + +ALTER TABLE t_ds_environment_worker_group_relation +ALTER COLUMN worker_group_id SET NOT NULL; diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapperTest.java index 84f140ff0be7..5b2d0ca967bd 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapperTest.java @@ -20,6 +20,7 @@ import org.apache.dolphinscheduler.dao.BaseDaoTest; import org.apache.dolphinscheduler.dao.entity.WorkerGroup; +import java.util.Collections; import java.util.Date; import java.util.List; @@ -93,6 +94,21 @@ public void testQueryWorkerGroupByName() { Assertions.assertEquals(0, workerGroups.size()); } + /** + * test query worker groups by names + */ + @Test + public void testQueryWorkerGroupByNames() { + WorkerGroup workerGroup = insertOneWorkerGroup(); + List workerGroups = + workerGroupMapper.queryWorkerGroupByNames(Collections.singleton(workerGroup.getName())); + Assertions.assertEquals(1, workerGroups.size()); + Assertions.assertEquals(workerGroup.getName(), workerGroups.get(0).getName()); + + workerGroups = workerGroupMapper.queryWorkerGroupByNames(Collections.singleton("server2")); + Assertions.assertEquals(0, workerGroups.size()); + } + /** * test update workerGroup */ From 05ef5125dfa3f6da5a9eca0e117d2800c52a0276 Mon Sep 17 00:00:00 2001 From: qiuyanjun Date: Tue, 16 Jun 2026 13:09:03 +0800 Subject: [PATCH 4/6] [Improvement-17928][API] Remove unrelated upgrade ddl newline change --- .../sql/upgrade/3.4.1_schema/mysql/dolphinscheduler_ddl.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/mysql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/mysql/dolphinscheduler_ddl.sql index e0556e265d70..30f6f2be6947 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/mysql/dolphinscheduler_ddl.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.1_schema/mysql/dolphinscheduler_ddl.sql @@ -16,4 +16,4 @@ */ ALTER TABLE `t_ds_serial_command` -MODIFY COLUMN `workflow_definition_code` BIGINT(20) NOT NULL COMMENT 'workflow definition code'; +MODIFY COLUMN `workflow_definition_code` BIGINT(20) NOT NULL COMMENT 'workflow definition code'; \ No newline at end of file From f592c0385179843dabb784a03d0f36f859c6fcf3 Mon Sep 17 00:00:00 2001 From: Yanjun Qiu <153984347+qiuyanjun888@users.noreply.github.com> Date: Tue, 16 Jun 2026 16:06:00 +0800 Subject: [PATCH 5/6] [Improvement-17928][API] Address worker group mapper review --- .../dao/entity/EnvironmentWorkerGroupRelation.java | 3 --- .../apache/dolphinscheduler/dao/mapper/WorkerGroupMapper.xml | 2 +- .../dolphinscheduler/dao/mapper/WorkerGroupMapperTest.java | 3 --- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/EnvironmentWorkerGroupRelation.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/EnvironmentWorkerGroupRelation.java index 9bcb2e0427bc..0ed20c3ed609 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/EnvironmentWorkerGroupRelation.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/EnvironmentWorkerGroupRelation.java @@ -39,9 +39,6 @@ public class EnvironmentWorkerGroupRelation { */ private Integer workerGroupId; - /** - * worker group name - */ private String workerGroup; /** diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapper.xml index af8cbd8f6d1b..c59c0757bb3d 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapper.xml @@ -29,7 +29,7 @@ where name = #{name}