Skip to content

Commit 97139f1

Browse files
committed
fix: Resource relate path invalid when tenant change
* fix can not get correct resource related path when user run workflow with differnet tenant of resource created * also fix can not get correct related path when we use `resource.storage.type=LOCAL`
1 parent 89da67d commit 97139f1

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

dolphinscheduler-storage-plugin/dolphinscheduler-storage-api/src/main/java/org/apache/dolphinscheduler/plugin/storage/api/StorageOperate.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.dolphinscheduler.plugin.storage.api;
1919

20+
import static org.apache.dolphinscheduler.common.constants.Constants.RESOURCE_TYPE_FILE;
21+
2022
import org.apache.dolphinscheduler.common.constants.Constants;
2123
import org.apache.dolphinscheduler.common.enums.ResUploadType;
2224
import org.apache.dolphinscheduler.common.utils.PropertyUtils;
@@ -72,7 +74,16 @@ public interface StorageOperate {
7274
*/
7375
default String getResourceFileName(String tenantCode, String fullName) {
7476
String resDir = getResDir(tenantCode);
75-
return fullName.replaceFirst(resDir, "");
77+
String filenameReplaceResDir = fullName.replaceFirst(resDir, "");
78+
if (!filenameReplaceResDir.equals(fullName)) {
79+
return filenameReplaceResDir;
80+
}
81+
82+
// Replace resource dir not effective in case of run workflow with different tenant from resource file's.
83+
// this is backup solution to get related path, by split with RESOURCE_TYPE_FILE
84+
return filenameReplaceResDir.contains(RESOURCE_TYPE_FILE)
85+
? filenameReplaceResDir.split(String.format("%s/", RESOURCE_TYPE_FILE))[1]
86+
: filenameReplaceResDir;
7687
}
7788

7889
/**

dolphinscheduler-storage-plugin/dolphinscheduler-storage-hdfs/src/main/java/org/apache/dolphinscheduler/plugin/storage/hdfs/HdfsStorageOperator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
@Slf4j
7272
public class HdfsStorageOperator implements Closeable, StorageOperate {
7373

74-
private static HdfsStorageProperties hdfsProperties = new HdfsStorageProperties();
74+
protected static HdfsStorageProperties hdfsProperties = new HdfsStorageProperties();
7575
private static final String HADOOP_UTILS_KEY = "HADOOP_UTILS_KEY";
7676

7777
private volatile boolean yarnEnabled = false;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.dolphinscheduler.plugin.storage.hdfs;
19+
20+
import lombok.extern.slf4j.Slf4j;
21+
22+
@Slf4j
23+
public class LocalStorageOperator extends HdfsStorageOperator {
24+
25+
public LocalStorageOperator() {
26+
super(new HdfsStorageProperties());
27+
}
28+
29+
public LocalStorageOperator(HdfsStorageProperties hdfsStorageProperties) {
30+
super(hdfsStorageProperties);
31+
}
32+
33+
@Override
34+
public String getResourceFileName(String tenantCode, String fullName) {
35+
// prefix schema `file:/` should be remove in local file mode
36+
String fullNameRemoveSchema = fullName.replaceFirst(hdfsProperties.getDefaultFS(), "");
37+
return super.getResourceFileName(tenantCode, fullNameRemoveSchema);
38+
}
39+
}

dolphinscheduler-storage-plugin/dolphinscheduler-storage-hdfs/src/main/java/org/apache/dolphinscheduler/plugin/storage/hdfs/LocalStorageOperatorFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class LocalStorageOperatorFactory implements StorageOperateFactory {
3232
public StorageOperate createStorageOperate() {
3333
HdfsStorageProperties hdfsStorageProperties = new HdfsStorageProperties();
3434
hdfsStorageProperties.setDefaultFS(LOCAL_DEFAULT_FS);
35-
return new HdfsStorageOperator(hdfsStorageProperties);
35+
return new LocalStorageOperator(hdfsStorageProperties);
3636
}
3737

3838
@Override

0 commit comments

Comments
 (0)