Skip to content

Commit d6d9488

Browse files
committed
Support config a seperate datasource for quartz
1 parent dbb7c4c commit d6d9488

5 files changed

Lines changed: 147 additions & 4 deletions

File tree

dolphinscheduler-master/src/main/resources/application.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ spring:
3030
hikari:
3131
connection-test-query: select 1
3232
pool-name: DolphinScheduler
33+
quartz-datasource:
34+
# By default, do not use a separate datasource for quartz
35+
# If you want to use a separate datasource, set it to true and configure the datasource below
36+
# If set true and you do not configure hikari below, it will use the same configuration as spring.datasource.hikari
37+
using-separate-datasource: false
38+
# hikari:
3339
quartz:
3440
job-store-type: jdbc
3541
jdbc:
@@ -156,3 +162,5 @@ spring:
156162
quartz:
157163
properties:
158164
org.quartz.jobStore.driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
165+
quartz-datasource:
166+
using-separate-datasource: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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.scheduler.quartz;
19+
20+
import javax.sql.DataSource;
21+
22+
import lombok.Data;
23+
import lombok.extern.slf4j.Slf4j;
24+
25+
import org.springframework.beans.factory.annotation.Autowired;
26+
import org.springframework.boot.context.properties.ConfigurationProperties;
27+
import org.springframework.context.annotation.Configuration;
28+
import org.springframework.validation.Errors;
29+
import org.springframework.validation.Validator;
30+
31+
import com.zaxxer.hikari.HikariConfig;
32+
import com.zaxxer.hikari.HikariDataSource;
33+
34+
@Slf4j
35+
@Data
36+
@Configuration
37+
@ConfigurationProperties(prefix = "spring.quartz-datasource")
38+
public class QuartzDataSourceConfig implements Validator {
39+
40+
private boolean usingSeparateDatasource = false;
41+
42+
private HikariConfig hikari;
43+
44+
@Autowired
45+
private DataSource dataSource;
46+
47+
@Override
48+
public boolean supports(Class<?> clazz) {
49+
return QuartzDataSourceConfig.class.isAssignableFrom(clazz);
50+
}
51+
52+
@Override
53+
public void validate(Object target, Errors errors) {
54+
QuartzDataSourceConfig quartzDataSourceConfig = (QuartzDataSourceConfig) target;
55+
if (!quartzDataSourceConfig.isUsingSeparateDatasource()) {
56+
log.info("Will use the application datasource for quartz");
57+
return;
58+
}
59+
if (quartzDataSourceConfig.getHikari() == null) {
60+
log.info(
61+
"The spring.quartz-datasource.hikari is null, will use the application datasource's hikari config for quartz");
62+
hikari = getDefaultQuartzHikariConfig();
63+
} else {
64+
log.info("Will use the datasource: {} for quartz", hikari.getPoolName());
65+
}
66+
}
67+
68+
private HikariConfig getDefaultQuartzHikariConfig() {
69+
HikariConfig defaultQuartzHikariConfig = new HikariConfig();
70+
HikariConfig applicationHikariConfig = (HikariDataSource) dataSource;
71+
applicationHikariConfig.copyStateTo(defaultQuartzHikariConfig);
72+
73+
defaultQuartzHikariConfig.setPoolName("QuartzHikariCP");
74+
return defaultQuartzHikariConfig;
75+
}
76+
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.scheduler.quartz;
19+
20+
import lombok.extern.slf4j.Slf4j;
21+
22+
import org.quartz.Scheduler;
23+
import org.springframework.boot.autoconfigure.AutoConfiguration;
24+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
25+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
26+
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
27+
import org.springframework.boot.autoconfigure.quartz.SchedulerFactoryBeanCustomizer;
28+
import org.springframework.context.annotation.Bean;
29+
import org.springframework.core.annotation.Order;
30+
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
31+
32+
import com.zaxxer.hikari.HikariDataSource;
33+
34+
@Slf4j
35+
@AutoConfiguration(after = {DataSourceAutoConfiguration.class}, before = QuartzSchedulerAutoConfiguration.class)
36+
@ConditionalOnClass(value = Scheduler.class)
37+
@ConditionalOnProperty(prefix = "spring.quartz-datasource", name = "using-separate-datasource", havingValue = "true")
38+
public class QuartzSchedulerDataSourceAutoConfiguration {
39+
40+
@Bean
41+
@Order(1)
42+
public SchedulerFactoryBeanCustomizer schedulerFactoryBeanCustomizer(QuartzDataSourceConfig quartzDataSourceConfig) {
43+
return schedulerFactoryBean -> {
44+
final HikariDataSource quartzDataSource = new HikariDataSource(quartzDataSourceConfig.getHikari());
45+
schedulerFactoryBean.setDataSource(quartzDataSource);
46+
schedulerFactoryBean.setTransactionManager(new DataSourceTransactionManager(quartzDataSource));
47+
};
48+
}
49+
50+
}

dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/resources/META-INF/spring.factories

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
#
1717

1818
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
19+
org.apache.dolphinscheduler.scheduler.quartz.QuartzSchedulerDataSourceAutoConfiguration,\
1920
org.apache.dolphinscheduler.scheduler.quartz.QuartzSchedulerAutoConfiguration

dolphinscheduler-standalone-server/src/main/resources/application.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ spring:
3232
url: jdbc:h2:mem:dolphinscheduler;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true
3333
username: sa
3434
password: ""
35+
hikari:
36+
connection-test-query: select 1
37+
pool-name: DolphinSchedulerDataSource
38+
quartz-datasource:
39+
using-separate-datasource: false
3540
quartz:
3641
job-store-type: jdbc
3742
jdbc:
@@ -161,7 +166,7 @@ master:
161166
# master heartbeat interval
162167
max-heartbeat-interval: 10s
163168
server-load-protection:
164-
enabled: true
169+
enabled: false
165170
# Master max system cpu usage, when the master's system cpu usage is smaller then this value, master server can execute workflow.
166171
max-system-cpu-usage-percentage-thresholds: 0.8
167172
# Master max jvm cpu usage, when the master's jvm cpu usage is smaller then this value, master server can execute workflow.
@@ -197,7 +202,7 @@ worker:
197202
# worker group name. If it is not set, the default value is default.
198203
group: default
199204
server-load-protection:
200-
enabled: true
205+
enabled: false
201206
# Worker max system cpu usage, when the worker's system cpu usage is smaller then this value, worker server can be dispatched tasks.
202207
max-system-cpu-usage-percentage-thresholds: 0.8
203208
# Worker max jvm cpu usage, when the worker's jvm cpu usage is smaller then this value, worker server can be dispatched tasks.
@@ -321,6 +326,8 @@ spring:
321326
schema-locations: classpath:sql/dolphinscheduler_mysql.sql
322327
datasource:
323328
driver-class-name: com.mysql.cj.jdbc.Driver
324-
url: jdbc:mysql://127.0.0.1:3306/dolphinscheduler?useUnicode=true&characterEncoding=UTF-8
329+
url: jdbc:mysql://127.0.0.1:3306/dolphinscheduler-dev?useUnicode=true&characterEncoding=UTF-8
325330
username: root
326-
password: root@123
331+
password: root
332+
quartz-datasource:
333+
using-separate-datasource: true

0 commit comments

Comments
 (0)