diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/QueueV2Controller.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/QueueV2Controller.java new file mode 100644 index 0000000000..a19aaed2c3 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/QueueV2Controller.java @@ -0,0 +1,174 @@ +/* + * 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. + */ + +package org.apache.dolphinscheduler.api.controller; + +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; + +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; +import org.apache.dolphinscheduler.api.dto.queue.QueueCreateRequest; +import org.apache.dolphinscheduler.api.dto.queue.QueueCreateResponse; +import org.apache.dolphinscheduler.api.dto.queue.QueueListPagingResponse; +import org.apache.dolphinscheduler.api.dto.queue.QueueListResponse; +import org.apache.dolphinscheduler.api.dto.queue.QueueQueryRequest; +import org.apache.dolphinscheduler.api.dto.queue.QueueUpdateRequest; +import org.apache.dolphinscheduler.api.dto.queue.QueueUpdateResponse; +import org.apache.dolphinscheduler.api.dto.queue.QueueVerifyRequest; +import org.apache.dolphinscheduler.api.dto.queue.QueueVerifyResponse; +import org.apache.dolphinscheduler.api.exceptions.ApiException; +import org.apache.dolphinscheduler.api.service.QueueService; +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.common.Constants; +import org.apache.dolphinscheduler.common.utils.ParameterUtils; +import org.apache.dolphinscheduler.dao.entity.User; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +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; + +/** + * queue controller + */ +@Api(tags = "QUEUE_TAG") +@RestController +@RequestMapping("/v2/queues") +public class QueueV2Controller extends BaseController { + + @Autowired + private QueueService queueService; + + /** + * query queue list + * + * @param loginUser login user + * @return queue list + */ + @ApiOperation(value = "queryList", notes = "QUERY_QUEUE_LIST_NOTES") + @GetMapping(value = "/list") + @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_QUEUE_LIST_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public QueueListResponse queryList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { + Result result = queueService.queryList(loginUser); + return new QueueListResponse(result); + } + + /** + * query queue list paging + * + * @param loginUser login user + * @param queueQueryRequest queueQueryRequest + * @return queue list + */ + @ApiOperation(value = "queryQueueListPaging", notes = "QUERY_QUEUE_LIST_PAGING_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataTypeClass = String.class), + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataTypeClass = int.class, example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataTypeClass = int.class, example = "20") + }) + @GetMapping() + @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_QUEUE_LIST_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public QueueListPagingResponse queryQueueListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + QueueQueryRequest queueQueryRequest) { + Result result = checkPageParams(queueQueryRequest.getPageNo(), queueQueryRequest.getPageSize()); + if (!result.checkResult()) { + return new QueueListPagingResponse(result); + } + + String searchVal = ParameterUtils.handleEscapes(queueQueryRequest.getSearchVal()); + result = queueService.queryList(loginUser, searchVal, queueQueryRequest.getPageNo(), queueQueryRequest.getPageSize()); + return new QueueListPagingResponse(result); + } + + /** + * create queue + * + * @param loginUser login user + * @param queueCreateRequest queueCreateRequest + * @return create result + */ + @ApiOperation(value = "createQueue", notes = "CREATE_QUEUE_NOTES") + @PostMapping(consumes = {"application/json"}) + @ResponseStatus(HttpStatus.CREATED) + @ApiException(CREATE_QUEUE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public QueueCreateResponse createQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestBody QueueCreateRequest queueCreateRequest) { + Result result = queueService.createQueue(loginUser, queueCreateRequest.getQueue(), queueCreateRequest.getQueueName()); + return new QueueCreateResponse(result); + } + + /** + * update queue + * + * @param loginUser login user + * @param id queue id + * @param queueUpdateRequest queueUpdateRequest + * @return update result code + */ + @ApiOperation(value = "updateQueue", notes = "UPDATE_QUEUE_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "QUEUE_ID", required = true, dataTypeClass = int.class, example = "100") + }) + @PutMapping(value = "/{id}", consumes = {"application/json"}) + @ResponseStatus(HttpStatus.CREATED) + @ApiException(UPDATE_QUEUE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public QueueUpdateResponse updateQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @PathVariable(value = "id") int id, @RequestBody QueueUpdateRequest queueUpdateRequest) { + Result result = queueService.updateQueue(loginUser, id, queueUpdateRequest.getQueue(), + queueUpdateRequest.getQueueName()); + return new QueueUpdateResponse(result); + } + + /** + * verify queue and queue name + * + * @param loginUser login user + * @param queueVerifyRequest queueVerifyRequest + * @return true if the queue name not exists, otherwise return false + */ + @ApiOperation(value = "verifyQueue", notes = "VERIFY_QUEUE_NOTES") + @PostMapping(value = "/verify", consumes = {"application/json"}) + @ResponseStatus(HttpStatus.OK) + @ApiException(VERIFY_QUEUE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public QueueVerifyResponse verifyQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestBody QueueVerifyRequest queueVerifyRequest) { + Result result = queueService.verifyQueue(queueVerifyRequest.getQueue(), queueVerifyRequest.getQueueName()); + return new QueueVerifyResponse(result); + } +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueCreateRequest.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueCreateRequest.java new file mode 100644 index 0000000000..702826fe32 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueCreateRequest.java @@ -0,0 +1,36 @@ +/* + * 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. + */ + +package org.apache.dolphinscheduler.api.dto.queue; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * queue create request + */ +@ApiModel("QUEUE-CREATE") +@Data +public class QueueCreateRequest { + + @ApiModelProperty(example = "queue11", required = true) + private String queue; + + @ApiModelProperty(example = "test_queue11", required = true) + private String queueName; +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueCreateResponse.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueCreateResponse.java new file mode 100644 index 0000000000..6d508f40d6 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueCreateResponse.java @@ -0,0 +1,39 @@ +/* + * 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. + */ + +package org.apache.dolphinscheduler.api.dto.queue; + +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.dao.entity.Queue; + +import lombok.Data; + +/** + * queue create response + */ +@Data +public class QueueCreateResponse extends Result { + + private Queue data; + + public QueueCreateResponse(Result result) { + super(); + this.setCode(result.getCode()); + this.setMsg(result.getMsg()); + this.setData((Queue) result.getData()); + } +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueListPagingResponse.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueListPagingResponse.java new file mode 100644 index 0000000000..da4f542cbf --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueListPagingResponse.java @@ -0,0 +1,40 @@ +/* + * 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. + */ + +package org.apache.dolphinscheduler.api.dto.queue; + +import org.apache.dolphinscheduler.api.utils.PageInfo; +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.dao.entity.Queue; + +import lombok.Data; + +/** + * queue list paging response + */ +@Data +public class QueueListPagingResponse extends Result { + + private PageInfo data; + + public QueueListPagingResponse(Result result) { + super(); + this.setCode(result.getCode()); + this.setMsg(result.getMsg()); + this.setData(result.getData()); + } +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueListResponse.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueListResponse.java new file mode 100644 index 0000000000..d0bfbb2abf --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueListResponse.java @@ -0,0 +1,43 @@ +/* + * 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. + */ + +package org.apache.dolphinscheduler.api.dto.queue; + +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.common.utils.JSONUtils; +import org.apache.dolphinscheduler.dao.entity.Project; +import org.apache.dolphinscheduler.dao.entity.Queue; + +import java.util.List; + +import lombok.Data; + +/** + * queue List response + */ +@Data +public class QueueListResponse extends Result { + + private List data; + + public QueueListResponse(Result result) { + super(); + this.setCode(result.getCode()); + this.setMsg(result.getMsg()); + this.setData(JSONUtils.toList(JSONUtils.toJsonString(result.getData()), Project.class)); + } +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueQueryRequest.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueQueryRequest.java new file mode 100644 index 0000000000..727d8b12c6 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueQueryRequest.java @@ -0,0 +1,40 @@ +/* + * 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. + */ + +package org.apache.dolphinscheduler.api.dto.queue; + +import org.apache.dolphinscheduler.api.dto.PageQueryDto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * queue query request + */ +@ApiModel("QUEUE-QUERY") +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@Data +public class QueueQueryRequest extends PageQueryDto { + + @ApiModelProperty(example = "queue11") + private String searchVal; +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueUpdateRequest.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueUpdateRequest.java new file mode 100644 index 0000000000..fd04318a03 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueUpdateRequest.java @@ -0,0 +1,41 @@ +/* + * 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. + */ + +package org.apache.dolphinscheduler.api.dto.queue; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * queue update request + */ +@ApiModel("QUEUE-UPDATE") +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@Data +public class QueueUpdateRequest { + + @ApiModelProperty(example = "queue11", required = true) + private String queue; + + @ApiModelProperty(example = "test_queue11", required = true) + private String queueName; +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueUpdateResponse.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueUpdateResponse.java new file mode 100644 index 0000000000..a0edf4b315 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueUpdateResponse.java @@ -0,0 +1,39 @@ +/* + * 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. + */ + +package org.apache.dolphinscheduler.api.dto.queue; + +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.dao.entity.Queue; + +import lombok.Data; + +/** + * queue update response + */ +@Data +public class QueueUpdateResponse extends Result { + + private Queue data; + + public QueueUpdateResponse(Result result) { + super(); + this.setCode(result.getCode()); + this.setMsg(result.getMsg()); + this.setData((Queue) result.getData()); + } +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueVerifyRequest.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueVerifyRequest.java new file mode 100644 index 0000000000..88e5359843 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueVerifyRequest.java @@ -0,0 +1,36 @@ +/* + * 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. + */ + +package org.apache.dolphinscheduler.api.dto.queue; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * queue verify request + */ +@ApiModel("QUEUE-Verify") +@Data +public class QueueVerifyRequest { + + @ApiModelProperty(example = "queue11", required = true) + private String queue; + + @ApiModelProperty(example = "queue11", required = true) + private String queueName; +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueVerifyResponse.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueVerifyResponse.java new file mode 100644 index 0000000000..fea6c9079f --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/queue/QueueVerifyResponse.java @@ -0,0 +1,39 @@ +/* + * 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. + */ + +package org.apache.dolphinscheduler.api.dto.queue; + +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.dao.entity.Queue; + +import lombok.Data; + +/** + * queue verify response + */ +@Data +public class QueueVerifyResponse extends Result { + + private Queue data; + + public QueueVerifyResponse(Result result) { + super(); + this.setCode(result.getCode()); + this.setMsg(result.getMsg()); + this.setData((Queue) result.getData()); + } +} diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/QueueV2ControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/QueueV2ControllerTest.java new file mode 100644 index 0000000000..e4235ad7f2 --- /dev/null +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/QueueV2ControllerTest.java @@ -0,0 +1,173 @@ +/* + * 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. + */ + +package org.apache.dolphinscheduler.api.controller; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.apache.dolphinscheduler.api.dto.queue.QueueCreateRequest; +import org.apache.dolphinscheduler.api.dto.queue.QueueQueryRequest; +import org.apache.dolphinscheduler.api.dto.queue.QueueUpdateRequest; +import org.apache.dolphinscheduler.api.dto.queue.QueueVerifyRequest; +import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.common.utils.JSONUtils; + +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MvcResult; + +/** + * queue v2 controller test + */ +public class QueueV2ControllerTest extends AbstractControllerTest { + private static final Logger logger = LoggerFactory.getLogger(QueueV2ControllerTest.class); + + private static final String QUEUE_CREATE_NAME = "queue_create"; + private static final String QUEUE_MODIFY_NAME = "queue_modify"; + private static final String QUEUE_NAME_CREATE_NAME = "queue_name_create"; + private static final String QUEUE_NAME_MODIFY_NAME = "queue_name_modify"; + private static final String NOT_EXISTS_NAME = "not_exists"; + + @Test + public void testQueryList() throws Exception { + MvcResult mvcResult = mockMvc.perform(get("/v2/queues/list") + .header(SESSION_ID, sessionId) + .accept(MediaType.ALL) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn(); + + Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); + Assert.assertNotNull(result); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); + logger.info("query list queue return result:{}", mvcResult.getResponse().getContentAsString()); + } + + @Test + public void testQueryQueueListPagingEmpty() throws Exception { + QueueQueryRequest queueQueryRequest = new QueueQueryRequest(); + queueQueryRequest.setSearchVal(""); + queueQueryRequest.setPageNo(1); + queueQueryRequest.setPageSize(20); + + MvcResult mvcResult = mockMvc.perform(get("/v2/queues") + .header(SESSION_ID, sessionId) + .accept(MediaType.ALL) + .contentType(MediaType.APPLICATION_JSON) + .content(JSONUtils.toJsonString(queueQueryRequest))) + .andExpect(status().isOk()) + .andReturn(); + Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); + + Assert.assertNotNull(result); + logger.info("query list-paging queue return result:{}", mvcResult.getResponse().getContentAsString()); + } + + @Test + public void testCreateQueue() throws Exception { + QueueCreateRequest queueCreateRequest = new QueueCreateRequest(); + queueCreateRequest.setQueue(QUEUE_CREATE_NAME); + queueCreateRequest.setQueueName(QUEUE_NAME_CREATE_NAME); + MvcResult mvcResult = mockMvc.perform(post("/v2/queues") + .header(SESSION_ID, sessionId) + .accept(MediaType.ALL) + .contentType(MediaType.APPLICATION_JSON) + .content(JSONUtils.toJsonString(queueCreateRequest))) + .andExpect(status().isCreated()) + .andReturn(); + Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); + + Assert.assertNotNull(result); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); + logger.info("create queue return result:{}", mvcResult.getResponse().getContentAsString()); + } + + @Test + public void testUpdateQueue() throws Exception { + QueueUpdateRequest queueUpdateRequest = new QueueUpdateRequest(); + queueUpdateRequest.setQueue(QUEUE_MODIFY_NAME); + queueUpdateRequest.setQueueName(QUEUE_NAME_MODIFY_NAME); + MvcResult mvcResult = mockMvc.perform(put("/v2/queues/{id}", 1) + .header(SESSION_ID, sessionId) + .accept(MediaType.ALL) + .contentType(MediaType.APPLICATION_JSON) + .content(JSONUtils.toJsonString(queueUpdateRequest))) + .andExpect(status().isCreated()) + .andReturn(); + Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); + + Assert.assertNotNull(result); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); + logger.info("update queue return result:{}", mvcResult.getResponse().getContentAsString()); + } + + @Test + public void testVerifyQueue() throws Exception { + // queue value exist + QueueVerifyRequest queueVerifyRequest = new QueueVerifyRequest(); + queueVerifyRequest.setQueue(QUEUE_MODIFY_NAME); + queueVerifyRequest.setQueueName(NOT_EXISTS_NAME); + MvcResult mvcResult = mockMvc.perform(post("/v2/queues/verify") + .header(SESSION_ID, sessionId) + .accept(MediaType.ALL) + .contentType(MediaType.APPLICATION_JSON) + .content(JSONUtils.toJsonString(queueVerifyRequest))) + .andExpect(status().isOk()) + .andReturn(); + + Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); + Assert.assertNotNull(result); + Assert.assertEquals(Status.QUEUE_VALUE_EXIST.getCode(), result.getCode().intValue()); + + // queue name exist + queueVerifyRequest.setQueue(NOT_EXISTS_NAME); + queueVerifyRequest.setQueueName(QUEUE_NAME_CREATE_NAME); + mvcResult = mockMvc.perform(post("/v2/queues/verify") + .header(SESSION_ID, sessionId) + .accept(MediaType.ALL) + .contentType(MediaType.APPLICATION_JSON) + .content(JSONUtils.toJsonString(queueVerifyRequest))) + .andExpect(status().isOk()) + .andReturn(); + result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); + Assert.assertNotNull(result); + Assert.assertEquals(Status.QUEUE_NAME_EXIST.getCode(), result.getCode().intValue()); + + // success + queueVerifyRequest.setQueue(NOT_EXISTS_NAME); + queueVerifyRequest.setQueueName(NOT_EXISTS_NAME); + mvcResult = mockMvc.perform(post("/v2/queues/verify") + .header(SESSION_ID, sessionId) + .accept(MediaType.ALL) + .contentType(MediaType.APPLICATION_JSON) + .content(JSONUtils.toJsonString(queueVerifyRequest))) + .andExpect(status().isOk()) + .andReturn(); + result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); + Assert.assertNotNull(result); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); + logger.info(mvcResult.getResponse().getContentAsString()); + logger.info("verify queue return result:{}", mvcResult.getResponse().getContentAsString()); + } +}