QueueController.java 8.7 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 21 22
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.QueueService;
import org.apache.dolphinscheduler.api.utils.Result;
23
import org.apache.dolphinscheduler.common.Constants;
Q
qiaozhanwei 已提交
24 25
import org.apache.dolphinscheduler.common.utils.ParameterUtils;
import org.apache.dolphinscheduler.dao.entity.User;
L
lidongdai 已提交
26 27 28 29
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
L
ligang 已提交
30 31 32 33 34
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 已提交
35
import springfox.documentation.annotations.ApiIgnore;
L
ligang 已提交
36 37 38 39 40 41 42

import java.util.Map;


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

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

    @Autowired
    private QueueService queueService;


    /**
     * query queue list
B
bao liang 已提交
56 57
     * @param loginUser login user
     * @return queue list
L
ligang 已提交
58
     */
L
lidongdai 已提交
59
    @ApiOperation(value = "queryList", notes= "QUERY_QUEUE_LIST_NOTES")
L
ligang 已提交
60 61
    @GetMapping(value="/list")
    @ResponseStatus(HttpStatus.OK)
L
lidongdai 已提交
62
    public Result queryList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser){
L
ligang 已提交
63 64 65 66 67
        try{
            logger.info("login user {}, query queue list", loginUser.getUserName());
            Map<String, Object> result = queueService.queryList(loginUser);
            return returnDataList(result);
        }catch (Exception e){
Q
qiaozhanwei 已提交
68 69
            logger.error(Status.QUERY_QUEUE_LIST_ERROR.getMsg(),e);
            return error(Status.QUERY_QUEUE_LIST_ERROR.getCode(), Status.QUERY_QUEUE_LIST_ERROR.getMsg());
L
ligang 已提交
70 71 72
        }
    }

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

B
baoliang 已提交
100
            searchVal = ParameterUtils.handleEscapes(searchVal);
L
ligang 已提交
101
            result = queueService.queryList(loginUser,searchVal,pageNo,pageSize);
L
ligang 已提交
102
            return returnDataListPaging(result);
L
ligang 已提交
103
        }catch (Exception e){
Q
qiaozhanwei 已提交
104 105
            logger.error(Status.QUERY_QUEUE_LIST_ERROR.getMsg(),e);
            return error(Status.QUERY_QUEUE_LIST_ERROR.getCode(), Status.QUERY_QUEUE_LIST_ERROR.getMsg());
L
ligang 已提交
106 107 108 109 110 111
        }
    }

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

        }catch (Exception e){
Q
qiaozhanwei 已提交
134 135
            logger.error(Status.CREATE_QUEUE_ERROR.getMsg(),e);
            return error(Status.CREATE_QUEUE_ERROR.getCode(), Status.CREATE_QUEUE_ERROR.getMsg());
L
ligang 已提交
136 137 138 139 140 141
        }
    }

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

        }catch (Exception e){
Q
qiaozhanwei 已提交
167 168
            logger.error(Status.UPDATE_QUEUE_ERROR.getMsg(),e);
            return error(Status.UPDATE_QUEUE_ERROR.getCode(), Status.UPDATE_QUEUE_ERROR.getMsg());
L
ligang 已提交
169 170 171
        }
    }

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

        try{
            logger.info("login user {}, verfiy queue: {} queue name: {}",
                    loginUser.getUserName(),queue,queueName);
            return queueService.verifyQueue(queue,queueName);
        }catch (Exception e){
Q
qiaozhanwei 已提交
198
            logger.error(Status.VERIFY_QUEUE_ERROR.getMsg(),e);
L
ligang 已提交
199 200 201 202
            return error(Status.VERIFY_QUEUE_ERROR.getCode(), Status.VERIFY_QUEUE_ERROR.getMsg());
        }
    }

L
ligang 已提交
203 204

}