github-code-scanning[bot] commented on code in PR #13343:
URL:
https://github.com/apache/dolphinscheduler/pull/13343#discussion_r1062196389
##########
dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/utils/TaskFilesTransferUtils.java:
##########
@@ -285,4 +312,83 @@
}
return newPath;
}
+
+ /**
+ * If have enough temporary storage, move output file to tmp dir and
replace srcPath with scp command.
+ *
+ * @param taskExecutionContext is the context of task
+ * @param srcPath is original source path
+ * @return new source path after using tmp storage (remain unchanged if
not use)
+ */
+ public static String moveIfUseTmpStorage(TaskExecutionContext
taskExecutionContext, String srcPath) {
+ long maxTmpFileSize = PropertyUtils.getLong(TMP_TRANSFER_FILE_SIZE,
100) * 1024 * 1024;
+ try {
+ String tmpDir = FileUtils.getTmpDir(
+ FileUtils.getTmpBaseDir(),
+ taskExecutionContext.getTenantCode(),
+ taskExecutionContext.getProjectCode(),
+ taskExecutionContext.getProcessDefineCode(),
+ taskExecutionContext.getProcessDefineVersion(),
+ taskExecutionContext.getProcessInstanceId());
+ long tmpDirSize = FileUtils.getDirectorySize(tmpDir);
+ if (tmpDirSize < maxTmpFileSize) {
+ String fileName =
srcPath.substring(srcPath.lastIndexOf(SINGLE_SLASH) + 1);
+ String tmpPath = String.format(FORMAT_S_S, tmpDir, fileName);
+ FileUtils.renameTo(srcPath, tmpPath);
+ logger.info("Save output files in temporary path: {}",
tmpPath);
+ // fill in partial scp command template
+ String preparedCommand = String.format(SCP_COMMAND_TEMPLATE,
+ taskExecutionContext.getTenantCode(),
+ taskExecutionContext.getHost().split(":")[0],
+ tmpPath,
+ FORMAT_S);
+ logger.info("Generate scp command template: {}",
preparedCommand);
+ FileUtils.writeContent2File(preparedCommand, srcPath);
+
+ String templatePath = srcPath + TEMPLATE_SUFFIX;
+ FileUtils.renameTo(srcPath, templatePath);
+ srcPath = templatePath;
+ }
+ } catch (IOException ex) {
+ throw new TaskException(ex.getMessage(), ex);
+ }
+ return srcPath;
+ }
+
+ /**
+ * Complete and execute scp command
+ *
+ * @param downloadPath is where to save scp files
+ * @param targetPath zip file will be unpacked later, rather, move to
targetPath directly
+ * @return true if fetch a zip file
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ public static boolean scpFetchFile(String downloadPath,
+ String targetPath) throws IOException,
InterruptedException {
+ String commandString = "";
+ try (FileInputStream fileInputStream = new
FileInputStream(downloadPath)) {
+ commandString = FileUtils.readFile2Str(fileInputStream);
+ } catch (IOException ex) {
+ logger.error("Read command file error.");
+ }
+
+ boolean isZip = downloadPath.endsWith(PACK_SUFFIX + TEMPLATE_SUFFIX);
+
+ String execCommand = String.format(commandString, downloadPath);
Review Comment:
## Unused format argument
This format call refers to 0 argument(s) but supplies 1 argument(s).
[Show more
details](https://github.com/apache/dolphinscheduler/security/code-scanning/2473)
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]