Skip to content

Commit 78e5569

Browse files
authored
[feat] Add type local turn on resource center by default (#13303)
1 parent 78ba71b commit 78e5569

10 files changed

Lines changed: 192 additions & 45 deletions

File tree

‎docs/docs/en/guide/resource/configuration.md‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@
99

1010
### Configure `common.properties`
1111

12-
If you deploy DolphinScheduler in `Cluster` or `Pseudo-Cluster` mode, you need to configure `api-server/conf/common.properties` and `worker-server/conf/common.properties`.
13-
If you deploy DolphinScheduler in `Standalone` mode, you only need to configure `standalone-server/conf/common.properties` as follows:
12+
DolphinScheduler Resource Center uses local file system by default, and does not require any additional configuration.
13+
But please make sure to change the following configuration at the same time when you need to modify the default value.
14+
15+
- If you deploy DolphinScheduler in `Cluster` or `Pseudo-Cluster` mode, you need to configure `api-server/conf/common.properties` and `worker-server/conf/common.properties`.
16+
- If you deploy DolphinScheduler in `Standalone` mode, you only need to configure `standalone-server/conf/common.properties` as follows:
17+
18+
The configuration you may need to change:
1419

1520
- Change `resource.storage.upload.base.path` to your local directory path. Please make sure the `tenant resource.hdfs.root.user` has read and write permissions for `resource.storage.upload.base.path`, e,g. `/tmp/dolphinscheduler`. `DolphinScheduler` will create the directory you configure if it does not exist.
16-
- Modify `resource.storage.type=HDFS` and `resource.hdfs.fs.defaultFS=file:///`.
1721

18-
> NOTE: Please modify the value of `resource.storage.upload.base.path` if you do not want to use the default value as the base path.
22+
> NOTE:
23+
> 1. LOCAL mode does not support reading and writing in distributed mode, which mean you can only use your resource in one machine, unless use shared file mount point
24+
> 2. Please modify the value of `resource.storage.upload.base.path` if you do not want to use the default value as the base path.
25+
> 3. The local config is `resource.storage.type=LOCAL` it has actually configured two setting, `resource.storage.type=HDFS`
26+
> and `resource.hdfs.fs.defaultFS=file:///`, The configuration of `resource.storage.type=LOCAL` is for user-friendly, and enables
27+
> the local resource center to be enabled by default
1928
2029
## Use HDFS or Remote Object Storage
2130

‎docs/docs/zh/guide/resource/configuration.md‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@
99

1010
### 配置 `common.properties` 文件
1111

12-
如果您以 `集群` 模式或者 `伪集群` 模式部署DolphinScheduler,您需要对以下路径的文件进行配置:`api-server/conf/common.properties``worker-server/conf/common.properties`
13-
若您以 `单机` 模式部署DolphinScheduler,您只需要配置 `standalone-server/conf/common.properties`,具体配置如下:
12+
Dolphinscheduler 资源中心使用本地系统默认是开启的,不需要用户做任何额外的配置,但是当用户需要对默认配置做修改时,请确保同时完成下面的修改。
13+
14+
- 如果您以 `集群` 模式或者 `伪集群` 模式部署DolphinScheduler,您需要对以下路径的文件进行配置:`api-server/conf/common.properties``worker-server/conf/common.properties`
15+
- 若您以 `单机` 模式部署DolphinScheduler,您只需要配置 `standalone-server/conf/common.properties`,具体配置如下:
16+
17+
您可能需要涉及如下的修改:
1418

1519
-`resource.storage.upload.base.path` 改为本地存储路径,请确保部署 DolphinScheduler 的用户拥有读写权限,例如:`resource.storage.upload.base.path=/tmp/dolphinscheduler`。当路径不存在时会自动创建文件夹
16-
- 修改 `resource.storage.type=HDFS``resource.hdfs.fs.defaultFS=file:///`
1720

18-
> **注意**:如果您不想用默认值作为资源中心的基础路径,请修改`resource.storage.upload.base.path`的值。
21+
> **注意**
22+
> 1. LOCAL模式不支持分布式模式读写,意味着上传的资源只能在一台机器上使用,除非使用共享文件挂载点
23+
> 2. 如果您不想用默认值作为资源中心的基础路径,请修改`resource.storage.upload.base.path`的值。
24+
> 3. 当配置 `resource.storage.type=LOCAL`,其实您配置了两个配置项,分别是 `resource.storage.type=HDFS``resource.hdfs.fs.defaultFS=file:///` ,我们单独配置 `resource.storage.type=LOCAL` 这个值是为了
25+
> 方便用户,并且能使得本地资源中心默认开启
1926
2027
## 对接分布式或远端对象存储
2128

@@ -46,8 +53,8 @@
4653
# user data local directory path, please make sure the directory exists and have read write permissions
4754
data.basedir.path=/tmp/dolphinscheduler
4855

49-
# resource storage type: HDFS, S3, OSS, NONE
50-
resource.storage.type=HDFS
56+
# resource storage type: LOCAL, HDFS, S3, OSS
57+
resource.storage.type=LOCAL
5158

5259
# resource store on HDFS/S3/OSS path, resource file will store to this hadoop hdfs path, self configuration,
5360
# please make sure the directory exists on hdfs and have read write permissions. "/dolphinscheduler" is recommended

‎dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/ResUploadType.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
* data base types
2222
*/
2323
public enum ResUploadType {
24-
HDFS, S3, OSS, NONE
24+
LOCAL, HDFS, S3, OSS, NONE
2525
}

‎dolphinscheduler-common/src/main/resources/common.properties‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ data.basedir.path=/tmp/dolphinscheduler
2121
# resource view suffixs
2222
#resource.view.suffixs=txt,log,sh,bat,conf,cfg,py,java,sql,xml,hql,properties,json,yml,yaml,ini,js
2323

24-
# resource storage type: HDFS, S3, OSS, NONE
25-
resource.storage.type=NONE
24+
# resource storage type: LOCAL, HDFS, S3, OSS, NONE. LOCAL type is a specific type of HDFS with "resource.hdfs.fs.defaultFS = file:///" configuration
25+
# please notice that LOCAL mode does not support reading and writing in distributed mode, which mean you can only use your resource in one machine, unless
26+
# use shared file mount point
27+
resource.storage.type=LOCAL
2628
# resource store on HDFS/S3 path, resource file will store to this base path, self configuration, please make sure the directory exists on hdfs and have read write permissions. "/dolphinscheduler" is recommended
2729
resource.storage.upload.base.path=/dolphinscheduler
2830

‎dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/PropertyUtilsTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public void getString() {
3131

3232
@Test
3333
public void getResUploadStartupState() {
34-
Assertions.assertFalse(PropertyUtils.getResUploadStartupState());
34+
Assertions.assertTrue(PropertyUtils.getResUploadStartupState());
3535
}
3636
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121

2222
public enum StorageType {
2323

24-
HDFS(0, "HDFS"),
25-
OSS(1, "OSS"),
26-
S3(2, "S3"),
24+
LOCAL(0, "LOCAL"),
25+
HDFS(1, "HDFS"),
26+
OSS(2, "OSS"),
27+
S3(3, "S3"),
2728
;
2829

2930
private final int code;

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

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,17 @@
7777
public class HdfsStorageOperator implements Closeable, StorageOperate {
7878

7979
private static final Logger logger = LoggerFactory.getLogger(HdfsStorageOperator.class);
80-
private String hdfsUser;
81-
public static final String RM_HA_IDS = PropertyUtils.getString(Constants.YARN_RESOURCEMANAGER_HA_RM_IDS);
82-
public static final String APP_ADDRESS = PropertyUtils.getString(Constants.YARN_APPLICATION_STATUS_ADDRESS);
83-
public static final String JOB_HISTORY_ADDRESS = PropertyUtils.getString(Constants.YARN_JOB_HISTORY_STATUS_ADDRESS);
84-
public static final int HADOOP_RESOURCE_MANAGER_HTTP_ADDRESS_PORT_VALUE =
85-
PropertyUtils.getInt(Constants.HADOOP_RESOURCE_MANAGER_HTTPADDRESS_PORT, 8088);
80+
private static HdfsStorageProperties hdfsProperties;
8681
private static final String HADOOP_UTILS_KEY = "HADOOP_UTILS_KEY";
8782

8883
private static final LoadingCache<String, HdfsStorageOperator> cache = CacheBuilder
8984
.newBuilder()
90-
.expireAfterWrite(PropertyUtils.getInt(Constants.KERBEROS_EXPIRE_TIME, 2), TimeUnit.HOURS)
85+
.expireAfterWrite(HdfsStorageProperties.getKerberosExpireTime(), TimeUnit.HOURS)
9186
.build(new CacheLoader<String, HdfsStorageOperator>() {
9287

9388
@Override
9489
public HdfsStorageOperator load(String key) throws Exception {
95-
return new HdfsStorageOperator();
90+
return new HdfsStorageOperator(hdfsProperties);
9691
}
9792
});
9893

@@ -101,8 +96,13 @@ public HdfsStorageOperator load(String key) throws Exception {
10196
private Configuration configuration;
10297
private FileSystem fs;
10398

104-
private HdfsStorageOperator() {
105-
hdfsUser = PropertyUtils.getString(Constants.HDFS_ROOT_USER);
99+
public HdfsStorageOperator() {
100+
this(new HdfsStorageProperties());
101+
}
102+
103+
public HdfsStorageOperator(HdfsStorageProperties hdfsStorageProperties) {
104+
// Overwrite config from passing hdfsStorageProperties
105+
hdfsProperties = hdfsStorageProperties;
106106
init();
107107
initHdfsPath();
108108
}
@@ -133,16 +133,12 @@ private void init() throws NullPointerException {
133133
try {
134134
configuration = new HdfsConfiguration();
135135

136+
String hdfsUser = hdfsProperties.getUser();
136137
if (CommonUtils.loadKerberosConf(configuration)) {
137138
hdfsUser = "";
138139
}
139140

140-
String defaultFS = configuration.get(Constants.FS_DEFAULT_FS);
141-
142-
if (StringUtils.isBlank(defaultFS)) {
143-
defaultFS = PropertyUtils.getString(Constants.FS_DEFAULT_FS);
144-
}
145-
141+
String defaultFS = getDefaultFS();
146142
// first get key from core-site.xml hdfs-site.xml ,if null ,then try to get from properties file
147143
// the default is the local file system
148144
if (StringUtils.isNotBlank(defaultFS)) {
@@ -189,7 +185,7 @@ public Configuration getConfiguration() {
189185
public String getDefaultFS() {
190186
String defaultFS = getConfiguration().get(Constants.FS_DEFAULT_FS);
191187
if (StringUtils.isBlank(defaultFS)) {
192-
defaultFS = PropertyUtils.getString(Constants.FS_DEFAULT_FS);
188+
defaultFS = hdfsProperties.getDefaultFS();
193189
}
194190
return defaultFS;
195191
}
@@ -207,18 +203,20 @@ public String getDefaultFS() {
207203
public String getApplicationUrl(String applicationId) throws BaseException {
208204

209205
yarnEnabled = true;
210-
String appUrl = StringUtils.isEmpty(RM_HA_IDS) ? APP_ADDRESS : getAppAddress(APP_ADDRESS, RM_HA_IDS);
206+
String appUrl = StringUtils.isEmpty(hdfsProperties.getYarnResourceRmIds())
207+
? hdfsProperties.getYarnAppStatusAddress()
208+
: getAppAddress(hdfsProperties.getYarnAppStatusAddress(), hdfsProperties.getYarnResourceRmIds());
211209
if (StringUtils.isBlank(appUrl)) {
212210
throw new BaseException("yarn application url generation failed");
213211
}
214212
logger.debug("yarn application url:{}, applicationId:{}", appUrl, applicationId);
215-
return String.format(appUrl, HADOOP_RESOURCE_MANAGER_HTTP_ADDRESS_PORT_VALUE, applicationId);
213+
return String.format(appUrl, hdfsProperties.getHadoopResourceManagerHttpAddressPort(), applicationId);
216214
}
217215

218216
public String getJobHistoryUrl(String applicationId) {
219217
// eg:application_1587475402360_712719 -> job_1587475402360_712719
220218
String jobId = applicationId.replace("application", "job");
221-
return String.format(JOB_HISTORY_ADDRESS, jobId);
219+
return String.format(hdfsProperties.getYarnJobHistoryStatusAddress(), jobId);
222220
}
223221

224222
/**
@@ -601,7 +599,7 @@ public boolean isYarnEnabled() {
601599
* @return data hdfs path
602600
*/
603601
public static String getHdfsDataBasePath() {
604-
String defaultFS = PropertyUtils.getString(Constants.FS_DEFAULT_FS);
602+
String defaultFS = hdfsProperties.getDefaultFS();
605603
defaultFS = defaultFS.endsWith("/") ? StringUtils.chop(defaultFS) : defaultFS;
606604
if (FOLDER_SEPARATOR.equals(RESOURCE_UPLOAD_PATH)) {
607605
return defaultFS + "";
@@ -764,7 +762,8 @@ public static String getActiveRMName(String protocol, String rmIds) {
764762

765763
String[] rmIdArr = rmIds.split(Constants.COMMA);
766764

767-
String yarnUrl = protocol + "%s:" + HADOOP_RESOURCE_MANAGER_HTTP_ADDRESS_PORT_VALUE + "/ws/v1/cluster/info";
765+
String yarnUrl =
766+
protocol + "%s:" + hdfsProperties.getHadoopResourceManagerHttpAddressPort() + "/ws/v1/cluster/info";
768767

769768
try {
770769

@@ -791,7 +790,7 @@ public static String getActiveRMName(String protocol, String rmIds) {
791790
public static String getRMState(String url) {
792791

793792
String retStr = Boolean.TRUE
794-
.equals(PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, false))
793+
.equals(hdfsProperties.isHadoopSecurityAuthStartupState())
795794
? KerberosHttpClient.get(url)
796795
: HttpUtils.get(url);
797796

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 static org.apache.dolphinscheduler.common.constants.Constants.FS_DEFAULT_FS;
21+
import static org.apache.dolphinscheduler.common.constants.Constants.HADOOP_RESOURCE_MANAGER_HTTPADDRESS_PORT;
22+
import static org.apache.dolphinscheduler.common.constants.Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE;
23+
import static org.apache.dolphinscheduler.common.constants.Constants.HDFS_ROOT_USER;
24+
import static org.apache.dolphinscheduler.common.constants.Constants.KERBEROS_EXPIRE_TIME;
25+
import static org.apache.dolphinscheduler.common.constants.Constants.YARN_APPLICATION_STATUS_ADDRESS;
26+
import static org.apache.dolphinscheduler.common.constants.Constants.YARN_JOB_HISTORY_STATUS_ADDRESS;
27+
import static org.apache.dolphinscheduler.common.constants.Constants.YARN_RESOURCEMANAGER_HA_RM_IDS;
28+
29+
import org.apache.dolphinscheduler.common.utils.PropertyUtils;
30+
31+
import lombok.Data;
32+
33+
import org.springframework.context.annotation.Configuration;
34+
35+
@Data
36+
@Configuration
37+
public class HdfsStorageProperties {
38+
39+
/**
40+
* HDFS storage user
41+
*/
42+
private String user = PropertyUtils.getString(HDFS_ROOT_USER);
43+
44+
/**
45+
* HDFS default fs
46+
*/
47+
private String defaultFS = PropertyUtils.getString(FS_DEFAULT_FS);
48+
49+
/**
50+
* YARN resource manager HA RM ids
51+
*/
52+
private String yarnResourceRmIds = PropertyUtils.getString(YARN_RESOURCEMANAGER_HA_RM_IDS);
53+
54+
/**
55+
* YARN application status address
56+
*/
57+
private String yarnAppStatusAddress = PropertyUtils.getString(YARN_APPLICATION_STATUS_ADDRESS);
58+
59+
/**
60+
* YARN job history status address
61+
*/
62+
private String yarnJobHistoryStatusAddress = PropertyUtils.getString(YARN_JOB_HISTORY_STATUS_ADDRESS);
63+
64+
/**
65+
* Hadoop resouece manager http address port
66+
*/
67+
private String hadoopResourceManagerHttpAddressPort =
68+
PropertyUtils.getString(HADOOP_RESOURCE_MANAGER_HTTPADDRESS_PORT);
69+
70+
/**
71+
* Hadoop security authentication startup state
72+
*/
73+
private boolean hadoopSecurityAuthStartupState =
74+
PropertyUtils.getBoolean(HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, false);
75+
76+
/**
77+
* Kerberos expire time
78+
*/
79+
public static int getKerberosExpireTime() {
80+
return PropertyUtils.getInt(KERBEROS_EXPIRE_TIME, 2);
81+
}
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 org.apache.dolphinscheduler.plugin.storage.api.StorageOperate;
21+
import org.apache.dolphinscheduler.plugin.storage.api.StorageOperateFactory;
22+
import org.apache.dolphinscheduler.plugin.storage.api.StorageType;
23+
24+
import com.google.auto.service.AutoService;
25+
26+
@AutoService(StorageOperateFactory.class)
27+
public class LocalStorageOperatorFactory implements StorageOperateFactory {
28+
29+
private static final String LOCAL_DEFAULT_FS = "file:///";
30+
31+
@Override
32+
public StorageOperate createStorageOperate() {
33+
HdfsStorageProperties hdfsStorageProperties = new HdfsStorageProperties();
34+
hdfsStorageProperties.setDefaultFS(LOCAL_DEFAULT_FS);
35+
return new HdfsStorageOperator(hdfsStorageProperties);
36+
}
37+
38+
@Override
39+
public StorageType getStorageOperate() {
40+
return StorageType.LOCAL;
41+
}
42+
}

‎dolphinscheduler-storage-plugin/dolphinscheduler-storage-hdfs/src/test/java/org/apache/dolphinscheduler/plugin/storage/hdfs/HdfsStorageOperatorTest.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,39 @@ public class HdfsStorageOperatorTest {
3939

4040
@Test
4141
public void getHdfsTenantDir() {
42-
logger.info(HdfsStorageOperator.getHdfsTenantDir("1234"));
42+
HdfsStorageOperator hdfsStorageOperator = new HdfsStorageOperator();
43+
logger.info(hdfsStorageOperator.getHdfsTenantDir("1234"));
4344
Assertions.assertTrue(true);
4445
}
4546

4647
@Test
4748
public void getHdfsUdfFileName() {
48-
logger.info(HdfsStorageOperator.getHdfsUdfFileName("admin", "file_name"));
49+
HdfsStorageOperator hdfsStorageOperator = new HdfsStorageOperator();
50+
logger.info(hdfsStorageOperator.getHdfsUdfFileName("admin", "file_name"));
4951
Assertions.assertTrue(true);
5052
}
5153

5254
@Test
5355
public void getHdfsResourceFileName() {
54-
logger.info(HdfsStorageOperator.getHdfsResourceFileName("admin", "file_name"));
56+
HdfsStorageOperator hdfsStorageOperator = new HdfsStorageOperator();
57+
logger.info(hdfsStorageOperator.getHdfsResourceFileName("admin", "file_name"));
5558
Assertions.assertTrue(true);
5659
}
5760

5861
@Test
5962
public void getHdfsFileName() {
60-
logger.info(HdfsStorageOperator.getHdfsFileName(ResourceType.FILE, "admin", "file_name"));
63+
HdfsStorageOperator hdfsStorageOperator = new HdfsStorageOperator();
64+
logger.info(hdfsStorageOperator.getHdfsFileName(ResourceType.FILE, "admin", "file_name"));
6165
Assertions.assertTrue(true);
6266
}
6367

6468
@Test
6569
public void getAppAddress() {
70+
HdfsStorageOperator hdfsStorageOperator = new HdfsStorageOperator();
6671
try (MockedStatic<HttpUtils> mockedHttpUtils = Mockito.mockStatic(HttpUtils.class)) {
6772
mockedHttpUtils.when(() -> HttpUtils.get("http://ds1:8088/ws/v1/cluster/info"))
6873
.thenReturn("{\"clusterInfo\":{\"state\":\"STARTED\",\"haState\":\"ACTIVE\"}}");
69-
logger.info(HdfsStorageOperator.getAppAddress("http://ds1:8088/ws/v1/cluster/apps/%s", "ds1,ds2"));
74+
logger.info(hdfsStorageOperator.getAppAddress("http://ds1:8088/ws/v1/cluster/apps/%s", "ds1,ds2"));
7075
Assertions.assertTrue(true);
7176
}
7277
}

0 commit comments

Comments
 (0)