WorkerGroupController.java 7.8 KB
Newer Older
B
baoliang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * 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.
 */
17

Q
qiaozhanwei 已提交
18
package org.apache.dolphinscheduler.api.controller;
B
baoliang 已提交
19

20
import static org.apache.dolphinscheduler.api.enums.Status.DELETE_WORKER_GROUP_FAIL;
21
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKER_ADDRESS_LIST_FAIL;
22
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKER_GROUP_FAIL;
23
import static org.apache.dolphinscheduler.api.enums.Status.SAVE_ERROR;
B
baoliang 已提交
24

25
import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
26
import org.apache.dolphinscheduler.api.enums.Status;
27
import org.apache.dolphinscheduler.api.exceptions.ApiException;
Q
qiaozhanwei 已提交
28 29
import org.apache.dolphinscheduler.api.service.WorkerGroupService;
import org.apache.dolphinscheduler.api.utils.Result;
30
import org.apache.dolphinscheduler.common.Constants;
Q
qiaozhanwei 已提交
31 32
import org.apache.dolphinscheduler.common.utils.ParameterUtils;
import org.apache.dolphinscheduler.dao.entity.User;
33 34 35

import java.util.Map;

B
baoliang 已提交
36 37
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
38
import org.springframework.web.bind.annotation.GetMapping;
39
import org.springframework.web.bind.annotation.PostMapping;
40 41 42 43 44
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
B
baoliang 已提交
45

46 47 48 49 50
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;
51

B
baoliang 已提交
52 53 54
/**
 * worker group controller
 */
55
@Api(tags = "WORKER_GROUP_TAG")
B
baoliang 已提交
56 57
@RestController
@RequestMapping("/worker-group")
58
public class WorkerGroupController extends BaseController {
B
baoliang 已提交
59 60 61 62

    @Autowired
    WorkerGroupService workerGroupService;

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    /**
     * create or update a worker group
     *
     * @param loginUser login user
     * @param id        worker group id
     * @param name      worker group name
     * @param addrList  addr list
     * @return create or update result code
     */
    @ApiOperation(value = "saveWorkerGroup", notes = "CREATE_WORKER_GROUP_NOTES")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "WORKER_GROUP_ID", dataType = "Int", example = "10", defaultValue = "0"),
            @ApiImplicitParam(name = "name", value = "WORKER_GROUP_NAME", required = true, dataType = "String"),
            @ApiImplicitParam(name = "addrList", value = "WORKER_ADDR_LIST", required = true, dataType = "String")
    })
    @PostMapping(value = "/save")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(SAVE_ERROR)
81
    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
82 83 84 85 86 87 88 89 90
    public Result saveWorkerGroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                  @RequestParam(value = "id", required = false, defaultValue = "0") int id,
                                  @RequestParam(value = "name") String name,
                                  @RequestParam(value = "addrList") String addrList
    ) {
        Map<String, Object> result = workerGroupService.saveWorkerGroup(loginUser, id, name, addrList);
        return returnDataList(result);
    }

B
baoliang 已提交
91 92
    /**
     * query worker groups paging
B
bao liang 已提交
93 94
     *
     * @param loginUser login user
95
     * @param pageNo    page number
B
bao liang 已提交
96
     * @param searchVal search value
97
     * @param pageSize  page size
B
bao liang 已提交
98
     * @return worker group list page
B
baoliang 已提交
99
     */
100
    @ApiOperation(value = "queryAllWorkerGroupsPaging", notes = "QUERY_WORKER_GROUP_PAGING_NOTES")
L
lidongdai 已提交
101
    @ApiImplicitParams({
102 103 104
            @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"),
            @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20"),
            @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String")
L
lidongdai 已提交
105
    })
B
baoliang 已提交
106
    @GetMapping(value = "/list-paging")
B
baoliang 已提交
107
    @ResponseStatus(HttpStatus.OK)
108
    @ApiException(QUERY_WORKER_GROUP_FAIL)
109
    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
Q
qiaozhanwei 已提交
110
    public Result queryAllWorkerGroupsPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
B
baoliang 已提交
111
                                             @RequestParam("pageNo") Integer pageNo,
112 113
                                             @RequestParam("pageSize") Integer pageSize,
                                             @RequestParam(value = "searchVal", required = false) String searchVal
B
baoliang 已提交
114
    ) {
115 116 117 118
        Map<String, Object> result = checkPageParams(pageNo, pageSize);
        if (result.get(Constants.STATUS) != Status.SUCCESS) {
            return returnDataListPaging(result);
        }
119
        searchVal = ParameterUtils.handleEscapes(searchVal);
120
        result = workerGroupService.queryAllGroupPaging(loginUser, pageNo, pageSize, searchVal);
121
        return returnDataListPaging(result);
B
baoliang 已提交
122 123
    }

B
baoliang 已提交
124 125
    /**
     * query all worker groups
B
bao liang 已提交
126 127 128
     *
     * @param loginUser login user
     * @return all worker group list
B
baoliang 已提交
129
     */
130
    @ApiOperation(value = "queryAllWorkerGroups", notes = "QUERY_WORKER_GROUP_LIST_NOTES")
B
baoliang 已提交
131 132
    @GetMapping(value = "/all-groups")
    @ResponseStatus(HttpStatus.OK)
133
    @ApiException(QUERY_WORKER_GROUP_FAIL)
134
    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
135
    public Result queryAllWorkerGroups(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
136 137
        Map<String, Object> result = workerGroupService.queryAllGroup();
        return returnDataList(result);
B
baoliang 已提交
138 139
    }

140 141 142 143 144 145 146 147 148 149 150 151 152 153
    /**
     * delete worker group by id
     *
     * @param loginUser login user
     * @param id        group id
     * @return delete result code
     */
    @ApiOperation(value = "deleteById", notes = "DELETE_WORKER_GROUP_BY_ID_NOTES")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "WORKER_GROUP_ID", required = true, dataType = "Int", example = "10"),
    })
    @PostMapping(value = "/delete-by-id")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(DELETE_WORKER_GROUP_FAIL)
154
    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
155 156 157 158 159 160
    public Result deleteById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                             @RequestParam("id") Integer id
    ) {
        Map<String, Object> result = workerGroupService.deleteWorkerGroupById(loginUser, id);
        return returnDataList(result);
    }
161

162 163 164 165 166 167 168 169 170 171
    /**
     * query worker address list
     *
     * @param loginUser login user
     * @return all worker address list
     */
    @ApiOperation(value = "queryWorkerAddressList", notes = "QUERY_WORKER_ADDRESS_LIST_NOTES")
    @GetMapping(value = "/worker-address-list")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(QUERY_WORKER_ADDRESS_LIST_FAIL)
172
    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
173 174 175 176 177
    public Result queryWorkerAddressList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
        Map<String, Object> result = workerGroupService.getWorkerAddressList();
        return returnDataList(result);
    }

B
baoliang 已提交
178
}