Skip to content

Commit

Permalink
[Fix][Server] Delete job along with related information (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
winghv authored Nov 23, 2023
1 parent 54a123b commit e18e063
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public interface JobScheduleService extends IService<JobSchedule> {

int deleteById(long id);

int deleteBySchedule(JobSchedule jobSchedule);

JobSchedule getById(long id);

JobSchedule getByJobId(Long jobId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public interface SlaJobService extends IService<SlaJob> {
IPage<SlaJobVO> pageSlaJob(Long slaId, String searchVal, Integer pageNumber, Integer pageSize);

boolean createOrUpdateSlaJob(SlaJobCreateOrUpdate createOrUpdate);

int deleteByJobId(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.datavines.server.enums.ScheduleJobType;
import io.datavines.server.repository.entity.Job;
import io.datavines.server.repository.entity.JobSchedule;
import io.datavines.server.repository.mapper.JobMapper;
import io.datavines.server.repository.mapper.JobScheduleMapper;
import io.datavines.server.repository.service.JobScheduleService;
import io.datavines.server.dqc.coordinator.quartz.QuartzExecutors;
Expand All @@ -36,7 +37,6 @@
import io.datavines.server.dqc.coordinator.quartz.cron.FunCron;

import io.datavines.server.enums.JobScheduleType;
import io.datavines.server.repository.service.JobService;
import io.datavines.server.utils.ContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
Expand All @@ -58,7 +58,7 @@ public class JobScheduleServiceImpl extends ServiceImpl<JobScheduleMapper, JobSc
private QuartzExecutors quartzExecutor;

@Autowired
private JobService jobService;
private JobMapper jobMapper;

@Override
@Transactional(rollbackFor = Exception.class)
Expand Down Expand Up @@ -87,7 +87,7 @@ private JobSchedule create(JobScheduleCreateOrUpdate jobScheduleCreate) throws D
jobSchedule.setStatus(true);

updateJobScheduleParam(jobSchedule, jobScheduleCreate.getType(), jobScheduleCreate.getParam());
Job job = jobService.getById(jobId);
Job job = jobMapper.selectById(jobId);
if (job == null) {
throw new DataVinesServerException(Status.JOB_NOT_EXIST_ERROR, jobId);
} else {
Expand Down Expand Up @@ -140,7 +140,7 @@ private JobSchedule update(JobScheduleCreateOrUpdate jobScheduleUpdate) throws D

updateJobScheduleParam(jobSchedule, jobScheduleUpdate.getType(), jobScheduleUpdate.getParam());
Long jobId = jobScheduleUpdate.getJobId();
Job job = jobService.getById(jobId);
Job job = jobMapper.selectById(jobId);
if (job == null) {
throw new DataVinesServerException(Status.JOB_NOT_EXIST_ERROR, jobId);
} else {
Expand Down Expand Up @@ -180,13 +180,20 @@ private ScheduleJobInfo getScheduleJobInfo(JobSchedule jobSchedule, Job job) {
@Transactional(rollbackFor = Exception.class)
public int deleteById(long id) {
JobSchedule jobSchedule = getById(id);
Job job = jobService.getById(jobSchedule.getJobId());
return deleteBySchedule(jobSchedule);
}

@Override
@Transactional(rollbackFor = Exception.class)
public int deleteBySchedule(JobSchedule jobSchedule) {
Job job = jobMapper.selectById(jobSchedule.getJobId());
ScheduleJobInfo scheduleJobInfo = getScheduleJobInfo(jobSchedule, job);
Boolean deleteJob = quartzExecutor.deleteJob(scheduleJobInfo);
if (!deleteJob ) {

boolean deleteJob = quartzExecutor.deleteJob(scheduleJobInfo);
if (!deleteJob) {
return 0;
}
return baseMapper.deleteById(id);
return baseMapper.deleteById(jobSchedule.getId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements JobSe
@Autowired
private SlaService slaService;

@Autowired
private SlaJobService slaJobService;

@Autowired
private CatalogEntityMetricJobRelService catalogEntityMetricJobRelService;

Expand All @@ -110,6 +113,9 @@ public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements JobSe
@Autowired
private CatalogEntityInstanceService catalogEntityInstanceService;

@Autowired
private JobScheduleService jobScheduleService;

@Override
@Transactional(rollbackFor = Exception.class)
public long create(JobCreate jobCreate) throws DataVinesServerException {
Expand Down Expand Up @@ -413,10 +419,18 @@ public List<Job> listByDataSourceId(Long dataSourceId) {
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteById(long id) {

catalogEntityMetricJobRelService.deleteByJobId(id);
jobExecutionService.deleteByJobId(id);
issueService.deleteByJobId(id);

JobSchedule jobSchedule = jobScheduleService.getByJobId(id);
if (jobSchedule != null) {
jobScheduleService.deleteBySchedule(jobSchedule);
}
slaJobService.deleteByJobId(id);

if (baseMapper.deleteById(id) > 0) {
catalogEntityMetricJobRelService.deleteByJobId(id);
jobExecutionService.deleteByJobId(id);
issueService.deleteByJobId(id);
return 1;
} else {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.datavines.server.repository.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
Expand All @@ -38,6 +39,7 @@
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Service
@Slf4j
Expand Down Expand Up @@ -98,4 +100,18 @@ public boolean createOrUpdateSlaJob(SlaJobCreateOrUpdate createOrUpdate) {
return save(slaJob);
}
}

@Override
public int deleteByJobId(Long id) {
List<SlaJob> slaJobs = baseMapper.selectList(new QueryWrapper<SlaJob>().eq("job_id", id));
if (CollectionUtils.isNotEmpty(slaJobs)) {
List<Long> ids = slaJobs.stream()
.map(SlaJob::getId)
.collect(Collectors.toList());
if (baseMapper.deleteBatchIds(ids) > 0) {
return 1;
}
}
return 0;
}
}

0 comments on commit e18e063

Please sign in to comment.