Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
DolphinScheduler
提交
c4516fd1
DolphinScheduler
项目概览
apache
/
DolphinScheduler
上一次同步 接近 2 年
通知
707
Star
9572
Fork
3514
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c4516fd1
编写于
9月 17, 2022
作者:
W
Wenjun Ruan
提交者:
GitHub
9月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use LineNumBer to read line (#150)
上级
34217ffe
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
53 addition
and
8 deletion
+53
-8
dolphinscheduler-log-server/src/main/java/org/apache/dolphinscheduler/server/log/LoggerRequestProcessor.java
...e/dolphinscheduler/server/log/LoggerRequestProcessor.java
+9
-4
dolphinscheduler-log-server/src/test/java/org/apache/dolphinscheduler/server/log/LoggerRequestProcessorTest.java
...lphinscheduler/server/log/LoggerRequestProcessorTest.java
+34
-3
dolphinscheduler-log-server/src/test/resources/mock.log
dolphinscheduler-log-server/src/test/resources/mock.log
+9
-0
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/log/RollViewLogResponseCommand.java
...eduler/remote/command/log/RollViewLogResponseCommand.java
+1
-1
未找到文件。
dolphinscheduler-log-server/src/main/java/org/apache/dolphinscheduler/server/log/LoggerRequestProcessor.java
浏览文件 @
c4516fd1
...
...
@@ -43,8 +43,10 @@ import org.springframework.stereotype.Component;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.LineNumberReader
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.List
;
...
...
@@ -180,7 +182,7 @@ public class LoggerRequestProcessor implements NettyRequestProcessor {
return
new
byte
[
0
];
}
pr
ivate
RollViewLogResponseCommand
readPartFileContent
(
RollViewLogRequestCommand
rollViewLogRequest
)
{
pr
otected
RollViewLogResponseCommand
readPartFileContent
(
RollViewLogRequestCommand
rollViewLogRequest
)
{
String
rollViewLogPath
=
rollViewLogRequest
.
getPath
();
if
(!
checkPathSecurity
(
rollViewLogPath
))
{
...
...
@@ -195,13 +197,16 @@ public class LoggerRequestProcessor implements NettyRequestProcessor {
int
skipLine
=
rollViewLogRequest
.
getSkipLineNum
();
int
limit
=
rollViewLogRequest
.
getLimit
();
try
(
Stream
<
String
>
stream
=
Files
.
lines
(
Paths
.
get
(
rollViewLogPath
)))
{
try
(
Stream
<
String
>
stream
=
Files
.
lines
(
Paths
.
get
(
rollViewLogPath
));
LineNumberReader
lineNumberReader
=
new
LineNumberReader
(
new
FileReader
(
rollViewLogPath
)))
{
List
<
String
>
lines
=
stream
.
skip
(
skipLine
).
limit
(
limit
).
collect
(
Collectors
.
toList
());
l
ong
totalLineNumber
=
stream
.
count
(
);
l
ineNumberReader
.
skip
(
Long
.
MAX_VALUE
);
return
RollViewLogResponseCommand
.
builder
()
.
currentLineNumber
(
skipLine
+
lines
.
size
())
.
currentTotalLineNumber
(
totalLineNumber
)
.
currentTotalLineNumber
(
lineNumberReader
.
getLineNumber
()
)
.
log
(
String
.
join
(
"\r\n"
,
lines
))
.
build
();
}
catch
(
IOException
e
)
{
...
...
dolphinscheduler-log-server/src/test/java/org/apache/dolphinscheduler/server/log/LoggerRequestProcessorTest.java
浏览文件 @
c4516fd1
...
...
@@ -17,12 +17,15 @@
package
org.apache.dolphinscheduler.server.log
;
import
io.netty.channel.Channel
;
import
org.apache.dolphinscheduler.common.utils.JSONUtils
;
import
org.apache.dolphinscheduler.common.utils.LoggerUtils
;
import
org.apache.dolphinscheduler.remote.command.Command
;
import
org.apache.dolphinscheduler.remote.command.CommandType
;
import
org.apache.dolphinscheduler.remote.command.log.RollViewLogRequestCommand
;
import
org.apache.dolphinscheduler.remote.command.log.RollViewLogResponseCommand
;
import
org.apache.dolphinscheduler.remote.command.log.ViewLogRequestCommand
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mockito
;
...
...
@@ -30,8 +33,6 @@ import org.powermock.api.mockito.PowerMockito;
import
org.powermock.core.classloader.annotations.PrepareForTest
;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
io.netty.channel.Channel
;
@RunWith
(
PowerMockRunner
.
class
)
@PrepareForTest
({
LoggerUtils
.
class
})
public
class
LoggerRequestProcessorTest
{
...
...
@@ -106,4 +107,34 @@ public class LoggerRequestProcessorTest {
LoggerRequestProcessor
loggerRequestProcessor
=
new
LoggerRequestProcessor
();
loggerRequestProcessor
.
process
(
channel
,
command
);
}
@Test
public
void
testReadPartFileContent
()
{
String
logPath
=
LoggerRequestProcessorTest
.
class
.
getResource
(
"/mock.log"
).
getPath
();
System
.
setProperty
(
"DOLPHINSCHEDULER_WORKER_HOME"
,
logPath
);
LoggerRequestProcessor
loggerRequestProcessor
=
new
LoggerRequestProcessor
();
RollViewLogRequestCommand
requestCommand
=
RollViewLogRequestCommand
.
builder
()
.
path
(
logPath
)
.
skipLineNum
(
0
)
.
limit
(
1
)
.
build
();
RollViewLogResponseCommand
responseCommand
=
loggerRequestProcessor
.
readPartFileContent
(
requestCommand
);
Assert
.
assertEquals
(
8
,
responseCommand
.
getCurrentTotalLineNumber
());
Assert
.
assertEquals
(
1
,
responseCommand
.
getCurrentLineNumber
());
Assert
.
assertEquals
(
"line1"
,
responseCommand
.
getLog
());
Assert
.
assertEquals
(
RollViewLogResponseCommand
.
Status
.
SUCCESS
,
responseCommand
.
getResponseStatus
());
RollViewLogRequestCommand
requestCommandSkipNumber
=
RollViewLogRequestCommand
.
builder
()
.
path
(
logPath
)
.
skipLineNum
(
1
)
.
limit
(
1
)
.
build
();
RollViewLogResponseCommand
requestCommandSkipNumberResponse
=
loggerRequestProcessor
.
readPartFileContent
(
requestCommandSkipNumber
);
Assert
.
assertEquals
(
8
,
requestCommandSkipNumberResponse
.
getCurrentTotalLineNumber
());
Assert
.
assertEquals
(
2
,
requestCommandSkipNumberResponse
.
getCurrentLineNumber
());
Assert
.
assertEquals
(
"line2"
,
requestCommandSkipNumberResponse
.
getLog
());
Assert
.
assertEquals
(
RollViewLogResponseCommand
.
Status
.
SUCCESS
,
requestCommandSkipNumberResponse
.
getResponseStatus
());
}
}
dolphinscheduler-log-server/src/test/resources/mock.log
0 → 100644
浏览文件 @
c4516fd1
line1
line2
line3
line4
line5
line6
line7
line8
line9
\ No newline at end of file
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/log/RollViewLogResponseCommand.java
浏览文件 @
c4516fd1
...
...
@@ -42,7 +42,6 @@ public class RollViewLogResponseCommand implements Serializable {
private
long
currentTotalLineNumber
;
public
static
RollViewLogResponseCommand
error
(
Status
status
)
{
RollViewLogResponseCommand
rollViewLogResponseCommand
=
new
RollViewLogResponseCommand
();
rollViewLogResponseCommand
.
setResponseStatus
(
status
);
...
...
@@ -58,6 +57,7 @@ public class RollViewLogResponseCommand implements Serializable {
}
public
enum
Status
{
SUCCESS
(
"success"
),
LOG_PATH_IS_NOT_SECURITY
(
"Log file path is not at a security directory"
),
LOG_FILE_NOT_FOUND
(
"Log file doesn't exist"
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录