Skip to content

Commit 3dbe656

Browse files
committed
fix CS version
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent ccc870c commit 3dbe656

4 files changed

Lines changed: 102 additions & 20 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,13 @@ protected void doUpgrades(GlobalLock lock) {
515515
String csVersion = parseSystemVmMetadata();
516516
final CloudStackVersion sysVmVersion = CloudStackVersion.parse(csVersion);
517517
final CloudStackVersion currentVersion = CloudStackVersion.parse(currentVersionValue);
518-
SystemVmTemplateRegistration.CS_MAJOR_VERSION = sysVmVersion.getMajorRelease() + "." + sysVmVersion.getMinorRelease();
519-
SystemVmTemplateRegistration.CS_TINY_VERSION = String.valueOf(sysVmVersion.getPatchRelease());
518+
if (sysVmVersion.usesNewVersioning()) {
519+
SystemVmTemplateRegistration.CS_MAJOR_VERSION = String.valueOf(sysVmVersion.getMajorRelease());
520+
SystemVmTemplateRegistration.CS_TINY_VERSION = String.valueOf(sysVmVersion.getMajorRelease());
521+
} else {
522+
SystemVmTemplateRegistration.CS_MAJOR_VERSION = String.format("%d.%d", sysVmVersion.getMajorRelease(), sysVmVersion.getMinorRelease());
523+
SystemVmTemplateRegistration.CS_TINY_VERSION = String.valueOf(sysVmVersion.getPatchRelease());
524+
}
520525

521526
LOGGER.info("DB version = {} Code Version = {}", dbVersion, currentVersion);
522527

plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/api/dto/Version.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,12 @@ public static Version fromPackageAndCSVersion(boolean complete) {
8787
}
8888
version.setMajor(String.valueOf(csVersion.getMajorRelease()));
8989
version.setMinor(String.valueOf(csVersion.getMinorRelease()));
90-
version.setBuild(String.valueOf(csVersion.getPatchRelease()));
91-
version.setRevision(String.valueOf(csVersion.getSecurityRelease()));
90+
if (csVersion.usesNewVersioning()) {
91+
version.setBuild(String.valueOf(csVersion.getSecurityRelease()));
92+
} else {
93+
version.setBuild(String.valueOf(csVersion.getPatchRelease()));
94+
version.setRevision(String.valueOf(csVersion.getSecurityRelease()));
95+
}
9296
return version;
9397
}
9498
}

