Browse Source
* [feat] New restful API for workflow and schedule CURD for workflow and schedule, different with exists API, this new restful api only operate single resource in each request, and return the latest. For example, previous workflow should also need to post tasks definition and tasks relation definition, but this patch will allow you to create workflow without task relate information * use checkProjectAndAuthThrowException, and fix CI error * Update dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ScheduleV2Controller.java * change method name from createProcessDefinitionV2 to createSingleProcessDefinition from updateProcessDefinitionV2 to updateSingleProcessDefinition Co-authored-by: caishunfeng <caishunfeng2021@gmail.com>3.2.0-release
Jiajie Zhong
2 years ago
committed by
GitHub
34 changed files with 2696 additions and 602 deletions
@ -0,0 +1,162 @@
|
||||
/* |
||||
* 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.schedule.ScheduleCreateRequest; |
||||
import org.apache.dolphinscheduler.api.dto.schedule.ScheduleFilterRequest; |
||||
import org.apache.dolphinscheduler.api.dto.schedule.ScheduleUpdateRequest; |
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException; |
||||
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; |
||||
|
||||
/** |
||||
* 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 Result<Schedule> createSchedule(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@RequestBody ScheduleCreateRequest scheduleCreateRequest) { |
||||
Schedule schedule = schedulerService.createSchedulesV2(loginUser, scheduleCreateRequest); |
||||
return Result.success(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 deleteSchedule(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@PathVariable("id") Integer id) { |
||||
schedulerService.deleteSchedulesById(loginUser, id); |
||||
return Result.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 Result<Schedule> updateSchedule(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@PathVariable("id") Integer id, |
||||
@RequestBody ScheduleUpdateRequest scheduleUpdateRequest) { |
||||
Schedule schedule = schedulerService.updateSchedulesV2(loginUser, id, scheduleUpdateRequest); |
||||
return Result.success(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 Result<Schedule> getSchedule(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@PathVariable("id") Integer id) { |
||||
Schedule schedule = schedulerService.getSchedule(loginUser, id); |
||||
return Result.success(schedule); |
||||
} |
||||
|
||||
/** |
||||
* Get resource schedule according to query parameter |
||||
* |
||||
* @param loginUser login user |
||||
* @ |
||||
* @return result Result |
||||
*/ |
||||
@ApiOperation(value = "get", notes = "QUERY_SCHEDULE_LIST_PAGING_NOTES") |
||||
@GetMapping(consumes = {"application/json"}) |
||||
@ResponseStatus(HttpStatus.OK) |
||||
@ApiException(QUERY_SCHEDULE_LIST_PAGING_ERROR) |
||||
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||
public Result<PageInfo<Schedule>> filterSchedule(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@RequestBody ScheduleFilterRequest scheduleFilterRequest) { |
||||
PageInfo<Schedule> schedules = schedulerService.filterSchedules(loginUser, scheduleFilterRequest); |
||||
return Result.success(schedules); |
||||
} |
||||
} |
@ -0,0 +1,165 @@
|
||||
/* |
||||
* 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_DEFINITION_ERROR; |
||||
import static org.apache.dolphinscheduler.api.enums.Status.DELETE_PROCESS_DEFINE_BY_CODE_ERROR; |
||||
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROCESS_DEFINITION_LIST; |
||||
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_PROCESS_DEFINITION_ERROR; |
||||
|
||||
import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; |
||||
import org.apache.dolphinscheduler.api.dto.workflow.WorkflowCreateRequest; |
||||
import org.apache.dolphinscheduler.api.dto.workflow.WorkflowFilterRequest; |
||||
import org.apache.dolphinscheduler.api.dto.workflow.WorkflowUpdateRequest; |
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException; |
||||
import org.apache.dolphinscheduler.api.service.ProcessDefinitionService; |
||||
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.ProcessDefinition; |
||||
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; |
||||
|
||||
/** |
||||
* workflow controller |
||||
*/ |
||||
@Api(tags = "WORKFLOW_TAG") |
||||
@RestController |
||||
@RequestMapping("/v2/workflows") |
||||
public class WorkflowV2Controller extends BaseController { |
||||
|
||||
@Autowired |
||||
private ProcessDefinitionService processDefinitionService; |
||||
|
||||
/** |
||||
* Create resource workflow |
||||
* |
||||
* @param loginUser login user |
||||
* @param workflowCreateRequest the new workflow object will be created |
||||
* @return ResourceResponse object created |
||||
*/ |
||||
@ApiOperation(value = "create", notes = "CREATE_WORKFLOWS_NOTES") |
||||
@PostMapping(consumes = {"application/json"}) |
||||
@ResponseStatus(HttpStatus.CREATED) |
||||
@ApiException(CREATE_PROCESS_DEFINITION_ERROR) |
||||
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||
public Result<ProcessDefinition> createWorkflow(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@RequestBody WorkflowCreateRequest workflowCreateRequest) { |
||||
ProcessDefinition processDefinition = |
||||
processDefinitionService.createSingleProcessDefinition(loginUser, workflowCreateRequest); |
||||
return Result.success(processDefinition); |
||||
} |
||||
|
||||
/** |
||||
* Delete workflow by code |
||||
* |
||||
* @param loginUser login user |
||||
* @param code process definition code |
||||
* @return Result result object delete |
||||
*/ |
||||
@ApiOperation(value = "delete", notes = "DELETE_WORKFLOWS_NOTES") |
||||
@ApiImplicitParams({ |
||||
@ApiImplicitParam(name = "code", value = "WORKFLOW_CODE", dataTypeClass = long.class, example = "123456", required = true) |
||||
}) |
||||
@DeleteMapping(value = "/{code}") |
||||
@ResponseStatus(HttpStatus.OK) |
||||
@ApiException(DELETE_PROCESS_DEFINE_BY_CODE_ERROR) |
||||
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||
public Result deleteWorkflow(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@PathVariable("code") Long code) { |
||||
processDefinitionService.deleteProcessDefinitionByCode(loginUser, code); |
||||
return Result.success(); |
||||
} |
||||
|
||||
/** |
||||
* Update resource workflow |
||||
* |
||||
* @param loginUser login user |
||||
* @param code workflow resource code you want to update |
||||
* @param workflowUpdateRequest workflowUpdateRequest |
||||
* @return ResourceResponse object updated |
||||
*/ |
||||
@ApiOperation(value = "update", notes = "UPDATE_WORKFLOWS_NOTES") |
||||
@PutMapping(value = "/{code}") |
||||
@ResponseStatus(HttpStatus.OK) |
||||
@ApiException(UPDATE_PROCESS_DEFINITION_ERROR) |
||||
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||
public Result<ProcessDefinition> updateWorkflow(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@PathVariable("code") Long code, |
||||
@RequestBody WorkflowUpdateRequest workflowUpdateRequest) { |
||||
ProcessDefinition processDefinition = |
||||
processDefinitionService.updateSingleProcessDefinition(loginUser, code, workflowUpdateRequest); |
||||
return Result.success(processDefinition); |
||||
} |
||||
|
||||
/** |
||||
* Get resource workflow |
||||
* |
||||
* @param loginUser login user |
||||
* @param code workflow resource code you want to update |
||||
* @return ResourceResponse object get from condition |
||||
*/ |
||||
@ApiOperation(value = "get", notes = "GET_WORKFLOWS_NOTES") |
||||
@GetMapping(value = "/{code}") |
||||
@ResponseStatus(HttpStatus.OK) |
||||
@ApiException(QUERY_PROCESS_DEFINITION_LIST) |
||||
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||
public Result<ProcessDefinition> getWorkflow(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@PathVariable("code") Long code) { |
||||
ProcessDefinition processDefinition = processDefinitionService.getProcessDefinition(loginUser, code); |
||||
return Result.success(processDefinition); |
||||
} |
||||
|
||||
/** |
||||
* Get resource workflows according to query parameter |
||||
* |
||||
* @param loginUser login user |
||||
* @param workflowFilterRequest workflowFilterRequest |
||||
* @return PageResourceResponse from condition |
||||
*/ |
||||
@ApiOperation(value = "get", notes = "FILTER_WORKFLOWS_NOTES") |
||||
@GetMapping(consumes = {"application/json"}) |
||||
@ResponseStatus(HttpStatus.OK) |
||||
@ApiException(QUERY_PROCESS_DEFINITION_LIST) |
||||
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||
public Result<PageInfo<ProcessDefinition>> filterWorkflows(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@RequestBody WorkflowFilterRequest workflowFilterRequest) { |
||||
PageInfo<ProcessDefinition> processDefinitions = |
||||
processDefinitionService.filterProcessDefinition(loginUser, workflowFilterRequest); |
||||
return Result.success(processDefinitions); |
||||
} |
||||
} |
@ -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 com.google.gson.Gson; |
||||
import com.google.gson.GsonBuilder; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
|
||||
import com.google.gson.Gson; |
||||
import com.google.gson.GsonBuilder; |
||||
|
||||
/** |
||||
* 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() { |
||||
Gson gson = new GsonBuilder().serializeNulls().create(); |
||||
ScheduleParam scheduleParam = new ScheduleParam(this.startTime, this.endTime, this.crontab, this.timezoneId); |
||||
return gson.toJson(scheduleParam); |
||||
} |
||||
|
||||
public Schedule convert2Schedule() { |
||||
Schedule schedule = new Schedule(); |
||||
|
||||
schedule.setProcessDefinitionCode(this.processDefinitionCode); |
||||
schedule.setCrontab(this.crontab); |
||||
schedule.setStartTime(stringToDate(this.startTime)); |
||||
schedule.setEndTime(stringToDate(this.endTime)); |
||||
schedule.setTimezoneId(this.timezoneId); |
||||
schedule.setWarningGroupId(this.warningGroupId); |
||||
schedule.setWorkerGroup(this.workerGroup); |
||||
schedule.setEnvironmentCode(this.environmentCode); |
||||
|
||||
FailureStrategy newFailureStrategy = |
||||
this.failureStrategy == null ? FailureStrategy.CONTINUE : FailureStrategy.valueOf(this.failureStrategy); |
||||
schedule.setFailureStrategy(newFailureStrategy); |
||||
|
||||
ReleaseState newReleaseState = |
||||
this.releaseState == null ? ReleaseState.OFFLINE : ReleaseState.valueOf(this.releaseState); |
||||
schedule.setReleaseState(newReleaseState); |
||||
|
||||
WarningType newWarningType = |
||||
this.warningType == null ? WarningType.NONE : WarningType.valueOf(this.warningType); |
||||
schedule.setWarningType(newWarningType); |
||||
|
||||
Priority newPriority = |
||||
this.processInstancePriority == null ? Priority.MEDIUM : Priority.valueOf(this.processInstancePriority); |
||||
schedule.setProcessInstancePriority(newPriority); |
||||
|
||||
Date date = new Date(); |
||||
schedule.setCreateTime(date); |
||||
schedule.setUpdateTime(date); |
||||
return schedule; |
||||
} |
||||
} |
@ -0,0 +1,63 @@
|
||||
/* |
||||
* 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 org.apache.dolphinscheduler.api.dto.PageQueryDto; |
||||
import org.apache.dolphinscheduler.common.enums.ReleaseState; |
||||
import org.apache.dolphinscheduler.dao.entity.Schedule; |
||||
|
||||
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; |
||||
|
||||
/** |
||||
* schedule query request |
||||
*/ |
||||
@ApiModel("SCHEDULE-QUERY") |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
@Data |
||||
public class ScheduleFilterRequest extends PageQueryDto { |
||||
|
||||
@ApiModelProperty(example = "project-name") |
||||
private String projectName; |
||||
|
||||
@ApiModelProperty(example = "process-definition-name") |
||||
private String processDefinitionName; |
||||
|
||||
@ApiModelProperty(allowableValues = "ONLINE / OFFLINE", example = "OFFLINE", notes = "default OFFLINE if value not provide.") |
||||
private String releaseState; |
||||
|
||||
public Schedule convert2Schedule() { |
||||
Schedule schedule = new Schedule(); |
||||
if (this.projectName != null) { |
||||
schedule.setProjectName(this.projectName); |
||||
} |
||||
if (this.processDefinitionName != null) { |
||||
schedule.setProcessDefinitionName(this.processDefinitionName); |
||||
} |
||||
if (this.releaseState != null) { |
||||
schedule.setReleaseState(ReleaseState.valueOf(this.releaseState)); |
||||
} |
||||
return schedule; |
||||
} |
||||
} |
@ -0,0 +1,38 @@
|
||||
/* |
||||
* 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 lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class ScheduleParam { |
||||
|
||||
private String startTime; |
||||
private String endTime; |
||||
private String crontab; |
||||
private String timezoneId; |
||||
|
||||
public ScheduleParam(String startTime, String endTime, String crontab, String timezoneId) { |
||||
this.startTime = startTime; |
||||
this.endTime = endTime; |
||||
this.crontab = crontab; |
||||
this.timezoneId = timezoneId; |
||||
} |
||||
} |
@ -0,0 +1,138 @@
|
||||
/* |
||||
* 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.dao.entity.Schedule; |
||||
|
||||
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 com.google.gson.Gson; |
||||
import com.google.gson.GsonBuilder; |
||||
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) throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException { |
||||
Schedule scheduleUpdate = this.mergeIntoSchedule(schedule); |
||||
|
||||
String startTimeUpdate = scheduleUpdate.getStartTime() == null ? null |
||||
: format(scheduleUpdate.getStartTime(), YYYY_MM_DD_HH_MM_SS, schedule.getTimezoneId()); |
||||
String endTimeUpdate = scheduleUpdate.getEndTime() == null ? null |
||||
: format(scheduleUpdate.getEndTime(), YYYY_MM_DD_HH_MM_SS, schedule.getTimezoneId()); |
||||
ScheduleParam scheduleParam = new ScheduleParam(startTimeUpdate, endTimeUpdate, scheduleUpdate.getCrontab(), |
||||
scheduleUpdate.getTimezoneId()); |
||||
|
||||
Gson gson = new GsonBuilder().serializeNulls().create(); |
||||
return gson.toJson(scheduleParam); |
||||
} |
||||
|
||||
public Schedule mergeIntoSchedule(Schedule schedule) throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException { |
||||
Schedule scheduleDeepCopy = (Schedule) BeanUtils.cloneBean(schedule);; |
||||
assert scheduleDeepCopy != null; |
||||
if (this.crontab != null) { |
||||
scheduleDeepCopy.setCrontab(this.crontab); |
||||
} |
||||
if (this.startTime != null) { |
||||
scheduleDeepCopy.setStartTime(stringToDate(this.startTime)); |
||||
} |
||||
if (this.endTime != null) { |
||||
scheduleDeepCopy.setEndTime(stringToDate(this.endTime)); |
||||
} |
||||
if (this.timezoneId != null) { |
||||
scheduleDeepCopy.setTimezoneId(this.timezoneId); |
||||
} |
||||
if (this.failureStrategy != null) { |
||||
scheduleDeepCopy.setFailureStrategy(FailureStrategy.valueOf(this.failureStrategy)); |
||||
} |
||||
if (this.releaseState != null) { |
||||
scheduleDeepCopy.setReleaseState(ReleaseState.valueOf(this.releaseState)); |
||||
} |
||||
if (this.warningType != null) { |
||||
scheduleDeepCopy.setWarningType(WarningType.valueOf(this.warningType)); |
||||
} |
||||
if (this.warningGroupId != 0) { |
||||
scheduleDeepCopy.setWarningGroupId(this.warningGroupId); |
||||
} |
||||
if (this.processInstancePriority != null) { |
||||
scheduleDeepCopy.setProcessInstancePriority(Priority.valueOf(this.processInstancePriority)); |
||||
} |
||||
if (this.workerGroup != null) { |
||||
scheduleDeepCopy.setWorkerGroup(this.workerGroup); |
||||
} |
||||
if (this.environmentCode != 0L) { |
||||
scheduleDeepCopy.setEnvironmentCode(this.environmentCode); |
||||
} |
||||
|
||||
scheduleDeepCopy.setUpdateTime(new Date()); |
||||
return scheduleDeepCopy; |
||||
} |
||||
} |
@ -0,0 +1,89 @@
|
||||
/* |
||||
* 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.workflow; |
||||
|
||||
import static org.apache.dolphinscheduler.common.Constants.VERSION_FIRST; |
||||
|
||||
import org.apache.dolphinscheduler.common.enums.ProcessExecutionTypeEnum; |
||||
import org.apache.dolphinscheduler.common.enums.ReleaseState; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
||||
|
||||
import java.util.Date; |
||||
|
||||
import lombok.Data; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
|
||||
/** |
||||
* workflow create request |
||||
*/ |
||||
@Data |
||||
public class WorkflowCreateRequest { |
||||
|
||||
@ApiModelProperty(example = "workflow name", required = true) |
||||
private String name; |
||||
|
||||
@ApiModelProperty(example = "workflow's description") |
||||
private String description; |
||||
|
||||
@ApiModelProperty(example = "12345", required = true) |
||||
private long projectCode; |
||||
|
||||
@ApiModelProperty(allowableValues = "ONLINE / OFFLINE", example = "OFFLINE", notes = "default OFFLINE if not provide.") |
||||
private String releaseState; |
||||
|
||||
@ApiModelProperty(example = "[{\"prop\":\"key\",\"value\":\"value\",\"direct\":\"IN\",\"type\":\"VARCHAR\"}]") |
||||
private String globalParams; |
||||
|
||||
@ApiModelProperty(example = "2") |
||||
private int warningGroupId; |
||||
|
||||
@ApiModelProperty(example = "60") |
||||
private int timeout; |
||||
|
||||
@ApiModelProperty(example = "tenant1", required = true) |
||||
private String tenantCode; |
||||
|
||||
@ApiModelProperty(allowableValues = "PARALLEL / SERIAL_WAIT / SERIAL_DISCARD / SERIAL_PRIORITY", example = "PARALLEL", notes = "default PARALLEL if not provide.") |
||||
private String executionType; |
||||
|
||||
public ProcessDefinition convert2ProcessDefinition() { |
||||
ProcessDefinition processDefinition = new ProcessDefinition(); |
||||
|
||||
processDefinition.setName(this.name); |
||||
processDefinition.setDescription(this.description); |
||||
processDefinition.setProjectCode(this.projectCode); |
||||
processDefinition.setGlobalParams(this.globalParams); |
||||
processDefinition.setWarningGroupId(this.warningGroupId); |
||||
processDefinition.setTimeout(this.timeout); |
||||
processDefinition.setTenantCode(this.tenantCode); |
||||
|
||||
ReleaseState pdReleaseState = |
||||
this.releaseState == null ? ReleaseState.OFFLINE : ReleaseState.valueOf(this.releaseState); |
||||
processDefinition.setReleaseState(pdReleaseState); |
||||
ProcessExecutionTypeEnum processExecutionTypeEnum = |
||||
this.executionType == null ? ProcessExecutionTypeEnum.PARALLEL |
||||
: ProcessExecutionTypeEnum.valueOf(this.executionType); |
||||
processDefinition.setExecutionType(processExecutionTypeEnum); |
||||
|
||||
processDefinition.setVersion(VERSION_FIRST); |
||||
Date date = new Date(); |
||||
processDefinition.setCreateTime(date); |
||||
processDefinition.setUpdateTime(date); |
||||
return processDefinition; |
||||
} |
||||
} |
@ -0,0 +1,63 @@
|
||||
/* |
||||
* 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.workflow; |
||||
|
||||
import org.apache.dolphinscheduler.api.dto.PageQueryDto; |
||||
import org.apache.dolphinscheduler.common.enums.ReleaseState; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
||||
|
||||
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; |
||||
|
||||
/** |
||||
* workflow query response |
||||
*/ |
||||
@ApiModel("WORKFLOW-QUERY") |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
@Data |
||||
public class WorkflowFilterRequest extends PageQueryDto { |
||||
|
||||
@ApiModelProperty(example = "project-name") |
||||
private String projectName; |
||||
|
||||
@ApiModelProperty(example = "workflow-name") |
||||
private String workflowName; |
||||
|
||||
@ApiModelProperty(example = "ONLINE / OFFLINE") |
||||
private String releaseState; |
||||
|
||||
@ApiModelProperty(example = "ONLINE / OFFLINE") |
||||
private String scheduleReleaseState; |
||||
|
||||
public ProcessDefinition convert2ProcessDefinition() { |
||||
ProcessDefinition processDefinition = new ProcessDefinition(); |
||||
if (this.workflowName != null) { |
||||
processDefinition.setName(this.workflowName); |
||||
} |
||||
if (this.releaseState != null) { |
||||
processDefinition.setReleaseState(ReleaseState.valueOf(this.releaseState)); |
||||
} |
||||
return processDefinition; |
||||
} |
||||
} |
@ -0,0 +1,99 @@
|
||||
/* |
||||
* 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.workflow; |
||||
|
||||
import org.apache.dolphinscheduler.common.enums.ProcessExecutionTypeEnum; |
||||
import org.apache.dolphinscheduler.common.enums.ReleaseState; |
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
||||
|
||||
import java.util.Date; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
import com.fasterxml.jackson.annotation.JsonInclude; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
|
||||
/** |
||||
* workflow update request |
||||
*/ |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
@Data |
||||
public class WorkflowUpdateRequest { |
||||
|
||||
@ApiModelProperty(example = "workflow's name") |
||||
private String name; |
||||
|
||||
@ApiModelProperty(example = "workflow's description") |
||||
private String description; |
||||
|
||||
@ApiModelProperty(allowableValues = "ONLINE / OFFLINE", example = "OFFLINE") |
||||
private String releaseState; |
||||
|
||||
@ApiModelProperty(example = "[{\"prop\":\"key\",\"value\":\"value\",\"direct\":\"IN\",\"type\":\"VARCHAR\"}]") |
||||
private String globalParams; |
||||
|
||||
@ApiModelProperty(example = "2") |
||||
private int warningGroupId; |
||||
|
||||
@ApiModelProperty(example = "60") |
||||
private int timeout; |
||||
|
||||
@ApiModelProperty(example = "tenantCode1") |
||||
private String tenantCode; |
||||
|
||||
@ApiModelProperty(allowableValues = "PARALLEL / SERIAL_WAIT / SERIAL_DISCARD / SERIAL_PRIORITY", example = "PARALLEL", notes = "default PARALLEL if not provide.") |
||||
private String executionType; |
||||
|
||||
public ProcessDefinition mergeIntoProcessDefinition(ProcessDefinition processDefinition) { |
||||
ProcessDefinition processDefinitionDeepCopy = |
||||
JSONUtils.parseObject(JSONUtils.toJsonString(processDefinition), ProcessDefinition.class); |
||||
assert processDefinitionDeepCopy != null; |
||||
if (this.name != null) { |
||||
processDefinitionDeepCopy.setName(this.name); |
||||
} |
||||
if (this.description != null) { |
||||
processDefinitionDeepCopy.setDescription(this.description); |
||||
} |
||||
if (this.releaseState != null) { |
||||
processDefinitionDeepCopy.setReleaseState(ReleaseState.valueOf(this.releaseState)); |
||||
} |
||||
if (this.globalParams != null) { |
||||
processDefinitionDeepCopy.setGlobalParams(this.globalParams); |
||||
} |
||||
if (this.warningGroupId != 0) { |
||||
processDefinitionDeepCopy.setWarningGroupId(this.warningGroupId); |
||||
} |
||||
if (this.timeout != 0) { |
||||
processDefinitionDeepCopy.setTimeout(this.timeout); |
||||
} |
||||
if (this.tenantCode != null) { |
||||
processDefinitionDeepCopy.setTenantCode(this.tenantCode); |
||||
} |
||||
if (this.executionType != null) { |
||||
processDefinitionDeepCopy.setExecutionType(ProcessExecutionTypeEnum.valueOf(this.executionType)); |
||||
} |
||||
|
||||
int version = processDefinitionDeepCopy.getVersion() + 1; |
||||
processDefinitionDeepCopy.setVersion(version); |
||||
processDefinitionDeepCopy.setUpdateTime(new Date()); |
||||
return processDefinitionDeepCopy; |
||||
} |
||||
} |
@ -0,0 +1,168 @@
|
||||
/* |
||||
* 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.common.Constants.EMPTY_STRING; |
||||
|
||||
import org.apache.dolphinscheduler.api.dto.workflow.WorkflowCreateRequest; |
||||
import org.apache.dolphinscheduler.api.dto.workflow.WorkflowFilterRequest; |
||||
import org.apache.dolphinscheduler.api.dto.workflow.WorkflowUpdateRequest; |
||||
import org.apache.dolphinscheduler.api.service.ProcessDefinitionService; |
||||
import org.apache.dolphinscheduler.api.utils.PageInfo; |
||||
import org.apache.dolphinscheduler.api.utils.Result; |
||||
import org.apache.dolphinscheduler.common.enums.ProcessExecutionTypeEnum; |
||||
import org.apache.dolphinscheduler.common.enums.ReleaseState; |
||||
import org.apache.dolphinscheduler.common.enums.UserType; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
||||
import org.apache.dolphinscheduler.dao.entity.User; |
||||
import org.apache.dolphinscheduler.dao.mapper.TenantMapper; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import org.junit.Assert; |
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
import org.junit.jupiter.api.Assertions; |
||||
import org.junit.runner.RunWith; |
||||
import org.mockito.InjectMocks; |
||||
import org.mockito.Mock; |
||||
import org.mockito.Mockito; |
||||
import org.mockito.junit.MockitoJUnitRunner; |
||||
|
||||
/** |
||||
* project v2 controller test |
||||
*/ |
||||
@RunWith(MockitoJUnitRunner.Silent.class) |
||||
public class WorkflowV2ControllerTest { |
||||
|
||||
protected User user; |
||||
@InjectMocks |
||||
private WorkflowV2Controller workflowV2Controller; |
||||
@Mock |
||||
private ProcessDefinitionService processDefinitionService; |
||||
@Mock |
||||
private TenantMapper tenantMapper; |
||||
|
||||
private final static String name = "workflowName"; |
||||
private final static String newName = "workflowNameNew"; |
||||
private final static String releaseState = "ONLINE"; |
||||
private final static int projectCode = 13579; |
||||
private final static String description = "the workflow description"; |
||||
private final static int timeout = 30; |
||||
private final static String tenantCode = "dolphinscheduler"; |
||||
private final static int warningGroupId = 0; |
||||
private final static String executionType = "PARALLEL"; |
||||
|
||||
@Before |
||||
public void before() { |
||||
User loginUser = new User(); |
||||
loginUser.setId(1); |
||||
loginUser.setUserType(UserType.GENERAL_USER); |
||||
loginUser.setUserName("admin"); |
||||
user = loginUser; |
||||
} |
||||
|
||||
@Test |
||||
public void testCreateWorkflow() { |
||||
WorkflowCreateRequest workflowCreateRequest = new WorkflowCreateRequest(); |
||||
workflowCreateRequest.setName(name); |
||||
workflowCreateRequest.setReleaseState(releaseState); |
||||
workflowCreateRequest.setProjectCode(projectCode); |
||||
workflowCreateRequest.setDescription(description); |
||||
workflowCreateRequest.setGlobalParams(EMPTY_STRING); |
||||
workflowCreateRequest.setTimeout(timeout); |
||||
workflowCreateRequest.setTenantCode(tenantCode); |
||||
workflowCreateRequest.setWarningGroupId(warningGroupId); |
||||
workflowCreateRequest.setExecutionType(executionType); |
||||
|
||||
Mockito.when(processDefinitionService.createSingleProcessDefinition(user, workflowCreateRequest)) |
||||
.thenReturn(this.getProcessDefinition(name)); |
||||
Result<ProcessDefinition> resourceResponse = workflowV2Controller.createWorkflow(user, workflowCreateRequest); |
||||
Assert.assertEquals(this.getProcessDefinition(name), resourceResponse.getData()); |
||||
} |
||||
|
||||
@Test |
||||
public void testUpdateWorkflow() { |
||||
WorkflowUpdateRequest workflowUpdateRequest = new WorkflowUpdateRequest(); |
||||
workflowUpdateRequest.setName(newName); |
||||
|
||||
Mockito.when(processDefinitionService.updateSingleProcessDefinition(user, 1L, workflowUpdateRequest)) |
||||
.thenReturn(this.getProcessDefinition(newName)); |
||||
Result<ProcessDefinition> resourceResponse = |
||||
workflowV2Controller.updateWorkflow(user, 1L, workflowUpdateRequest); |
||||
|
||||
Assert.assertEquals(this.getProcessDefinition(newName), resourceResponse.getData()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetWorkflow() { |
||||
Mockito.when(processDefinitionService.getProcessDefinition(user, 1L)) |
||||
.thenReturn(this.getProcessDefinition(name)); |
||||
Result<ProcessDefinition> resourceResponse = workflowV2Controller.getWorkflow(user, 1L); |
||||
Assertions.assertEquals(this.getProcessDefinition(name), resourceResponse.getData()); |
||||
} |
||||
|
||||
@Test |
||||
public void testFilterWorkflow() { |
||||
WorkflowFilterRequest workflowFilterRequest = new WorkflowFilterRequest(); |
||||
workflowFilterRequest.setWorkflowName(name); |
||||
|
||||
Mockito.when(processDefinitionService.filterProcessDefinition(user, workflowFilterRequest)) |
||||
.thenReturn(this.getProcessDefinitionPage(name)); |
||||
Result<PageInfo<ProcessDefinition>> pageResourceResponse = |
||||
workflowV2Controller.filterWorkflows(user, workflowFilterRequest); |
||||
|
||||
PageInfo<ProcessDefinition> processDefinitionPage = pageResourceResponse.getData(); |
||||
Assertions.assertIterableEquals(this.getProcessDefinitionPage(name).getTotalList(), |
||||
processDefinitionPage.getTotalList()); |
||||
} |
||||
|
||||
private ProcessDefinition getProcessDefinition(String pdName) { |
||||
ProcessDefinition processDefinition = new ProcessDefinition(); |
||||
processDefinition.setId(1); |
||||
processDefinition.setName(pdName); |
||||
processDefinition.setDescription(description); |
||||
processDefinition.setReleaseState(ReleaseState.valueOf(releaseState)); |
||||
processDefinition.setProjectCode(projectCode); |
||||
processDefinition.setTenantId(1); |
||||
processDefinition.setExecutionType(ProcessExecutionTypeEnum.valueOf(executionType)); |
||||
processDefinition.setWarningGroupId(warningGroupId); |
||||
processDefinition.setGlobalParams(EMPTY_STRING); |
||||
return processDefinition; |
||||
} |
||||
|
||||
private PageInfo<ProcessDefinition> getProcessDefinitionPage(String pdName) { |
||||
ProcessDefinition processDefinition = new ProcessDefinition(); |
||||
processDefinition.setId(1); |
||||
processDefinition.setName(pdName); |
||||
processDefinition.setDescription(description); |
||||
processDefinition.setReleaseState(ReleaseState.valueOf(releaseState)); |
||||
processDefinition.setProjectCode(projectCode); |
||||
processDefinition.setTenantId(1); |
||||
processDefinition.setExecutionType(ProcessExecutionTypeEnum.valueOf(executionType)); |
||||
processDefinition.setWarningGroupId(warningGroupId); |
||||
processDefinition.setGlobalParams(EMPTY_STRING); |
||||
|
||||
PageInfo<ProcessDefinition> pageInfoProcessDefinitions = new PageInfo<ProcessDefinition>(); |
||||
List<ProcessDefinition> processDefinitions = new ArrayList<ProcessDefinition>(); |
||||
processDefinitions.add(processDefinition); |
||||
pageInfoProcessDefinitions.setTotalList(processDefinitions); |
||||
return pageInfoProcessDefinitions; |
||||
} |
||||
} |
@ -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.service; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status; |
||||
import org.apache.dolphinscheduler.common.Constants; |
||||
|
||||
import java.text.MessageFormat; |
||||
import java.util.Map; |
||||
|
||||
public class BaseServiceTestTool { |
||||
|
||||
protected void putMsg(Map<String, Object> result, Status status, Object... statusParams) { |
||||
result.put(Constants.STATUS, status); |
||||
if (statusParams != null && statusParams.length > 0) { |
||||
result.put(Constants.MSG, MessageFormat.format(status.getMsg(), statusParams)); |
||||
} else { |
||||
result.put(Constants.MSG, status.getMsg()); |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue