|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.dolphinscheduler.api.controller; |
| 19 | + |
| 20 | +import static org.apache.dolphinscheduler.api.enums.Status.CLOSE_TASK_GROUP_ERROR; |
| 21 | +import static org.apache.dolphinscheduler.api.enums.Status.CREATE_TASK_GROUP_ERROR; |
| 22 | +import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_GROUP_LIST_ERROR; |
| 23 | +import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_GROUP_QUEUE_LIST_ERROR; |
| 24 | +import static org.apache.dolphinscheduler.api.enums.Status.START_TASK_GROUP_ERROR; |
| 25 | +import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_TASK_GROUP_ERROR; |
| 26 | + |
| 27 | +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; |
| 28 | +import org.apache.dolphinscheduler.api.exceptions.ApiException; |
| 29 | +import org.apache.dolphinscheduler.api.service.TaskGroupQueueService; |
| 30 | +import org.apache.dolphinscheduler.api.service.TaskGroupService; |
| 31 | +import org.apache.dolphinscheduler.api.utils.Result; |
| 32 | +import org.apache.dolphinscheduler.common.Constants; |
| 33 | +import org.apache.dolphinscheduler.dao.entity.User; |
| 34 | + |
| 35 | +import java.util.Map; |
| 36 | + |
| 37 | +import org.springframework.beans.factory.annotation.Autowired; |
| 38 | +import org.springframework.http.HttpStatus; |
| 39 | +import org.springframework.web.bind.annotation.GetMapping; |
| 40 | +import org.springframework.web.bind.annotation.PostMapping; |
| 41 | +import org.springframework.web.bind.annotation.RequestAttribute; |
| 42 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 43 | +import org.springframework.web.bind.annotation.RequestParam; |
| 44 | +import org.springframework.web.bind.annotation.ResponseStatus; |
| 45 | +import org.springframework.web.bind.annotation.RestController; |
| 46 | + |
| 47 | +import io.swagger.annotations.Api; |
| 48 | +import io.swagger.annotations.ApiImplicitParam; |
| 49 | +import io.swagger.annotations.ApiImplicitParams; |
| 50 | +import io.swagger.annotations.ApiOperation; |
| 51 | +import springfox.documentation.annotations.ApiIgnore; |
| 52 | + |
| 53 | + |
| 54 | +/** |
| 55 | + * task group controller |
| 56 | + */ |
| 57 | +@Api(tags = "task group") |
| 58 | +@RestController |
| 59 | +@RequestMapping("/task-group") |
| 60 | +public class TaskGroupController extends BaseController { |
| 61 | + |
| 62 | + @Autowired |
| 63 | + private TaskGroupService taskGroupService; |
| 64 | + |
| 65 | + /** |
| 66 | + * query task group list |
| 67 | + * |
| 68 | + * @param loginUser login user |
| 69 | + * @param name name |
| 70 | + * @param description description |
| 71 | + * @param groupSize group size |
| 72 | + * @param name project id |
| 73 | + * @return result and msg code |
| 74 | + */ |
| 75 | + @ApiOperation(value = "createTaskGroup", notes = "CREATE_TAKS_GROUP_NOTE") |
| 76 | + @ApiImplicitParams({ |
| 77 | + @ApiImplicitParam(name = "name", value = "NAME", dataType = "String"), |
| 78 | + @ApiImplicitParam(name = "description", value = "DESCRIPTION", dataType = "String"), |
| 79 | + @ApiImplicitParam(name = "groupSize", value = "GROUPSIZE", dataType = "Int"), |
| 80 | + |
| 81 | + }) |
| 82 | + @PostMapping(value = "/create") |
| 83 | + @ResponseStatus(HttpStatus.CREATED) |
| 84 | + @ApiException(CREATE_TASK_GROUP_ERROR) |
| 85 | + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
| 86 | + public Result createTaskGroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
| 87 | + @RequestParam("name") String name, |
| 88 | + @RequestParam("description") String description, |
| 89 | + @RequestParam("groupSize") Integer groupSize) { |
| 90 | + Map<String, Object> result = taskGroupService.createTaskGroup(loginUser, name, description, groupSize); |
| 91 | + return returnDataList(result); |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * update task group list |
| 96 | + * |
| 97 | + * @param loginUser login user |
| 98 | + * @param name name |
| 99 | + * @param description description |
| 100 | + * @param groupSize group size |
| 101 | + * @param name project id |
| 102 | + * @return result and msg code |
| 103 | + */ |
| 104 | + @ApiOperation(value = "updateTaskGroup", notes = "UPDATE_TAKS_GROUP_NOTE") |
| 105 | + @ApiImplicitParams({ |
| 106 | + @ApiImplicitParam(name = "id", value = "id", dataType = "Int"), |
| 107 | + @ApiImplicitParam(name = "name", value = "NAME", dataType = "String"), |
| 108 | + @ApiImplicitParam(name = "description", value = "DESCRIPTION", dataType = "String"), |
| 109 | + @ApiImplicitParam(name = "groupSize", value = "GROUPSIZE", dataType = "Int"), |
| 110 | + |
| 111 | + }) |
| 112 | + @PostMapping(value = "/update") |
| 113 | + @ResponseStatus(HttpStatus.CREATED) |
| 114 | + @ApiException(UPDATE_TASK_GROUP_ERROR) |
| 115 | + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
| 116 | + public Result updateTaskGroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
| 117 | + @RequestParam("id") Integer id, |
| 118 | + @RequestParam("name") String name, |
| 119 | + @RequestParam("description") String description, |
| 120 | + @RequestParam("groupSize") Integer groupSize) { |
| 121 | + Map<String, Object> result = taskGroupService.updateTaskGroup(loginUser, id, name, description, groupSize); |
| 122 | + return returnDataList(result); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * query task group list paging |
| 127 | + * |
| 128 | + * @param loginUser login user |
| 129 | + * @param pageNo page number |
| 130 | + * @param pageSize page size |
| 131 | + * @return queue list |
| 132 | + */ |
| 133 | + @ApiOperation(value = "queryAllTaskGroup", notes = "QUERY_ALL_TASK_GROUP_NOTES") |
| 134 | + @ApiImplicitParams({ |
| 135 | + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), |
| 136 | + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") |
| 137 | + }) |
| 138 | + @GetMapping(value = "/query-list-all") |
| 139 | + @ResponseStatus(HttpStatus.OK) |
| 140 | + @ApiException(QUERY_TASK_GROUP_LIST_ERROR) |
| 141 | + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
| 142 | + public Result queryAllTaskGroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
| 143 | + @RequestParam("pageNo") Integer pageNo, |
| 144 | + @RequestParam("pageSize") Integer pageSize) { |
| 145 | + Map<String, Object> result = taskGroupService.queryAllTaskGroup(loginUser, pageNo, pageSize); |
| 146 | + return returnDataList(result); |
| 147 | + } |
| 148 | + |
| 149 | + /** |
| 150 | + * query task group list paging |
| 151 | + * |
| 152 | + * @param loginUser login user |
| 153 | + * @param pageNo page number |
| 154 | + * @param status status |
| 155 | + * @param pageSize page size |
| 156 | + * @return queue list |
| 157 | + */ |
| 158 | + @ApiOperation(value = "queryTaskGroupByStatus", notes = "QUERY_TASK_GROUP_LIST_BY_STSATUS_NOTES") |
| 159 | + @ApiImplicitParams({ |
| 160 | + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), |
| 161 | + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20"), |
| 162 | + @ApiImplicitParam(name = "status", value = "status", required = true, dataType = "Int") |
| 163 | + }) |
| 164 | + @GetMapping(value = "/query-list-by-status") |
| 165 | + @ResponseStatus(HttpStatus.OK) |
| 166 | + @ApiException(QUERY_TASK_GROUP_LIST_ERROR) |
| 167 | + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
| 168 | + public Result queryTaskGroupByStatus(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
| 169 | + @RequestParam("pageNo") Integer pageNo, |
| 170 | + @RequestParam(value = "status", required = false) Integer status, |
| 171 | + @RequestParam("pageSize") Integer pageSize) { |
| 172 | + Map<String, Object> result = taskGroupService.queryTaskGroupByStatus(loginUser, pageNo, pageSize, status); |
| 173 | + return returnDataList(result); |
| 174 | + } |
| 175 | + |
| 176 | + /** |
| 177 | + * query task group list paging by project id |
| 178 | + * |
| 179 | + * @param loginUser login user |
| 180 | + * @param pageNo page number |
| 181 | + * @param name project id |
| 182 | + * @param pageSize page size |
| 183 | + * @return queue list |
| 184 | + */ |
| 185 | + @ApiOperation(value = "queryTaskGroupByName", notes = "QUERY_TASK_GROUP_LIST_BY_PROJECT_ID_NOTES") |
| 186 | + @ApiImplicitParams({ |
| 187 | + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), |
| 188 | + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20"), |
| 189 | + @ApiImplicitParam(name = "name", value = "PROJECT_ID", required = true, dataType = "String") |
| 190 | + }) |
| 191 | + @GetMapping(value = "/query-list-by-name") |
| 192 | + @ResponseStatus(HttpStatus.OK) |
| 193 | + @ApiException(QUERY_TASK_GROUP_LIST_ERROR) |
| 194 | + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
| 195 | + public Result queryTaskGroupByName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
| 196 | + @RequestParam("pageNo") Integer pageNo, |
| 197 | + @RequestParam(value = "name", required = false) String name, |
| 198 | + @RequestParam("pageSize") Integer pageSize) { |
| 199 | + Map<String, Object> result = taskGroupService.queryTaskGroupByName(loginUser, pageNo, pageSize, name); |
| 200 | + return returnDataList(result); |
| 201 | + } |
| 202 | + |
| 203 | + /** |
| 204 | + * close a task group |
| 205 | + * |
| 206 | + * @param loginUser login user |
| 207 | + * @param id id |
| 208 | + * @return result |
| 209 | + */ |
| 210 | + @ApiOperation(value = "closeTaskGroup", notes = "CLOSE_TASK_GROUP_NOTES") |
| 211 | + @ApiImplicitParams({ |
| 212 | + @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Int") |
| 213 | + }) |
| 214 | + @PostMapping(value = "/close-task-group") |
| 215 | + @ResponseStatus(HttpStatus.CREATED) |
| 216 | + @ApiException(CLOSE_TASK_GROUP_ERROR) |
| 217 | + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
| 218 | + public Result closeTaskGroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
| 219 | + @RequestParam(value = "id", required = false) Integer id) { |
| 220 | + |
| 221 | + Map<String, Object> result = taskGroupService.closeTaskGroup(loginUser, id); |
| 222 | + return returnDataList(result); |
| 223 | + } |
| 224 | + |
| 225 | + /** |
| 226 | + * start a task group |
| 227 | + * |
| 228 | + * @param loginUser login user |
| 229 | + * @param id id |
| 230 | + * @return result |
| 231 | + */ |
| 232 | + @ApiOperation(value = "startTaskGroup", notes = "START_TASK_GROUP_NOTES") |
| 233 | + @ApiImplicitParams({ |
| 234 | + @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Int") |
| 235 | + }) |
| 236 | + @PostMapping(value = "/start-task-group") |
| 237 | + @ResponseStatus(HttpStatus.CREATED) |
| 238 | + @ApiException(START_TASK_GROUP_ERROR) |
| 239 | + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
| 240 | + public Result startTaskGroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
| 241 | + @RequestParam(value = "id", required = false) Integer id) { |
| 242 | + Map<String, Object> result = taskGroupService.startTaskGroup(loginUser, id); |
| 243 | + return returnDataList(result); |
| 244 | + } |
| 245 | + |
| 246 | + /** |
| 247 | + * force start task without task group |
| 248 | + * |
| 249 | + * @param loginUser login user |
| 250 | + * @param taskId task id |
| 251 | + * @return result |
| 252 | + */ |
| 253 | + @ApiOperation(value = "wakeCompulsively", notes = "WAKE_TASK_COMPULSIVELY_NOTES") |
| 254 | + @ApiImplicitParams({ |
| 255 | + @ApiImplicitParam(name = "taskId", value = "TASKID", required = true, dataType = "Int") |
| 256 | + }) |
| 257 | + @PostMapping(value = "/wake-task-compulsively") |
| 258 | + @ResponseStatus(HttpStatus.CREATED) |
| 259 | + @ApiException(START_TASK_GROUP_ERROR) |
| 260 | + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
| 261 | + public Result wakeCompulsively(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
| 262 | + @RequestParam(value = "taskId") Integer taskId) { |
| 263 | + Map<String, Object> result = taskGroupService.wakeTaskcompulsively(loginUser, taskId); |
| 264 | + return returnDataList(result); |
| 265 | + } |
| 266 | + |
| 267 | + @Autowired |
| 268 | + private TaskGroupQueueService taskGroupQueueService; |
| 269 | + |
| 270 | + /** |
| 271 | + * query task group queue list paging |
| 272 | + * |
| 273 | + * @param loginUser login user |
| 274 | + * @param pageNo page number |
| 275 | + * @param pageSize page size |
| 276 | + * @return queue list |
| 277 | + */ |
| 278 | + @ApiOperation(value = "queryTasksByGroupId", notes = "QUERY_ALL_TASKS_NOTES") |
| 279 | + @ApiImplicitParams({ |
| 280 | + @ApiImplicitParam(name = "groupId", value = "GROUP_ID", required = true, dataType = "Int", example = "1"), |
| 281 | + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), |
| 282 | + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") |
| 283 | + }) |
| 284 | + @GetMapping(value = "/query-list-by-group-id") |
| 285 | + @ResponseStatus(HttpStatus.OK) |
| 286 | + @ApiException(QUERY_TASK_GROUP_QUEUE_LIST_ERROR) |
| 287 | + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
| 288 | + public Result queryTasksByGroupId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
| 289 | + @RequestParam("groupId") Integer groupId, |
| 290 | + @RequestParam("pageNo") Integer pageNo, |
| 291 | + @RequestParam("pageSize") Integer pageSize) { |
| 292 | + Map<String, Object> result = taskGroupQueueService.queryTasksByGroupId(loginUser, groupId, pageNo, pageSize); |
| 293 | + return returnDataList(result); |
| 294 | + } |
| 295 | + |
| 296 | +} |
0 commit comments