You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/09/29 07:53:40 UTC

[GitHub] [dolphinscheduler] zhongjiajie commented on a diff in pull request #12116: [Feature][API] New restful API task and task relation

zhongjiajie commented on code in PR #12116:
URL: https://github.com/apache/dolphinscheduler/pull/12116#discussion_r983186132


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessTaskRelationV2Controller.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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_PROCESS_TASK_RELATION_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.DELETE_TASK_PROCESS_RELATION_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_UPSTREAM_TASK_PROCESS_RELATION_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.taskRelation.TaskRelationCreateRequest;
+import org.apache.dolphinscheduler.api.dto.taskRelation.TaskRelationDeleteRequest;
+import org.apache.dolphinscheduler.api.dto.taskRelation.TaskRelationUpdateUpstreamRequest;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.ProcessTaskRelationService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.Constants;
+import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import springfox.documentation.annotations.ApiIgnore;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.DeleteMapping;
+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;
+
+/**
+ * process task relation controller
+ */
+@Api(tags = "PROCESS_TASK_RELATION_TAG")
+@RestController
+@RequestMapping("v2/relations")
+public class ProcessTaskRelationV2Controller extends BaseController {
+
+    @Autowired
+    private ProcessTaskRelationService processTaskRelationService;
+
+    /**
+     * create resource process task relation
+     *
+     * @param loginUser login user
+     * @param TaskRelationCreateRequest process task definition json contains the object you want to create
+     * @return Result object created
+     */
+    @ApiOperation(value = "create", notes = "CREATE_PROCESS_TASK_RELATION_NOTES")
+    @PostMapping(consumes = {"application/json"})
+    @ResponseStatus(HttpStatus.CREATED)
+    @ApiException(CREATE_PROCESS_TASK_RELATION_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result<ProcessTaskRelation> createTaskRelation(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                                          @RequestBody TaskRelationCreateRequest TaskRelationCreateRequest) {
+        ProcessTaskRelation processTaskRelation =
+                processTaskRelationService.createProcessTaskRelationV2(loginUser, TaskRelationCreateRequest);
+        return Result.success(processTaskRelation);
+    }
+
+    /**
+     * delete resource process task relation
+     *
+     * @param loginUser login user
+     * @param codePair code pair you want to delete the task relation, use `upstream,downstream` as example, will delete exists relation upstream -> downstream, throw error if not exists
+     * @return delete result code
+     */
+    @ApiOperation(value = "delete", notes = "DELETE_PROCESS_TASK_RELATION_NOTES")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "code-pair", value = "TASK_DEFINITION_CODE", dataTypeClass = long.class, example = "123456,78901", required = true)
+    })
+    @DeleteMapping(value = "/{code-pair}")

Review Comment:
   I think it is ok, we have a actual example like `http://127.0.0.1:12345/dolphinscheduler/v2/relations/7009653961024,7009740799936`. We also have workflow API like `http://127.0.0.1:12345/dolphinscheduler/projects/7009653961024/process-definition/7009740799936` also have two snowflake id in url too



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org