Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improvement-16835][Worker] Clear empty directory under task working path after task instance finish #16836

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,11 @@ public static String getUploadFileLocalTmpAbsolutePath() {
/**
* directory of process execution
*
* @param tenant tenant
* @param projectCode project code
* @param processDefineCode process definition Code
* @param processDefineVersion process definition version
* @param processInstanceId process instance id
* @param taskInstanceId task instance id
* @return directory of process execution
*/
public static String getTaskInstanceWorkingDirectory(String tenant,
long projectCode,
long processDefineCode,
int processDefineVersion,
int processInstanceId,
int taskInstanceId) {
return String.format(
"%s/exec/process/%s/%d/%d_%d/%d/%d",
DATA_BASEDIR,
tenant,
projectCode,
processDefineCode,
processDefineVersion,
processInstanceId,
taskInstanceId);
public static String getTaskInstanceWorkingDirectory(int taskInstanceId) {
return String.format("%s/exec/process/%d", DATA_BASEDIR, taskInstanceId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public void testGetUploadFilename() {

@Test
public void testGetProcessExecDir() {
String dir = FileUtils.getTaskInstanceWorkingDirectory("test", 1L, 2L, 1, 3, 4);
Assertions.assertEquals("/tmp/dolphinscheduler/exec/process/test/1/2_1/3/4", dir);
String dir = FileUtils.getTaskInstanceWorkingDirectory(4);
Assertions.assertEquals("/tmp/dolphinscheduler/exec/process/4", dir);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,8 @@ public class ProcessUtils {
taskExecutionContext.setAppIds(String.join(TaskConstants.COMMA, appIds));
if (StringUtils.isEmpty(taskExecutionContext.getExecutePath())) {
taskExecutionContext
.setExecutePath(FileUtils.getTaskInstanceWorkingDirectory(
taskExecutionContext.getTenantCode(),
taskExecutionContext.getProjectCode(),
taskExecutionContext.getWorkflowDefinitionCode(),
taskExecutionContext.getWorkflowDefinitionVersion(),
taskExecutionContext.getWorkflowInstanceId(),
taskExecutionContext.getTaskInstanceId()));
.setExecutePath(FileUtils
.getTaskInstanceWorkingDirectory(taskExecutionContext.getTaskInstanceId()));
}
FileUtils.createDirectoryWith755(Paths.get(taskExecutionContext.getExecutePath()));
org.apache.dolphinscheduler.plugin.task.api.utils.ProcessUtils.cancelApplication(taskExecutionContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,8 @@ public class TaskExecutionContextUtils {

public static void createTaskInstanceWorkingDirectory(TaskExecutionContext taskExecutionContext) throws TaskException {
// local execute path
String taskInstanceWorkingDirectory = FileUtils.getTaskInstanceWorkingDirectory(
taskExecutionContext.getTenantCode(),
taskExecutionContext.getProjectCode(),
taskExecutionContext.getWorkflowDefinitionCode(),
taskExecutionContext.getWorkflowDefinitionVersion(),
taskExecutionContext.getWorkflowInstanceId(),
taskExecutionContext.getTaskInstanceId());
String taskInstanceWorkingDirectory =
FileUtils.getTaskInstanceWorkingDirectory(taskExecutionContext.getTaskInstanceId());
try {
if (new File(taskInstanceWorkingDirectory).exists()) {
FileUtils.deleteFile(taskInstanceWorkingDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,8 @@ void createTaskInstanceWorkingDirectory() throws IOException {
taskExecutionContext.setWorkflowInstanceId(1);
taskExecutionContext.setTaskInstanceId(1);

String taskWorkingDirectory = FileUtils.getTaskInstanceWorkingDirectory(
taskExecutionContext.getTenantCode(),
taskExecutionContext.getProjectCode(),
taskExecutionContext.getWorkflowDefinitionCode(),
taskExecutionContext.getWorkflowDefinitionVersion(),
taskExecutionContext.getWorkflowInstanceId(),
taskExecutionContext.getTaskInstanceId());
String taskWorkingDirectory =
FileUtils.getTaskInstanceWorkingDirectory(taskExecutionContext.getTaskInstanceId());
try {
// Test if the working directory is exist
// will delete it and recreate
Expand Down
Loading