Skip to content

Commit f6d9667

Browse files
committed
Adds support for four position versions and optional db upgrades
Often, patch and security releases do not require schema migrations or data migrations. However, if an empty upgrade class and associated scripts are not defined, the upgrade process will break. With this change, if a release does not have an upgrade, a noop DbUpgrade is added to the upgrade path. This approach allows the upgrade to proceed and for the database to properly reflect the installed version. This change should make the release process simpler as RMs no longer need to rememeber to create this boilerplate code when starting a new release. Beginning with the 4.8.2.0 and 4.9.1.0 releases, the project will formally adopt a four (4) position release number to properly accomodate rekeases that contain only CVE fixes. The DatabaseUpgradeChecker and Version classes made assumptions that they would always parse and compare three (3) position version numbers. This change adds the CloudStackVersion value object that supports both three (3) and four (4) version numbers. It encapsulates version comparsion logic, as well as, the rules to allow three (3) and four (4) to interoperate. * Modifies DatabaseUpgradeChecker to handle derive an upgrade path for a version that was not explicitly specified. It determines the releases the first release before it with database migrations and uses that list as the basis for the list for version being calculated. A noop upgrade is then added to the list which causes no schema changes or data migrations, but will update the database to the version. * Adds unit tests for the upgrade path calculation logic in DatabaseUpgradeChecker * Removes dummy upgrade logic for the 4.8.2.0 introduced in previous versions of this patch * Introduces the CloudStackVersion value object which parses and compares three (3) and four (4) position version numbers. This class is intended to replace com.cloud.maint.Version. * Adds the junit-dataprovider dependency -- allowing test data to be concisely generated separately from the execution of a test case. Used extensively in the CloudStackVersionTest.
1 parent cfa1dcc commit f6d9667

File tree

7 files changed

+763
-199
lines changed

7 files changed

+763
-199
lines changed

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

