QueueController.java 8.4 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 23 24 25
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.QueueService;
import org.apache.dolphinscheduler.api.utils.Constants;
import org.apache.dolphinscheduler.api.utils.Result;
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 56 57 58
@RestController
@RequestMapping("/queue")
public class QueueController extends BaseController{

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

    @Autowired
    private QueueService queueService;


    /**
     * query queue list
     * @param loginUser
     * @return
     */
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 75 76 77
    /**
     * query queue list paging
     * @param loginUser
     * @return
     */
L
lidongdai 已提交
78 79 80 81 82 83
    @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 已提交
84 85
    @GetMapping(value="/list-paging")
    @ResponseStatus(HttpStatus.OK)
L
lidongdai 已提交
86
    public Result queryQueueListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
L
ligang 已提交
87 88 89 90 91 92 93 94 95 96
                                  @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 已提交
97
            searchVal = ParameterUtils.handleEscapes(searchVal);
L
ligang 已提交
98
            result = queueService.queryList(loginUser,searchVal,pageNo,pageSize);
L
ligang 已提交
99
            return returnDataListPaging(result);
L
ligang 已提交
100
        }catch (Exception e){
Q
qiaozhanwei 已提交
101 102
            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 已提交
103 104 105 106 107 108 109 110 111 112 113
        }
    }

    /**
     * create queue
     *
     * @param loginUser
     * @param queue
     * @param queueName
     * @return
     */
L
lidongdai 已提交
114 115 116 117 118
    @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 已提交
119 120
    @PostMapping(value = "/create")
    @ResponseStatus(HttpStatus.CREATED)
L
lidongdai 已提交
121
    public Result createQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
L
ligang 已提交
122 123 124 125 126 127 128 129 130
                               @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 已提交
131 132
            logger.error(Status.CREATE_QUEUE_ERROR.getMsg(),e);
            return error(Status.CREATE_QUEUE_ERROR.getCode(), Status.CREATE_QUEUE_ERROR.getMsg());
L
ligang 已提交
133 134 135 136 137 138 139 140 141 142 143
        }
    }

    /**
     * update queue
     *
     * @param loginUser
     * @param queue
     * @param queueName
     * @return
     */
L
lidongdai 已提交
144 145 146 147 148 149
    @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 已提交
150 151
    @PostMapping(value = "/update")
    @ResponseStatus(HttpStatus.CREATED)
L
lidongdai 已提交
152
    public Result updateQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
L
ligang 已提交
153 154 155 156 157 158 159 160 161 162
                              @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 已提交
163 164
            logger.error(Status.UPDATE_QUEUE_ERROR.getMsg(),e);
            return error(Status.UPDATE_QUEUE_ERROR.getCode(), Status.UPDATE_QUEUE_ERROR.getMsg());
L
ligang 已提交
165 166 167
        }
    }

L
ligang 已提交
168 169 170 171 172 173 174 175
    /**
     * verify queue and queue name
     *
     * @param loginUser
     * @param queue
     * @param queueName
     * @return
     */
L
lidongdai 已提交
176 177 178 179 180 181
    @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 已提交
182 183
    @PostMapping(value = "/verify-queue")
    @ResponseStatus(HttpStatus.OK)
L
lidongdai 已提交
184
    public Result verifyQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
L
ligang 已提交
185 186 187 188 189 190 191 192 193
                                   @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 已提交
194
            logger.error(Status.VERIFY_QUEUE_ERROR.getMsg(),e);
L
ligang 已提交
195 196 197 198
            return error(Status.VERIFY_QUEUE_ERROR.getCode(), Status.VERIFY_QUEUE_ERROR.getMsg());
        }
    }

L
ligang 已提交
199 200

}