QueueController.java 8.6 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

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

import java.util.Map;

L
ligang 已提交
35 36 37 38
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
39 40 41 42 43 44 45
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;
46

47 48 49 50 51
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 已提交
52 53 54 55

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

    private static final Logger logger = LoggerFactory.getLogger(QueueController.class);

    @Autowired
    private QueueService queueService;


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

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

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

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

    /**
     * update queue
     *
B
bao liang 已提交
144
     * @param loginUser login user
145 146
     * @param queue     queue
     * @param id        queue id
B
bao liang 已提交
147 148
     * @param queueName queue name
     * @return update result code
L
ligang 已提交
149
     */
150
    @ApiOperation(value = "updateQueue", notes = "UPDATE_QUEUE_NOTES")
L
lidongdai 已提交
151
    @ApiImplicitParams({
152 153 154
            @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 已提交
155
    })
L
ligang 已提交
156 157
    @PostMapping(value = "/update")
    @ResponseStatus(HttpStatus.CREATED)
158
    @ApiException(UPDATE_QUEUE_ERROR)
L
lidongdai 已提交
159
    public Result updateQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
L
ligang 已提交
160 161 162 163
                              @RequestParam(value = "id") int id,
                              @RequestParam(value = "queue") String queue,
                              @RequestParam(value = "queueName") String queueName) {
        logger.info("login user {}, update queue, id: {}, queue: {}, queueName: {}",
164 165 166
                loginUser.getUserName(), id, queue, queueName);
        Map<String, Object> result = queueService.updateQueue(loginUser, id, queue, queueName);
        return returnDataList(result);
L
ligang 已提交
167 168
    }

L
ligang 已提交
169 170 171
    /**
     * verify queue and queue name
     *
B
bao liang 已提交
172
     * @param loginUser login user
173
     * @param queue     queue
B
bao liang 已提交
174 175
     * @param queueName queue name
     * @return true if the queue name not exists, otherwise return false
L
ligang 已提交
176
     */
177
    @ApiOperation(value = "verifyQueue", notes = "VERIFY_QUEUE_NOTES")
L
lidongdai 已提交
178
    @ApiImplicitParams({
179 180 181
            @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 已提交
182
    })
L
ligang 已提交
183 184
    @PostMapping(value = "/verify-queue")
    @ResponseStatus(HttpStatus.OK)
185
    @ApiException(VERIFY_QUEUE_ERROR)
L
lidongdai 已提交
186
    public Result verifyQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
187 188
                              @RequestParam(value = "queue") String queue,
                              @RequestParam(value = "queueName") String queueName
L
ligang 已提交
189 190
    ) {

191 192 193
        logger.info("login user {}, verfiy queue: {} queue name: {}",
                loginUser.getUserName(), queue, queueName);
        return queueService.verifyQueue(queue, queueName);
L
ligang 已提交
194 195
    }

L
ligang 已提交
196 197

}