You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by ma...@apache.org on 2016/03/17 03:10:38 UTC
[7/7] kylin git commit: KYLIN-1595 revise KylinVersion class
KYLIN-1595 revise KylinVersion class
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/24b7d910
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/24b7d910
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/24b7d910
Branch: refs/heads/master
Commit: 24b7d9105e237856c9a29a92cffc17fa9a7bc412
Parents: f5030b6
Author: Hongbin Ma <ma...@apache.org>
Authored: Thu Mar 17 10:10:02 2016 +0800
Committer: Hongbin Ma <ma...@apache.org>
Committed: Thu Mar 17 10:10:02 2016 +0800
----------------------------------------------------------------------
.../org/apache/kylin/common/KylinVersion.java | 73 ++++++++++++--------
.../persistence/RootPersistentEntity.java | 2 +-
.../org/apache/kylin/cube/model/CubeDesc.java | 4 +-
3 files changed, 46 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/24b7d910/core-common/src/main/java/org/apache/kylin/common/KylinVersion.java
----------------------------------------------------------------------
diff --git a/core-common/src/main/java/org/apache/kylin/common/KylinVersion.java b/core-common/src/main/java/org/apache/kylin/common/KylinVersion.java
index a006e1c..4bf5999 100644
--- a/core-common/src/main/java/org/apache/kylin/common/KylinVersion.java
+++ b/core-common/src/main/java/org/apache/kylin/common/KylinVersion.java
@@ -21,34 +21,50 @@ import java.util.Set;
import javax.annotation.Nullable;
-import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
public class KylinVersion {
- static class Version {
- public int major;
- public int minor;
- public int revision;
+ public int major;
+ public int minor;
+ public int revision;
+ public boolean isSnapshot;
- public Version(String version) {
- String[] splits = version.split("\\.");
- major = Integer.parseInt(splits[0]);
- minor = Integer.parseInt(splits[1]);
- revision = Integer.parseInt(splits[2]);
+ public KylinVersion(String version) {
+
+ Preconditions.checkNotNull(version);
+
+ int index = version.indexOf("-");//index of "-SNAPSHOT"
+ String[] splits;
+ if (index == -1) {
+ splits = version.split("\\.");
+ isSnapshot = false;
+ } else {
+ splits = version.substring(0, index).split("\\.");
+ isSnapshot = true;
}
+
+ major = Integer.parseInt(splits[0]);
+ minor = Integer.parseInt(splits[1]);
+ revision = Integer.parseInt(splits[2]);
+ }
+
+ @Override
+ public String toString() {
+ return "" + major + "." + minor + "." + revision;
}
/**
* Require MANUAL updating kylin version per ANY upgrading.
*/
- private static final String CURRENT_KYLIN_VERSION = "1.5.1";
+ private static final KylinVersion CURRENT_KYLIN_VERSION = new KylinVersion("1.5.1");
- private static final Set<String> SIGNATURE_INCOMPATIBLE_REVISIONS = new HashSet<String>();
+ private static final Set<KylinVersion> SIGNATURE_INCOMPATIBLE_REVISIONS = new HashSet<KylinVersion>();
static {
- SIGNATURE_INCOMPATIBLE_REVISIONS.add("1.5.1");
+ SIGNATURE_INCOMPATIBLE_REVISIONS.add(new KylinVersion("1.5.1"));
}
/**
@@ -58,13 +74,12 @@ public class KylinVersion {
*
* @return current kylin version in String
*/
- public static String getCurrentVersion() {
+ public static KylinVersion getCurrentVersion() {
return CURRENT_KYLIN_VERSION;
}
- public static boolean isCompatibleWith(String version) {
- Version v = new Version(version);
- Version current = new Version(CURRENT_KYLIN_VERSION);
+ public boolean isCompatibleWith(KylinVersion v) {
+ KylinVersion current = CURRENT_KYLIN_VERSION;
if (current.major != v.major || current.minor != v.minor) {
return false;
} else {
@@ -72,27 +87,25 @@ public class KylinVersion {
}
}
- public static boolean isSignatureCompatibleWith(String version) {
- if (!isCompatibleWith(version)) {
+ public boolean isSignatureCompatibleWith(final KylinVersion v) {
+ if (!isCompatibleWith(v)) {
return false;
}
- final Version v = new Version(version);
+
+ if (v.isSnapshot || isSnapshot) {
+ return false;//for snapshot versions things are undetermined
+ }
+
boolean signatureIncompatible = Iterables.any(Iterables.filter(
- Iterables.transform(SIGNATURE_INCOMPATIBLE_REVISIONS, new Function<String, Version>() {
- @Nullable
- @Override
- public Version apply(@Nullable String input) {
- return new Version(input);
- }
- }), new Predicate<Version>() {
+ SIGNATURE_INCOMPATIBLE_REVISIONS, new Predicate<KylinVersion>() {
@Override
- public boolean apply(@Nullable Version input) {
+ public boolean apply(@Nullable KylinVersion input) {
return v.major == input.major && v.minor == input.minor;
}
- }), new Predicate<Version>() {
+ }), new Predicate<KylinVersion>() {
@Override
- public boolean apply(@Nullable Version input) {
+ public boolean apply(@Nullable KylinVersion input) {
return input.revision > v.revision;
}
});
http://git-wip-us.apache.org/repos/asf/kylin/blob/24b7d910/core-common/src/main/java/org/apache/kylin/common/persistence/RootPersistentEntity.java
----------------------------------------------------------------------
diff --git a/core-common/src/main/java/org/apache/kylin/common/persistence/RootPersistentEntity.java b/core-common/src/main/java/org/apache/kylin/common/persistence/RootPersistentEntity.java
index a82de15..716f5b2 100644
--- a/core-common/src/main/java/org/apache/kylin/common/persistence/RootPersistentEntity.java
+++ b/core-common/src/main/java/org/apache/kylin/common/persistence/RootPersistentEntity.java
@@ -78,7 +78,7 @@ abstract public class RootPersistentEntity implements AclEntity, Serializable {
* User info only, we don't do version control
*/
@JsonProperty("version")
- protected String version = KylinVersion.getCurrentVersion();
+ protected String version = KylinVersion.getCurrentVersion().toString();
public String getVersion() {
return version;
http://git-wip-us.apache.org/repos/asf/kylin/blob/24b7d910/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
----------------------------------------------------------------------
diff --git a/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java b/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
index 4a019ca..cb94447 100644
--- a/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
+++ b/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
@@ -442,11 +442,11 @@ public class CubeDesc extends RootPersistentEntity {
* this method is to prevent malicious metadata change by checking the saved signature
* with the calculated signature.
*
- * if you're comparing two cube desc prefer to use consistentWith()
+ * if you're comparing two cube descs, prefer to use consistentWith()
* @return
*/
public boolean checkSignature() {
- if (KylinVersion.isCompatibleWith(getVersion()) && !KylinVersion.isSignatureCompatibleWith(getVersion())) {
+ if (KylinVersion.getCurrentVersion().isCompatibleWith(new KylinVersion(getVersion())) && !KylinVersion.getCurrentVersion().isSignatureCompatibleWith(new KylinVersion(getVersion()))) {
logger.info("checkSignature on {} is skipped as the its version is {} (not signature compatible but compatible) ", getName(), getVersion());
return true;
}