Skip to content

Commit 575cbcd

Browse files
committed
Upgrade: check systemvm template before db changes
1 parent b482da8 commit 575cbcd

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.apache.log4j.Logger;
3535

3636
import com.cloud.upgrade.dao.DbUpgrade;
37+
import com.cloud.upgrade.dao.DbUpgradeSystemVmTemplate;
3738
import com.cloud.upgrade.dao.Upgrade217to218;
3839
import com.cloud.upgrade.dao.Upgrade218to22;
3940
import com.cloud.upgrade.dao.Upgrade218to224DomainVlans;
@@ -237,6 +238,32 @@ protected void upgrade(CloudStackVersion dbVersion, CloudStackVersion currentVer
237238

238239
final DbUpgrade[] upgrades = calculateUpgradePath(dbVersion, currentVersion);
239240

241+
for (int i = upgrades.length - 1; i >= 0; i--) {
242+
DbUpgrade upgrade = upgrades[i];
243+
if (upgrade instanceof DbUpgradeSystemVmTemplate) {
244+
TransactionLegacy txn = TransactionLegacy.open("Upgrade");
245+
txn.start();
246+
try {
247+
Connection conn;
248+
try {
249+
conn = txn.getConnection();
250+
} catch (SQLException e) {
251+
String errorMessage = "Unable to upgrade the database";
252+
s_logger.error(errorMessage, e);
253+
throw new CloudRuntimeException(errorMessage, e);
254+
}
255+
((DbUpgradeSystemVmTemplate)upgrade).updateSystemVmTemplates(conn);
256+
break;
257+
} catch (CloudRuntimeException e) {
258+
String errorMessage = "Unable to upgrade the database";
259+
s_logger.error(errorMessage, e);
260+
throw new CloudRuntimeException(errorMessage, e);
261+
} finally {
262+
txn.close();
263+
}
264+
}
265+
}
266+
240267
for (DbUpgrade upgrade : upgrades) {
241268
VersionVO version;
242269
s_logger.debug("Running upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
package com.cloud.upgrade.dao;
19+
20+
import java.sql.Connection;
21+
22+
public interface DbUpgradeSystemVmTemplate {
23+
24+
void updateSystemVmTemplates(Connection conn);
25+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import com.cloud.hypervisor.Hypervisor;
3636
import com.cloud.utils.exception.CloudRuntimeException;
3737

38-
public class Upgrade41400to41500 implements DbUpgrade {
38+
public class Upgrade41400to41500 implements DbUpgrade, DbUpgradeSystemVmTemplate {
3939

4040
final static Logger LOG = Logger.getLogger(Upgrade41400to41500.class);
4141

@@ -67,10 +67,10 @@ public InputStream[] getPrepareScripts() {
6767

6868
@Override
6969
public void performDataMigration(Connection conn) {
70-
updateSystemVmTemplates(conn);
7170
addRolePermissionsForNewReadOnlyAndSupportRoles(conn);
7271
}
7372

73+
@Override
7474
@SuppressWarnings("serial")
7575
private void updateSystemVmTemplates(final Connection conn) {
7676
LOG.debug("Updating System Vm template IDs");

0 commit comments

Comments
 (0)