You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by tk...@apache.org on 2022/09/26 08:33:34 UTC
[ignite-3] branch main updated: IGNITE-17146 Add support for alpha, beta, etc. releases in IgniteProductVersion (#1116)
This is an automated email from the ASF dual-hosted git repository.
tkalkirill pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 22af7bdfa8 IGNITE-17146 Add support for alpha, beta, etc. releases in IgniteProductVersion (#1116)
22af7bdfa8 is described below
commit 22af7bdfa800534a1b8ae4362de25049673af4a9
Author: Kirill Tkalenko <tk...@yandex.ru>
AuthorDate: Mon Sep 26 11:33:28 2022 +0300
IGNITE-17146 Add support for alpha, beta, etc. releases in IgniteProductVersion (#1116)
---
.../rest/ClusterManagementController.java | 8 +-
.../internal/properties/IgniteProductVersion.java | 86 +++++++++-----
.../properties/IgniteProductVersionTest.java | 59 +++++++---
.../internal/rest/api/cluster/ClusterStateDto.java | 6 +-
.../rest/api/cluster/IgniteProductVersionDto.java | 127 ---------------------
5 files changed, 109 insertions(+), 177 deletions(-)
diff --git a/modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/rest/ClusterManagementController.java b/modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/rest/ClusterManagementController.java
index d1ca54e580..88b2af6624 100644
--- a/modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/rest/ClusterManagementController.java
+++ b/modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/rest/ClusterManagementController.java
@@ -30,7 +30,6 @@ import org.apache.ignite.internal.logger.Loggers;
import org.apache.ignite.internal.rest.api.cluster.ClusterManagementApi;
import org.apache.ignite.internal.rest.api.cluster.ClusterStateDto;
import org.apache.ignite.internal.rest.api.cluster.ClusterTagDto;
-import org.apache.ignite.internal.rest.api.cluster.IgniteProductVersionDto;
import org.apache.ignite.internal.rest.api.cluster.InitCommand;
import org.apache.ignite.internal.rest.exception.ClusterNotInitializedException;
import org.apache.ignite.lang.IgniteException;
@@ -86,10 +85,9 @@ public class ClusterManagementController implements ClusterManagementApi {
return new ClusterStateDto(
clusterState.cmgNodes(),
clusterState.metaStorageNodes(),
- new IgniteProductVersionDto(clusterState.igniteVersion().major(), clusterState.igniteVersion().minor(),
- clusterState.igniteVersion().maintenance(), clusterState.igniteVersion().snapshot(),
- clusterState.igniteVersion().alphaVersion()),
- new ClusterTagDto(clusterState.clusterTag().clusterName(), clusterState.clusterTag().clusterId()));
+ clusterState.igniteVersion().toString(),
+ new ClusterTagDto(clusterState.clusterTag().clusterName(), clusterState.clusterTag().clusterId())
+ );
}
private RuntimeException mapException(Throwable ex) {
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/properties/IgniteProductVersion.java b/modules/core/src/main/java/org/apache/ignite/internal/properties/IgniteProductVersion.java
index 0a5cf07d62..5b85c4137a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/properties/IgniteProductVersion.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/properties/IgniteProductVersion.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.properties;
import java.io.Serializable;
import java.util.Objects;
+import java.util.StringJoiner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.ignite.internal.util.StringUtils;
@@ -28,12 +29,34 @@ import org.jetbrains.annotations.Nullable;
* Class representing an Ignite version.
*/
public class IgniteProductVersion implements Serializable {
- private static final Pattern VERSION_PATTERN =
- Pattern.compile("(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<maintenance>\\d+)((?<snapshot>-SNAPSHOT)|-(?<alpha>alpha\\d+))?");
-
/**
- * Version of the current node.
+ * Ignite version in the following formats "major.minor.maintenance(.patch)?(-preRelease)?".
+ *
+ * <p>Given a version number major.minor.maintenance.patch, increment the:
+ * <ul>
+ * <li>Major version when you make incompatible API changes.</li>
+ * <li>Minor version when you add functionality in a backwards compatible manner.</li>
+ * <li>Maintenance version when you make backwards compatible bug fixes.</li>
+ * <li>Patch version when you make backwards compatible bug fixes for an existing release.</li>
+ * </ul>
+ *
+ * <p>Additional labels for pre-release and build metadata are available as extensions to the major.minor.maintenance.patch format.
+ *
+ * <p>Ignite Version examples:
+ * <ul>
+ * <li>3.0.0</li>
+ * <li>3.1.0</li>
+ * <li>3.1.2</li>
+ * <li>3.1.2.1</li>
+ * <li>3.1.3-alpha1</li>
+ * <li>3.1.3-SNAPSHOT</li>
+ * </ul>
*/
+ private static final Pattern VERSION_PATTERN = Pattern.compile(
+ "(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<maintenance>\\d+)(?:\\.(?<patch>\\d+))?(?:-(?<preRelease>[0-9A-Za-z]+))?"
+ );
+
+ /** Version of the current node. */
public static final IgniteProductVersion CURRENT_VERSION = fromString(IgniteProperties.get(IgniteProperties.VERSION));
/** Major version number. */
@@ -45,23 +68,24 @@ public class IgniteProductVersion implements Serializable {
/** Maintenance version number. */
private final byte maintenance;
- /** Flag indicating if this is a snapshot release. */
- private final boolean isSnapshot;
+ /** Patch version number. */
+ @Nullable
+ private final Byte patch;
- /** Alpha version part or an empty string if this is not an alpha release. */
- // TODO: IGNITE-17146 Fix and add support for beta and other releases
- private final String alphaVersion;
+ /** Pre-release version. */
+ @Nullable
+ private final String preRelease;
- private IgniteProductVersion(byte major, byte minor, byte maintenance, boolean isSnapshot, @Nullable String alphaVersion) {
+ private IgniteProductVersion(byte major, byte minor, byte maintenance, @Nullable Byte patch, @Nullable String preRelease) {
this.major = major;
this.minor = minor;
this.maintenance = maintenance;
- this.isSnapshot = isSnapshot;
- this.alphaVersion = alphaVersion == null ? "" : alphaVersion;
+ this.patch = patch;
+ this.preRelease = preRelease;
}
/**
- * Parses Ignite version in either {@code "X.X.X-SNAPSHOT"} or {@code "X.X.X"} formats.
+ * Parsing the Ignite version in the following formats "major.minor.maintenance(.patch)?(-preRelease)?".
*
* @param versionStr String representation of an Ignite version.
* @return Parsed Ignite version.
@@ -78,12 +102,15 @@ public class IgniteProductVersion implements Serializable {
throw new IllegalArgumentException("Unexpected Ignite version format: " + versionStr);
}
+ String patch = matcher.group("patch");
+ String preRelease = matcher.group("preRelease");
+
return new IgniteProductVersion(
Byte.parseByte(matcher.group("major")),
Byte.parseByte(matcher.group("minor")),
Byte.parseByte(matcher.group("maintenance")),
- matcher.group("snapshot") != null,
- matcher.group("alpha")
+ StringUtils.nullOrBlank(patch) ? null : Byte.parseByte(patch),
+ StringUtils.nullOrBlank(preRelease) ? null : preRelease
);
}
@@ -109,17 +136,17 @@ public class IgniteProductVersion implements Serializable {
}
/**
- * Returns {@code true} if this is a snapshot release, {@code false} otherwise.
+ * Returns the patch version number, {@code null} if no patch version has been specified.
*/
- public boolean snapshot() {
- return isSnapshot;
+ public @Nullable Byte patch() {
+ return patch;
}
/**
- * Returns the alpha version of this release or an empty string if this is not an alpha release.
+ * Returns the pre-release version, {@code null} if no pre-release version has been specified.
*/
- public String alphaVersion() {
- return alphaVersion;
+ public @Nullable String preRelease() {
+ return preRelease;
}
@Override
@@ -127,23 +154,30 @@ public class IgniteProductVersion implements Serializable {
if (this == o) {
return true;
}
+
if (o == null || getClass() != o.getClass()) {
return false;
}
+
IgniteProductVersion that = (IgniteProductVersion) o;
- return major == that.major && minor == that.minor && maintenance == that.maintenance && isSnapshot == that.isSnapshot
- && alphaVersion.equals(that.alphaVersion);
+
+ return major == that.major && minor == that.minor && maintenance == that.maintenance
+ && Objects.equals(patch, that.patch) && Objects.equals(preRelease, that.preRelease);
}
@Override
public int hashCode() {
- return Objects.hash(major, minor, maintenance, isSnapshot, alphaVersion);
+ return Objects.hash(major, minor, maintenance, patch, preRelease);
}
@Override
public String toString() {
- String version = String.join(".", String.valueOf(major), String.valueOf(minor), String.valueOf(maintenance));
+ StringJoiner joiner = new StringJoiner(".").add(String.valueOf(major)).add(String.valueOf(minor)).add(String.valueOf(maintenance));
+
+ if (patch != null) {
+ joiner.add(patch.toString());
+ }
- return version + (alphaVersion.isEmpty() ? "" : "-" + alphaVersion) + (isSnapshot ? "-SNAPSHOT" : "");
+ return joiner + (preRelease == null ? "" : "-" + preRelease);
}
}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/properties/IgniteProductVersionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/properties/IgniteProductVersionTest.java
index 7335678804..fbbe141c21 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/properties/IgniteProductVersionTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/properties/IgniteProductVersionTest.java
@@ -18,9 +18,9 @@
package org.apache.ignite.internal.properties;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
@@ -31,32 +31,59 @@ import org.junit.jupiter.api.Test;
public class IgniteProductVersionTest {
@Test
void testValidVersions() {
- IgniteProductVersion version = IgniteProductVersion.fromString("3.0.0-SNAPSHOT");
+ IgniteProductVersion version = IgniteProductVersion.fromString("3.2.4-SNAPSHOT");
assertThat(version.major(), is((byte) 3));
- assertThat(version.minor(), is((byte) 0));
- assertThat(version.maintenance(), is((byte) 0));
- assertThat(version.snapshot(), is(true));
- assertThat(version.alphaVersion(), is(emptyString()));
- assertThat(version.toString(), is(equalTo("3.0.0-SNAPSHOT")));
+ assertThat(version.minor(), is((byte) 2));
+ assertThat(version.maintenance(), is((byte) 4));
+ assertThat(version.patch(), is(nullValue()));
+ assertThat(version.preRelease(), is(equalTo("SNAPSHOT")));
+ assertThat(version.toString(), is(equalTo("3.2.4-SNAPSHOT")));
+
+ version = IgniteProductVersion.fromString("3.2.4.5-SNAPSHOT");
+
+ assertThat(version.major(), is((byte) 3));
+ assertThat(version.minor(), is((byte) 2));
+ assertThat(version.maintenance(), is((byte) 4));
+ assertThat(version.patch(), is((byte) 5));
+ assertThat(version.preRelease(), is(equalTo("SNAPSHOT")));
+ assertThat(version.toString(), is(equalTo("3.2.4.5-SNAPSHOT")));
version = IgniteProductVersion.fromString("1.2.3");
assertThat(version.major(), is((byte) 1));
assertThat(version.minor(), is((byte) 2));
assertThat(version.maintenance(), is((byte) 3));
- assertThat(version.snapshot(), is(false));
- assertThat(version.alphaVersion(), is(emptyString()));
+ assertThat(version.patch(), is(nullValue()));
+ assertThat(version.preRelease(), is(nullValue()));
assertThat(version.toString(), is(equalTo("1.2.3")));
- version = IgniteProductVersion.fromString("3.0.0-alpha22");
+ version = IgniteProductVersion.fromString("1.2.3.4");
+
+ assertThat(version.major(), is((byte) 1));
+ assertThat(version.minor(), is((byte) 2));
+ assertThat(version.maintenance(), is((byte) 3));
+ assertThat(version.patch(), is((byte) 4));
+ assertThat(version.preRelease(), is(nullValue()));
+ assertThat(version.toString(), is(equalTo("1.2.3.4")));
+
+ version = IgniteProductVersion.fromString("3.1.2-alpha22");
+
+ assertThat(version.major(), is((byte) 3));
+ assertThat(version.minor(), is((byte) 1));
+ assertThat(version.maintenance(), is((byte) 2));
+ assertThat(version.patch(), is(nullValue()));
+ assertThat(version.preRelease(), is(equalTo("alpha22")));
+ assertThat(version.toString(), is(equalTo("3.1.2-alpha22")));
+
+ version = IgniteProductVersion.fromString("3.1.2.3-beta23");
assertThat(version.major(), is((byte) 3));
- assertThat(version.minor(), is((byte) 0));
- assertThat(version.maintenance(), is((byte) 0));
- assertThat(version.snapshot(), is(false));
- assertThat(version.alphaVersion(), is("alpha22"));
- assertThat(version.toString(), is(equalTo("3.0.0-alpha22")));
+ assertThat(version.minor(), is((byte) 1));
+ assertThat(version.maintenance(), is((byte) 2));
+ assertThat(version.patch(), is((byte) 3));
+ assertThat(version.preRelease(), is(equalTo("beta23")));
+ assertThat(version.toString(), is(equalTo("3.1.2.3-beta23")));
}
@Test
@@ -64,8 +91,8 @@ public class IgniteProductVersionTest {
assertThrows(IllegalArgumentException.class, () -> IgniteProductVersion.fromString(" "));
assertThrows(IllegalArgumentException.class, () -> IgniteProductVersion.fromString("1.2"));
assertThrows(IllegalArgumentException.class, () -> IgniteProductVersion.fromString("a.b.c"));
+ assertThrows(IllegalArgumentException.class, () -> IgniteProductVersion.fromString("a.b.c.d"));
assertThrows(IllegalArgumentException.class, () -> IgniteProductVersion.fromString("1.2.3-"));
- assertThrows(IllegalArgumentException.class, () -> IgniteProductVersion.fromString("1.2.3-SSDAD"));
assertThrows(IllegalArgumentException.class, () -> IgniteProductVersion.fromString("1.2.3-SNAPSHOT-alpha123"));
}
}
diff --git a/modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/cluster/ClusterStateDto.java b/modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/cluster/ClusterStateDto.java
index baf677b5b7..082ace2fda 100644
--- a/modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/cluster/ClusterStateDto.java
+++ b/modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/cluster/ClusterStateDto.java
@@ -32,7 +32,7 @@ public class ClusterStateDto {
private final Collection<String> msNodes;
- private final IgniteProductVersionDto igniteVersion;
+ private final String igniteVersion;
private final ClusterTagDto clusterTag;
@@ -48,7 +48,7 @@ public class ClusterStateDto {
public ClusterStateDto(
@JsonProperty("cmgNodes") Collection<String> cmgNodes,
@JsonProperty("msNodes") Collection<String> msNodes,
- @JsonProperty("igniteVersion") IgniteProductVersionDto igniteVersion,
+ @JsonProperty("igniteVersion") String igniteVersion,
@JsonProperty("clusterTag") ClusterTagDto clusterTag
) {
this.cmgNodes = cmgNodes;
@@ -68,7 +68,7 @@ public class ClusterStateDto {
}
@JsonProperty
- public IgniteProductVersionDto igniteVersion() {
+ public String igniteVersion() {
return igniteVersion;
}
diff --git a/modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/cluster/IgniteProductVersionDto.java b/modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/cluster/IgniteProductVersionDto.java
deleted file mode 100644
index 7ea03276fc..0000000000
--- a/modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/cluster/IgniteProductVersionDto.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * 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 org.apache.ignite.internal.rest.api.cluster;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonGetter;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import io.swagger.v3.oas.annotations.media.Schema;
-import java.util.Objects;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * REST representation of {@link org.apache.ignite.internal.properties.IgniteProductVersion}.
- */
-@Schema(name = "IgniteProductVersion")
-public class IgniteProductVersionDto {
- /** Major version number. */
- private final short major;
-
- /** Minor version number. */
- private final short minor;
-
- /** Maintenance version number. */
- private final short maintenance;
-
- /** Flag indicating if this is a snapshot release. */
- private final boolean isSnapshot;
-
- /** Alpha version part or an empty string if this is not an alpha release. */
- // TODO: IGNITE-17146 Fix and add support for beta and other releases
- private final String alphaVersion;
-
- /** Constructor. */
- @JsonCreator
- public IgniteProductVersionDto(
- @JsonProperty("major") short major,
- @JsonProperty("minor") short minor,
- @JsonProperty("maintenance") short maintenance,
- @JsonProperty("isSnapshot") boolean isSnapshot,
- @JsonProperty("alphaVersion") @Nullable String alphaVersion) {
- this.major = major;
- this.minor = minor;
- this.maintenance = maintenance;
- this.isSnapshot = isSnapshot;
- this.alphaVersion = alphaVersion == null ? "" : alphaVersion;
- }
-
- /**
- * Returns the major version number.
- */
- @JsonGetter
- public short major() {
- return major;
- }
-
- /**
- * Returns the minor version number.
- */
- @JsonGetter
- public short minor() {
- return minor;
- }
-
- /**
- * Returns the maintenance version number.
- */
- @JsonGetter
- public short maintenance() {
- return maintenance;
- }
-
- /**
- * Returns {@code true} if this is a snapshot release, {@code false} otherwise.
- */
- @JsonGetter
- public boolean snapshot() {
- return isSnapshot;
- }
-
- /**
- * Returns the alpha version of this release or an empty string if this is not an alpha release.
- */
- @JsonGetter
- public String alphaVersion() {
- return alphaVersion;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- IgniteProductVersionDto that = (IgniteProductVersionDto) o;
- return major == that.major && minor == that.minor && maintenance == that.maintenance && isSnapshot == that.isSnapshot
- && alphaVersion.equals(that.alphaVersion);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(major, minor, maintenance, isSnapshot, alphaVersion);
- }
-
- @Override
- public String toString() {
- String version = String.join(".", String.valueOf(major), String.valueOf(minor), String.valueOf(maintenance));
-
- return version + (alphaVersion.isEmpty() ? "" : "-" + alphaVersion) + (isSnapshot ? "-SNAPSHOT" : "");
- }
-}