use of org.apache.cloudstack.utils.CloudStackVersion in project cloudstack by apache.
the class DatabaseUpgradeChecker method calculateUpgradePath.
// Default visibility to support unit testing ...
DbUpgrade[] calculateUpgradePath(final CloudStackVersion dbVersion, final CloudStackVersion currentVersion) {
checkArgument(dbVersion != null);
checkArgument(currentVersion != null);
checkArgument(currentVersion.compareTo(dbVersion) > 0);
final DbUpgrade[] upgrades = _upgradeMap.containsKey(dbVersion) ? _upgradeMap.get(dbVersion) : findMostRecentUpgradePath(dbVersion);
// When there is no upgrade defined for the target version, we assume that there were no schema changes or
// data migrations required. Based on that assumption, we add a noop DbUpgrade to the end of the list ...
final CloudStackVersion tailVersion = upgrades.length > 0 ? CloudStackVersion.parse(upgrades[upgrades.length - 1].getUpgradedVersion()) : dbVersion;
if (currentVersion.compareTo(tailVersion) != 0) {
return concat(upgrades, new NoopDbUpgrade(tailVersion, currentVersion));
}
return upgrades;
}
use of org.apache.cloudstack.utils.CloudStackVersion in project cloudstack by apache.
the class DatabaseUpgradeCheckerTest method testCalculateUpgradePath490to4910.
@Test
public void testCalculateUpgradePath490to4910() {
final CloudStackVersion dbVersion = CloudStackVersion.parse("4.9.0");
assertNotNull(dbVersion);
final CloudStackVersion currentVersion = CloudStackVersion.parse("4.9.1.0");
assertNotNull(currentVersion);
final DatabaseUpgradeChecker checker = new DatabaseUpgradeChecker();
final DbUpgrade[] upgrades = checker.calculateUpgradePath(dbVersion, currentVersion);
assertNotNull(upgrades);
assertTrue(upgrades.length >= 1);
assertTrue(upgrades[0] instanceof Upgrade490to4910);
assertTrue(Arrays.equals(new String[] { "4.9.0", currentVersion.toString() }, upgrades[0].getUpgradableVersionRange()));
assertEquals(currentVersion.toString(), upgrades[0].getUpgradedVersion());
}
use of org.apache.cloudstack.utils.CloudStackVersion in project cloudstack by apache.
the class DatabaseUpgradeCheckerTest method testFindUpgradePath452to490.
@Test
public void testFindUpgradePath452to490() {
final CloudStackVersion dbVersion = CloudStackVersion.parse("4.5.2");
assertNotNull(dbVersion);
final CloudStackVersion currentVersion = CloudStackVersion.parse("4.9.0");
assertNotNull(currentVersion);
final DatabaseUpgradeChecker checker = new DatabaseUpgradeChecker();
final DbUpgrade[] upgrades = checker.calculateUpgradePath(dbVersion, currentVersion);
assertNotNull(upgrades);
assertTrue(upgrades[0] instanceof Upgrade452to460);
assertTrue(upgrades[1] instanceof Upgrade460to461);
assertTrue(upgrades[2] instanceof Upgrade461to470);
assertTrue(upgrades[3] instanceof Upgrade470to471);
assertTrue(upgrades[4] instanceof Upgrade471to480);
assertTrue(upgrades[5] instanceof Upgrade480to481);
assertTrue(Arrays.equals(new String[] { "4.8.1", currentVersion.toString() }, upgrades[6].getUpgradableVersionRange()));
assertEquals(currentVersion.toString(), upgrades[6].getUpgradedVersion());
}
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();
}
}
use of org.apache.cloudstack.utils.CloudStackVersion in project cloudstack by apache.
the class DatabaseUpgradeCheckerTest method testCalculateUpgradePath480to481.
@Test
public void testCalculateUpgradePath480to481() {
final CloudStackVersion dbVersion = CloudStackVersion.parse("4.8.0");
assertNotNull(dbVersion);
final CloudStackVersion currentVersion = CloudStackVersion.parse("4.8.1");
assertNotNull(currentVersion);
final DatabaseUpgradeChecker checker = new DatabaseUpgradeChecker();
final DbUpgrade[] upgrades = checker.calculateUpgradePath(dbVersion, currentVersion);
assertNotNull(upgrades);
assertTrue(upgrades.length >= 1);
assertTrue(upgrades[0] instanceof Upgrade480to481);
}
Aggregations