下载构建日志

This commit is contained in:
bwcx_jzy 2019-07-20 20:02:33 +08:00
parent 2f5eadc6f8
commit 6873345b2e
5 changed files with 37 additions and 15 deletions

View File

@ -38,7 +38,7 @@ public class FileTailWatcher implements Runnable {
/**
* 缓存近10条
*/
private LimitQueue limitQueue = new LimitQueue(10);
private LimitQueue<String> limitQueue = new LimitQueue<>(10);
private final RandomAccessFile randomFile;
/**
* 所有会话

View File

@ -8,7 +8,7 @@ import java.util.concurrent.ConcurrentLinkedDeque;
* @author jiangzeyin
* @date 2019/3/16
*/
public class LimitQueue extends ConcurrentLinkedDeque<String> {
public class LimitQueue<E> extends ConcurrentLinkedDeque<E> {
private final int limit;
public LimitQueue(int limit) {
@ -16,21 +16,19 @@ public class LimitQueue extends ConcurrentLinkedDeque<String> {
}
@Override
public boolean offerFirst(String s) {
pollOver();
public boolean offerFirst(E s) {
if (full()) {
pollLast();
}
return super.offerFirst(s);
}
@Override
public boolean offerLast(String s) {
pollOver();
return super.offerLast(s);
}
private void pollOver() {
public boolean offerLast(E s) {
if (full()) {
poll();
pollFirst();
}
return super.offerLast(s);
}
public boolean full() {

View File

@ -37,6 +37,7 @@ import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* 构建历史
@ -102,6 +103,23 @@ public class BuildHistoryController extends BaseServerController {
}
}
@RequestMapping(value = "download_log.html", method = RequestMethod.GET)
@ResponseBody
public void downloadLog(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据") String logId) throws IOException {
BuildHistoryLog buildHistoryLog = dbBuildHistoryLogService.getByKey(logId);
Objects.requireNonNull(buildHistoryLog);
BuildModel item = buildService.getItem(buildHistoryLog.getBuildDataId());
Objects.requireNonNull(item);
File logFile = BuildUtil.getLogFile(item.getId(), buildHistoryLog.getBuildNumberId());
if (!logFile.exists()) {
return;
}
if (logFile.isFile()) {
ServletUtil.write(getResponse(), logFile);
}
}
@RequestMapping(value = "history_list.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public String historyList(String status,

View File

@ -22,6 +22,7 @@ import cn.keepbx.jpom.model.log.BuildHistoryLog;
import cn.keepbx.jpom.model.log.UserOperateLogV1;
import cn.keepbx.jpom.service.build.BuildService;
import cn.keepbx.jpom.service.dblog.DbBuildHistoryLogService;
import cn.keepbx.util.LimitQueue;
import com.alibaba.fastjson.JSONObject;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
@ -32,8 +33,6 @@ import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
/**
@ -176,7 +175,7 @@ public class BuildManageController extends BaseServerController {
data.put("buildRun", item.getStatus() == BuildModel.Status.Ing.getCode());
// 读取文件
int linesInt = Convert.toInt(line, 1);
List<String> lines = new LinkedList<>();
LimitQueue<String> lines = new LimitQueue<>(500);
final int[] readCount = {0};
FileUtil.readLines(file, CharsetUtil.CHARSET_UTF_8, (LineHandler) line1 -> {
readCount[0]++;

View File

@ -89,6 +89,10 @@
});
}
function downloadLog(id) {
window.open("./download_log.html?logId=" + id);
}
function loadSuccess() {
tableRender({
id: 'tab_user',
@ -101,7 +105,10 @@
{field: 'buildName', title: '构建名称'},
{
field: 'buildIdStr', title: '构建ID', width: '6%', templet: function (d) {
return "<a herf='' style='color: blue;' onclick='openLog(\"" + d.buildDataId + "\"," + d.buildNumberId + ")'>" + d.buildIdStr + "</a>";
return "<div>" +
"<a herf='' style='color: blue;' onclick='openLog(\"" + d.buildDataId + "\"," + d.buildNumberId + ")'>" + d.buildIdStr + "</a>" +
"<a herf='' style='color: blue;' onclick='downloadLog(\"" + d.id + "\")'>&nbsp;<i class=\"layui-icon layui-icon-download-circle\"></i> </a>" +
"</div>";
}
},
{