BoYiZhang
4 years ago
committed by
GitHub
33 changed files with 592 additions and 168 deletions
@ -0,0 +1,76 @@ |
|||||||
|
/* |
||||||
|
* 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 org.apache.dolphinscheduler.server.utils; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.dao.entity.TaskInstance; |
||||||
|
import org.apache.dolphinscheduler.server.entity.TaskExecutionContext; |
||||||
|
import org.apache.dolphinscheduler.server.log.TaskLogDiscriminator; |
||||||
|
|
||||||
|
import java.nio.file.Path; |
||||||
|
import java.nio.file.Paths; |
||||||
|
import java.util.Optional; |
||||||
|
|
||||||
|
import javax.transaction.NotSupportedException; |
||||||
|
|
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import ch.qos.logback.classic.sift.SiftingAppender; |
||||||
|
import ch.qos.logback.classic.spi.ILoggingEvent; |
||||||
|
import ch.qos.logback.core.spi.AppenderAttachable; |
||||||
|
|
||||||
|
public class LogUtils { |
||||||
|
|
||||||
|
private LogUtils() throws NotSupportedException { |
||||||
|
throw new NotSupportedException(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* get task log path |
||||||
|
*/ |
||||||
|
@SuppressWarnings("unchecked") |
||||||
|
private static String getTaskLogPath(int processDefinitionId, int processInstanceId, int taskInstanceId) { |
||||||
|
// Optional.map will be skipped if null
|
||||||
|
return Optional.of(LoggerFactory.getILoggerFactory()) |
||||||
|
.map(e -> (AppenderAttachable<ILoggingEvent>) (e.getLogger("ROOT"))) |
||||||
|
.map(e -> (SiftingAppender) (e.getAppender("TASKLOGFILE"))) |
||||||
|
.map(e -> ((TaskLogDiscriminator) (e.getDiscriminator()))) |
||||||
|
.map(TaskLogDiscriminator::getLogBase) |
||||||
|
.map(e -> Paths.get(e) |
||||||
|
.toAbsolutePath() |
||||||
|
.resolve(String.valueOf(processDefinitionId)) |
||||||
|
.resolve(String.valueOf(processInstanceId)) |
||||||
|
.resolve(taskInstanceId + ".log")) |
||||||
|
.map(Path::toString) |
||||||
|
.orElse(""); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* get task log path by TaskInstance |
||||||
|
*/ |
||||||
|
public static String getTaskLogPath(TaskInstance taskInstance) { |
||||||
|
return getTaskLogPath(taskInstance.getProcessDefinitionId(), taskInstance.getProcessInstanceId(), taskInstance.getId()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* get task log path by TaskExecutionContext |
||||||
|
*/ |
||||||
|
public static String getTaskLogPath(TaskExecutionContext taskExecutionContext) { |
||||||
|
return getTaskLogPath(taskExecutionContext.getProcessDefineId(), taskExecutionContext.getProcessInstanceId(), taskExecutionContext.getTaskInstanceId()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,66 @@ |
|||||||
|
/* |
||||||
|
* 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 org.apache.dolphinscheduler.server.utils; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.dao.entity.TaskInstance; |
||||||
|
import org.apache.dolphinscheduler.server.log.TaskLogDiscriminator; |
||||||
|
|
||||||
|
import java.nio.file.Path; |
||||||
|
import java.nio.file.Paths; |
||||||
|
|
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.mockito.Mockito; |
||||||
|
import org.mockito.junit.MockitoJUnitRunner; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import ch.qos.logback.classic.Logger; |
||||||
|
import ch.qos.logback.classic.sift.SiftingAppender; |
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class) |
||||||
|
public class LogUtilsTest { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testGetTaskLogPath() { |
||||||
|
TaskInstance taskInstance = new TaskInstance(); |
||||||
|
taskInstance.setProcessDefinitionId(1); |
||||||
|
taskInstance.setProcessInstanceId(100); |
||||||
|
taskInstance.setId(1000); |
||||||
|
|
||||||
|
Logger rootLogger = (Logger) LoggerFactory.getILoggerFactory().getLogger("ROOT"); |
||||||
|
Assert.assertNotNull(rootLogger); |
||||||
|
|
||||||
|
SiftingAppender appender = Mockito.mock(SiftingAppender.class); |
||||||
|
// it's a trick to mock logger.getAppend("TASKLOGFILE")
|
||||||
|
Mockito.when(appender.getName()).thenReturn("TASKLOGFILE"); |
||||||
|
rootLogger.addAppender(appender); |
||||||
|
|
||||||
|
Path logBase = Paths.get("path").resolve("to").resolve("test"); |
||||||
|
|
||||||
|
TaskLogDiscriminator taskLogDiscriminator = Mockito.mock(TaskLogDiscriminator.class); |
||||||
|
Mockito.when(taskLogDiscriminator.getLogBase()).thenReturn(logBase.toString()); |
||||||
|
Mockito.when(appender.getDiscriminator()).thenReturn(taskLogDiscriminator); |
||||||
|
|
||||||
|
Path logPath = Paths.get(".").toAbsolutePath().getParent() |
||||||
|
.resolve(logBase) |
||||||
|
.resolve("1").resolve("100").resolve("1000.log"); |
||||||
|
Assert.assertEquals(logPath.toString(), LogUtils.getTaskLogPath(taskInstance)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,108 @@ |
|||||||
|
/* |
||||||
|
* 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. |
||||||
|
*/ |
||||||
|
<template> |
||||||
|
<div class="pre_tasks-model"> |
||||||
|
<div class="clearfix list"> |
||||||
|
<div class="text-box"> |
||||||
|
<span>{{$t('Pre tasks')}}</span> |
||||||
|
</div> |
||||||
|
<div class="cont-box"> |
||||||
|
<div class="label-box"> |
||||||
|
<x-select |
||||||
|
ref="preTasksSelector" |
||||||
|
style="width: 100%;" |
||||||
|
filterable |
||||||
|
multiple |
||||||
|
v-model="preTasks" |
||||||
|
:disabled="isDetails" |
||||||
|
:id="preTasksSelectorId"> |
||||||
|
<x-option |
||||||
|
v-for="task in preTaskList" |
||||||
|
:key="task.id" |
||||||
|
:value="task.id" |
||||||
|
:label="task.name"> |
||||||
|
</x-option> |
||||||
|
</x-select> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
<script> |
||||||
|
import disabledState from '@/module/mixin/disabledState' |
||||||
|
export default { |
||||||
|
name: 'pre_tasks', |
||||||
|
mixins: [disabledState], |
||||||
|
props: { |
||||||
|
backfillItem: Object |
||||||
|
}, |
||||||
|
data () { |
||||||
|
return { |
||||||
|
preTasksSelectorId: '_preTasksSelectorId', // Refresh target vue-component by changing id |
||||||
|
preTasks: [], |
||||||
|
preTasksOld: [], |
||||||
|
} |
||||||
|
}, |
||||||
|
mounted () { |
||||||
|
this.preTasks = this.backfillItem['preTasks'] || this.preTasks |
||||||
|
this.preTasksOld = this.preTasks |
||||||
|
|
||||||
|
// Refresh target vue-component by changing id |
||||||
|
this.$nextTick(() => { |
||||||
|
this.preTasksSelectorId = 'preTasksSelectorId' |
||||||
|
}) |
||||||
|
}, |
||||||
|
computed: { |
||||||
|
preTaskList: function () { |
||||||
|
let currentTaskId = this.backfillItem['id'] || this.id |
||||||
|
let cacheTasks = Object.assign({}, this.store.state.dag.tasks) |
||||||
|
let keys = Object.keys(cacheTasks) |
||||||
|
for (let i = 0; i < keys.length; i++) { |
||||||
|
let key = keys[i] |
||||||
|
if ((!cacheTasks[key].id || !cacheTasks[key].name) || (currentTaskId && cacheTasks[key].id === currentTaskId)) { |
||||||
|
// Clean undefined and current task data |
||||||
|
delete cacheTasks[key] |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return cacheTasks |
||||||
|
}, |
||||||
|
// preTaskIds used to create new connection |
||||||
|
preTasksToAdd: function () { |
||||||
|
let toAddTasks = this.preTasks.filter(taskId => { |
||||||
|
return (this.preTasksOld.indexOf(taskId) === -1) |
||||||
|
}) |
||||||
|
return toAddTasks |
||||||
|
}, |
||||||
|
// preTaskIds used to delete connection |
||||||
|
preTasksToDelete: function () { |
||||||
|
return this.preTasksOld.filter(taskId => this.preTasks.indexOf(taskId) === -1) |
||||||
|
}, |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
// Pass data to parent-level to process dag |
||||||
|
_verification () { |
||||||
|
this.$emit('on-pre-tasks', { |
||||||
|
preTasks: this.preTasks, |
||||||
|
preTasksToAdd: this.preTasksToAdd, |
||||||
|
preTasksToDelete: this.preTasksToDelete, |
||||||
|
}) |
||||||
|
return true |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
</script> |
Loading…
Reference in new issue