mirror of https://github.com/apache/cloudstack.git
upgrade: check systemvm template before db changes (#4582)
* Upgrade: check systemvm template before db changes * Upgrade: move some codes to a separated method * #4582 add txn.commit()
This commit is contained in:
parent
ba43825a9b
commit
5a3ae159ca
|
|
@ -34,6 +34,7 @@ import org.apache.commons.lang.StringUtils;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.upgrade.dao.DbUpgrade;
|
||||
import com.cloud.upgrade.dao.DbUpgradeSystemVmTemplate;
|
||||
import com.cloud.upgrade.dao.Upgrade217to218;
|
||||
import com.cloud.upgrade.dao.Upgrade218to22;
|
||||
import com.cloud.upgrade.dao.Upgrade218to224DomainVlans;
|
||||
|
|
@ -235,11 +236,42 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
|
|||
|
||||
}
|
||||
|
||||
private void updateSystemVmTemplates(DbUpgrade[] upgrades) {
|
||||
for (int i = upgrades.length - 1; i >= 0; i--) {
|
||||
DbUpgrade upgrade = upgrades[i];
|
||||
if (upgrade instanceof DbUpgradeSystemVmTemplate) {
|
||||
TransactionLegacy txn = TransactionLegacy.open("Upgrade");
|
||||
txn.start();
|
||||
try {
|
||||
Connection conn;
|
||||
try {
|
||||
conn = txn.getConnection();
|
||||
} catch (SQLException e) {
|
||||
String errorMessage = "Unable to upgrade the database";
|
||||
s_logger.error(errorMessage, e);
|
||||
throw new CloudRuntimeException(errorMessage, e);
|
||||
}
|
||||
((DbUpgradeSystemVmTemplate)upgrade).updateSystemVmTemplates(conn);
|
||||
txn.commit();
|
||||
break;
|
||||
} catch (CloudRuntimeException e) {
|
||||
String errorMessage = "Unable to upgrade the database";
|
||||
s_logger.error(errorMessage, e);
|
||||
throw new CloudRuntimeException(errorMessage, e);
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void upgrade(CloudStackVersion dbVersion, CloudStackVersion currentVersion) {
|
||||
s_logger.info("Database upgrade must be performed from " + dbVersion + " to " + currentVersion);
|
||||
|
||||
final DbUpgrade[] upgrades = calculateUpgradePath(dbVersion, currentVersion);
|
||||
|
||||
updateSystemVmTemplates(upgrades);
|
||||
|
||||
for (DbUpgrade upgrade : upgrades) {
|
||||
VersionVO version;
|
||||
s_logger.debug("Running upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
// 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.
|
||||
|
||||
package com.cloud.upgrade.dao;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
public interface DbUpgradeSystemVmTemplate {
|
||||
|
||||
void updateSystemVmTemplates(Connection conn);
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ import org.apache.log4j.Logger;
|
|||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class Upgrade41400to41500 implements DbUpgrade {
|
||||
public class Upgrade41400to41500 implements DbUpgrade, DbUpgradeSystemVmTemplate {
|
||||
|
||||
final static Logger LOG = Logger.getLogger(Upgrade41400to41500.class);
|
||||
|
||||
|
|
@ -67,12 +67,12 @@ public class Upgrade41400to41500 implements DbUpgrade {
|
|||
|
||||
@Override
|
||||
public void performDataMigration(Connection conn) {
|
||||
updateSystemVmTemplates(conn);
|
||||
addRolePermissionsForNewReadOnlyAndSupportRoles(conn);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
private void updateSystemVmTemplates(final Connection conn) {
|
||||
public void updateSystemVmTemplates(final Connection conn) {
|
||||
LOG.debug("Updating System Vm template IDs");
|
||||
final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
|
||||
try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue