QueueController.java 8.0 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.
 */
Q
qiaozhanwei 已提交
17
package org.apache.dolphinscheduler.api.controller;
L
ligang 已提交
18 19


Q
qiaozhanwei 已提交
20
import org.apache.dolphinscheduler.api.enums.Status;
21
import org.apache.dolphinscheduler.api.exceptions.ApiException;
Q
qiaozhanwei 已提交
22 23
import org.apache.dolphinscheduler.api.service.QueueService;
import org.apache.dolphinscheduler.api.utils.Result;
24
import org.apache.dolphinscheduler.common.Constants;
Q
qiaozhanwei 已提交
25 26
import org.apache.dolphinscheduler.common.utils.ParameterUtils;
import org.apache.dolphinscheduler.dao.entity.User;
L
lidongdai 已提交
27 28 29 30
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
L
ligang 已提交
31 32 33 34 35
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
L
lidongdai 已提交
36
import springfox.documentation.annotations.ApiIgnore;
L
ligang 已提交
37 38 39

import java.util.Map;

40 41
import static org.apache.dolphinscheduler.api.enums.Status.*;

L
ligang 已提交
42 43 44 45

/**
 * queue controller
 */
L
lidongdai 已提交
46
@Api(tags = "QUEUE_TAG", position = 1)
L
ligang 已提交
47 48
@RestController
@RequestMapping("/queue")
49
public class QueueController extends BaseController {
L
ligang 已提交
50 51 52 53 54 55 56 57 58

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

    @Autowired
    private QueueService queueService;


    /**
     * query queue list
59
     *
B
bao liang 已提交
60 61
     * @param loginUser login user
     * @return queue list
L
ligang 已提交
62
     */
63 64
    @ApiOperation(value = "queryList", notes = "QUERY_QUEUE_LIST_NOTES")
    @GetMapping(value = "/list")
L
ligang 已提交
65
    @ResponseStatus(HttpStatus.OK)
66 67 68 69 70
    @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 已提交
71 72
    }

L
ligang 已提交
73 74
    /**
     * query queue list paging
75
     *
B
bao liang 已提交
76
     * @param loginUser login user
77
     * @param pageNo    page number
B
bao liang 已提交
78
     * @param searchVal search value
79
     * @param pageSize  page size
B
bao liang 已提交
80
     * @return queue list
L
ligang 已提交
81
     */
82
    @ApiOperation(value = "queryQueueListPaging", notes = "QUERY_QUEUE_LIST_PAGING_NOTES")
L
lidongdai 已提交
83
    @ApiImplicitParams({
84
            @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"),
L
lidongdai 已提交
85
            @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"),
86
            @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20")
L
lidongdai 已提交
87
    })
88
    @GetMapping(value = "/list-paging")
L
ligang 已提交
89
    @ResponseStatus(HttpStatus.OK)
90
    @ApiException(QUERY_QUEUE_LIST_ERROR)
L
lidongdai 已提交
91
    public Result queryQueueListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
92 93 94 95 96 97
                                       @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 已提交
98
            return returnDataListPaging(result);
L
ligang 已提交
99
        }
100 101 102 103

        searchVal = ParameterUtils.handleEscapes(searchVal);
        result = queueService.queryList(loginUser, searchVal, pageNo, pageSize);
        return returnDataListPaging(result);
L
ligang 已提交
104 105 106 107 108
    }

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

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

L
ligang 已提交
159 160 161
    /**
     * verify queue and queue name
     *
B
bao liang 已提交
162
     * @param loginUser login user
163
     * @param queue     queue
B
bao liang 已提交
164 165
     * @param queueName queue name
     * @return true if the queue name not exists, otherwise return false
L
ligang 已提交
166
     */
167
    @ApiOperation(value = "verifyQueue", notes = "VERIFY_QUEUE_NOTES")
L
lidongdai 已提交
168
    @ApiImplicitParams({
169 170 171
            @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 已提交
172
    })
L
ligang 已提交
173 174
    @PostMapping(value = "/verify-queue")
    @ResponseStatus(HttpStatus.OK)
175
    @ApiException(VERIFY_QUEUE_ERROR)
L
lidongdai 已提交
176
    public Result verifyQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
177 178
                              @RequestParam(value = "queue") String queue,
                              @RequestParam(value = "queueName") String queueName
L
ligang 已提交
179 180
    ) {

181 182 183
        logger.info("login user {}, verfiy queue: {} queue name: {}",
                loginUser.getUserName(), queue, queueName);
        return queueService.verifyQueue(queue, queueName);
L
ligang 已提交
184 185
    }

L
ligang 已提交
186 187

}