Lines changed: 257 additions & 159 deletions
Large diffs are not rendered by default.
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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+
package com.cloud.upgrade;
18+
19+
import com.cloud.upgrade.dao.DbUpgrade;
20+
import com.cloud.upgrade.dao.Upgrade452to460;
21+
import com.cloud.upgrade.dao.Upgrade460to461;
22+
import com.cloud.upgrade.dao.Upgrade461to470;
23+
import com.cloud.upgrade.dao.Upgrade470to471;
24+
import com.cloud.upgrade.dao.Upgrade471to480;
25+
import com.cloud.upgrade.dao.Upgrade480to481;
26+
import org.apache.cloudstack.utils.CloudStackVersion;
27+
import org.junit.Test;
28+
29+
import java.util.Arrays;
30+
31+
import static org.junit.Assert.assertEquals;
32+
import static org.junit.Assert.assertNotNull;
33+
import static org.junit.Assert.assertTrue;
34+
35+
public class DatabaseUpgradeCheckerTest {
36+
37+
@Test
38+
public void testCalculateUpgradePath480to481() {
39+
40+
final CloudStackVersion dbVersion = CloudStackVersion.parse("4.8.0");
41+
assertNotNull(dbVersion);
42+
43+
final CloudStackVersion currentVersion = CloudStackVersion.parse("4.8.1");
44+
assertNotNull(currentVersion);
45+
46+
final DatabaseUpgradeChecker checker = new DatabaseUpgradeChecker();
47+
final DbUpgrade[] upgrades = checker.calculateUpgradePath(dbVersion, currentVersion);
48+
49+
assertNotNull(upgrades);
50+
assertEquals(1, upgrades.length);
51+
assertTrue(upgrades[0] instanceof Upgrade480to481);
52+
53+
}
54+
55+
@Test
56+
public void testCalculateUpgradePath480to4820() {
57+
58+
final CloudStackVersion dbVersion = CloudStackVersion.parse("4.8.0");
59+
assertNotNull(dbVersion);
60+
61+
final CloudStackVersion currentVersion = CloudStackVersion.parse("4.8.2.0");
62+
assertNotNull(currentVersion);
63+
64+
final DatabaseUpgradeChecker checker = new DatabaseUpgradeChecker();
65+
final DbUpgrade[] upgrades = checker.calculateUpgradePath(dbVersion, currentVersion);
66+
67+
assertNotNull(upgrades);
68+
assertEquals(2, upgrades.length);
69+
70+
assertTrue(upgrades[0] instanceof Upgrade480to481);
71+
72+
assertTrue(Arrays.equals(new String[] { "4.8.1", currentVersion.toString()}, upgrades[1].getUpgradableVersionRange()));
73+
assertEquals(currentVersion.toString(), upgrades[1].getUpgradedVersion());
74+
75+
}
76+
77+
@Test
78+
public void testCalculateUpgradePath481to4820() {
79+
80+
final CloudStackVersion dbVersion = CloudStackVersion.parse("4.8.1");
81+
assertNotNull(dbVersion);
82+
83+
final CloudStackVersion currentVersion = CloudStackVersion.parse("4.8.2.0");
84+
assertNotNull(currentVersion);
85+
86+
final DatabaseUpgradeChecker checker = new DatabaseUpgradeChecker();
87+
final DbUpgrade[] upgrades = checker.calculateUpgradePath(dbVersion, currentVersion);
88+
89+
assertNotNull(upgrades);
90+
assertEquals(1, upgrades.length);
91+
92+
assertTrue(Arrays.equals(new String[] { "4.8.1", currentVersion.toString()}, upgrades[0].getUpgradableVersionRange()));
93+
assertEquals(currentVersion.toString(), upgrades[0].getUpgradedVersion());
94+
95+
}
96+
97+
@Test
98+
public void testFindUpgradePath470to481() {
99+
100+
final CloudStackVersion dbVersion = CloudStackVersion.parse("4.7.0");
101+
assertNotNull(dbVersion);
102+
103+
final CloudStackVersion currentVersion = CloudStackVersion.parse("4.8.1");
104+
assertNotNull(currentVersion);
105+
106+
final DatabaseUpgradeChecker checker = new DatabaseUpgradeChecker();
107+
final DbUpgrade[] upgrades = checker.calculateUpgradePath(dbVersion, currentVersion);
108+
109+
assertNotNull(upgrades);
110+
assertEquals(3, upgrades.length);
111+
112+
assertTrue(upgrades[0] instanceof Upgrade470to471);
113+
assertTrue(upgrades[1] instanceof Upgrade471to480);
114+
assertTrue(upgrades[2] instanceof Upgrade480to481);
115+
116+
}
117+
118+
@Test
119+
public void testFindUpgradePath452to4820() {
120+
121+
final CloudStackVersion dbVersion = CloudStackVersion.parse("4.5.2");
122+
assertNotNull(dbVersion);
123+
124+
final CloudStackVersion currentVersion = CloudStackVersion.parse("4.8.2.0");
125+
assertNotNull(currentVersion);
126+
127+
final DatabaseUpgradeChecker checker = new DatabaseUpgradeChecker();
128+
final DbUpgrade[] upgrades = checker.calculateUpgradePath(dbVersion, currentVersion);
129+
130+
assertNotNull(upgrades);
131+
assertEquals(7, upgrades.length);
132+
133+
assertTrue(upgrades[0] instanceof Upgrade452to460);
134+
assertTrue(upgrades[1] instanceof Upgrade460to461);
135+
assertTrue(upgrades[2] instanceof Upgrade461to470);
136+
assertTrue(upgrades[3] instanceof Upgrade470to471);
137+
assertTrue(upgrades[4] instanceof Upgrade471to480);
138+
assertTrue(upgrades[5] instanceof Upgrade480to481);
139+
140+
assertTrue(Arrays.equals(new String[] { "4.8.1", currentVersion.toString()}, upgrades[6].getUpgradableVersionRange()));
141+
assertEquals(currentVersion.toString(), upgrades[6].getUpgradedVersion());
142+
143+
}
144+
}

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<!-- do not forget to also upgrade hamcrest library with junit -->
7575
<cs.junit.version>4.11</cs.junit.version>
7676
<cs.hamcrest.version>1.3</cs.hamcrest.version>
77+
<cs.junit.dataprovider.version>1.10.0</cs.junit.dataprovider.version>
7778
<cs.bcprov.version>1.46</cs.bcprov.version>
7879
<cs.jsch.version>0.1.51</cs.jsch.version>
7980
<cs.jpa.version>2.1.0</cs.jpa.version>
@@ -473,6 +474,12 @@
473474
</exclusion>
474475
</exclusions>
475476
</dependency>
477+
<dependency>
478+
<groupId>com.tngtech.java</groupId>
479+
<artifactId>junit-dataprovider</artifactId>
480+
<version>${cs.junit.dataprovider.version}</version>
481+
<scope>test</scope>
482+
</dependency>
476483
<dependency>
477484
<groupId>org.powermock</groupId>
478485
<artifactId>powermock-module-junit4</artifactId>

setup/db/db/schema-481to4820-cleanup.sql

Lines changed: 0 additions & 20 deletions
This file was deleted.

setup/db/db/schema-481to4820.sql

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)