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:05:41 UTC

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

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


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/task/TaskCreateRequest.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.task;
+
+import static org.apache.dolphinscheduler.common.Constants.VERSION_FIRST;
+
+import org.apache.dolphinscheduler.common.enums.Flag;
+import org.apache.dolphinscheduler.common.enums.Priority;
+import org.apache.dolphinscheduler.common.enums.TimeoutFlag;
+import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskTimeoutStrategy;
+
+import java.util.Date;
+
+import lombok.Data;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * task create request
+ */
+@Data
+public class TaskCreateRequest {
+
+    @ApiModelProperty(example = "workflow-code", required = true)
+    private long workflowCode;
+    @ApiModelProperty(example = "task-name", required = true)
+    private String name;
+    @ApiModelProperty(example = "describe what this task actual do", required = true)
+    private String description;
+
+    @ApiModelProperty(example = "6816095515584", dataType = "Long")
+    private long projectCode;
+
+    @ApiModelProperty(example = "SHELL", required = true)
+    private String taskType;
+
+    // todo
+    @ApiModelProperty(example = "{\"localParams\": [], \"rawScript\": \"echo 1\", \"resourceList\": []}", required = true, notes = "task definition params")
+    private String taskParams;
+
+    @ApiModelProperty(example = "YES", allowableValues = "YES,NO", notes = "default YES is not provided")
+    private String flag;
+
+    @ApiModelProperty(example = "MEDIUM", allowableValues = "HIGHEST,HIGH,MEDIUM,LOW,LOWEST", notes = "default MEDIUM is not provided")
+    private String taskPriority;
+
+    @ApiModelProperty(example = "default", notes = "default 'default' if not provided")
+    private String workerGroup;
+
+    @ApiModelProperty(example = "6563415109312", dataType = "Long")
+    private long environmentCode;
+
+    @ApiModelProperty(example = "0", dataType = "Integer", notes = "default 0 not provided")
+    private int failRetryTimes;
+
+    @ApiModelProperty(example = "1")
+    private int failRetryInterval;
+
+    @ApiModelProperty(example = "SHELL")
+    private int timeout;
+
+    @ApiModelProperty(example = "CLOSE", allowableValues = "CLOSE,OPEN", notes = "default CLOSE is not provided")
+    private String timeoutFlag;
+
+    @ApiModelProperty(example = "MEDIUM", allowableValues = "WARN,FAILED,WARNFAILED", notes = "default MEDIUM is not provided")
+    private String timeoutNotifyStrategy;
+
+    @ApiModelProperty(example = "1,2,3")
+    private String resourceIds;
+
+    @ApiModelProperty(example = "2")
+    private int taskGroupId;
+
+    @ApiModelProperty(example = "1", dataType = "Integer", notes = "A priority number for execute task, the bigger the high priority, default null if not provided")
+    private int taskGroupPriority;
+
+    @ApiModelProperty(example = "0.1", dataType = "Float", notes = "default unlimited if not provided")
+    private Integer cpuQuota;
+
+    @ApiModelProperty(example = "0.1", dataType = "Float", notes = "default unlimited if not provided")
+    private Integer memoryMax;
+
+    @ApiModelProperty(example = "upstream-task-codes1,upstream-task-codes2", notes = "use , to split multiple upstream task codes")
+    private String upstreamTasksCodes;
+
+    public TaskDefinition convert2TaskDefinition() {
+        TaskDefinition taskDefinition = new TaskDefinition();
+
+        taskDefinition.setName(this.name);
+        taskDefinition.setDescription(this.description);
+        taskDefinition.setProjectCode(this.projectCode);
+        taskDefinition.setTaskType(this.taskType);
+        taskDefinition.setTaskParams(this.taskParams);
+        taskDefinition.setWorkerGroup(this.workerGroup == null ? "default" : this.workerGroup);

Review Comment:
   use constant "default"



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/task/TaskUpdateRequest.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.task;
+
+import org.apache.dolphinscheduler.common.enums.Flag;
+import org.apache.dolphinscheduler.common.enums.Priority;
+import org.apache.dolphinscheduler.common.enums.TimeoutFlag;
+import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskTimeoutStrategy;
+
+import org.apache.commons.beanutils.BeanUtils;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Date;
+
+import lombok.Data;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * task update request
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@Data
+public class TaskUpdateRequest {
+
+    @ApiModelProperty(example = "workflow-code", required = true)
+    private long workflowCode;
+    @ApiModelProperty(example = "task-name")
+    private String name;
+    @ApiModelProperty(example = "describe what this task actual do")
+    private String description;
+
+    @ApiModelProperty(example = "SHELL")
+    private String taskType;
+
+    // todo
+    @ApiModelProperty(example = "{\"localParams\": [], \"rawScript\": \"echo 1\", \"resourceList\": []}", notes = "task definition params")
+    private String taskParams;
+
+    @ApiModelProperty(example = "YES", allowableValues = "YES,NO", notes = "default YES is not provided")
+    private String flag;
+
+    @ApiModelProperty(example = "MEDIUM", allowableValues = "HIGHEST,HIGH,MEDIUM,LOW,LOWEST", notes = "default MEDIUM is not provided")
+    private String taskPriority;
+
+    @ApiModelProperty(example = "default", notes = "default 'default' if not provided")
+    private String workerGroup;
+
+    @ApiModelProperty(example = "6563415109312", dataType = "Long")
+    private long environmentCode;
+
+    @ApiModelProperty(example = "0", dataType = "Integer", notes = "default 0 not provided")
+    private int failRetryTimes;
+
+    @ApiModelProperty(example = "1")
+    private int failRetryInterval;
+
+    @ApiModelProperty(example = "SHELL")
+    private int timeout;
+
+    @ApiModelProperty(example = "CLOSE", allowableValues = "CLOSE,OPEN", notes = "default CLOSE is not provided")
+    private String timeoutFlag;
+
+    @ApiModelProperty(example = "MEDIUM", allowableValues = "WARN,FAILED,WARNFAILED", notes = "default MEDIUM is not provided")
+    private String timeoutNotifyStrategy;
+
+    @ApiModelProperty(example = "1,2,3")
+    private String resourceIds;
+
+    @ApiModelProperty(example = "2")
+    private int taskGroupId;
+
+    @ApiModelProperty(example = "1", dataType = "Integer", notes = "A priority number for execute task, the bigger the high priority, default null if not provided")
+    private int taskGroupPriority;
+
+    @ApiModelProperty(example = "0.1", dataType = "Float", notes = "default unlimited if not provided")
+    private Integer cpuQuota;
+
+    @ApiModelProperty(example = "0.1", dataType = "Float", notes = "default unlimited if not provided")
+    private Integer memoryMax;
+
+    @ApiModelProperty(example = "upstream-task-codes1,upstream-task-codes2", notes = "use , to split multiple upstream task codes")
+    private String upstreamTasksCodes;
+
+    public TaskDefinition mergeIntoProcessDefinition(TaskDefinition taskDefinition) throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException {

Review Comment:
   Please add the comments for it.



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessTaskRelationServiceImpl.java:
##########
@@ -165,6 +174,84 @@ public Map<String, Object> createProcessTaskRelation(User loginUser, long projec
         return result;
     }
 
+    private ProcessTaskRelationLog syncObj2Log(User user, ProcessTaskRelation processTaskRelation) {
+        ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(processTaskRelation);
+        processTaskRelationLog.setOperator(user.getId());
+        processTaskRelationLog.setOperateTime(new Date());
+        int result = processTaskRelationLogMapper.insert(processTaskRelationLog);
+        if (result <= 0) {
+            throw new ServiceException(Status.CREATE_PROCESS_TASK_RELATION_LOG_ERROR,
+                    processTaskRelationLog.getPreTaskCode(), processTaskRelationLog.getPostTaskCode());
+        }
+        return processTaskRelationLog;
+    }
+
+    private List<ProcessTaskRelationLog> batchSyncObj2Log(User user, List<ProcessTaskRelation> processTaskRelations) {

Review Comment:
   ```suggestion
       private List<ProcessTaskRelationLog> convert2ProcessTaskRelationLog(User user, List<ProcessTaskRelation> processTaskRelations) {
   ```



##########
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:
   It seems the url path can get very long.



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/taskRelation/TaskRelationDeleteRequest.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.taskRelation;
+
+import static org.apache.dolphinscheduler.common.Constants.COMMA;
+
+import java.util.stream.Stream;
+
+import lombok.Setter;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * task relation want to delete request
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@Setter
+public class TaskRelationDeleteRequest {
+
+    @ApiModelProperty(example = "12345678,87654321", required = true, notes = "relation pair want to delete relation, separated by comma")
+    private String codePair;
+
+    private long[] parseCodePair(String codePair) {
+        return Stream.of(codePair.split(COMMA))
+                .map(String::trim)
+                .mapToLong(Long::parseLong)
+                .toArray();
+    }
+
+    public long getUpstreamCode() {
+        return this.parseCodePair(codePair)[0];
+    }
+
+    public long getDownstreamCode() {
+        return this.parseCodePair(codePair)[1];
+    }

Review Comment:
   It's better to split in constructor, and then we don't need to split it many times.



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/taskRelation/TaskRelationFilterRequest.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.taskRelation;
+
+import org.apache.dolphinscheduler.api.dto.PageQueryDto;
+import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation;
+
+import lombok.Data;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * task relation query request
+ */
+@ApiModel("TASK-RELATION-QUERY")
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@Data
+public class TaskRelationFilterRequest extends PageQueryDto {
+
+    @ApiModelProperty(example = "1234567890123")
+    private long workflowCode;
+
+    @ApiModelProperty(example = "1234567890123")
+    private long preTaskCode;
+
+    @ApiModelProperty(example = "1234567890123")
+    private long postTaskCode;
+
+    public TaskRelationFilterRequest(long workflowCode, long preTaskCode, long postTaskCode) {
+        this.workflowCode = workflowCode;
+        this.preTaskCode = preTaskCode;
+        this.postTaskCode = postTaskCode;
+    }
+
+    public TaskRelationFilterRequest(long preTaskCode, long postTaskCode) {
+        this.preTaskCode = preTaskCode;
+        this.postTaskCode = postTaskCode;
+    }
+
+    public ProcessTaskRelation convert2TaskDefinition() {
+        ProcessTaskRelation processTaskRelation = new ProcessTaskRelation();
+        if (this.workflowCode != 0L) {
+            processTaskRelation.setProcessDefinitionCode(this.workflowCode);
+        }
+        if (this.preTaskCode != 0L) {
+            processTaskRelation.setPreTaskCode(this.preTaskCode);
+        }
+        if (this.postTaskCode != 0L) {
+            processTaskRelation.setPostTaskCode(this.postTaskCode);
+        }

Review Comment:
   Don't need to deal with version?



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java:
##########
@@ -166,6 +181,91 @@ public Map<String, Object> createTaskDefinition(User loginUser,
         return result;
     }
 
+    private TaskDefinitionLog syncObj2Log(User user, TaskDefinition taskDefinition) {

Review Comment:
   ```suggestion
       private TaskDefinitionLog convert2TaskDefinitionLog(User user, TaskDefinition taskDefinition) {
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessTaskRelationServiceImpl.java:
##########
@@ -165,6 +174,84 @@ public Map<String, Object> createProcessTaskRelation(User loginUser, long projec
         return result;
     }
 
+    private ProcessTaskRelationLog syncObj2Log(User user, ProcessTaskRelation processTaskRelation) {

Review Comment:
   ```suggestion
       private ProcessTaskRelationLog convert2ProcessTaskRelationLog(User user, ProcessTaskRelation processTaskRelation) {
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java:
##########
@@ -166,6 +181,91 @@ public Map<String, Object> createTaskDefinition(User loginUser,
         return result;
     }
 
+    private TaskDefinitionLog syncObj2Log(User user, TaskDefinition taskDefinition) {
+        TaskDefinitionLog taskDefinitionLog = new TaskDefinitionLog(taskDefinition);
+        taskDefinitionLog.setOperator(user.getId());
+        taskDefinitionLog.setOperateTime(new Date());
+        int result = taskDefinitionLogMapper.insert(taskDefinitionLog);
+        if (result <= 0) {
+            throw new ServiceException(Status.CREATE_TASK_DEFINITION_LOG_ERROR, taskDefinitionLog.getName());
+        }
+        return taskDefinitionLog;
+    }
+
+    private void TaskDefinitionValid(User user, TaskDefinition taskDefinition, String permissions) {

Review Comment:
   ```suggestion
       private void checkTaskDefinitionValid(User user, TaskDefinition taskDefinition, String permissions) {
   ```



-- 
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