-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Improvement][UI] Improve job view link (#452)
- Loading branch information
Showing
9 changed files
with
231 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...erver/src/main/java/io/datavines/server/api/controller/JobHistoryExecutionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 io.datavines.server.api.controller; | ||
|
||
import io.datavines.core.constant.DataVinesConstants; | ||
import io.datavines.core.entity.ResultMap; | ||
import io.datavines.core.enums.Status; | ||
import io.datavines.core.exception.DataVinesServerException; | ||
import io.datavines.server.api.annotation.AuthIgnore; | ||
import io.datavines.server.dqc.coordinator.log.LogService; | ||
import io.datavines.server.repository.entity.JobExecution; | ||
import io.datavines.server.repository.service.JobExecutionService; | ||
import io.datavines.server.utils.FileUtils; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.annotation.Resource; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
import static io.datavines.common.utils.OSUtils.judgeConcurrentHost; | ||
|
||
|
||
@Slf4j | ||
@Api(value = "job", tags = "job", produces = MediaType.APPLICATION_JSON_VALUE) | ||
@RestController | ||
@RequestMapping(value = DataVinesConstants.BASE_API_PATH + "/history/job/execution", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public class JobHistoryExecutionController { | ||
|
||
@Autowired | ||
private JobExecutionService jobExecutionService; | ||
|
||
@Resource | ||
private LogService logService; | ||
|
||
|
||
@AuthIgnore | ||
@ApiOperation(value = "queryLogWithOffsetLine", notes = "query task log with offsetLine") | ||
@GetMapping(value = "/queryLogWithOffsetLine") | ||
public Object queryLogWithOffsetLine(@RequestParam("taskId") Long taskId, | ||
@RequestParam("offsetLine") int offsetLine, | ||
HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
String taskHost = jobExecutionService.getJobExecutionHost(taskId); | ||
Boolean isConcurrentHost = judgeConcurrentHost(taskHost); | ||
if (isConcurrentHost) { | ||
return ResponseEntity.ok(new ResultMap().success().payload(logService.queryLog(taskId, offsetLine))); | ||
} | ||
|
||
response.sendRedirect(request.getScheme() + "://" + taskHost + | ||
"/api/v1/history/job/execution/queryLogWithOffsetLine?offsetLine=" + offsetLine + "&taskId=" + taskId + "&Authorization=" + request.getHeader("Authorization")); | ||
return null; | ||
} | ||
|
||
@AuthIgnore | ||
@ApiOperation(value = "download", notes = "download log file") | ||
@GetMapping(value = "/download") | ||
public void download(@RequestParam("taskId") Long taskId, HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
JobExecution jobExecution = jobExecutionService.getById(taskId); | ||
if(null == jobExecution){ | ||
throw new DataVinesServerException(Status.TASK_NOT_EXIST_ERROR, taskId); | ||
} | ||
String taskHost = jobExecution.getExecuteHost(); | ||
if(StringUtils.isEmpty(taskHost)){ | ||
throw new DataVinesServerException(Status.TASK_EXECUTE_HOST_NOT_EXIST_ERROR, taskId); | ||
} | ||
Boolean isConcurrentHost = judgeConcurrentHost(taskHost); | ||
if (isConcurrentHost) { | ||
if(StringUtils.isEmpty(jobExecution.getLogPath())){ | ||
throw new DataVinesServerException(Status.TASK_LOG_PATH_NOT_EXIST_ERROR, taskId); | ||
} | ||
FileUtils.downloadToResp(jobExecution.getLogPath(), response); | ||
return; | ||
} | ||
response.sendRedirect(request.getScheme() + "://" + taskHost + "/api/v1/history/job/execution/download?taskId=" + taskId+"&Authorization="+request.getHeader("Authorization")); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// @ts-ignore | ||
import { decode } from "base-64"; | ||
|
||
export function base64Decode(encodedString: string): string | null { | ||
try { | ||
return decode(encodedString); | ||
} catch (error) { | ||
console.error('Base64 decoding error:', error); | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* eslint-disable react/no-danger */ | ||
import React, {useRef, useState, useImperativeHandle} from 'react'; | ||
import { DownloadOutlined, SyncOutlined} from '@ant-design/icons'; | ||
import {usePersistFn, useMount,} from '@/common'; | ||
import {useIntl} from 'react-intl'; | ||
import {$http} from '@/http'; | ||
import {download} from '@/utils'; | ||
import querystring from "querystring"; | ||
import {base64Decode} from "utils/base64"; | ||
|
||
const JobHistory = () => { | ||
const intl = useIntl(); | ||
const innerRef = useRef<any>(); | ||
const dealMsg = (msg: string) => { | ||
if (msg) { | ||
return msg.replace(/\r\n/g, '<br>'); | ||
} | ||
return ''; | ||
}; | ||
const [loading, setLoading] = useState(false); | ||
const [wholeLog, setWholeLog] = useState<{ offsetLine: number, msg: string }[]>([]); | ||
let executionId = querystring.parse(base64Decode(window.location.href.split('?')[1] as string) || '').executionId; | ||
const getData = async (offsetLine: number) => { | ||
try { | ||
setLoading(true); | ||
const res = (await $http.get('history/job/execution/queryLogWithOffsetLine', { | ||
taskId: executionId, | ||
offsetLine, | ||
})) || []; | ||
res.msg = dealMsg(res.msg); | ||
if (offsetLine === 0) { | ||
setWholeLog([res]); | ||
} else { | ||
setWholeLog([...wholeLog, res]); | ||
} | ||
} catch (error) { | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
const onDownload = usePersistFn(async () => { | ||
try { | ||
const blob = await $http.get('history/job/execution/download', { taskId: executionId }, { | ||
responseType: 'blob', | ||
}); | ||
download(blob); | ||
} catch (error) { | ||
} | ||
}); | ||
|
||
useMount(async () => { | ||
getData(0); | ||
}); | ||
useImperativeHandle(innerRef, () => ({ | ||
onRefresh() { | ||
getData(wholeLog[wholeLog.length - 1]?.offsetLine || 0); | ||
}, | ||
})); | ||
return ( | ||
<div className={"ant-modal-content"}> | ||
<div style={{position: 'fixed', padding: "10px 0", top: 0, left: 0, width: '100%', zIndex: 1000, display: 'flex', justifyContent: 'space-between', alignItems: 'center',fontSize:16,fontWeight:600,lineHeight:1.5}}> | ||
<span style={{marginLeft: 20}}>{intl.formatMessage({id: 'job_log_view_log'})}</span> | ||
<div style={{marginRight: 30,color:'#1677ff'}}> | ||
<a | ||
style={{marginRight: 10}} | ||
onClick={() => { | ||
innerRef.current.onRefresh(); | ||
}} | ||
> | ||
<SyncOutlined style={{marginRight: 5}}/> | ||
{intl.formatMessage({id: 'job_log_refresh'})} | ||
</a> | ||
<a style={{marginRight: 10}} onClick={onDownload}> | ||
<DownloadOutlined style={{marginRight: 5}}/> | ||
{intl.formatMessage({id: 'job_log_download'})} | ||
</a> | ||
|
||
</div> | ||
</div> | ||
<div style={{minHeight: 300, padding: "60px 20px",lineHeight:1.5,fontSize:14}}> | ||
{ | ||
wholeLog.map((item) => ( | ||
<div dangerouslySetInnerHTML={{__html: item.msg}}/> | ||
)) | ||
} | ||
<div/> | ||
</div> | ||
</div> | ||
) | ||
|
||
} | ||
export default JobHistory; | ||
|
||
|
||
|
||
|
||
|