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

[1.7.0]Dev 1.7.0 bug fix #565

Merged
merged 5 commits into from
Aug 9, 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
Expand Up @@ -127,4 +127,6 @@ void updateJobHistoryCancelById(

List<JobHistory> selectJobHistoryByTaskidList(
@Param("idList") List<String> idList, @Param("umUser") String username);

List<JobHistory> selectJobHistoryNoMetrics(JobHistory jobReq);
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ public class QueryTaskVO {
private boolean canRetry;

private String observeInfo;
private String isReuse;
private Boolean isReuse;
private Date requestStartTime;
private Date requestEndTime;
private Long requestSpendTime;

private String metrics;

public List<SubJobDetail> getSubJobs() {
return subJobs;
}
Expand Down Expand Up @@ -298,11 +300,11 @@ public void setExecuteUser(String executeUser) {
this.executeUser = executeUser;
}

public String getIsReuse() {
public Boolean getIsReuse() {
return isReuse;
}

public void setIsReuse(String isReuse) {
public void setIsReuse(Boolean isReuse) {
this.isReuse = isReuse;
}

Expand All @@ -329,4 +331,12 @@ public Long getRequestSpendTime() {
public void setRequestSpendTime(Long requestSpendTime) {
this.requestSpendTime = requestSpendTime;
}

public String getMetrics() {
return metrics;
}

public void setMetrics(String metrics) {
this.metrics = metrics;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.apache.linkis.common.conf.Configuration;
import org.apache.linkis.governance.common.constant.job.JobRequestConstants;
import org.apache.linkis.governance.common.entity.job.QueryException;
import org.apache.linkis.governance.common.protocol.conf.DepartmentRequest;
import org.apache.linkis.governance.common.protocol.conf.DepartmentResponse;
import org.apache.linkis.jobhistory.cache.impl.DefaultQueryCacheManager;
import org.apache.linkis.jobhistory.conf.JobhistoryConfiguration;
import org.apache.linkis.jobhistory.conversions.TaskConversions;
Expand Down Expand Up @@ -106,10 +104,11 @@ public Message getTaskByID(HttpServletRequest req, @PathVariable("id") Long jobI
|| Configuration.isDepartmentAdmin(username)) {
username = null;
}
JobHistory jobHistory = jobHistoryQueryService.getJobHistoryByIdAndName(jobId, username);
JobHistory jobHistory =
jobHistoryQueryService.getJobHistoryByIdAndNameNoMetrics(jobId, username);

try {
if (JobhistoryConfiguration.JOB_HISTORY_QUERY_EXECUTION_CODE_SWITCH() && null != jobHistory) {
if (null != jobHistory) {
QueryUtils.exchangeExecutionCode(jobHistory);
}
} catch (Exception e) {
Expand Down Expand Up @@ -210,17 +209,11 @@ public Message list(
username = null;
}
} else if (null != isDeptView && isDeptView) {
Object responseObject = sender.ask(new DepartmentRequest(username));
if (responseObject instanceof DepartmentResponse) {
DepartmentResponse departmentResponse = (DepartmentResponse) responseObject;
if (StringUtils.isNotBlank(departmentResponse.departmentId())) {
departmentId = departmentResponse.departmentId();
if (StringUtils.isNotBlank(proxyUser)) {
username = proxyUser;
} else {
username = null;
}
}
departmentId = JobhistoryUtils.getDepartmentByuser(username);
if (StringUtils.isNotBlank(departmentId)) {
username = proxyUser;
} else {
username = null;
}
}
if (StringUtils.isBlank(instance)) {
Expand Down Expand Up @@ -496,23 +489,42 @@ public Message jobeExtraInfo(
if (null == jobId) {
return Message.error("Invalid jobId cannot be empty");
}
if (Configuration.isJobHistoryAdmin(username)
|| Configuration.isAdmin(username)
|| Configuration.isDepartmentAdmin(username)) {
JobHistory jobHistory = null;
if (Configuration.isJobHistoryAdmin(username) || Configuration.isAdmin(username)) {
username = null;
jobHistory = jobHistoryQueryService.getJobHistoryByIdAndName(jobId, username);
} else {
if (Configuration.isDepartmentAdmin(username)) {
String departmentId = JobhistoryUtils.getDepartmentByuser(username);
if (StringUtils.isNotBlank(departmentId)) {
List<JobHistory> list =
jobHistoryQueryService.search(
jobId, null, null, null, null, null, null, null, null, departmentId, null);
if (!CollectionUtils.isEmpty(list)) {
jobHistory = list.get(0);
}
}
} else {
jobHistory = jobHistoryQueryService.getJobHistoryByIdAndName(jobId, username);
}
}
JobHistory jobHistory = jobHistoryQueryService.getJobHistoryByIdAndName(jobId, username);
String runtime = TaskConversions.getJobRuntime(jobHistory);
try {
if (null != jobHistory) {

if (jobHistory == null) {
return Message.error(
"The corresponding job was not found, or there may be no permission to view the job"
+ "(没有找到对应的job,也可能是没有查看该job的权限)");
} else {
try {
QueryUtils.exchangeExecutionCode(jobHistory);
} catch (Exception e) {
log.error("Exchange executionCode for job with id : {} failed, {}", jobHistory.getId(), e);
}
} catch (Exception e) {
log.error("Exchange executionCode for job with id : {} failed, {}", jobHistory.getId(), e);
}
return Message.ok()
.data("runtime", runtime)
.data("executionCode", jobHistory.getExecutionCode());
Map<String, String> metricsMap =
BDPJettyServerHelper.gson().fromJson(jobHistory.getMetrics(), Map.class);
metricsMap.put("executionCode", jobHistory.getExecutionCode());
metricsMap.put("runtime", TaskConversions.getJobRuntime(metricsMap));
return Message.ok().data("metricsMap", metricsMap);
}

@ApiOperation(
Expand Down Expand Up @@ -563,7 +575,8 @@ public void downloadJobList(
List<QueryTaskVO> queryTaskVOList =
BDPJettyServerHelper.gson()
.fromJson(jsonStr, new TypeToken<List<QueryTaskVO>>() {}.getType());
byte[] bytes = JobhistoryUtils.downLoadJobToExcel(queryTaskVOList, language);
byte[] bytes =
JobhistoryUtils.downLoadJobToExcel(queryTaskVOList, language, isAdminView, isDeptView);
response.setCharacterEncoding(Consts.UTF_8.toString());
response.addHeader("Content-Type", "application/json;charset=UTF-8");
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@

package org.apache.linkis.jobhistory.util;

import org.apache.linkis.common.conf.Configuration;
import org.apache.linkis.common.utils.Utils;
import org.apache.linkis.governance.common.protocol.conf.DepartmentRequest;
import org.apache.linkis.governance.common.protocol.conf.DepartmentResponse;
import org.apache.linkis.jobhistory.conversions.TaskConversions;
import org.apache.linkis.jobhistory.entity.QueryTaskVO;
import org.apache.linkis.rpc.Sender;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

Expand All @@ -32,24 +37,36 @@
public class JobhistoryUtils {

public static String headersStr =
"任务ID,来源,查询语句,状态,已耗时,关键信息,应用/引擎,创建时间,是否复用,申请开始时间,申请结束时间,申请花费时间";
"任务ID,来源,查询语句,状态,已耗时,关键信息,是否复用,申请开始时间,申请结束时间,申请耗时,应用/引擎,用户,创建时间";
public static String headersEnStr =
"JobID,Source,Execution Code,Status,Time Elapsed,Key Information,App / Engine,Created at,IsRuse,Application Start Time,Application End Time,Application Takes Time";
"JobID,Source,Execution Code,Status,Time Elapsed,Key Information,IsRuse,Application Start Time,Application End Time,Application Takes Time,App / Engine,User,Created at";
private static Sender sender =
Sender.getSender(
Configuration.CLOUD_CONSOLE_CONFIGURATION_SPRING_APPLICATION_NAME().getValue());;

public static byte[] downLoadJobToExcel(List<QueryTaskVO> jobHistoryList, String language)
public static byte[] downLoadJobToExcel(
List<QueryTaskVO> jobHistoryList, String language, Boolean isAdminView, Boolean isDeptView)
throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Workbook workbook = new XSSFWorkbook();
byte[] byteArray = new byte[0];

Sheet sheet = workbook.createSheet("任务信息表");
// Create header row
Row headerRow = sheet.createRow(0);
String headers = "";
Boolean viewResult = isAdminView || isDeptView;
if (!"en".equals(language)) {
headers = headersStr;
if (viewResult) {
headers = headersStr;
} else {
headers = headersStr.replace(",用户", "");
}
} else {
headers = headersEnStr;
if (viewResult) {
headers = headersEnStr;
} else {
headers = headersEnStr.replace(",User", "");
}
}
String[] headersArray = headers.split(",");
for (int i = 0; i < headersArray.length; i++) {
Expand All @@ -62,26 +79,39 @@ public static byte[] downLoadJobToExcel(List<QueryTaskVO> jobHistoryList, String
Row row = sheet.createRow(rowNum++);
row.createCell(0).setCellValue(queryTaskVO.getTaskID());
row.createCell(1).setCellValue(queryTaskVO.getSourceTailor());
row.createCell(2).setCellValue(queryTaskVO.getExecutionCode());
String executionCode = queryTaskVO.getExecutionCode();
if (executionCode.length() >= 32767) {
executionCode = executionCode.substring(0, 32767);
}
row.createCell(2).setCellValue(executionCode);
row.createCell(3).setCellValue(queryTaskVO.getStatus());
if (null == queryTaskVO.getCostTime()) {
queryTaskVO.setCostTime(0L);
}
row.createCell(4).setCellValue(Utils.msDurationToString(queryTaskVO.getCostTime()));
row.createCell(5).setCellValue(queryTaskVO.getErrDesc());
row.createCell(6)
if (null == queryTaskVO.getIsReuse()) {
row.createCell(6).setCellValue("");
} else {
row.createCell(6).setCellValue(queryTaskVO.getIsReuse());
}
row.createCell(7).setCellValue(TaskConversions.dateFomat(queryTaskVO.getRequestStartTime()));
row.createCell(8).setCellValue(TaskConversions.dateFomat(queryTaskVO.getRequestEndTime()));
if (null == queryTaskVO.getRequestSpendTime()) {
queryTaskVO.setRequestSpendTime(0L);
}
row.createCell(9).setCellValue(Utils.msDurationToString(queryTaskVO.getRequestSpendTime()));
row.createCell(10)
.setCellValue(
queryTaskVO.getExecuteApplicationName()
+ "/"
+ queryTaskVO.getRequestApplicationName());
row.createCell(7).setCellValue(TaskConversions.dateFomat(queryTaskVO.getCreatedTime()));
row.createCell(8).setCellValue(queryTaskVO.getIsReuse());
row.createCell(9).setCellValue(TaskConversions.dateFomat(queryTaskVO.getRequestStartTime()));
row.createCell(10).setCellValue(TaskConversions.dateFomat(queryTaskVO.getRequestEndTime()));
if (null == queryTaskVO.getRequestSpendTime()) {
queryTaskVO.setRequestSpendTime(0L);
if (viewResult) {
row.createCell(11).setCellValue(queryTaskVO.getUmUser());
row.createCell(12).setCellValue(TaskConversions.dateFomat(queryTaskVO.getCreatedTime()));
} else {
row.createCell(11).setCellValue(TaskConversions.dateFomat(queryTaskVO.getCreatedTime()));
}
row.createCell(11).setCellValue(Utils.msDurationToString(queryTaskVO.getRequestSpendTime()));
}
try {
workbook.write(outputStream);
Expand All @@ -94,4 +124,16 @@ public static byte[] downLoadJobToExcel(List<QueryTaskVO> jobHistoryList, String
}
return byteArray;
}

public static String getDepartmentByuser(String username) {
String departmentId = "";
Object responseObject = sender.ask(new DepartmentRequest(username));
if (responseObject instanceof DepartmentResponse) {
DepartmentResponse departmentResponse = (DepartmentResponse) responseObject;
if (StringUtils.isNotBlank(departmentResponse.departmentId())) {
departmentId = departmentResponse.departmentId();
}
}
return departmentId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@

<sql id="job_list">
`id`, `job_req_id`, `submit_user`, `execute_user`, `source`, `labels`, `params`,
`progress`, `status`, `log_path`, `error_code`, `error_desc`, `created_time`, `updated_time`,
`instances`, `metrics`,`engine_type`, `execution_code`, `result_location`
`status`, `log_path`, `error_code`, `error_desc`, `created_time`, `updated_time`,
`instances`,`engine_type`, `result_location`, `observe_info`
</sql>

<sql id="insert_job_list">
Expand Down Expand Up @@ -80,6 +80,24 @@
</where>
</select>

<select id="selectJobHistoryNoMetrics" useCache="false" resultMap="jobHistoryMap" parameterType="org.apache.linkis.jobhistory.entity.JobHistory">
SELECT
<include refid="job_list"/>
FROM linkis_ps_job_history_group_history
<where>
<if test="id != null">id = #{id}</if>
<if test="jobReqId != null">and job_req_id = #{jobReqId}</if>
<if test="submitUser != null">and submit_user = #{submitUser}</if>
<if test="executeUser != null">and execute_user = #{executeUser}</if>
<if test="progress != null">and progress = #{progress}</if>
<if test="status != null">and status = #{status}</if>
<if test="createdTime != null">and created_time = #{createdTime}</if>
<if test="updatedTime != null">and updated_time = #{updatedTime}</if>
<if test="instances != null">and instances = #{instances}</if>
<if test="engineType != null">and engine_type = #{engineType}</if>
</where>
</select>


<select id="search" useCache="true" resultMap="jobHistoryMap" >
/*slave*/ SELECT * FROM linkis_ps_job_history_group_history job
Expand Down Expand Up @@ -251,4 +269,5 @@
<if test="umUser != null">and submit_user = #{umUser}</if>
ORDER BY linkis_ps_job_history_group_history.created_time DESC
</select>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ import org.apache.linkis.protocol.constants.TaskConstant
import org.apache.linkis.protocol.utils.ZuulEntranceUtils
import org.apache.linkis.server.{toScalaBuffer, toScalaMap, BDPJettyServerHelper}

import org.apache.commons.lang3.StringUtils
import org.apache.commons.lang3.{BooleanUtils, StringUtils}

import org.springframework.beans.BeanUtils

import java.text.SimpleDateFormat
import java.util
import java.util.Date
import java.util.{Date, Map}

import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsScalaMapConverter}

Expand Down Expand Up @@ -278,7 +278,9 @@ object TaskConversions extends Logging {
null != metrics && metrics.containsKey(TaskConstant.JOB_IS_REUSE) && metrics
.get(TaskConstant.JOB_IS_REUSE) != null
) {
taskVO.setIsReuse(metrics.get(TaskConstant.JOB_IS_REUSE).toString)

taskVO.setIsReuse(BooleanUtils.toBoolean(metrics.get(TaskConstant.JOB_IS_REUSE).toString))

}

var requestStartTime: Date = null
Expand Down Expand Up @@ -313,7 +315,7 @@ object TaskConversions extends Logging {
taskVO.setCostTime(System.currentTimeMillis() - createTime.getTime)
}
}
if (metrics.containsKey(TaskConstant.ENGINE_INSTANCE)) {
if (null != metrics && metrics.containsKey(TaskConstant.ENGINE_INSTANCE)) {
taskVO.setEngineInstance(metrics.get(TaskConstant.ENGINE_INSTANCE).toString)
} else if (TaskStatus.Failed.toString.equals(job.getStatus)) {
taskVO.setCanRetry(true)
Expand Down Expand Up @@ -342,6 +344,7 @@ object TaskConversions extends Logging {
}
}
taskVO.setObserveInfo(job.getObserveInfo)
taskVO.setMetrics(job.getMetrics)
taskVO
}

Expand Down Expand Up @@ -377,9 +380,7 @@ object TaskConversions extends Logging {
}
}

def getJobRuntime(jobHistory: JobHistory): String = {
val metricsMap =
BDPJettyServerHelper.gson.fromJson((jobHistory.getMetrics), classOf[util.Map[String, Object]])
def getJobRuntime(metricsMap: util.Map[String, String]): String = {
var runTime = ""
if (metricsMap.containsKey(TaskConstant.JOB_COMPLETE_TIME)) {
val completeTime = dealString2Date(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public interface JobHistoryQueryService {

JobHistory getJobHistoryByIdAndName(Long jobID, String userName);

JobHistory getJobHistoryByIdAndNameNoMetrics(Long jobID, String userName);

List<JobHistory> search(Long jobId, String username, String creator, String status, Date sDate, Date eDate, String engineType, Long startJobId, String instance, String departmentId, String engineInstance);

Integer countUndoneTasks(String username, String creator, Date sDate, Date eDate, String engineType, Long startJobId);
Expand Down
Loading
Loading