|
|
|
@ -75,6 +75,7 @@ import org.apache.dolphinscheduler.dao.mapper.UserMapper;
|
|
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService; |
|
|
|
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
|
|
|
|
import java.io.BufferedOutputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
@ -719,23 +720,28 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code); |
|
|
|
|
|
|
|
|
|
if (processDefinition == null) { |
|
|
|
|
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, code); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
switch (releaseState) { |
|
|
|
|
case ONLINE: |
|
|
|
|
List<ProcessTaskRelation> relationList = processService.findRelationByCode(projectCode, code); |
|
|
|
|
if (CollectionUtils.isEmpty(relationList)) { |
|
|
|
|
putMsg(result, Status.PROCESS_DAG_IS_EMPTY); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
processDefinition.setReleaseState(releaseState); |
|
|
|
|
processDefinitionMapper.updateById(processDefinition); |
|
|
|
|
break; |
|
|
|
|
case OFFLINE: |
|
|
|
|
processDefinition.setReleaseState(releaseState); |
|
|
|
|
int updateProcess = processDefinitionMapper.updateById(processDefinition); |
|
|
|
|
List<Schedule> scheduleList = scheduleMapper.selectAllByProcessDefineArray( |
|
|
|
|
new long[]{processDefinition.getCode()} |
|
|
|
|
); |
|
|
|
|
if (updateProcess > 0 && scheduleList.size() == 1) { |
|
|
|
|
Schedule schedule = scheduleList.get(0); |
|
|
|
|
logger.info("set schedule offline, project id: {}, schedule id: {}, process definition code: {}", project.getId(), schedule.getId(), code); |
|
|
|
|
Schedule schedule = scheduleMapper.queryByProcessDefinitionCode(code); |
|
|
|
|
if (updateProcess > 0 && schedule != null) { |
|
|
|
|
logger.info("set schedule offline, project code: {}, schedule id: {}, process definition code: {}", projectCode, schedule.getId(), code); |
|
|
|
|
// set status
|
|
|
|
|
schedule.setReleaseState(ReleaseState.OFFLINE); |
|
|
|
|
schedule.setReleaseState(releaseState); |
|
|
|
|
int updateSchedule = scheduleMapper.updateById(schedule); |
|
|
|
|
if (updateSchedule == 0) { |
|
|
|
|
putMsg(result, Status.OFFLINE_SCHEDULE_ERROR); |
|
|
|
@ -1585,7 +1591,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (scheduleJson == null || scheduleJson.trim().isEmpty()) { |
|
|
|
|
if (StringUtils.isBlank(scheduleJson)) { |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1613,14 +1619,19 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|
|
|
|
long projectCode, |
|
|
|
|
long processDefinitionCode, |
|
|
|
|
String scheduleJson) { |
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
Schedule schedule = JSONUtils.parseObject(scheduleJson, Schedule.class); |
|
|
|
|
if (schedule == null) { |
|
|
|
|
putMsg(result, Status.DATA_IS_NOT_VALID, scheduleJson); |
|
|
|
|
throw new ServiceException(Status.DATA_IS_NOT_VALID); |
|
|
|
|
} |
|
|
|
|
// set default value
|
|
|
|
|
FailureStrategy failureStrategy = schedule.getFailureStrategy() == null ? FailureStrategy.CONTINUE : schedule.getFailureStrategy(); |
|
|
|
|
WarningType warningType = schedule.getWarningType() == null ? WarningType.NONE : schedule.getWarningType(); |
|
|
|
|
Priority processInstancePriority = schedule.getProcessInstancePriority() == null ? Priority.MEDIUM : schedule.getProcessInstancePriority(); |
|
|
|
|
int warningGroupId = schedule.getWarningGroupId() == 0 ? 1 : schedule.getWarningGroupId(); |
|
|
|
|
String workerGroup = schedule.getWorkerGroup() == null ? "default" : schedule.getWorkerGroup(); |
|
|
|
|
Long environmentCode = schedule.getEnvironmentCode() == null ? -1 : schedule.getEnvironmentCode(); |
|
|
|
|
long environmentCode = schedule.getEnvironmentCode() == null ? -1 : schedule.getEnvironmentCode(); |
|
|
|
|
|
|
|
|
|
ScheduleParam param = new ScheduleParam(); |
|
|
|
|
param.setStartTime(schedule.getStartTime()); |
|
|
|
@ -1711,7 +1722,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (scheduleJson == null || scheduleJson.trim().isEmpty()) { |
|
|
|
|
if (StringUtils.isBlank(scheduleJson)) { |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
// update dag schedule
|
|
|
|
@ -1746,14 +1757,19 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|
|
|
|
long projectCode, |
|
|
|
|
long processDefinitionCode, |
|
|
|
|
String scheduleJson) { |
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
Schedule schedule = JSONUtils.parseObject(scheduleJson, Schedule.class); |
|
|
|
|
if (schedule == null) { |
|
|
|
|
putMsg(result, Status.DATA_IS_NOT_VALID, scheduleJson); |
|
|
|
|
throw new ServiceException(Status.DATA_IS_NOT_VALID); |
|
|
|
|
} |
|
|
|
|
// set default value
|
|
|
|
|
FailureStrategy failureStrategy = schedule.getFailureStrategy() == null ? FailureStrategy.CONTINUE : schedule.getFailureStrategy(); |
|
|
|
|
WarningType warningType = schedule.getWarningType() == null ? WarningType.NONE : schedule.getWarningType(); |
|
|
|
|
Priority processInstancePriority = schedule.getProcessInstancePriority() == null ? Priority.MEDIUM : schedule.getProcessInstancePriority(); |
|
|
|
|
int warningGroupId = schedule.getWarningGroupId() == 0 ? 1 : schedule.getWarningGroupId(); |
|
|
|
|
String workerGroup = schedule.getWorkerGroup() == null ? "default" : schedule.getWorkerGroup(); |
|
|
|
|
Long environmentCode = schedule.getEnvironmentCode() == null ? -1 : schedule.getEnvironmentCode(); |
|
|
|
|
long environmentCode = schedule.getEnvironmentCode() == null ? -1 : schedule.getEnvironmentCode(); |
|
|
|
|
|
|
|
|
|
ScheduleParam param = new ScheduleParam(); |
|
|
|
|
param.setStartTime(schedule.getStartTime()); |
|
|
|
@ -1783,21 +1799,62 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|
|
|
|
* @param releaseState releaseState |
|
|
|
|
* @return update result code |
|
|
|
|
*/ |
|
|
|
|
@Transactional(rollbackFor = RuntimeException.class) |
|
|
|
|
@Override |
|
|
|
|
public Map<String, Object> releaseWorkflowAndSchedule(User loginUser, long projectCode, long code, ReleaseState releaseState) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
Project project = projectMapper.queryByCode(projectCode); |
|
|
|
|
//check user access for project
|
|
|
|
|
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectCode); |
|
|
|
|
if (result.get(Constants.STATUS) != Status.SUCCESS) { |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
// check state
|
|
|
|
|
if (null == releaseState) { |
|
|
|
|
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, RELEASESTATE); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* delete process definition and schedule |
|
|
|
|
* |
|
|
|
|
* @param loginUser login user |
|
|
|
|
* @param projectCode project code |
|
|
|
|
* @param code process definition code |
|
|
|
|
* @return update result code |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Map<String, Object> deleteWorkflowAndSchedule(User loginUser, long projectCode, long code) { |
|
|
|
|
return null; |
|
|
|
|
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code); |
|
|
|
|
if (processDefinition == null) { |
|
|
|
|
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, code); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
Schedule scheduleObj = scheduleMapper.queryByProcessDefinitionCode(code); |
|
|
|
|
if (scheduleObj == null) { |
|
|
|
|
putMsg(result, Status.SCHEDULE_CRON_NOT_EXISTS, "processDefinitionCode:" + code); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
switch (releaseState) { |
|
|
|
|
case ONLINE: |
|
|
|
|
List<ProcessTaskRelation> relationList = processService.findRelationByCode(projectCode, code); |
|
|
|
|
if (CollectionUtils.isEmpty(relationList)) { |
|
|
|
|
putMsg(result, Status.PROCESS_DAG_IS_EMPTY); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
processDefinition.setReleaseState(releaseState); |
|
|
|
|
processDefinitionMapper.updateById(processDefinition); |
|
|
|
|
scheduleMapper.updateById(scheduleObj); |
|
|
|
|
break; |
|
|
|
|
case OFFLINE: |
|
|
|
|
processDefinition.setReleaseState(releaseState); |
|
|
|
|
int updateProcess = processDefinitionMapper.updateById(processDefinition); |
|
|
|
|
if (updateProcess > 0) { |
|
|
|
|
logger.info("set schedule offline, project code: {}, schedule id: {}, process definition code: {}", projectCode, scheduleObj.getId(), code); |
|
|
|
|
// set status
|
|
|
|
|
scheduleObj.setReleaseState(ReleaseState.OFFLINE); |
|
|
|
|
int updateSchedule = scheduleMapper.updateById(scheduleObj); |
|
|
|
|
if (updateSchedule == 0) { |
|
|
|
|
putMsg(result, Status.OFFLINE_SCHEDULE_ERROR); |
|
|
|
|
throw new ServiceException(Status.OFFLINE_SCHEDULE_ERROR); |
|
|
|
|
} |
|
|
|
|
schedulerService.deleteSchedule(project.getId(), scheduleObj.getId()); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, RELEASESTATE); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|