Browse Source

verify whether the filename start with '/' (#2544)

* fix #2442 when the resource name contains '$',need translate it to '\$'

* fix #2442 when the resource name contains '$',need translate it to '/$'

* verify whether the filename start with '/'

Co-authored-by: qiaozhanwei <qiaozhanwei@outlook.com>
Co-authored-by: dailidong <dailidong66@gmail.com>
pull/2/head
lgcareer 5 years ago committed by GitHub
parent
commit
fd79be39a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HadoopUtils.java
  2. 12
      dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HadoopUtilsTest.java

9
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HadoopUtils.java

@ -503,6 +503,9 @@ public class HadoopUtils implements Closeable {
* @return hdfs file name * @return hdfs file name
*/ */
public static String getHdfsFileName(ResourceType resourceType, String tenantCode, String fileName) { public static String getHdfsFileName(ResourceType resourceType, String tenantCode, String fileName) {
if (fileName.startsWith("/")) {
fileName = fileName.replaceFirst("/","");
}
return String.format("%s/%s", getHdfsDir(resourceType,tenantCode), fileName); return String.format("%s/%s", getHdfsDir(resourceType,tenantCode), fileName);
} }
@ -514,6 +517,9 @@ public class HadoopUtils implements Closeable {
* @return get absolute path and name for file on hdfs * @return get absolute path and name for file on hdfs
*/ */
public static String getHdfsResourceFileName(String tenantCode, String fileName) { public static String getHdfsResourceFileName(String tenantCode, String fileName) {
if (fileName.startsWith("/")) {
fileName = fileName.replaceFirst("/","");
}
return String.format("%s/%s", getHdfsResDir(tenantCode), fileName); return String.format("%s/%s", getHdfsResDir(tenantCode), fileName);
} }
@ -525,6 +531,9 @@ public class HadoopUtils implements Closeable {
* @return get absolute path and name for udf file on hdfs * @return get absolute path and name for udf file on hdfs
*/ */
public static String getHdfsUdfFileName(String tenantCode, String fileName) { public static String getHdfsUdfFileName(String tenantCode, String fileName) {
if (fileName.startsWith("/")) {
fileName = fileName.replaceFirst("/","");
}
return String.format("%s/%s", getHdfsUdfDir(tenantCode), fileName); return String.format("%s/%s", getHdfsUdfDir(tenantCode), fileName);
} }

12
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HadoopUtilsTest.java

@ -127,6 +127,18 @@ public class HadoopUtilsTest {
Assert.assertEquals("/dolphinscheduler/11000/resources/aa.txt", result); Assert.assertEquals("/dolphinscheduler/11000/resources/aa.txt", result);
} }
@Test
public void getHdfsResourceFileName() {
String result = hadoopUtils.getHdfsResourceFileName("11000","aa.txt");
Assert.assertEquals("/dolphinscheduler/11000/resources/aa.txt", result);
}
@Test
public void getHdfsUdfFileName() {
String result = hadoopUtils.getHdfsFileName(ResourceType.UDF,"11000","aa.txt");
Assert.assertEquals("/dolphinscheduler/11000/udfs/aa.txt", result);
}
@Test @Test
public void isYarnEnabled() { public void isYarnEnabled() {
boolean result = hadoopUtils.isYarnEnabled(); boolean result = hadoopUtils.isYarnEnabled();

Loading…
Cancel
Save