yangyichao-mango commented on a change in pull request #3442:
URL:
https://github.com/apache/incubator-dolphinscheduler/pull/3442#discussion_r469275546
##########
File path:
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterBaseTaskExecThread.java
##########
@@ -247,30 +252,27 @@ public Boolean call() throws Exception {
* @return log path
*/
public String getTaskLogPath(TaskInstance task) {
- String logPath;
- try{
- String baseLog = ((TaskLogDiscriminator) ((SiftingAppender)
((LoggerContext) LoggerFactory.getILoggerFactory())
- .getLogger("ROOT")
- .getAppender("TASKLOGFILE"))
- .getDiscriminator()).getLogBase();
- if (baseLog.startsWith(Constants.SINGLE_SLASH)){
- logPath = baseLog + Constants.SINGLE_SLASH +
- task.getProcessDefinitionId() + Constants.SINGLE_SLASH
+
- task.getProcessInstanceId() + Constants.SINGLE_SLASH +
- task.getId() + ".log";
- }else{
- logPath = System.getProperty("user.dir") +
Constants.SINGLE_SLASH +
- baseLog + Constants.SINGLE_SLASH +
- task.getProcessDefinitionId() + Constants.SINGLE_SLASH
+
- task.getProcessInstanceId() + Constants.SINGLE_SLASH +
+ try {
+ // Optional.map will be skipped if null
+ String baseLog =
Optional.of(LoggerFactory.getILoggerFactory().getLogger("ROOT"))
+ .map(e -> (AppenderAttachable<ILoggingEvent>) e)
+ .map(e -> (SiftingAppender) (e.getAppender("TASKLOGFILE")))
+ .map(e -> ((TaskLogDiscriminator) (e.getDiscriminator())))
+ .map(e -> e.getLogBase())
+ .orElse(null);
+ if (baseLog != null) {
+ if (!baseLog.startsWith(Constants.SINGLE_SLASH)) {
+ // complement the relative path
+ baseLog = System.getProperty("user.dir") +
Constants.SINGLE_SLASH + baseLog;
+ }
+ return baseLog + Constants.SINGLE_SLASH +
+ task.getProcessDefinitionId() + Constants.SINGLE_SLASH
+
+ task.getProcessInstanceId() + Constants.SINGLE_SLASH +
Review comment:
Good solution about this NPE situation.
This is the checkstyle format result, please update.
And the sonar fail is because the lower 33.3% test coverage of new code,
please resolve.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]