This is an automated email from the ASF dual-hosted git repository.

shwstppr pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/main by this push:
     new 889fc62b605 schema: Add upgrade path from 4.21.0.0 to 4.22.0.0 (#11469)
889fc62b605 is described below

commit 889fc62b6050436c066712bc30041c5b2fa801c3
Author: Wei Zhou <[email protected]>
AuthorDate: Sat Aug 30 12:37:50 2025 +0200

    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
---
 .../com/cloud/upgrade/DatabaseUpgradeChecker.java  |  2 ++
 .../main/java/com/cloud/upgrade/dao/DbUpgrade.java | 33 +++++++++++++++++++---
 .../upgrade/dao/DbUpgradeSystemVmTemplate.java     | 16 ++++++++++-
 ...temVmTemplate.java => Upgrade42100to42200.java} | 13 ++++++---
 .../META-INF/db/schema-42100to42200-cleanup.sql    | 20 +++++++++++++
 .../resources/META-INF/db/schema-42100to42200.sql  | 20 +++++++++++++
 6 files changed, 95 insertions(+), 9 deletions(-)

diff --git 
a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java 
b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java
index 827b8f54757..c211b3e9728 100644
--- a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java
+++ b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java
@@ -90,6 +90,7 @@ import com.cloud.upgrade.dao.Upgrade41900to41910;
 import com.cloud.upgrade.dao.Upgrade41910to42000;
 import com.cloud.upgrade.dao.Upgrade42000to42010;
 import com.cloud.upgrade.dao.Upgrade42010to42100;
+import com.cloud.upgrade.dao.Upgrade42100to42200;
 import com.cloud.upgrade.dao.Upgrade420to421;
 import com.cloud.upgrade.dao.Upgrade421to430;
 import com.cloud.upgrade.dao.Upgrade430to440;
@@ -234,6 +235,7 @@ public class DatabaseUpgradeChecker implements 
SystemIntegrityChecker {
                 .next("4.19.1.0", new Upgrade41910to42000())
                 .next("4.20.0.0", new Upgrade42000to42010())
                 .next("4.20.1.0", new Upgrade42010to42100())
+                .next("4.21.0.0", new Upgrade42100to42200())
                 .build();
     }
 
diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgrade.java 
b/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgrade.java
index 6001f940b2c..fa0d0506ac1 100644
--- a/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgrade.java
+++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgrade.java
@@ -16,6 +16,8 @@
 // under the License.
 package com.cloud.upgrade.dao;
 
+import com.cloud.utils.exception.CloudRuntimeException;
+
 import java.io.InputStream;
 import java.sql.Connection;
 
@@ -24,20 +26,43 @@ public interface DbUpgrade {
 
     String getUpgradedVersion();
 
-    boolean supportsRollingUpgrade();
+    default boolean supportsRollingUpgrade() {
+        return false;
+    }
 
     /**
      * @return the script to prepare the database schema for the
      * data migration step.
      */
-    InputStream[] getPrepareScripts();
+    default InputStream[] getPrepareScripts() {
+        String fromVersion = getUpgradableVersionRange()[0];
+        String toVersion = getUpgradableVersionRange()[1];
+        final String scriptFile = 
String.format("META-INF/db/schema-%sto%s.sql", fromVersion.replace(".", ""), 
toVersion.replace(".", ""));
+        final InputStream script = 
Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
+        if (script == null) {
+            throw new CloudRuntimeException("Unable to find " + scriptFile);
+        }
+
+        return new InputStream[]{script};
+    }
 
     /**
      * Performs the actual data migration.
      */
-    void performDataMigration(Connection conn);
+    default void performDataMigration(Connection conn) {
+    }
 
-    InputStream[] getCleanupScripts();
+    default InputStream[] getCleanupScripts() {
+        String fromVersion = getUpgradableVersionRange()[0];
+        String toVersion = getUpgradableVersionRange()[1];
+        final String scriptFile = 
String.format("META-INF/db/schema-%sto%s-cleanup.sql", fromVersion.replace(".", 
""), toVersion.replace(".", ""));
+        final InputStream script = 
Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
+        if (script == null) {
+            throw new CloudRuntimeException("Unable to find " + scriptFile);
+        }
+
+        return new InputStream[]{script};
+    }
 
     default boolean refreshPoolConnectionsAfterUpgrade() {
         return false;
diff --git 
a/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeSystemVmTemplate.java
 
b/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeSystemVmTemplate.java
index 4211898adc7..a8d2436672e 100644
--- 
a/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeSystemVmTemplate.java
+++ 
b/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeSystemVmTemplate.java
@@ -17,9 +17,23 @@
 
 package com.cloud.upgrade.dao;
 
+import com.cloud.upgrade.SystemVmTemplateRegistration;
+import com.cloud.utils.exception.CloudRuntimeException;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
 import java.sql.Connection;
 
 public interface DbUpgradeSystemVmTemplate {
 
-    void updateSystemVmTemplates(Connection conn);
+    default void updateSystemVmTemplates(Connection conn) {
+        Logger logger = LogManager.getLogger(getClass());
+        logger.debug("Updating System Vm template IDs");
+        try {
+            SystemVmTemplateRegistration systemVmTemplateRegistration = new 
SystemVmTemplateRegistration("");
+            systemVmTemplateRegistration.updateSystemVmTemplates(conn);
+        } catch (Exception e) {
+            throw new CloudRuntimeException("Failed to find / register 
SystemVM template(s)");
+        }
+    }
 }
diff --git 
a/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeSystemVmTemplate.java
 b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42100to42200.java
similarity index 72%
copy from 
engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeSystemVmTemplate.java
copy to 
engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42100to42200.java
index 4211898adc7..c2cfd02c15c 100644
--- 
a/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeSystemVmTemplate.java
+++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42100to42200.java
@@ -14,12 +14,17 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-
 package com.cloud.upgrade.dao;
 
-import java.sql.Connection;
+public class Upgrade42100to42200 extends DbUpgradeAbstractImpl implements 
DbUpgrade, DbUpgradeSystemVmTemplate {
 
-public interface DbUpgradeSystemVmTemplate {
+    @Override
+    public String[] getUpgradableVersionRange() {
+        return new String[]{"4.21.0.0", "4.22.0.0"};
+    }
 
-    void updateSystemVmTemplates(Connection conn);
+    @Override
+    public String getUpgradedVersion() {
+        return "4.22.0.0";
+    }
 }
diff --git 
a/engine/schema/src/main/resources/META-INF/db/schema-42100to42200-cleanup.sql 
b/engine/schema/src/main/resources/META-INF/db/schema-42100to42200-cleanup.sql
new file mode 100644
index 00000000000..0546613dfa3
--- /dev/null
+++ 
b/engine/schema/src/main/resources/META-INF/db/schema-42100to42200-cleanup.sql
@@ -0,0 +1,20 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--   http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+--;
+-- Schema upgrade cleanup from 4.21.0.0 to 4.22.0.0
+--;
diff --git 
a/engine/schema/src/main/resources/META-INF/db/schema-42100to42200.sql 
b/engine/schema/src/main/resources/META-INF/db/schema-42100to42200.sql
new file mode 100644
index 00000000000..0f4e8b6f2a2
--- /dev/null
+++ b/engine/schema/src/main/resources/META-INF/db/schema-42100to42200.sql
@@ -0,0 +1,20 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--   http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+--;
+-- Schema upgrade from 4.21.0.0 to 4.22.0.0
+--;

Reply via email to