Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix][Server] fix Execution record interface data duplication #402

Merged
merged 2 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 io.datavines.server.api.dto.vo;

import lombok.Data;

@Data
public class JobExecutionAggState {

private Long jobExecutionId;

private Integer checkState;

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package io.datavines.server.repository.mapper;

import io.datavines.server.api.dto.vo.JobExecutionAggState;
import io.datavines.server.repository.entity.JobExecutionResult;
import org.apache.ibatis.annotations.Mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
Expand All @@ -34,4 +35,6 @@ public interface JobExecutionResultMapper extends BaseMapper<JobExecutionResult>
List<JobExecutionResult> listByJobIdAndTimeRange(@Param("jobId") Long jobId,
@Param("startTime")String startTime,
@Param("endTime")String endTime);

List<JobExecutionAggState> listByJobExecutionId(@Param("jobExecutionIdList") List<Long> jobExecutionIdList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
import io.datavines.server.api.dto.bo.job.JobExecutionPageParam;
import io.datavines.server.api.dto.vo.*;
import io.datavines.core.exception.DataVinesServerException;
import io.datavines.server.enums.DqJobExecutionState;
import io.datavines.server.repository.entity.JobExecution;
import io.datavines.server.repository.entity.JobExecutionResult;
import io.datavines.server.repository.mapper.JobExecutionResultMapper;
import io.datavines.server.repository.service.*;
import io.datavines.server.repository.entity.Command;
import io.datavines.server.repository.mapper.JobExecutionMapper;
Expand All @@ -60,14 +62,17 @@
import static io.datavines.core.constant.DataVinesConstants.SPARK;

@Service("jobExecutionService")
public class JobExecutionServiceImpl extends ServiceImpl<JobExecutionMapper, JobExecution> implements JobExecutionService {
public class JobExecutionServiceImpl extends ServiceImpl<JobExecutionMapper, JobExecution> implements JobExecutionService {

@Autowired
private CommandService commandService;

@Autowired
private JobExecutionResultService jobExecutionResultService;

@Autowired
private JobExecutionResultMapper jobExecutionResultMapper;

@Autowired
private ActualValuesService actualValuesService;

Expand Down Expand Up @@ -113,8 +118,25 @@ public int deleteByJobId(long jobId) {
@Override
public IPage<JobExecutionVO> getJobExecutionPage(JobExecutionPageParam pageParam) {
Page<JobExecutionVO> page = new Page<>(pageParam.getPageNumber(), pageParam.getPageSize());
return baseMapper.getJobExecutionPage(page, pageParam.getSearchVal(), pageParam.getJobId(), pageParam.getDatasourceId(), pageParam.getStatus(), pageParam.getMetricType(), pageParam.getSchemaName(), pageParam.getTableName(), pageParam.getColumnName(), pageParam.getStartTime(), pageParam.getEndTime(),
IPage<JobExecutionVO> jobExecutionPage = baseMapper.getJobExecutionPage(page, pageParam.getSearchVal(), pageParam.getJobId(), pageParam.getDatasourceId(), pageParam.getStatus(), pageParam.getMetricType(), pageParam.getSchemaName(), pageParam.getTableName(), pageParam.getColumnName(), pageParam.getStartTime(), pageParam.getEndTime(),
pageParam.getSchemaSearch(), pageParam.getTableSearch(), pageParam.getColumnSearch());
List<JobExecutionVO> jobExecutionList = jobExecutionPage.getRecords();
// get jobExecution checkState separately
if(CollectionUtils.isNotEmpty(jobExecutionList)){
List<Long> jobExecutionIdList = jobExecutionList.stream()
.filter(r -> r != null && r.getId() != null)
.map(JobExecutionVO::getId).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(jobExecutionIdList)) {
List<JobExecutionAggState> jobExecutionAggStateList = jobExecutionResultMapper.listByJobExecutionId(jobExecutionIdList);
Map<Long, Integer> jobExecutionStateMap = jobExecutionAggStateList.stream()
.collect(Collectors.toMap(
JobExecutionAggState::getJobExecutionId,
JobExecutionAggState::getCheckState
));
jobExecutionList.forEach(jobExecution -> jobExecution.setCheckState(DqJobExecutionState.of(jobExecutionStateMap.get(jobExecution.getId()))));
}
}
return jobExecutionPage;
}

@Override
Expand All @@ -129,8 +151,8 @@ public Long submitJob(SubmitJob submitJob) throws DataVinesServerException {
jobExecution.setExecutePlatformParameter(JSONUtils.toJsonString(submitJob.getExecutePlatformParameter()));
}

if(SPARK.equals(jobExecution.getEngineType())) {
Map<String,Object> defaultEngineParameter = new HashMap<>();
if (SPARK.equals(jobExecution.getEngineType())) {
Map<String, Object> defaultEngineParameter = new HashMap<>();
defaultEngineParameter.put("programType", "JAVA");
defaultEngineParameter.put("deployMode", "cluster");
defaultEngineParameter.put("driverCores", 1);
Expand All @@ -157,8 +179,8 @@ public Long submitJob(SubmitJob submitJob) throws DataVinesServerException {
public Long executeJob(JobExecution jobExecution) throws DataVinesServerException {
Long jobExecutionId = create(jobExecution);

Map<String,String> parameter = new HashMap<>();
parameter.put("engine",jobExecution.getEngineType());
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", jobExecution.getEngineType());
// add a command
Command command = new Command();
command.setType(CommandType.START);
Expand All @@ -178,8 +200,8 @@ public Long killJob(Long jobExecutionId) {
}

Command command = new Command();
Map<String,String> parameter = new HashMap<>();
parameter.put("engine",jobExecution.getEngineType());
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", jobExecution.getEngineType());

command.setType(CommandType.STOP);
command.setPriority(Priority.MEDIUM);
Expand All @@ -201,7 +223,7 @@ public List<JobExecution> listNeedFailover(String host) {
public List<JobExecution> listJobExecutionNotInServerList(List<String> hostList) {
return baseMapper.selectList(new QueryWrapper<JobExecution>().lambda()
.notIn(JobExecution::getExecuteHost, hostList)
.in(JobExecution::getStatus,ExecutionStatus.RUNNING_EXECUTION.getCode(), ExecutionStatus.SUBMITTED_SUCCESS.getCode()));
.in(JobExecution::getStatus, ExecutionStatus.RUNNING_EXECUTION.getCode(), ExecutionStatus.SUBMITTED_SUCCESS.getCode()));
}

private void checkJobExecutionParameter(JobExecutionParameter jobExecutionParameter, String engineType) throws DataVinesServerException {
Expand Down Expand Up @@ -256,22 +278,22 @@ private void checkJobExecutionParameter(JobExecutionParameter jobExecutionParame
}



/**
* get task host from jobExecutionId
*
* @param jobExecutionId
*/
@Override
public String getJobExecutionHost(Long jobExecutionId) {
JobExecution jobExecution = baseMapper.selectById(jobExecutionId);
if(null == jobExecution){
if (null == jobExecution) {
throw new DataVinesServerException(Status.TASK_NOT_EXIST_ERROR, jobExecutionId);
}
if(jobExecution.getStatus() == ExecutionStatus.SUBMITTED_SUCCESS){
if (jobExecution.getStatus() == ExecutionStatus.SUBMITTED_SUCCESS) {
throw new DataVinesServerException(Status.TASK_EXECUTE_NOT_RUNNING, jobExecutionId);
}
String executeHost = jobExecution.getExecuteHost();
if(StringUtils.isEmpty(executeHost)){
if (StringUtils.isEmpty(executeHost)) {
throw new DataVinesServerException(Status.TASK_EXECUTE_HOST_NOT_EXIST_ERROR, jobExecutionId);
}
return executeHost;
Expand Down Expand Up @@ -303,31 +325,31 @@ public List<MetricExecutionDashBoard> getMetricExecutionDashBoard(Long jobId, St

@Override
public List<JobExecutionAggItem> getJobExecutionAggPie(JobExecutionDashboardParam dashboardParam) {
List<String> statusList = new ArrayList<>(Arrays.asList("6","7"));
List<String> statusList = new ArrayList<>(Arrays.asList("6", "7"));

String startDateStr = "";
String endDateStr = "";
if (StringUtils.isEmpty(dashboardParam.getStartTime()) && StringUtils.isEmpty(dashboardParam.getEndTime())) {
startDateStr = DateUtils.format(DateUtils.addDays(new Date(), -5),"yyyy-MM-dd");
endDateStr = DateUtils.format(DateUtils.addDays(new Date(), +1),"yyyy-MM-dd");
startDateStr = DateUtils.format(DateUtils.addDays(new Date(), -5), "yyyy-MM-dd");
endDateStr = DateUtils.format(DateUtils.addDays(new Date(), +1), "yyyy-MM-dd");
} else {
if (StringUtils.isEmpty(dashboardParam.getEndTime()) && StringUtils.isNotEmpty(dashboardParam.getStartTime())) {
startDateStr = dashboardParam.getStartTime().substring(0,10);
startDateStr = dashboardParam.getStartTime().substring(0, 10);
Date startDate = DateUtils.stringToDate(dashboardParam.getStartTime());
endDateStr = DateUtils.format(DateUtils.addDays(startDate,7),"yyyy-MM-dd");
endDateStr = DateUtils.format(DateUtils.addDays(startDate, 7), "yyyy-MM-dd");
} else if (StringUtils.isEmpty(dashboardParam.getStartTime()) && StringUtils.isNotEmpty(dashboardParam.getEndTime())) {
endDateStr = dashboardParam.getEndTime().substring(0,10);
endDateStr = dashboardParam.getEndTime().substring(0, 10);
Date endDate = DateUtils.stringToDate(dashboardParam.getEndTime());
startDateStr = DateUtils.format(DateUtils.addDays(endDate,-6),"yyyy-MM-dd");
startDateStr = DateUtils.format(DateUtils.addDays(endDate, -6), "yyyy-MM-dd");
} else {
Date endDate = DateUtils.parse(dashboardParam.getEndTime(), YYYY_MM_DD_HH_MM_SS);
Date startDate = DateUtils.parse(dashboardParam.getStartTime(), YYYY_MM_DD_HH_MM_SS);
long days = DateUtils.diffDays(endDate,startDate);
long days = DateUtils.diffDays(endDate, startDate);
if (days > 7) {
endDate = DateUtils.addDays(startDate, 7);
}
startDateStr = DateUtils.format(startDate,"yyyy-MM-dd");
endDateStr = DateUtils.format(endDate,"yyyy-MM-dd");
startDateStr = DateUtils.format(startDate, "yyyy-MM-dd");
endDateStr = DateUtils.format(endDate, "yyyy-MM-dd");
}
}
startDateStr += " 00:00:00";
Expand Down Expand Up @@ -386,26 +408,26 @@ public JobExecutionTrendBar getJobExecutionTrendBar(JobExecutionDashboardParam d
String startDateStr = "";
String endDateStr = "";
if (StringUtils.isEmpty(dashboardParam.getStartTime()) && StringUtils.isEmpty(dashboardParam.getEndTime())) {
startDateStr = DateUtils.format(DateUtils.addDays(new Date(), -5),"yyyy-MM-dd");
endDateStr = DateUtils.format(DateUtils.addDays(new Date(), +1),"yyyy-MM-dd");
startDateStr = DateUtils.format(DateUtils.addDays(new Date(), -5), "yyyy-MM-dd");
endDateStr = DateUtils.format(DateUtils.addDays(new Date(), +1), "yyyy-MM-dd");
} else {
if (StringUtils.isEmpty(dashboardParam.getEndTime()) && StringUtils.isNotEmpty(dashboardParam.getStartTime())) {
startDateStr = dashboardParam.getStartTime().substring(0,10);
startDateStr = dashboardParam.getStartTime().substring(0, 10);
Date startDate = DateUtils.stringToDate(dashboardParam.getStartTime());
endDateStr = DateUtils.format(DateUtils.addDays(startDate,7),"yyyy-MM-dd");
endDateStr = DateUtils.format(DateUtils.addDays(startDate, 7), "yyyy-MM-dd");
} else if (StringUtils.isEmpty(dashboardParam.getStartTime()) && StringUtils.isNotEmpty(dashboardParam.getEndTime())) {
endDateStr = dashboardParam.getEndTime().substring(0,10);
endDateStr = dashboardParam.getEndTime().substring(0, 10);
Date endDate = DateUtils.stringToDate(dashboardParam.getEndTime());
startDateStr = DateUtils.format(DateUtils.addDays(endDate,-6),"yyyy-MM-dd");
startDateStr = DateUtils.format(DateUtils.addDays(endDate, -6), "yyyy-MM-dd");
} else {
Date endDate = DateUtils.parse(dashboardParam.getEndTime(), YYYY_MM_DD_HH_MM_SS);
Date startDate = DateUtils.parse(dashboardParam.getStartTime(), YYYY_MM_DD_HH_MM_SS);
long days = DateUtils.diffDays(endDate,startDate);
long days = DateUtils.diffDays(endDate, startDate);
if (days > 7) {
endDate = DateUtils.addDays(startDate, 7);
}
startDateStr = DateUtils.format(startDate,"yyyy-MM-dd");
endDateStr = DateUtils.format(endDate,"yyyy-MM-dd");
startDateStr = DateUtils.format(startDate, "yyyy-MM-dd");
endDateStr = DateUtils.format(endDate, "yyyy-MM-dd");
}
}

Expand Down Expand Up @@ -455,14 +477,14 @@ public JobExecutionTrendBar getJobExecutionTrendBar(JobExecutionDashboardParam d
} else {
int success = 0;
int failure = 0;
for (JobExecutionTrendBarItem item :list) {
for (JobExecutionTrendBarItem item : list) {
if (item.getStatus() == 6) {
failure += item.getNum();
} else if (item.getStatus() == 7) {
success += item.getNum();
}
}
allList.add(failure+success);
allList.add(failure + success);
failureList.add(failure);
successList.add(success);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
</sql>

<select id="getJobExecutionPage" resultType="io.datavines.server.api.dto.vo.JobExecutionVO">
select p.id, p.name, p.schema_name, p.table_name, p.column_name, p.metric_type, p.job_type, p.status, r.state as checkState, p.start_time, p.end_time, p.update_time from (<include refid="basic_sql"/>) p left join dv_job_execution_result r on p.id = r.job_execution_id
select p.id, p.name, p.schema_name, p.table_name, p.column_name, p.metric_type, p.job_type, p.status, p.start_time, p.end_time, p.update_time
from (<include refid="basic_sql"/>) p
<where>
<if test="searchVal != null">
LOWER(p.`name`) LIKE CONCAT(CONCAT('%', LOWER(#{searchVal})), '%')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--

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.

-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="io.datavines.server.repository.mapper.JobExecutionResultMapper">
<select id="listByJobExecutionId" resultType="io.datavines.server.api.dto.vo.JobExecutionAggState">
select job_execution_id, max(state) as check_state
from dv_job_execution_result
where job_execution_id in
<foreach item="jobExecutionId" collection="jobExecutionIdList" separator="," open="(" close=")" index="">
#{jobExecutionId, jdbcType=INTEGER}
</foreach>
group by job_execution_id

</select>


</mapper>
Loading