QueueController.java 8.1 KB
Newer Older
L
ligang 已提交
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;
L
ligang 已提交
19

20 21 22 23
import static org.apache.dolphinscheduler.api.enums.Status.CREATE_QUEUE_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_QUEUE_LIST_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_QUEUE_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_QUEUE_ERROR;
L
ligang 已提交
24

25
import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
Q
qiaozhanwei 已提交
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.QueueService;
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;

L
ligang 已提交
36 37
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
38 39 40 41 42 43 44
import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
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;
L
ligang 已提交
51 52 53 54

/**
 * queue controller
 */
55
@Api(tags = "QUEUE_TAG")
L
ligang 已提交
56 57
@RestController
@RequestMapping("/queue")
58
public class QueueController extends BaseController {
L
ligang 已提交
59 60 61 62 63 64 65

    @Autowired
    private QueueService queueService;


    /**
     * query queue list
66
     *
B
bao liang 已提交
67 68
     * @param loginUser login user
     * @return queue list
L
ligang 已提交
69
     */
70 71
    @ApiOperation(value = "queryList", notes = "QUERY_QUEUE_LIST_NOTES")
    @GetMapping(value = "/list")
L
ligang 已提交
72
    @ResponseStatus(HttpStatus.OK)
73
    @ApiException(QUERY_QUEUE_LIST_ERROR)
74
    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
75 76 77
    public Result queryList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
        Map<String, Object> result = queueService.queryList(loginUser);
        return returnDataList(result);
L
ligang 已提交
78 79
    }

L
ligang 已提交
80 81
    /**
     * query queue list paging
82
     *
B
bao liang 已提交
83
     * @param loginUser login user
84
     * @param pageNo    page number
B
bao liang 已提交
85
     * @param searchVal search value
86
     * @param pageSize  page size
B
bao liang 已提交
87
     * @return queue list
L
ligang 已提交
88
     */
89
    @ApiOperation(value = "queryQueueListPaging", notes = "QUERY_QUEUE_LIST_PAGING_NOTES")
L
lidongdai 已提交
90
    @ApiImplicitParams({
91
            @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"),
L
lidongdai 已提交
92
            @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"),
93
            @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20")
L
lidongdai 已提交
94
    })
95
    @GetMapping(value = "/list-paging")
L
ligang 已提交
96
    @ResponseStatus(HttpStatus.OK)
97
    @ApiException(QUERY_QUEUE_LIST_ERROR)
98
    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
L
lidongdai 已提交
99
    public Result queryQueueListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
100 101 102 103 104
                                       @RequestParam("pageNo") Integer pageNo,
                                       @RequestParam(value = "searchVal", required = false) String searchVal,
                                       @RequestParam("pageSize") Integer pageSize) {
        Map<String, Object> result = checkPageParams(pageNo, pageSize);
        if (result.get(Constants.STATUS) != Status.SUCCESS) {
L
ligang 已提交
105
            return returnDataListPaging(result);
L
ligang 已提交
106
        }
107 108 109 110

        searchVal = ParameterUtils.handleEscapes(searchVal);
        result = queueService.queryList(loginUser, searchVal, pageNo, pageSize);
        return returnDataListPaging(result);
L
ligang 已提交
111 112 113 114 115
    }

    /**
     * create queue
     *
B
bao liang 已提交
116
     * @param loginUser login user
117
     * @param queue     queue
B
bao liang 已提交
118 119
     * @param queueName queue name
     * @return create result
L
ligang 已提交
120
     */
121
    @ApiOperation(value = "createQueue", notes = "CREATE_QUEUE_NOTES")
L
lidongdai 已提交
122
    @ApiImplicitParams({
123 124
            @ApiImplicitParam(name = "queue", value = "YARN_QUEUE_NAME", required = true, dataType = "String"),
            @ApiImplicitParam(name = "queueName", value = "QUEUE_NAME", required = true, dataType = "String")
L
lidongdai 已提交
125
    })
L
ligang 已提交
126 127
    @PostMapping(value = "/create")
    @ResponseStatus(HttpStatus.CREATED)
128
    @ApiException(CREATE_QUEUE_ERROR)
129
    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
L
lidongdai 已提交
130
    public Result createQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
131 132 133 134
                              @RequestParam(value = "queue") String queue,
                              @RequestParam(value = "queueName") String queueName) {
        Map<String, Object> result = queueService.createQueue(loginUser, queue, queueName);
        return returnDataList(result);
L
ligang 已提交
135 136 137 138 139
    }

    /**
     * update queue
     *
B
bao liang 已提交
140
     * @param loginUser login user
141 142
     * @param queue     queue
     * @param id        queue id
B
bao liang 已提交
143 144
     * @param queueName queue name
     * @return update result code
L
ligang 已提交
145
     */
146
    @ApiOperation(value = "updateQueue", notes = "UPDATE_QUEUE_NOTES")
L
lidongdai 已提交
147
    @ApiImplicitParams({
148 149 150
            @ApiImplicitParam(name = "id", value = "QUEUE_ID", required = true, dataType = "Int", example = "100"),
            @ApiImplicitParam(name = "queue", value = "YARN_QUEUE_NAME", required = true, dataType = "String"),
            @ApiImplicitParam(name = "queueName", value = "QUEUE_NAME", required = true, dataType = "String")
L
lidongdai 已提交
151
    })
L
ligang 已提交
152 153
    @PostMapping(value = "/update")
    @ResponseStatus(HttpStatus.CREATED)
154
    @ApiException(UPDATE_QUEUE_ERROR)
155
    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
L
lidongdai 已提交
156
    public Result updateQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
L
ligang 已提交
157 158 159
                              @RequestParam(value = "id") int id,
                              @RequestParam(value = "queue") String queue,
                              @RequestParam(value = "queueName") String queueName) {
160 161
        Map<String, Object> result = queueService.updateQueue(loginUser, id, queue, queueName);
        return returnDataList(result);
L
ligang 已提交
162 163
    }

L
ligang 已提交
164 165 166
    /**
     * verify queue and queue name
     *
B
bao liang 已提交
167
     * @param loginUser login user
168
     * @param queue     queue
B
bao liang 已提交
169 170
     * @param queueName queue name
     * @return true if the queue name not exists, otherwise return false
L
ligang 已提交
171
     */
172
    @ApiOperation(value = "verifyQueue", notes = "VERIFY_QUEUE_NOTES")
L
lidongdai 已提交
173
    @ApiImplicitParams({
174 175
            @ApiImplicitParam(name = "queue", value = "YARN_QUEUE_NAME", required = true, dataType = "String"),
            @ApiImplicitParam(name = "queueName", value = "QUEUE_NAME", required = true, dataType = "String")
L
lidongdai 已提交
176
    })
L
ligang 已提交
177 178
    @PostMapping(value = "/verify-queue")
    @ResponseStatus(HttpStatus.OK)
179
    @ApiException(VERIFY_QUEUE_ERROR)
180
    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
L
lidongdai 已提交
181
    public Result verifyQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
182 183
                              @RequestParam(value = "queue") String queue,
                              @RequestParam(value = "queueName") String queueName
L
ligang 已提交
184 185
    ) {

186
        return queueService.verifyQueue(queue, queueName);
L
ligang 已提交
187 188
    }

L
ligang 已提交
189 190

}