Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature-14863][API] Support to manage what worker groups can be used for a project. #15600

Merged
merged 32 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4984c9e
define the table structure of the relation of the project and worker …
calvinjiang Sep 13, 2023
e9e6fb3
finish the mapper of project and worker group
calvinjiang Sep 19, 2023
eec7ca1
Merge branch 'dev' into f-worker-group-project
calvinjiang Sep 19, 2023
e0be11b
the service of project and worker group
calvinjiang Sep 19, 2023
87dab90
finish the implementation of the service
calvinjiang Sep 21, 2023
9afd993
Merge branch 'dev' into f-worker-group-project
calvinjiang Sep 27, 2023
d3e69c9
finish the implementation of the service
calvinjiang Oct 10, 2023
4391b5e
Merge branch 'dev' into f-worker-group-project
calvinjiang Oct 10, 2023
ef649c3
add a few test cases
calvinjiang Oct 21, 2023
ab4a269
Merge branch 'dev' into f-worker-group-project
calvinjiang Oct 21, 2023
e597124
add a few test cases
calvinjiang Oct 21, 2023
89928dc
add a few test cases
calvinjiang Oct 22, 2023
442662f
merge from dev
calvinjiang Nov 25, 2023
bf76ad0
add a function to query work groups by a certain project
calvinjiang Nov 25, 2023
125949c
Merge branch 'dev' into f-worker-group-project
calvinjiang Nov 30, 2023
498f0f1
add the worker group modal
calvinjiang Dec 2, 2023
86546c8
add the worker group modal
calvinjiang Dec 2, 2023
d12d8ee
finish the service of project and worker groups
calvinjiang Dec 10, 2023
37cd7c8
Merge branch 'dev' into f-worker-group-project
calvinjiang Jan 28, 2024
8c817e8
Merge branch 'dev' into f-worker-group-project
calvinjiang Feb 18, 2024
6fc4a24
modify worker-group-modal
calvinjiang Feb 18, 2024
8d7b7ab
the coding was done
calvinjiang Feb 19, 2024
3971d04
the coding was done
calvinjiang Feb 19, 2024
64e1fd6
the coding was done
calvinjiang Feb 19, 2024
df1707c
Merge branch 'dev' into f-worker-group-project
calvinjiang Feb 19, 2024
188980e
the coding was done
calvinjiang Feb 19, 2024
b385958
the coding was done
calvinjiang Feb 19, 2024
58ccceb
the coding was done
calvinjiang Feb 20, 2024
e73916c
the coding was done
calvinjiang Feb 20, 2024
088ef53
prettier front-end code
calvinjiang Feb 20, 2024
dcc02b4
prettier front-end code
calvinjiang Feb 20, 2024
f918784
prettier front-end code
calvinjiang Feb 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* 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.controller;

import static org.apache.dolphinscheduler.api.enums.Status.ASSIGN_WORKER_GROUP_TO_PROJECT_ERROR;

import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.ProjectWorkerGroupRelationService;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.dao.entity.User;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
* project and worker group controller
*/
@Tag(name = "PROJECT_WORKER_GROUP_TAG")
@RestController
@RequestMapping("projects/{projectCode}/worker-group")
@Slf4j
public class ProjectWorkerGroupController extends BaseController {

@Autowired
private ProjectWorkerGroupRelationService projectWorkerGroupRelationService;

/**
* assign worker groups to the project
*
* @param loginUser login user
* @param projectCode project code
@ @RequestParam(value = "workerGroups", required = false) String workerGroups
* @return create result code
*/
@Operation(summary = "assignWorkerGroups", description = "CREATE_PROCESS_DEFINITION_NOTES")
@Parameters({
@Parameter(name = "projectCode", description = "PROJECT_CODE", schema = @Schema(implementation = long.class, example = "123456")),
@Parameter(name = "workerGroups", description = "WORKER_GROUP_LIST", schema = @Schema(implementation = List.class))
})
@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
@ApiException(ASSIGN_WORKER_GROUP_TO_PROJECT_ERROR)
public Result assignWorkerGroups(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@Parameter(name = "workerGroups") String[] workerGroups) {

List<String> workerGroupList = Arrays.stream(workerGroups).collect(Collectors.toList());
return projectWorkerGroupRelationService.assignWorkerGroupsToProject(loginUser, projectCode, workerGroupList);
}

/**
* query worker groups that assigned to the project
*
* @param projectCode project code
* @return worker group list
*/
@Operation(summary = "queryWorkerGroups", description = "QUERY_WORKER_GROUP_LIST")
@Parameters({
@Parameter(name = "projectCode", description = "PROJECT_CODE", schema = @Schema(implementation = long.class, example = "123456"))
})
@GetMapping()
@ResponseStatus(HttpStatus.OK)
public Map<String, Object> queryWorkerGroups(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode) {
return projectWorkerGroupRelationService.queryWorkerGroupsByProject(loginUser, projectCode);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,4 @@ public Result queryWorkerAddressList(@Parameter(hidden = true) @RequestAttribute
Map<String, Object> result = workerGroupService.getWorkerAddressList();
return returnDataList(result);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,15 @@ public enum Status {
WORKER_GROUP_DEPENDENT_ENVIRONMENT_EXISTS(1401002,
"You can not modify or remove this worker group, cause it has [{0}] dependent environments.",
"不能修改或删除该Worker组,有 [{0}] 个环境配置正在使用"),

WORKER_GROUP_NOT_EXIST(1402001, "The Worker group [{0}] not exists", "Worker组[{0}]不存在."),
ASSIGN_WORKER_GROUP_TO_PROJECT_ERROR(1402002, "Failed to assign these worker groups to the project",
"给项目分配工作组失败"),
WORKER_GROUP_TO_PROJECT_IS_EMPTY(1402003, "Need to assign at least one worker group to the project",
"需要给项目至少分配一个Worker组"),
USED_WORKER_GROUP_EXISTS(1402004,
"You can not reassign worker groups to the project, cause these worker groups {0} are already used.",
"Worker组{0}被项目中任务或定时引用,无法重新分配"),
;
private final int code;
private final String enMsg;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.service;

import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.dao.entity.User;

import java.util.List;
import java.util.Map;

/**
* the service of project and worker group
*/
public interface ProjectWorkerGroupRelationService {

/**
* assign worker groups to a project
*
* @param loginUser the login user
* @param projectCode the project code
* @param workerGroups assigned worker group names
*/
Result assignWorkerGroupsToProject(User loginUser, Long projectCode, List<String> workerGroups);

/**
* query worker groups that assigned to the project
*
* @param loginUser the login user
* @param projectCode project code
*/
Map<String, Object> queryWorkerGroupsByProject(User loginUser, Long projectCode);

}
Loading
Loading