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


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/schedule/ScheduleUpdateRequest.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.schedule;
+
+import static org.apache.dolphinscheduler.common.Constants.YYYY_MM_DD_HH_MM_SS;
+import static org.apache.dolphinscheduler.common.utils.DateUtils.format;
+import static org.apache.dolphinscheduler.common.utils.DateUtils.stringToDate;
+
+import org.apache.dolphinscheduler.common.enums.FailureStrategy;
+import org.apache.dolphinscheduler.common.enums.Priority;
+import org.apache.dolphinscheduler.common.enums.ReleaseState;
+import org.apache.dolphinscheduler.common.enums.WarningType;
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.dao.entity.Schedule;
+
+import java.util.Date;
+
+import lombok.Data;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * schedule update request
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@Data
+public class ScheduleUpdateRequest {
+
+    @ApiModelProperty(example = "schedule timezone", required = true)
+    private String crontab;
+
+    @ApiModelProperty(example = "2021-01-01 10:00:00", required = true)
+    private String startTime;
+
+    @ApiModelProperty(example = "2022-01-01 12:00:00", required = true)
+    private String endTime;
+
+    @ApiModelProperty(example = "Asia/Shanghai", required = true)
+    private String timezoneId;
+
+    @ApiModelProperty(allowableValues = "CONTINUE / END", example = 
"CONTINUE", notes = "default CONTINUE if value not provide.")
+    private String failureStrategy;
+
+    @ApiModelProperty(allowableValues = "ONLINE / OFFLINE", example = 
"OFFLINE", notes = "default OFFLINE if value not provide.")
+    private String releaseState;
+
+    @ApiModelProperty(allowableValues = "NONE / SUCCESS / FAILURE / ALL", 
example = "SUCCESS", notes = "default NONE if value not provide.")
+    private String warningType;
+
+    @ApiModelProperty(example = "2", notes = "default 0 if value not provide.")
+    private int warningGroupId;
+
+    @ApiModelProperty(allowableValues = "HIGHEST / HIGH / MEDIUM / LOW / 
LOWEST", example = "MEDIUM", notes = "default MEDIUM if value not provide.")
+    private String processInstancePriority;
+
+    @ApiModelProperty(example = "worker-group-name")
+    private String workerGroup;
+
+    @ApiModelProperty(example = "environment-code")
+    private long environmentCode;
+
+    public String updateScheduleParam(Schedule schedule) {
+        Schedule scheduleUpdate = this.mergeIntoSchedule(schedule);
+        return "{\"startTime\":\"" +
+                format(scheduleUpdate.getStartTime(), YYYY_MM_DD_HH_MM_SS, 
schedule.getTimezoneId()) +
+                "\",\"endTime\":\"" +
+                format(scheduleUpdate.getEndTime(), YYYY_MM_DD_HH_MM_SS, 
schedule.getTimezoneId()) +
+                "\",\"crontab\":\"" +
+                scheduleUpdate.getCrontab() +
+                "\",\"timezoneId\":\"" +
+                scheduleUpdate.getTimezoneId() +
+                "\"}";
+    }
+
+    public Schedule mergeIntoSchedule(Schedule schedule) {
+        Schedule scheduleDeepCopy = 
JSONUtils.parseObject(JSONUtils.toJsonString(schedule), Schedule.class);

Review Comment:
   use BeanUtils.cloneBean



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/schedule/ScheduleCreateRequest.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.schedule;
+
+import static org.apache.dolphinscheduler.common.utils.DateUtils.stringToDate;
+
+import org.apache.dolphinscheduler.common.enums.FailureStrategy;
+import org.apache.dolphinscheduler.common.enums.Priority;
+import org.apache.dolphinscheduler.common.enums.ReleaseState;
+import org.apache.dolphinscheduler.common.enums.WarningType;
+import org.apache.dolphinscheduler.dao.entity.Schedule;
+
+import java.util.Date;
+
+import lombok.Data;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * schedule create request
+ */
+@Data
+public class ScheduleCreateRequest {
+
+    @ApiModelProperty(example = "1234567890123", required = true)
+    private long processDefinitionCode;
+
+    @ApiModelProperty(example = "schedule timezone", required = true)
+    private String crontab;
+
+    @ApiModelProperty(example = "2021-01-01 10:00:00", required = true)
+    private String startTime;
+
+    @ApiModelProperty(example = "2022-01-01 12:00:00", required = true)
+    private String endTime;
+
+    @ApiModelProperty(example = "Asia/Shanghai", required = true)
+    private String timezoneId;
+
+    @ApiModelProperty(allowableValues = "CONTINUE / END", example = 
"CONTINUE", notes = "default CONTINUE if value not provide.")
+    private String failureStrategy;
+
+    @ApiModelProperty(allowableValues = "ONLINE / OFFLINE", example = 
"OFFLINE", notes = "default OFFLINE if value not provide.")
+    private String releaseState;
+
+    @ApiModelProperty(allowableValues = "NONE / SUCCESS / FAILURE / ALL", 
example = "SUCCESS", notes = "default NONE if value not provide.")
+    private String warningType;
+
+    @ApiModelProperty(example = "2", notes = "default 0 if value not provide.")
+    private int warningGroupId;
+
+    @ApiModelProperty(allowableValues = "HIGHEST / HIGH / MEDIUM / LOW / 
LOWEST", example = "MEDIUM", notes = "default MEDIUM if value not provide.")
+    private String processInstancePriority;
+
+    @ApiModelProperty(example = "worker-group-name")
+    private String workerGroup;
+
+    @ApiModelProperty(example = "environment-code")
+    private long environmentCode;
+
+    public String getScheduleParam() {

Review Comment:
   Why not use json util?



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ScheduleV2Controller.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.controller;
+
+import static 
org.apache.dolphinscheduler.api.enums.Status.CREATE_SCHEDULE_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.DELETE_SCHEDULE_BY_ID_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.QUERY_SCHEDULE_LIST_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.QUERY_SCHEDULE_LIST_PAGING_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.UPDATE_SCHEDULE_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.PageResourceResponse;
+import org.apache.dolphinscheduler.api.dto.ResourceResponse;
+import org.apache.dolphinscheduler.api.dto.schedule.ScheduleCreateRequest;
+import org.apache.dolphinscheduler.api.dto.schedule.ScheduleFilterRequest;
+import org.apache.dolphinscheduler.api.dto.schedule.ScheduleUpdateRequest;
+import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.ProcessDefinitionService;
+import org.apache.dolphinscheduler.api.service.SchedulerService;
+import org.apache.dolphinscheduler.api.utils.PageInfo;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.Constants;
+import org.apache.dolphinscheduler.dao.entity.Schedule;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import springfox.documentation.annotations.ApiIgnore;
+
+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.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;
+
+/**
+ * schedule controller
+ */
+@Api(tags = "SCHEDULER_TAG")
+@RestController
+@RequestMapping("/v2/schedules")
+public class ScheduleV2Controller extends BaseController {
+
+    @Autowired
+    private SchedulerService schedulerService;
+
+    @Autowired
+    private ProcessDefinitionService processDefinitionService;
+
+    /**
+     * Create resource schedule
+     *
+     * @param loginUser             login user
+     * @param scheduleCreateRequest the new schedule object will be created
+     * @return ResourceResponse object created
+     */
+    @ApiOperation(value = "create", notes = "CREATE_SCHEDULE_NOTES")
+    @PostMapping(consumes = {"application/json"})
+    @ResponseStatus(HttpStatus.CREATED)
+    @ApiException(CREATE_SCHEDULE_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public ResourceResponse createSchedules(@ApiIgnore @RequestAttribute(value 
= Constants.SESSION_USER) User loginUser,
+                                            @RequestBody ScheduleCreateRequest 
scheduleCreateRequest) {
+        Schedule schedule = schedulerService.createSchedulesV2(loginUser, 
scheduleCreateRequest);
+        return new ResourceResponse(schedule);
+    }
+
+    /**
+     * Delete schedule by id
+     *
+     * @param loginUser login user
+     * @param id        schedule object id
+     */
+    @ApiOperation(value = "delete", notes = "DELETE_SCHEDULE_NOTES")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "SCHEDULE_ID", 
dataTypeClass = long.class, example = "123456", required = true)
+    })
+    @DeleteMapping(value = "/{id}")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(DELETE_SCHEDULE_BY_ID_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result deleteSchedules(@ApiIgnore @RequestAttribute(value = 
Constants.SESSION_USER) User loginUser,
+                                  @PathVariable("id") Integer id) {
+        schedulerService.deleteSchedulesById(loginUser, id);
+        return new Result(Status.SUCCESS);
+    }
+
+    /**
+     * Update resource schedule
+     *
+     * @param loginUser        login user
+     * @param id               schedule object id
+     * @param scheduleUpdateRequest the schedule object will be updated
+     * @return result Result
+     */
+    @ApiOperation(value = "update", notes = "UPDATE_SCHEDULE_NOTES")
+    @PutMapping(value = "/{id}")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(UPDATE_SCHEDULE_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public ResourceResponse updateSchedules(@ApiIgnore @RequestAttribute(value 
= Constants.SESSION_USER) User loginUser,
+                                            @PathVariable("id") Integer id,
+                                            @RequestBody ScheduleUpdateRequest 
scheduleUpdateRequest) {
+        Schedule schedule = schedulerService.updateSchedulesV2(loginUser, id, 
scheduleUpdateRequest);
+        return new ResourceResponse(schedule);
+    }
+
+    /**
+     * Get resource schedule by id
+     *
+     * @param loginUser        login user
+     * @param id               schedule object id
+     * @return result Result
+     */
+    @ApiOperation(value = "get", notes = "GET_SCHEDULE_BY_ID_NOTES")
+    @GetMapping(value = "/{id}")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_SCHEDULE_LIST_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public ResourceResponse getSchedules(@ApiIgnore @RequestAttribute(value = 
Constants.SESSION_USER) User loginUser,
+                                         @PathVariable("id") Integer id) {
+        Schedule schedule = schedulerService.getSchedules(loginUser, id);

Review Comment:
   ```suggestion
           Schedule schedule = schedulerService.getSchedule(loginUser, id);
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java:
##########
@@ -67,6 +70,15 @@ Map<String, Object> createProcessDefinition(User loginUser,
                                                 String otherParamsJson,
                                                 ProcessExecutionTypeEnum 
executionType);
 
+    /**
+     * create process definition V2
+     *
+     * @param loginUser login user
+     * @param workflowCreateRequest the new workflow object will be created
+     * @return New ProcessDefinition object created just now
+     */
+    ProcessDefinition createProcessDefinitionV2(User loginUser, 
WorkflowCreateRequest workflowCreateRequest);

Review Comment:
   What's the different between v1 and v2? Maybe v2 it's not a good guide for 
developers if v1 can not be replaced with v2. 



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ScheduleV2Controller.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.controller;
+
+import static 
org.apache.dolphinscheduler.api.enums.Status.CREATE_SCHEDULE_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.DELETE_SCHEDULE_BY_ID_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.QUERY_SCHEDULE_LIST_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.QUERY_SCHEDULE_LIST_PAGING_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.UPDATE_SCHEDULE_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.PageResourceResponse;
+import org.apache.dolphinscheduler.api.dto.ResourceResponse;
+import org.apache.dolphinscheduler.api.dto.schedule.ScheduleCreateRequest;
+import org.apache.dolphinscheduler.api.dto.schedule.ScheduleFilterRequest;
+import org.apache.dolphinscheduler.api.dto.schedule.ScheduleUpdateRequest;
+import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.ProcessDefinitionService;
+import org.apache.dolphinscheduler.api.service.SchedulerService;
+import org.apache.dolphinscheduler.api.utils.PageInfo;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.Constants;
+import org.apache.dolphinscheduler.dao.entity.Schedule;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import springfox.documentation.annotations.ApiIgnore;
+
+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.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;
+
+/**
+ * schedule controller
+ */
+@Api(tags = "SCHEDULER_TAG")
+@RestController
+@RequestMapping("/v2/schedules")
+public class ScheduleV2Controller extends BaseController {
+
+    @Autowired
+    private SchedulerService schedulerService;
+
+    @Autowired
+    private ProcessDefinitionService processDefinitionService;
+
+    /**
+     * Create resource schedule
+     *
+     * @param loginUser             login user
+     * @param scheduleCreateRequest the new schedule object will be created
+     * @return ResourceResponse object created
+     */
+    @ApiOperation(value = "create", notes = "CREATE_SCHEDULE_NOTES")
+    @PostMapping(consumes = {"application/json"})
+    @ResponseStatus(HttpStatus.CREATED)
+    @ApiException(CREATE_SCHEDULE_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public ResourceResponse createSchedules(@ApiIgnore @RequestAttribute(value 
= Constants.SESSION_USER) User loginUser,
+                                            @RequestBody ScheduleCreateRequest 
scheduleCreateRequest) {
+        Schedule schedule = schedulerService.createSchedulesV2(loginUser, 
scheduleCreateRequest);
+        return new ResourceResponse(schedule);
+    }
+
+    /**
+     * Delete schedule by id
+     *
+     * @param loginUser login user
+     * @param id        schedule object id
+     */
+    @ApiOperation(value = "delete", notes = "DELETE_SCHEDULE_NOTES")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "SCHEDULE_ID", 
dataTypeClass = long.class, example = "123456", required = true)
+    })
+    @DeleteMapping(value = "/{id}")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(DELETE_SCHEDULE_BY_ID_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result deleteSchedules(@ApiIgnore @RequestAttribute(value = 
Constants.SESSION_USER) User loginUser,
+                                  @PathVariable("id") Integer id) {
+        schedulerService.deleteSchedulesById(loginUser, id);
+        return new Result(Status.SUCCESS);
+    }
+
+    /**
+     * Update resource schedule
+     *
+     * @param loginUser        login user
+     * @param id               schedule object id
+     * @param scheduleUpdateRequest the schedule object will be updated
+     * @return result Result
+     */
+    @ApiOperation(value = "update", notes = "UPDATE_SCHEDULE_NOTES")
+    @PutMapping(value = "/{id}")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(UPDATE_SCHEDULE_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public ResourceResponse updateSchedules(@ApiIgnore @RequestAttribute(value 
= Constants.SESSION_USER) User loginUser,
+                                            @PathVariable("id") Integer id,
+                                            @RequestBody ScheduleUpdateRequest 
scheduleUpdateRequest) {
+        Schedule schedule = schedulerService.updateSchedulesV2(loginUser, id, 
scheduleUpdateRequest);
+        return new ResourceResponse(schedule);
+    }
+
+    /**
+     * Get resource schedule by id
+     *
+     * @param loginUser        login user
+     * @param id               schedule object id
+     * @return result Result
+     */
+    @ApiOperation(value = "get", notes = "GET_SCHEDULE_BY_ID_NOTES")
+    @GetMapping(value = "/{id}")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_SCHEDULE_LIST_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public ResourceResponse getSchedules(@ApiIgnore @RequestAttribute(value = 
Constants.SESSION_USER) User loginUser,
+                                         @PathVariable("id") Integer id) {
+        Schedule schedule = schedulerService.getSchedules(loginUser, id);

Review Comment:
   Or change into multi method.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to