utils/src/main/java/org/apache/cloudstack/utils/CloudStackVersion.java

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,23 @@
3939
*/
4040
public final class CloudStackVersion implements Comparable<CloudStackVersion> {
4141

42-
private final static Pattern NUMBER_VERSION_FORMAT = Pattern.compile("(\\d+\\.){2}(\\d+\\.)?\\d+");
43-
private final static Pattern FULL_VERSION_FORMAT = Pattern.compile("(\\d+\\.){2}(\\d+\\.)?\\d+(-[a-zA-Z]+)?(-\\d+)?(-SNAPSHOT)?");
42+
private final static Pattern NUMBER_VERSION_FORMAT = Pattern.compile("\\d+\\.\\d+\\.\\d+(?:\\.\\d+)?");
43+
private final static Pattern FULL_VERSION_FORMAT = Pattern.compile("\\d+\\.\\d+\\.\\d+(?:\\.\\d+)?(?:-[a-zA-Z]+)?(?:-\\d+)?(?:-SNAPSHOT)?");
44+
private final static int NEW_VERSIONING_CUTOVER_MAJOR_VERSION = 24;
4445

4546
private final int majorRelease;
4647
private final int minorRelease;
47-
private final int patchRelease;
48+
private final Integer patchRelease;
4849
private final Integer securityRelease;
4950

50-
private CloudStackVersion(final int majorRelease, final int minorRelease, final int patchRelease, final Integer securityRelease) {
51+
private CloudStackVersion(final int majorRelease, final int minorRelease, final Integer patchRelease, final Integer securityRelease) {
5152

5253
super();
5354

5455
checkArgument(majorRelease >= 0, CloudStackVersion.class.getName() + "(int, int, int, Integer) requires a majorRelease greater than 0.");
5556
checkArgument(minorRelease >= 0, CloudStackVersion.class.getName() + "(int, int, int, Integer) requires a minorRelease greater than 0.");
56-
checkArgument(patchRelease >= 0, CloudStackVersion.class.getName() + "(int, int, int, Integer) requires a patchRelease greater than 0.");
57-
checkArgument((securityRelease != null && securityRelease >= 0) || (securityRelease == null),
57+
checkArgument(patchRelease == null || patchRelease >= 0, CloudStackVersion.class.getName() + "(int, int, int, Integer) requires a patchRelease greater than 0.");
58+
checkArgument(securityRelease == null || securityRelease >= 0,
5859
CloudStackVersion.class.getName() + "(int, int, int, Integer) requires a null securityRelease or a non-null value greater than 0.");
5960

6061
this.majorRelease = majorRelease;
@@ -69,11 +70,13 @@ private CloudStackVersion(final int majorRelease, final int minorRelease, final
6970
* Parses a <code>String</code> representation of a version that conforms one of the following
7071
* formats into a <code>CloudStackVersion</code> instance:
7172
* <ul>
72-
* <li><code>&lt;major&gt;.&lt;minor&gt;.&lt;patch&gt;.&lt;security&gt;</code></li>
73-
* <li><code>&lt;major&gt;.&lt;minor&gt;.&lt;patch&gt;.&lt;security&gt;.&lt;security&gt;</code></li>
74-
* <li><code>&lt;major&gt;.&lt;minor&gt;.&lt;patch&gt;.&lt;security&gt;.&lt;security&gt;-&lt;any string&gt;</code></li>
73+
* <li><code>&lt;major&gt;.&lt;minor&gt;.&lt;patch&gt;</code> (legacy, deprecated since 24.0.0, allowed only below major version 24)</li>
74+
* <li><code>&lt;major&gt;.&lt;minor&gt;.&lt;patch&gt;.&lt;security&gt;</code> (legacy, deprecated since 24.0.0, allowed only below major version 24)</li>
75+
* <li><code>&lt;major&gt;.&lt;minor&gt;.&lt;security release&gt;</code> (for versions &gt;= 24.0.0)</li>
7576
* </ul>
7677
*
78+
* Legacy patch-based formats remain supported for backward compatibility.
79+
*
7780
* If the string contains a suffix that begins with a "-" character, then the "-" and all characters following it
7881
* will be dropped.
7982
*
@@ -91,7 +94,7 @@ public static CloudStackVersion parse(final String value) {
9194

9295
checkArgument(StringUtils.isNotBlank(trimmedValue), CloudStackVersion.class.getName() + ".parse(String) requires a non-blank value");
9396
checkArgument(NUMBER_VERSION_FORMAT.matcher(trimmedValue).matches(), CloudStackVersion.class.getName() + ".parse(String) passed " +
94-
value + ", but requires a value in the format of int.int.int(.int)(-<legacy patch>)");
97+
value + ", but requires a value in the format of int.int.int(.int)(-<suffix>)");
9598

9699
final String[] components = trimmedValue.split("\\.");
97100

@@ -100,8 +103,26 @@ public static CloudStackVersion parse(final String value) {
100103

101104
final int majorRelease = Integer.valueOf(components[0]);
102105
final int minorRelease = Integer.valueOf(components[1]);
103-
final int patchRelease = Integer.valueOf(components[2]);
104-
final Integer securityRelease = components.length == 3 ? null : Integer.valueOf(components[3]);
106+
final int thirdComponent = Integer.valueOf(components[2]);
107+
108+
final int patchRelease;
109+
final Integer securityRelease;
110+
111+
if (components.length == 4) {
112+
checkArgument(isLegacyVersioning(majorRelease), CloudStackVersion.class.getName() + ".parse(String) passed " + value +
113+
", but major versions at or above 24 do not support legacy int.int.int.int format");
114+
// Deprecated legacy format: major.minor.patch.security
115+
patchRelease = thirdComponent;
116+
securityRelease = Integer.valueOf(components[3]);
117+
} else if (isNewVersioning(majorRelease)) {
118+
// New format: major.minor.securityRelease (patch dropped)
119+
patchRelease = 0;
120+
securityRelease = thirdComponent;
121+
} else {
122+
// Deprecated legacy format: major.minor.patch
123+
patchRelease = thirdComponent;
124+
securityRelease = null;
125+
}
105126

106127
return new CloudStackVersion(majorRelease, minorRelease, patchRelease, securityRelease);
107128

@@ -207,6 +228,14 @@ private static ImmutableList<Integer> normalizeVersionValues(final ImmutableList
207228

208229
}
209230

231+
private static boolean isLegacyVersioning(final int majorRelease) {
232+
return majorRelease < NEW_VERSIONING_CUTOVER_MAJOR_VERSION;
233+
}
234+
235+
private static boolean isNewVersioning(final int majorRelease) {
236+
return majorRelease >= NEW_VERSIONING_CUTOVER_MAJOR_VERSION;
237+
}
238+
210239
/**
211240
*
212241
* @return The components of this version as an {@link ImmutableList} in order of major release, minor release,
@@ -244,6 +273,10 @@ public Integer getSecurityRelease() {
244273
return securityRelease;
245274
}
246275

276+
public boolean usesNewVersioning() {
277+
return isNewVersioning(majorRelease);
278+
}
279+
247280
@Override
248281
public boolean equals(final Object thatObject) {
249282

@@ -270,6 +303,11 @@ public int hashCode() {
270303

271304
@Override
272305
public String toString() {
306+
// Canonicalize cutover-and-later versions to major.minor.securityRelease.
307+
if (securityRelease != null && patchRelease == 0 && isNewVersioning(majorRelease)) {
308+
return Joiner.on(".").join(ImmutableList.of(majorRelease, minorRelease, securityRelease));
309+
}
310+
273311
return Joiner.on(".").join(asList());
274312
}
275313

utils/src/test/java/org/apache/cloudstack/utils/CloudStackVersionTest.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,40 @@ public final class CloudStackVersionTest {
3636
"1.2.3, 1.2.3",
3737
"1.2.3.4, 1.2.3.4",
3838
"1.2.3-12, 1.2.3",
39-
"1.2.3.4-14, 1.2.3.4"
39+
"1.2.3.4-14, 1.2.3.4",
40+
"23.9.5, 23.9.5",
41+
"24.0.0, 24.0.0",
42+
"24.0.1, 24.0.1",
43+
"25.1.1, 25.1.1"
4044
})
4145
public void testValidParse(final String inputValue, final String expectedVersion) {
4246
final CloudStackVersion version = CloudStackVersion.parse(inputValue);
4347
assertNotNull(version);
4448
assertEquals(expectedVersion, version.toString());
4549
}
4650

51+
@Test
52+
public void testParseComponentMappingForLegacyAndNewVersioning() {
53+
final CloudStackVersion legacyVersion = CloudStackVersion.parse("23.9.5");
54+
assertEquals(23, legacyVersion.getMajorRelease());
55+
assertEquals(9, legacyVersion.getMinorRelease());
56+
assertEquals(5, legacyVersion.getPatchRelease());
57+
Assert.assertNull(legacyVersion.getSecurityRelease());
58+
59+
final CloudStackVersion newVersion = CloudStackVersion.parse("24.0.1");
60+
assertEquals(24, newVersion.getMajorRelease());
61+
assertEquals(0, newVersion.getMinorRelease());
62+
// Patch is retained as 0 to represent "no patch" in the new major.minor.security scheme.
63+
assertEquals(0, newVersion.getPatchRelease());
64+
assertEquals(Integer.valueOf(1), newVersion.getSecurityRelease());
65+
66+
final CloudStackVersion futureNewVersion = CloudStackVersion.parse("25.1.1");
67+
assertEquals(25, futureNewVersion.getMajorRelease());
68+
assertEquals(1, futureNewVersion.getMinorRelease());
69+
assertEquals(0, futureNewVersion.getPatchRelease());
70+
assertEquals(Integer.valueOf(1), futureNewVersion.getSecurityRelease());
71+
}
72+
4773
@Test(expected = IllegalArgumentException.class)
4874
@DataProvider({
4975
"1.2",
@@ -52,7 +78,10 @@ public void testValidParse(final String inputValue, final String expectedVersion
5278
"aaaa",
5379
"",
5480
" ",
55-
"1.2.3.4.5"
81+
"1.2.3.4.5",
82+
"24.0.0.1",
83+
"25.0.0.1",
84+
"26.2.3.4"
5685
})
5786
public void testInvalidParse(final String invalidValue) {
5887
CloudStackVersion.parse(invalidValue);
@@ -147,7 +176,9 @@ public void testEqualCompareDirect(final String value, final String thatValue) {
147176
"1.2.3.4-10, 1.0.0.0-5",
148177
"1.2.3-10, 1.0.0-5",
149178
"1.2.3.4, 1.0.0.0-5",
150-
"1.2.3.4-10, 1.0.0"
179+
"1.2.3.4-10, 1.0.0",
180+
"24.0.2, 24.0.1",
181+
"24.1.0, 24.0.9"
151182
})
152183
public void testGreaterThanAndLessThanCompareTo(final String value, final String thatValue) {
153184

@@ -178,7 +209,9 @@ public void testGreaterThanAndLessThanCompareTo(final String value, final String
178209
"1.2.3.4-10, 1.0.0.0-5",
179210
"1.2.3-10, 1.0.0-5",
180211
"1.2.3.4, 1.0.0.0-5",
181-
"1.2.3.4-10, 1.0.0"
212+
"1.2.3.4-10, 1.0.0",
213+
"24.0.2, 24.0.1",
214+
"24.1.0, 24.0.9"
182215
})
183216
public void testGreaterThanAndLessThanCompareDirect(final String value, final String thatValue) {
184217

@@ -213,6 +246,7 @@ private void verifyGetVMwareParentVersion(String hypervisorVersion, String expec
213246
Assert.assertEquals(CloudStackVersion.getVMwareParentVersion(hypervisorVersion), expectedParentVersion);
214247
}
215248
}
249+
216250
@Test
217251
public void testGetParentVersion() {
218252
verifyGetVMwareParentVersion(null, null);
@@ -223,5 +257,6 @@ public void testGetParentVersion() {
223257
verifyGetVMwareParentVersion("8.0.0", "8.0");
224258
verifyGetVMwareParentVersion("8.0.0.2", "8.0");
225259
verifyGetVMwareParentVersion("8.0.1.0", "8.0.1");
260+
verifyGetVMwareParentVersion("24.1.1", "24.1");
226261
}
227262
}

0 commit comments

Comments
 (0)