Browse Source

upgrade to 3.0.0 fix

3.0.0/version-upgrade
WangJPLeo 2 years ago
parent
commit
a00b1503e3
  1. 6
      dolphinscheduler-tools/pom.xml
  2. 2
      dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/DolphinSchedulerManager.java
  3. 1
      dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/UpgradeDolphinScheduler.java
  4. 9
      dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/dao/UpgradeDao.java
  5. 25
      dolphinscheduler-tools/src/main/resources/application.yaml

6
dolphinscheduler-tools/pom.xml

@ -33,6 +33,12 @@
<groupId>org.apache.dolphinscheduler</groupId> <groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-dao</artifactId> <artifactId>dolphinscheduler-dao</artifactId>
</dependency> </dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

2
dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/DolphinSchedulerManager.java

@ -50,6 +50,7 @@ public class DolphinSchedulerManager {
private DbType getCurrentDbType(DataSource dataSource) throws Exception { private DbType getCurrentDbType(DataSource dataSource) throws Exception {
try (Connection conn = dataSource.getConnection()) { try (Connection conn = dataSource.getConnection()) {
String name = conn.getMetaData().getDatabaseProductName().toUpperCase(); String name = conn.getMetaData().getDatabaseProductName().toUpperCase();
logger.info("Current db type: {}", name);
return DbType.valueOf(name); return DbType.valueOf(name);
} }
} }
@ -101,6 +102,7 @@ public class DolphinSchedulerManager {
// The target version of the upgrade // The target version of the upgrade
String schemaVersion = ""; String schemaVersion = "";
String currentVersion = version; String currentVersion = version;
logger.info("Begin upgrading handle schemaList");
for (String schemaDir : schemaList) { for (String schemaDir : schemaList) {
schemaVersion = schemaDir.split("_")[0]; schemaVersion = schemaDir.split("_")[0];
if (SchemaUtils.isAGreatVersion(schemaVersion, version)) { if (SchemaUtils.isAGreatVersion(schemaVersion, version)) {

1
dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/UpgradeDolphinScheduler.java

@ -32,7 +32,6 @@ public class UpgradeDolphinScheduler {
} }
@Component @Component
@Profile("upgrade")
static class UpgradeRunner implements CommandLineRunner { static class UpgradeRunner implements CommandLineRunner {
private static final Logger logger = LoggerFactory.getLogger(UpgradeRunner.class); private static final Logger logger = LoggerFactory.getLogger(UpgradeRunner.class);

9
dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/dao/UpgradeDao.java

@ -291,6 +291,10 @@ public abstract class UpgradeDao {
String schemaVersion = schemaDir.split("_")[0]; String schemaVersion = schemaDir.split("_")[0];
Resource sqlFilePath = new ClassPathResource(String.format("sql/upgrade/%s/%s/dolphinscheduler_dml.sql", schemaDir, getDbType().name().toLowerCase())); Resource sqlFilePath = new ClassPathResource(String.format("sql/upgrade/%s/%s/dolphinscheduler_dml.sql", schemaDir, getDbType().name().toLowerCase()));
logger.info("sqlSQLFilePath: {}", sqlFilePath); logger.info("sqlSQLFilePath: {}", sqlFilePath);
if (!sqlFilePath.exists()) {
logger.info("sqlSQLFilePath: {} not exist", sqlFilePath);
return;
}
Connection conn = null; Connection conn = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try { try {
@ -353,6 +357,10 @@ public abstract class UpgradeDao {
*/ */
private void upgradeDolphinSchedulerDDL(String schemaDir, String scriptFile) { private void upgradeDolphinSchedulerDDL(String schemaDir, String scriptFile) {
Resource sqlFilePath = new ClassPathResource(String.format("sql/upgrade/%s/%s/%s", schemaDir, getDbType().name().toLowerCase(), scriptFile)); Resource sqlFilePath = new ClassPathResource(String.format("sql/upgrade/%s/%s/%s", schemaDir, getDbType().name().toLowerCase(), scriptFile));
if (!sqlFilePath.exists()) {
logger.info("sqlFilePath {} not exist", sqlFilePath);
return;
}
Connection conn = null; Connection conn = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try { try {
@ -363,6 +371,7 @@ public abstract class UpgradeDao {
// Execute the dolphinscheduler ddl.sql for the upgrade // Execute the dolphinscheduler ddl.sql for the upgrade
ScriptRunner scriptRunner = new ScriptRunner(conn, true, true); ScriptRunner scriptRunner = new ScriptRunner(conn, true, true);
Reader sqlReader = new InputStreamReader(sqlFilePath.getInputStream()); Reader sqlReader = new InputStreamReader(sqlFilePath.getInputStream());
logger.info("Start ddl file: {}-{}", schemaDir, scriptFile);
scriptRunner.runScript(sqlReader); scriptRunner.runScript(sqlReader);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {

25
dolphinscheduler-tools/src/main/resources/application.yaml

@ -18,10 +18,10 @@ spring:
main: main:
banner-mode: off banner-mode: off
datasource: datasource:
driver-class-name: org.postgresql.Driver driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:postgresql://127.0.0.1:5432/dolphinscheduler url: jdbc:mysql://127.0.0.1:3306/whalescheduler?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false
username: root username: root
password: root password: root@123
hikari: hikari:
connection-test-query: select 1 connection-test-query: select 1
minimum-idle: 5 minimum-idle: 5
@ -33,22 +33,3 @@ spring:
idle-timeout: 600000 idle-timeout: 600000
leak-detection-threshold: 0 leak-detection-threshold: 0
initialization-fail-timeout: 1 initialization-fail-timeout: 1
# Override by profile
---
spring:
config:
activate:
on-profile: mysql
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/dolphinscheduler?useUnicode=true&characterEncoding=UTF-8
---
spring:
config:
activate:
on-profile: postgresql
datasource:
driver-class-name: org.postgresql.Driver

Loading…
Cancel
Save