Browse Source

Fix createFile with permission will not work (#15556)

dev_wenjun_refactorMaster
Wenjun Ruan 10 months ago committed by GitHub
parent
commit
4d15932ede
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 139
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
  2. 24
      dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java
  3. 3
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/utils/ProcessUtils.java
  4. 3
      dolphinscheduler-storage-plugin/dolphinscheduler-storage-abs/src/main/java/org/apache/dolphinscheduler/plugin/storage/abs/AbsStorageOperator.java
  5. 3
      dolphinscheduler-storage-plugin/dolphinscheduler-storage-gcs/src/main/java/org/apache/dolphinscheduler/plugin/storage/gcs/GcsStorageOperator.java
  6. 3
      dolphinscheduler-storage-plugin/dolphinscheduler-storage-obs/src/main/java/org/apache/dolphinscheduler/plugin/storage/obs/ObsStorageOperator.java
  7. 3
      dolphinscheduler-storage-plugin/dolphinscheduler-storage-oss/src/main/java/org/apache/dolphinscheduler/plugin/storage/oss/OssStorageOperator.java
  8. 3
      dolphinscheduler-storage-plugin/dolphinscheduler-storage-s3/src/main/java/org/apache/dolphinscheduler/plugin/storage/s3/S3StorageOperator.java
  9. 8
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/shell/BaseLinuxShellInterceptorBuilder.java
  10. 3
      dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/test/java/org/apache/dolphinscheduler/plugin/task/java/JavaTaskTest.java
  11. 3
      dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/utils/TaskExecutionContextUtils.java
  12. 2
      dolphinscheduler-worker/src/test/java/org/apache/dolphinscheduler/server/worker/utils/TaskExecutionContextUtilsTest.java

139
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java

@ -25,8 +25,6 @@ import static org.apache.dolphinscheduler.common.constants.Constants.RESOURCE_VI
import static org.apache.dolphinscheduler.common.constants.Constants.UTF_8; import static org.apache.dolphinscheduler.common.constants.Constants.UTF_8;
import static org.apache.dolphinscheduler.common.constants.DateConstants.YYYYMMDDHHMMSS; import static org.apache.dolphinscheduler.common.constants.DateConstants.YYYYMMDDHHMMSS;
import org.apache.dolphinscheduler.common.exception.FileOperateException;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.SystemUtils; import org.apache.commons.lang3.SystemUtils;
@ -38,9 +36,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions; import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set; import java.util.Set;
@ -48,11 +44,10 @@ import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream; import java.util.zip.CheckedInputStream;
import lombok.NonNull; import lombok.NonNull;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
/** @UtilityClass
* file utils
*/
@Slf4j @Slf4j
public class FileUtils { public class FileUtils {
@ -62,14 +57,7 @@ public class FileUtils {
public static final String KUBE_CONFIG_FILE = "config"; public static final String KUBE_CONFIG_FILE = "config";
private static final String RWXR_XR_X = "rwxr-xr-x"; private static final Set<PosixFilePermission> PERMISSION_755 = PosixFilePermissions.fromString("rwxr-xr-x");
private static final FileAttribute<Set<PosixFilePermission>> PERMISSION_755 =
PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString(RWXR_XR_X));
private FileUtils() {
throw new UnsupportedOperationException("Construct FileUtils");
}
/** /**
* get download file absolute path and name * get download file absolute path and name
@ -161,34 +149,6 @@ public class FileUtils {
return PropertyUtils.getString(RESOURCE_VIEW_SUFFIXES, RESOURCE_VIEW_SUFFIXES_DEFAULT_VALUE); return PropertyUtils.getString(RESOURCE_VIEW_SUFFIXES, RESOURCE_VIEW_SUFFIXES_DEFAULT_VALUE);
} }
/**
* create directory if absent
*
* @param execLocalPath execute local path
* @throws IOException errors
*/
public static void createWorkDirIfAbsent(String execLocalPath) throws IOException {
// if work dir exists, first delete
File execLocalPathFile = new File(execLocalPath);
if (execLocalPathFile.exists()) {
try {
org.apache.commons.io.FileUtils.forceDelete(execLocalPathFile);
} catch (Exception ex) {
if (ex instanceof NoSuchFileException || ex.getCause() instanceof NoSuchFileException) {
// this file is already be deleted.
} else {
throw ex;
}
}
}
// create work dir
org.apache.commons.io.FileUtils.forceMkdir(execLocalPathFile);
String mkdirLog = "create dir success " + execLocalPath;
log.info(mkdirLog);
}
/** /**
* write content to file ,if parent path not exists, it will do one's utmost to mkdir * write content to file ,if parent path not exists, it will do one's utmost to mkdir
* *
@ -231,25 +191,6 @@ public class FileUtils {
org.apache.commons.io.FileUtils.deleteQuietly(new File(filename)); org.apache.commons.io.FileUtils.deleteQuietly(new File(filename));
} }
/**
* Gets all the parent subdirectories of the parentDir directory
*
* @param parentDir parent dir
* @return all dirs
*/
public static File[] getAllDir(String parentDir) {
if (parentDir == null || "".equals(parentDir)) {
throw new RuntimeException("parentDir can not be empty");
}
File file = new File(parentDir);
if (!file.exists() || !file.isDirectory()) {
throw new RuntimeException("parentDir not exist, or is not a directory:" + parentDir);
}
return file.listFiles(File::isDirectory);
}
/** /**
* Get Content * Get Content
* *
@ -325,59 +266,47 @@ public class FileUtils {
return crcString; return crcString;
} }
public static void setFileOwner(Path filePath, String fileOwner) throws FileOperateException { public static void createFileWith755(@NonNull Path path) throws IOException {
try { if (SystemUtils.IS_OS_WINDOWS) {
// We use linux command to set the file owner, since jdk api will not use sudo. Files.createFile(path);
String command = String.format("sudo chown %s %s", fileOwner, filePath.toString()); } else {
Runtime.getRuntime().exec(command); Files.createFile(path);
Process process = Runtime.getRuntime().exec(command); Files.setPosixFilePermissions(path, PERMISSION_755);
int exitCode = process.waitFor();
if (0 != exitCode) {
throw new FileOperateException(
"Set file: " + filePath + " to owner: " + fileOwner + " failed, existCode(" + exitCode + ")");
}
} catch (FileOperateException ex) {
throw ex;
} catch (Exception ex) {
throw new FileOperateException("Set directory: " + filePath + " to owner: " + fileOwner + " failed");
} }
} }
public static void setDirectoryOwner(Path filePath, String fileOwner) throws FileOperateException { public static void createDirectoryWith755(@NonNull Path path) throws IOException {
try { if (path.toFile().exists()) {
// We use linux command to set the file owner, since jdk api will not use sudo. return;
String command = String.format("sudo chown -R %s %s", fileOwner, filePath.toString()); }
Runtime.getRuntime().exec(command); if (OSUtils.isWindows()) {
Process process = Runtime.getRuntime().exec(command); Files.createDirectories(path);
int exitCode = process.waitFor(); } else {
if (0 != exitCode) { Path parent = path.getParent();
throw new FileOperateException("Set directory: " + filePath + " to owner: " + fileOwner if (parent != null && !parent.toFile().exists()) {
+ " failed, existCode(" + exitCode + ")"); createDirectoryWith755(parent);
} }
} catch (FileOperateException ex) {
throw ex; Files.createDirectory(path);
} catch (Exception ex) { Files.setPosixFilePermissions(path, PERMISSION_755);
throw new FileOperateException("Set directory: " + filePath + " to owner: " + fileOwner + " failed");
} }
} }
public static void createDirectoryIfNotPresent(Path path) throws IOException { public static void setFileTo755(File file) throws IOException {
if (Files.exists(path)) { if (OSUtils.isWindows()) {
return; return;
} }
Files.createDirectories(path); if (file.isFile()) {
} Files.setPosixFilePermissions(file.toPath(), PERMISSION_755);
return;
/** }
* Create a file with '755'. Files.setPosixFilePermissions(file.toPath(), PERMISSION_755);
*/ File[] files = file.listFiles();
public static void createFileWith755(@NonNull Path path) throws IOException { if (files != null) {
if (SystemUtils.IS_OS_WINDOWS) { for (File f : files) {
Files.createFile(path); setFileTo755(f);
} else { }
Files.createFile(path, PERMISSION_755);
} }
} }

24
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java

@ -19,8 +19,13 @@ package org.apache.dolphinscheduler.common.utils;
import static org.apache.dolphinscheduler.common.constants.DateConstants.YYYYMMDDHHMMSS; import static org.apache.dolphinscheduler.common.constants.DateConstants.YYYYMMDDHHMMSS;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
@ -55,12 +60,23 @@ public class FileUtilsTest {
} }
@Test @Test
public void testCreateWorkDirIfAbsent() { public void createDirectoryWith755() throws IOException {
Path path = Paths.get("/tmp/createWorkDirAndUserIfAbsent");
try { try {
FileUtils.createWorkDirIfAbsent("/tmp/createWorkDirAndUserIfAbsent"); FileUtils.createDirectoryWith755(path);
Assertions.assertTrue(true); File file = path.toFile();
Assertions.assertTrue(file.exists());
Assertions.assertTrue(file.isDirectory());
Assertions.assertTrue(file.canExecute());
Assertions.assertTrue(file.canRead());
Assertions.assertTrue(file.canWrite());
FileUtils.createDirectoryWith755(Paths.get("/"));
} catch (Exception e) { } catch (Exception e) {
Assertions.fail(); e.printStackTrace();
Assertions.fail(e.getMessage());
} finally {
Files.deleteIfExists(path);
} }
} }

3
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/utils/ProcessUtils.java

@ -30,6 +30,7 @@ import org.apache.commons.lang3.SystemUtils;
import java.io.File; import java.io.File;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -176,7 +177,7 @@ public class ProcessUtils {
taskExecutionContext.getProcessInstanceId(), taskExecutionContext.getProcessInstanceId(),
taskExecutionContext.getTaskInstanceId())); taskExecutionContext.getTaskInstanceId()));
} }
FileUtils.createWorkDirIfAbsent(taskExecutionContext.getExecutePath()); FileUtils.createDirectoryWith755(Paths.get(taskExecutionContext.getExecutePath()));
org.apache.dolphinscheduler.plugin.task.api.utils.ProcessUtils.cancelApplication(taskExecutionContext); org.apache.dolphinscheduler.plugin.task.api.utils.ProcessUtils.cancelApplication(taskExecutionContext);
return appIds; return appIds;
} else { } else {

3
dolphinscheduler-storage-plugin/dolphinscheduler-storage-abs/src/main/java/org/apache/dolphinscheduler/plugin/storage/abs/AbsStorageOperator.java

@ -25,6 +25,7 @@ import static org.apache.dolphinscheduler.common.constants.Constants.RESOURCE_TY
import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.enums.ResUploadType; import org.apache.dolphinscheduler.common.enums.ResUploadType;
import org.apache.dolphinscheduler.common.utils.FileUtils;
import org.apache.dolphinscheduler.common.utils.PropertyUtils; import org.apache.dolphinscheduler.common.utils.PropertyUtils;
import org.apache.dolphinscheduler.plugin.storage.api.StorageEntity; import org.apache.dolphinscheduler.plugin.storage.api.StorageEntity;
import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate; import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate;
@ -170,7 +171,7 @@ public class AbsStorageOperator implements Closeable, StorageOperate {
if (dstFile.isDirectory()) { if (dstFile.isDirectory()) {
Files.delete(dstFile.toPath()); Files.delete(dstFile.toPath());
} else { } else {
Files.createDirectories(dstFile.getParentFile().toPath()); FileUtils.createDirectoryWith755(dstFile.getParentFile().toPath());
} }
BlobClient blobClient = blobContainerClient.getBlobClient(srcFilePath); BlobClient blobClient = blobContainerClient.getBlobClient(srcFilePath);

3
dolphinscheduler-storage-plugin/dolphinscheduler-storage-gcs/src/main/java/org/apache/dolphinscheduler/plugin/storage/gcs/GcsStorageOperator.java

@ -25,6 +25,7 @@ import static org.apache.dolphinscheduler.common.constants.Constants.RESOURCE_TY
import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.enums.ResUploadType; import org.apache.dolphinscheduler.common.enums.ResUploadType;
import org.apache.dolphinscheduler.common.utils.FileUtils;
import org.apache.dolphinscheduler.common.utils.PropertyUtils; import org.apache.dolphinscheduler.common.utils.PropertyUtils;
import org.apache.dolphinscheduler.plugin.storage.api.StorageEntity; import org.apache.dolphinscheduler.plugin.storage.api.StorageEntity;
import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate; import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate;
@ -143,7 +144,7 @@ public class GcsStorageOperator implements Closeable, StorageOperate {
if (dstFile.isDirectory()) { if (dstFile.isDirectory()) {
Files.delete(dstFile.toPath()); Files.delete(dstFile.toPath());
} else { } else {
Files.createDirectories(dstFile.getParentFile().toPath()); FileUtils.createDirectoryWith755(dstFile.getParentFile().toPath());
} }
Blob blob = gcsStorage.get(BlobId.of(bucketName, srcFilePath)); Blob blob = gcsStorage.get(BlobId.of(bucketName, srcFilePath));

3
dolphinscheduler-storage-plugin/dolphinscheduler-storage-obs/src/main/java/org/apache/dolphinscheduler/plugin/storage/obs/ObsStorageOperator.java

@ -24,6 +24,7 @@ import static org.apache.dolphinscheduler.common.constants.Constants.RESOURCE_TY
import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.enums.ResUploadType; import org.apache.dolphinscheduler.common.enums.ResUploadType;
import org.apache.dolphinscheduler.common.utils.FileUtils;
import org.apache.dolphinscheduler.common.utils.PropertyUtils; import org.apache.dolphinscheduler.common.utils.PropertyUtils;
import org.apache.dolphinscheduler.plugin.storage.api.StorageEntity; import org.apache.dolphinscheduler.plugin.storage.api.StorageEntity;
import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate; import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate;
@ -187,7 +188,7 @@ public class ObsStorageOperator implements Closeable, StorageOperate {
if (dstFile.isDirectory()) { if (dstFile.isDirectory()) {
Files.delete(dstFile.toPath()); Files.delete(dstFile.toPath());
} else { } else {
Files.createDirectories(dstFile.getParentFile().toPath()); FileUtils.createDirectoryWith755(dstFile.getParentFile().toPath());
} }
ObsObject obsObject = obsClient.getObject(bucketName, srcFilePath); ObsObject obsObject = obsClient.getObject(bucketName, srcFilePath);
try ( try (

3
dolphinscheduler-storage-plugin/dolphinscheduler-storage-oss/src/main/java/org/apache/dolphinscheduler/plugin/storage/oss/OssStorageOperator.java

@ -26,6 +26,7 @@ import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.enums.ResUploadType; import org.apache.dolphinscheduler.common.enums.ResUploadType;
import org.apache.dolphinscheduler.common.factory.OssClientFactory; import org.apache.dolphinscheduler.common.factory.OssClientFactory;
import org.apache.dolphinscheduler.common.model.OssConnection; import org.apache.dolphinscheduler.common.model.OssConnection;
import org.apache.dolphinscheduler.common.utils.FileUtils;
import org.apache.dolphinscheduler.common.utils.PropertyUtils; import org.apache.dolphinscheduler.common.utils.PropertyUtils;
import org.apache.dolphinscheduler.plugin.storage.api.StorageEntity; import org.apache.dolphinscheduler.plugin.storage.api.StorageEntity;
import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate; import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate;
@ -213,7 +214,7 @@ public class OssStorageOperator implements Closeable, StorageOperate {
if (dstFile.isDirectory()) { if (dstFile.isDirectory()) {
Files.delete(dstFile.toPath()); Files.delete(dstFile.toPath());
} else { } else {
Files.createDirectories(dstFile.getParentFile().toPath()); FileUtils.createDirectoryWith755(dstFile.getParentFile().toPath());
} }
OSSObject ossObject = ossClient.getObject(bucketName, srcFilePath); OSSObject ossObject = ossClient.getObject(bucketName, srcFilePath);
try ( try (

3
dolphinscheduler-storage-plugin/dolphinscheduler-storage-s3/src/main/java/org/apache/dolphinscheduler/plugin/storage/s3/S3StorageOperator.java

@ -25,6 +25,7 @@ import static org.apache.dolphinscheduler.common.constants.Constants.RESOURCE_TY
import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.enums.ResUploadType; import org.apache.dolphinscheduler.common.enums.ResUploadType;
import org.apache.dolphinscheduler.common.utils.FileUtils;
import org.apache.dolphinscheduler.common.utils.PropertyUtils; import org.apache.dolphinscheduler.common.utils.PropertyUtils;
import org.apache.dolphinscheduler.plugin.storage.api.StorageEntity; import org.apache.dolphinscheduler.plugin.storage.api.StorageEntity;
import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate; import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate;
@ -200,7 +201,7 @@ public class S3StorageOperator implements Closeable, StorageOperate {
if (dstFile.isDirectory()) { if (dstFile.isDirectory()) {
Files.delete(dstFile.toPath()); Files.delete(dstFile.toPath());
} else { } else {
Files.createDirectories(dstFile.getParentFile().toPath()); FileUtils.createDirectoryWith755(dstFile.getParentFile().toPath());
} }
S3Object o = s3Client.getObject(bucketName, srcFilePath); S3Object o = s3Client.getObject(bucketName, srcFilePath);
try ( try (

8
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/shell/BaseLinuxShellInterceptorBuilder.java

@ -17,8 +17,6 @@
package org.apache.dolphinscheduler.plugin.task.api.shell; package org.apache.dolphinscheduler.plugin.task.api.shell;
import org.apache.dolphinscheduler.common.constants.TenantConstants;
import org.apache.dolphinscheduler.common.exception.FileOperateException;
import org.apache.dolphinscheduler.common.utils.FileUtils; import org.apache.dolphinscheduler.common.utils.FileUtils;
import org.apache.dolphinscheduler.common.utils.PropertyUtils; import org.apache.dolphinscheduler.common.utils.PropertyUtils;
import org.apache.dolphinscheduler.plugin.task.api.utils.AbstractCommandExecutorConstants; import org.apache.dolphinscheduler.plugin.task.api.utils.AbstractCommandExecutorConstants;
@ -71,12 +69,8 @@ public abstract class BaseLinuxShellInterceptorBuilder<T extends BaseLinuxShellI
"****************************** Script Content *****************************************************************"); "****************************** Script Content *****************************************************************");
} }
protected List<String> generateBootstrapCommand() throws FileOperateException { protected List<String> generateBootstrapCommand() {
if (sudoEnable) { if (sudoEnable) {
if (!TenantConstants.BOOTSTRAPT_SYSTEM_USER.equals(runUser)) {
// Set the tenant owner as the working directory
FileUtils.setDirectoryOwner(Paths.get(shellDirectory), runUser);
}
return bootstrapCommandInSudoMode(); return bootstrapCommandInSudoMode();
} }
return bootstrapCommandInNormalMode(); return bootstrapCommandInNormalMode();

3
dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/test/java/org/apache/dolphinscheduler/plugin/task/java/JavaTaskTest.java

@ -22,6 +22,7 @@ import static org.apache.dolphinscheduler.plugin.task.api.enums.Direct.IN;
import static org.apache.dolphinscheduler.plugin.task.java.JavaConstants.RUN_TYPE_JAR; import static org.apache.dolphinscheduler.plugin.task.java.JavaConstants.RUN_TYPE_JAR;
import static org.apache.dolphinscheduler.plugin.task.java.JavaConstants.RUN_TYPE_JAVA; import static org.apache.dolphinscheduler.plugin.task.java.JavaConstants.RUN_TYPE_JAVA;
import org.apache.dolphinscheduler.common.utils.FileUtils;
import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.plugin.task.api.TaskCallBack; import org.apache.dolphinscheduler.plugin.task.api.TaskCallBack;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
@ -155,7 +156,7 @@ public class JavaTaskTest {
try { try {
Path path = Paths.get(fileName); Path path = Paths.get(fileName);
if (!Files.exists(path)) { if (!Files.exists(path)) {
Files.createDirectories(path); FileUtils.createDirectoryWith755(path);
} }
javaTask.createJavaSourceFileIfNotExists(sourceCode, fileName); javaTask.createJavaSourceFileIfNotExists(sourceCode, fileName);
} finally { } finally {

3
dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/utils/TaskExecutionContextUtils.java

@ -97,7 +97,7 @@ public class TaskExecutionContextUtils {
log.warn("The TaskInstance WorkingDirectory: {} is exist, will recreate again", log.warn("The TaskInstance WorkingDirectory: {} is exist, will recreate again",
taskInstanceWorkingDirectory); taskInstanceWorkingDirectory);
} }
Files.createDirectories(Paths.get(taskInstanceWorkingDirectory)); FileUtils.createDirectoryWith755(Paths.get(taskInstanceWorkingDirectory));
taskExecutionContext.setExecutePath(taskInstanceWorkingDirectory); taskExecutionContext.setExecutePath(taskInstanceWorkingDirectory);
taskExecutionContext.setAppInfoPath(FileUtils.getAppInfoPath(taskInstanceWorkingDirectory)); taskExecutionContext.setAppInfoPath(FileUtils.getAppInfoPath(taskInstanceWorkingDirectory));
@ -137,6 +137,7 @@ public class TaskExecutionContextUtils {
storageOperate.download(resourceAbsolutePathInStorage, resourceAbsolutePathInLocal, true); storageOperate.download(resourceAbsolutePathInStorage, resourceAbsolutePathInLocal, true);
log.debug("Download resource file {} under: {} successfully", resourceAbsolutePathInStorage, log.debug("Download resource file {} under: {} successfully", resourceAbsolutePathInStorage,
resourceAbsolutePathInLocal); resourceAbsolutePathInLocal);
FileUtils.setFileTo755(file);
WorkerServerMetrics WorkerServerMetrics
.recordWorkerResourceDownloadTime(System.currentTimeMillis() - resourceDownloadStartTime); .recordWorkerResourceDownloadTime(System.currentTimeMillis() - resourceDownloadStartTime);
WorkerServerMetrics WorkerServerMetrics

2
dolphinscheduler-worker/src/test/java/org/apache/dolphinscheduler/server/worker/utils/TaskExecutionContextUtilsTest.java

@ -49,7 +49,7 @@ class TaskExecutionContextUtilsTest {
try { try {
// Test if the working directory is exist // Test if the working directory is exist
// will delete it and recreate // will delete it and recreate
Files.createDirectories(Paths.get(taskWorkingDirectory)); FileUtils.createDirectoryWith755(Paths.get(taskWorkingDirectory));
Files.createFile(Paths.get(taskWorkingDirectory, "text.txt")); Files.createFile(Paths.get(taskWorkingDirectory, "text.txt"));
Assertions.assertTrue(Files.exists(Paths.get(taskWorkingDirectory, "text.txt"))); Assertions.assertTrue(Files.exists(Paths.get(taskWorkingDirectory, "text.txt")));

Loading…
Cancel
Save