Repository: kylin Updated Branches: refs/heads/1.3.x 25902223b -> 0aeb71cae (forced update) refs/heads/1.3.x-HBase1.1.3 693385833 -> 20a47e67f (forced update) refs/heads/1.4-rc b6f83ff19 -> 7a8134b3c (forced update) refs/heads/KYLIN-1122-B1 57545dfa2 -> 4960a54f4 (forced update) refs/heads/KYLIN-1122-B2 9e960f621 -> 41bb1eea6 (forced update) refs/heads/KYLIN-1356 7b87d88be -> 1bc461349 (forced update) refs/heads/document 691f9dcc5 -> ef365bd4e (forced update) refs/heads/helix-rebase 4e2dd05b2 -> 3e6993536 (forced update) refs/heads/master aa2a024da -> 2dd49eb07 (forced update) refs/heads/v1.3.0-release 0441ceb40 -> 579c2eb08 (forced update) refs/heads/v1.5.0-release b6c559b29 -> 128336134 (forced update) Updated Tags: refs/tags/kylin-1.2 5bb31d4a7 -> 2528aa531 refs/tags/kylin-1.3 688c28b15 -> 57e9ca5ba refs/tags/kylin-1.3.0 b4f5fa753 -> 5cc56d5b3 refs/tags/kylin-1.4-alpha 629f87843 -> 9086efe8d refs/tags/kylin-1.5.0 97e35ee4a -> 9e3ecf72b
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/98f8e0af Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/98f8e0af Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/98f8e0af Branch: refs/heads/master Commit: 98f8e0af015de9aa10a2d1ca48f0a92d87cc72e0 Parents: d95d089 Author: Hongbin Ma <[email protected]> Authored: Thu Mar 17 10:10:02 2016 +0800 Committer: Hongbin Ma <[email protected]> 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/98f8e0af/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/98f8e0af/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/98f8e0af/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; }
