Zhou Zheng
4 years ago
72 changed files with 2176 additions and 1496 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.getProcessId(), taskExecutionContext.getProcessInstanceId(), taskExecutionContext.getTaskInstanceId()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,159 @@ |
|||||||
|
/* |
||||||
|
* 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.master; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.common.enums.ExecutionStatus; |
||||||
|
import org.apache.dolphinscheduler.common.enums.TaskType; |
||||||
|
import org.apache.dolphinscheduler.common.model.TaskNode; |
||||||
|
import org.apache.dolphinscheduler.common.thread.Stopper; |
||||||
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.TaskInstance; |
||||||
|
import org.apache.dolphinscheduler.server.master.config.MasterConfig; |
||||||
|
import org.apache.dolphinscheduler.server.master.runner.SubProcessTaskExecThread; |
||||||
|
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; |
||||||
|
import org.apache.dolphinscheduler.service.process.ProcessService; |
||||||
|
|
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.mockito.Mockito; |
||||||
|
import org.powermock.api.mockito.PowerMockito; |
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest; |
||||||
|
import org.powermock.modules.junit4.PowerMockRunner; |
||||||
|
import org.springframework.context.ApplicationContext; |
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class) |
||||||
|
@PrepareForTest({ |
||||||
|
Stopper.class, |
||||||
|
}) |
||||||
|
public class SubProcessTaskTest { |
||||||
|
|
||||||
|
/** |
||||||
|
* TaskNode.runFlag : task can be run normally |
||||||
|
*/ |
||||||
|
public static final String FLOWNODE_RUN_FLAG_NORMAL = "NORMAL"; |
||||||
|
|
||||||
|
private ProcessService processService; |
||||||
|
|
||||||
|
private ProcessInstance processInstance; |
||||||
|
|
||||||
|
@Before |
||||||
|
public void before() { |
||||||
|
ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class); |
||||||
|
SpringApplicationContext springApplicationContext = new SpringApplicationContext(); |
||||||
|
springApplicationContext.setApplicationContext(applicationContext); |
||||||
|
|
||||||
|
MasterConfig config = new MasterConfig(); |
||||||
|
Mockito.when(applicationContext.getBean(MasterConfig.class)).thenReturn(config); |
||||||
|
config.setMasterTaskCommitRetryTimes(3); |
||||||
|
config.setMasterTaskCommitInterval(1000); |
||||||
|
|
||||||
|
PowerMockito.mockStatic(Stopper.class); |
||||||
|
PowerMockito.when(Stopper.isRunning()).thenReturn(true); |
||||||
|
|
||||||
|
processService = Mockito.mock(ProcessService.class); |
||||||
|
Mockito.when(applicationContext.getBean(ProcessService.class)).thenReturn(processService); |
||||||
|
|
||||||
|
processInstance = getProcessInstance(); |
||||||
|
Mockito.when(processService |
||||||
|
.findProcessInstanceById(processInstance.getId())) |
||||||
|
.thenReturn(processInstance); |
||||||
|
|
||||||
|
// for SubProcessTaskExecThread.setTaskInstanceState
|
||||||
|
Mockito.when(processService |
||||||
|
.updateTaskInstance(Mockito.any())) |
||||||
|
.thenReturn(true); |
||||||
|
|
||||||
|
// for MasterBaseTaskExecThread.submit
|
||||||
|
Mockito.when(processService |
||||||
|
.submitTask(Mockito.any())) |
||||||
|
.thenAnswer(t -> t.getArgument(0)); |
||||||
|
} |
||||||
|
|
||||||
|
private TaskInstance testBasicInit(ExecutionStatus expectResult) { |
||||||
|
TaskInstance taskInstance = getTaskInstance(getTaskNode(), processInstance); |
||||||
|
|
||||||
|
ProcessInstance subProcessInstance = getSubProcessInstance(expectResult); |
||||||
|
// for SubProcessTaskExecThread.waitTaskQuit
|
||||||
|
Mockito.when(processService |
||||||
|
.findProcessInstanceById(subProcessInstance.getId())) |
||||||
|
.thenReturn(subProcessInstance); |
||||||
|
Mockito.when(processService |
||||||
|
.findSubProcessInstance(processInstance.getId(), taskInstance.getId())) |
||||||
|
.thenReturn(subProcessInstance); |
||||||
|
|
||||||
|
return taskInstance; |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testBasicSuccess() throws Exception { |
||||||
|
TaskInstance taskInstance = testBasicInit(ExecutionStatus.SUCCESS); |
||||||
|
SubProcessTaskExecThread taskExecThread = new SubProcessTaskExecThread(taskInstance); |
||||||
|
taskExecThread.call(); |
||||||
|
Assert.assertEquals(ExecutionStatus.SUCCESS, taskExecThread.getTaskInstance().getState()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testBasicFailure() throws Exception { |
||||||
|
TaskInstance taskInstance = testBasicInit(ExecutionStatus.FAILURE); |
||||||
|
SubProcessTaskExecThread taskExecThread = new SubProcessTaskExecThread(taskInstance); |
||||||
|
taskExecThread.call(); |
||||||
|
Assert.assertEquals(ExecutionStatus.FAILURE, taskExecThread.getTaskInstance().getState()); |
||||||
|
} |
||||||
|
|
||||||
|
private TaskNode getTaskNode() { |
||||||
|
TaskNode taskNode = new TaskNode(); |
||||||
|
taskNode.setId("tasks-10"); |
||||||
|
taskNode.setName("S"); |
||||||
|
taskNode.setType(TaskType.SUB_PROCESS.toString()); |
||||||
|
taskNode.setRunFlag(FLOWNODE_RUN_FLAG_NORMAL); |
||||||
|
return taskNode; |
||||||
|
} |
||||||
|
|
||||||
|
private ProcessInstance getProcessInstance() { |
||||||
|
ProcessInstance processInstance = new ProcessInstance(); |
||||||
|
processInstance.setId(100); |
||||||
|
processInstance.setProcessDefinitionId(1); |
||||||
|
processInstance.setState(ExecutionStatus.RUNNING_EXECUTION); |
||||||
|
|
||||||
|
return processInstance; |
||||||
|
} |
||||||
|
|
||||||
|
private ProcessInstance getSubProcessInstance(ExecutionStatus executionStatus) { |
||||||
|
ProcessInstance processInstance = new ProcessInstance(); |
||||||
|
processInstance.setId(102); |
||||||
|
processInstance.setProcessDefinitionId(2); |
||||||
|
processInstance.setState(executionStatus); |
||||||
|
|
||||||
|
return processInstance; |
||||||
|
} |
||||||
|
|
||||||
|
private TaskInstance getTaskInstance(TaskNode taskNode, ProcessInstance processInstance) { |
||||||
|
TaskInstance taskInstance = new TaskInstance(); |
||||||
|
taskInstance.setId(1000); |
||||||
|
taskInstance.setTaskJson(JSONUtils.toJsonString(taskNode)); |
||||||
|
taskInstance.setName(taskNode.getName()); |
||||||
|
taskInstance.setTaskType(taskNode.getType()); |
||||||
|
taskInstance.setProcessInstanceId(processInstance.getId()); |
||||||
|
taskInstance.setProcessDefinitionId(processInstance.getProcessDefinitionId()); |
||||||
|
taskInstance.setState(ExecutionStatus.SUBMITTED_SUCCESS); |
||||||
|
return taskInstance; |
||||||
|
} |
||||||
|
} |
@ -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,94 @@ |
|||||||
|
/* |
||||||
|
* 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> |
||||||
|
<m-popup |
||||||
|
ref="popup" |
||||||
|
:ok-text="$t('Confirm')" |
||||||
|
:nameText="$t('Related items')" |
||||||
|
@ok="_ok"> |
||||||
|
<template slot="content"> |
||||||
|
<div class="create-tenement-model"> |
||||||
|
<m-list-box-f> |
||||||
|
<template slot="name"><strong>*</strong>{{$t('Project Name')}}</template> |
||||||
|
<template slot="content"> |
||||||
|
<x-select v-model="itemId"> |
||||||
|
<x-option |
||||||
|
v-for="item in itemList" |
||||||
|
:key="item.id" |
||||||
|
:value="item.id" |
||||||
|
:label="item.name"> |
||||||
|
</x-option> |
||||||
|
</x-select> |
||||||
|
</template> |
||||||
|
</m-list-box-f> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
</m-popup> |
||||||
|
</template> |
||||||
|
<script> |
||||||
|
import _ from 'lodash' |
||||||
|
import i18n from '@/module/i18n' |
||||||
|
import store from '@/conf/home/store' |
||||||
|
import mPopup from '@/module/components/popup/popup' |
||||||
|
import mListBoxF from '@/module/components/listBoxF/listBoxF' |
||||||
|
|
||||||
|
export default { |
||||||
|
name: 'create-tenement', |
||||||
|
data () { |
||||||
|
return { |
||||||
|
store, |
||||||
|
itemList: [], |
||||||
|
itemId: '' |
||||||
|
} |
||||||
|
}, |
||||||
|
props: { |
||||||
|
tmp: Boolean |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
_ok () { |
||||||
|
if(this._verification()) { |
||||||
|
if(this.tmp) { |
||||||
|
this.$emit('onBatchMove',this.itemId) |
||||||
|
} else { |
||||||
|
this.$emit('onBatchCopy',this.itemId) |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
_verification() { |
||||||
|
if(!this.itemId) { |
||||||
|
this.$message.warning(`${i18n.$t('Project name is required')}`) |
||||||
|
return false |
||||||
|
} |
||||||
|
return true |
||||||
|
} |
||||||
|
|
||||||
|
}, |
||||||
|
watch: { |
||||||
|
}, |
||||||
|
created () { |
||||||
|
this.store.dispatch('dag/getAllItems', {}).then(res => { |
||||||
|
if(res.data.length> 0) { |
||||||
|
this.itemList = res.data |
||||||
|
} |
||||||
|
}) |
||||||
|
}, |
||||||
|
mounted () { |
||||||
|
|
||||||
|
}, |
||||||
|
components: { mPopup, mListBoxF } |
||||||
|
} |
||||||
|
</script> |
Loading…
Reference in new issue