Search in sources :

Example 6 with CloudStackVersion

use of org.apache.cloudstack.utils.CloudStackVersion in project cloudstack by apache.

the class DatabaseUpgradeChecker method check.

@Override
public void check() {
    GlobalLock lock = GlobalLock.getInternLock("DatabaseUpgrade");
    try {
        s_logger.info("Grabbing lock to check for database upgrade.");
        if (!lock.lock(20 * 60)) {
            throw new CloudRuntimeException("Unable to acquire lock to check for database integrity.");
        }
        try {
            final CloudStackVersion dbVersion = CloudStackVersion.parse(_dao.getCurrentVersion());
            final String currentVersionValue = this.getClass().getPackage().getImplementationVersion();
            if (StringUtils.isBlank(currentVersionValue)) {
                return;
            }
            final CloudStackVersion currentVersion = CloudStackVersion.parse(currentVersionValue);
            s_logger.info("DB version = " + dbVersion + " Code Version = " + currentVersion);
            if (dbVersion.compareTo(currentVersion) > 0) {
                throw new CloudRuntimeException("Database version " + dbVersion + " is higher than management software version " + currentVersionValue);
            }
            if (dbVersion.compareTo(currentVersion) == 0) {
                s_logger.info("DB version and code version matches so no upgrade needed.");
                return;
            }
            upgrade(dbVersion, currentVersion);
        } finally {
            lock.unlock();
        }
    } finally {
        lock.releaseRef();
    }
}
Also used : GlobalLock(com.cloud.utils.db.GlobalLock) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CloudStackVersion(org.apache.cloudstack.utils.CloudStackVersion)

Aggregations

CloudStackVersion (org.apache.cloudstack.utils.CloudStackVersion)6 DbUpgrade (com.cloud.upgrade.dao.DbUpgrade)5 Test (org.junit.Test)4 Upgrade480to481 (com.cloud.upgrade.dao.Upgrade480to481)3 Upgrade470to471 (com.cloud.upgrade.dao.Upgrade470to471)2 Upgrade471to480 (com.cloud.upgrade.dao.Upgrade471to480)2 Upgrade452to460 (com.cloud.upgrade.dao.Upgrade452to460)1 Upgrade460to461 (com.cloud.upgrade.dao.Upgrade460to461)1 Upgrade461to470 (com.cloud.upgrade.dao.Upgrade461to470)1 Upgrade490to4910 (com.cloud.upgrade.dao.Upgrade490to4910)1 GlobalLock (com.cloud.utils.db.GlobalLock)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1