Skip to content

Commit 889fc62

Browse files
schema: Add upgrade path from 4.21.0.0 to 4.22.0.0 (#11469)
* Add upgrade path from 4.21.0.0 to 4.22.0.0 * Optimize DbUpgrade files
1 parent 2eb80e0 commit 889fc62

File tree

6 files changed

+116
-5
lines changed

6 files changed

+116
-5
lines changed

engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
import com.cloud.upgrade.dao.Upgrade41910to42000;
9191
import com.cloud.upgrade.dao.Upgrade42000to42010;
9292
import com.cloud.upgrade.dao.Upgrade42010to42100;
93+
import com.cloud.upgrade.dao.Upgrade42100to42200;
9394
import com.cloud.upgrade.dao.Upgrade420to421;
9495
import com.cloud.upgrade.dao.Upgrade421to430;
9596
import com.cloud.upgrade.dao.Upgrade430to440;
@@ -234,6 +235,7 @@ public DatabaseUpgradeChecker() {
234235
.next("4.19.1.0", new Upgrade41910to42000())
235236
.next("4.20.0.0", new Upgrade42000to42010())
236237
.next("4.20.1.0", new Upgrade42010to42100())
238+
.next("4.21.0.0", new Upgrade42100to42200())
237239
.build();
238240
}
239241

engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgrade.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// under the License.
1717
package com.cloud.upgrade.dao;
1818

19+
import com.cloud.utils.exception.CloudRuntimeException;
20+
1921
import java.io.InputStream;
2022
import java.sql.Connection;
2123

@@ -24,20 +26,43 @@ public interface DbUpgrade {
2426

2527
String getUpgradedVersion();
2628

27-
boolean supportsRollingUpgrade();
29+
default boolean supportsRollingUpgrade() {
30+
return false;
31+
}
2832

2933
/**
3034
* @return the script to prepare the database schema for the
3135
* data migration step.
3236
*/
33-
InputStream[] getPrepareScripts();
37+
default InputStream[] getPrepareScripts() {
38+
String fromVersion = getUpgradableVersionRange()[0];
39+
String toVersion = getUpgradableVersionRange()[1];
40+
final String scriptFile = String.format("META-INF/db/schema-%sto%s.sql", fromVersion.replace(".", ""), toVersion.replace(".", ""));
41+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
42+
if (script == null) {
43+
throw new CloudRuntimeException("Unable to find " + scriptFile);
44+
}
45+
46+
return new InputStream[]{script};
47+
}
3448

3549
/**
3650
* Performs the actual data migration.
3751
*/
38-
void performDataMigration(Connection conn);
52+
default void performDataMigration(Connection conn) {
53+
}
3954

40-
InputStream[] getCleanupScripts();
55+
default InputStream[] getCleanupScripts() {
56+
String fromVersion = getUpgradableVersionRange()[0];
57+
String toVersion = getUpgradableVersionRange()[1];
58+
final String scriptFile = String.format("META-INF/db/schema-%sto%s-cleanup.sql", fromVersion.replace(".", ""), toVersion.replace(".", ""));
59+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
60+
if (script == null) {
61+
throw new CloudRuntimeException("Unable to find " + scriptFile);
62+
}
63+
64+
return new InputStream[]{script};
65+
}
4166

4267
default boolean refreshPoolConnectionsAfterUpgrade() {
4368
return false;

engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeSystemVmTemplate.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,23 @@
1717

1818
package com.cloud.upgrade.dao;
1919

20+
import com.cloud.upgrade.SystemVmTemplateRegistration;
21+
import com.cloud.utils.exception.CloudRuntimeException;
22+
import org.apache.logging.log4j.LogManager;
23+
import org.apache.logging.log4j.Logger;
24+
2025
import java.sql.Connection;
2126

2227
public interface DbUpgradeSystemVmTemplate {
2328

24-
void updateSystemVmTemplates(Connection conn);
29+
default void updateSystemVmTemplates(Connection conn) {
30+
Logger logger = LogManager.getLogger(getClass());
31+
logger.debug("Updating System Vm template IDs");
32+
try {
33+
SystemVmTemplateRegistration systemVmTemplateRegistration = new SystemVmTemplateRegistration("");
34+
systemVmTemplateRegistration.updateSystemVmTemplates(conn);
35+
} catch (Exception e) {
36+
throw new CloudRuntimeException("Failed to find / register SystemVM template(s)");
37+
}
38+
}
2539
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with 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,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.upgrade.dao;
18+
19+
public class Upgrade42100to42200 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate {
20+
21+
@Override
22+
public String[] getUpgradableVersionRange() {
23+
return new String[]{"4.21.0.0", "4.22.0.0"};
24+
}
25+
26+
@Override
27+
public String getUpgradedVersion() {
28+
return "4.22.0.0";
29+
}
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with 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,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
--;
19+
-- Schema upgrade cleanup from 4.21.0.0 to 4.22.0.0
20+
--;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with 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,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
--;
19+
-- Schema upgrade from 4.21.0.0 to 4.22.0.0
20+
--;

0 commit comments

Comments
 (0)