Add MESOS_{MAJOR|MINOR|PATCH}_VERSION.
Also exposed the library version to Java via MesosNativeLibrary.
Review: https://reviews.apache.org/r/32151
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9706bb0e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9706bb0e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9706bb0e
Branch: refs/heads/master
Commit: 9706bb0e4f36120f5882f7cfa091251f6fcbc234
Parents: 4809d16
Author: Joris Van Remoortere <[email protected]>
Authored: Sun Mar 29 11:54:00 2015 -0700
Committer: Benjamin Hindman <[email protected]>
Committed: Sun Mar 29 12:44:36 2015 -0700
----------------------------------------------------------------------
configure.ac | 14 ++
include/mesos/version.hpp.in | 6 +-
src/Makefile.am | 1 +
.../org/apache/mesos/MesosNativeLibrary.java.in | 158 ++++++++++++++++++-
.../jni/org_apache_mesos_MesosNativeLibrary.cpp | 26 +++
5 files changed, 203 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/9706bb0e/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 9b2d7f1..868c041 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1319,4 +1319,18 @@ AM_CONDITIONAL([WITHOUT_PYTHON_DEPS],
AM_CONDITIONAL([GIT_REPO], [test -d ${srcdir}"/.git"])
+# Provide more granular version numbers based on the version string,
+# using the format MAJOR.MINOR.PATCH[-SUFFIX], where SUFFIX can itself
+# contain dashes.
+#
+# NOTE: This definition must not be named such that it conflicts with
+# existing definitions, e.g., 'version', 'ver'.
+m4_define([major_minor_patch],
+ m4_split(m4_translit(AC_PACKAGE_VERSION, [-], [.]), [\.]))
+
+AC_SUBST(MESOS_MAJOR_VERSION, m4_car(major_minor_patch))
+AC_SUBST(MESOS_MINOR_VERSION, m4_car(m4_shift(major_minor_patch)))
+AC_SUBST(MESOS_PATCH_VERSION, m4_car(m4_shift2(major_minor_patch)))
+
+
AC_OUTPUT
http://git-wip-us.apache.org/repos/asf/mesos/blob/9706bb0e/include/mesos/version.hpp.in
----------------------------------------------------------------------
diff --git a/include/mesos/version.hpp.in b/include/mesos/version.hpp.in
index 524cebc..c8fbc82 100644
--- a/include/mesos/version.hpp.in
+++ b/include/mesos/version.hpp.in
@@ -21,6 +21,10 @@
#define MESOS_VERSION "@PACKAGE_VERSION@"
-// TODO(benh): MESOS_MAJOR_VERSION, MESOS_MINOR_VERSION, MESOS_PATCH_VERSION.
+#define MESOS_MAJOR_VERSION "@MESOS_MAJOR_VERSION@"
+
+#define MESOS_MINOR_VERSION "@MESOS_MINOR_VERSION@"
+
+#define MESOS_PATCH_VERSION "@MESOS_PATCH_VERSION@"
#endif // __MESOS_VERSION_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/9706bb0e/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 9ce85a6..56ed9d9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -966,6 +966,7 @@ libjava_la_SOURCES =
\
java/jni/construct.cpp \
java/jni/construct.hpp \
java/jni/org_apache_mesos_Log.cpp \
+ java/jni/org_apache_mesos_MesosNativeLibrary.cpp \
java/jni/org_apache_mesos_MesosSchedulerDriver.cpp \
java/jni/org_apache_mesos_MesosExecutorDriver.cpp \
java/jni/org_apache_mesos_state_AbstractState.cpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/9706bb0e/src/java/generated/org/apache/mesos/MesosNativeLibrary.java.in
----------------------------------------------------------------------
diff --git a/src/java/generated/org/apache/mesos/MesosNativeLibrary.java.in
b/src/java/generated/org/apache/mesos/MesosNativeLibrary.java.in
index 668647f..c54d903 100644
--- a/src/java/generated/org/apache/mesos/MesosNativeLibrary.java.in
+++ b/src/java/generated/org/apache/mesos/MesosNativeLibrary.java.in
@@ -20,11 +20,116 @@ package org.apache.mesos;
public class MesosNativeLibrary {
/**
+ * Represent a 'libmesos' version with Major, Minor, and Patch versions. We
+ * use a class here to make it easier to do version compatibility checking.
+ * For example:
+ * static Version BugFixVersion = new Version(0, 22, 1);
+ * public static void myFunction() {
+ * if (version().compareTo(BugFixVersion) >= 0) {
+ * // New behavior with bug fix.
+ * } else {
+ * // Old behavior for backwards compatibility.
+ * }
+ * }
+ */
+ public static class Version implements Comparable<Version> {
+ public Version(long major, long minor, long patch) {
+ if (major < 0) {
+ throw new IllegalArgumentException(
+ "Major version must not be negative");
+ }
+
+ if (minor < 0) {
+ throw new IllegalArgumentException(
+ "Minor version must not be negative");
+ }
+
+ if (patch < 0) {
+ throw new IllegalArgumentException(
+ "Patch version must not be negative");
+ }
+
+ this.major = major;
+ this.minor = minor;
+ this.patch = patch;
+ }
+
+ public Version(long major, long minor) {
+ this(major, minor, 0);
+ }
+
+ public Version(long major) {
+ this(major, 0, 0);
+ }
+
+ public boolean equals(Version other) {
+ return other != null &&
+ major == other.major &&
+ minor == other.minor &&
+ patch == other.patch;
+ }
+
+ /**
+ * Compare this version to an 'other' one. The comparison is done
+ * lexicographically. This returns -1 if this version is 'lesser' than the
+ * other, 0 if they are equivalent, and 1 if this version is 'greater'.
+ */
+ @Override
+ public int compareTo(Version other) {
+ if (other == null) {
+ throw new IllegalArgumentException("other Version must not be null");
+ }
+
+ if (major < other.major) {
+ return -1;
+ } else if (major > other.major) {
+ return 1;
+ }
+
+ if (minor < other.minor) {
+ return -1;
+ } else if (minor > other.minor) {
+ return 1;
+ }
+
+ if (patch < other.patch) {
+ return -1;
+ } else if (patch > other.patch) {
+ return 1;
+ }
+
+ return 0;
+ }
+
+ /**
+ * A helper that is easier to use than 'compareTo', this returns
+ * true if 'this' version is strictly 'less than', not 'less than
+ * or equal to' the 'other' version.
+ */
+ public boolean before(Version other) {
+ return this.compareTo(other) < 0;
+ }
+
+ /**
+ * A helper that is easier to use than 'compareTo', this returns
+ * true if 'this' version is strictly 'greater than', not 'greater
+ * than or equal to' the 'other' version.
+ */
+ public boolean after(Version other) {
+ return this.compareTo(other) > 0;
+ }
+
+ public final long major;
+ public final long minor;
+ public final long patch;
+ }
+
+ /**
* Attempts to load the native library (if it was not previously loaded)
* from the given path. If the path is null 'java.library.path' is used to
* load the library.
*/
- public static void load(String path) {
+ public static synchronized void load(String path) {
// Our JNI library will actually set 'loaded' to true once it is
// loaded, that way the library can get loaded by a user via
// 'System.load' in the event that they want to specify an
@@ -79,7 +184,58 @@ public class MesosNativeLibrary {
load(path);
}
+ /**
+ * Returns the version of the native loaded library, or throws a
+ * runtime exception if the library is not loaded. This was
+ * introduced in MESOS 0.22.1. Any version prior to that will be
+ * 0.0.0. This means you should not make version specific decision
+ * before the 0.22.1 version boundary. For example, if you found a
+ * bug that was fixed in 0.19.0, you will *not* be able to perform
+ * the following check correctly:
+ *
+ * if (version().before(new Version(0, 19, 0))) {
+ * ...
+ * }
+ *
+ * This predicate will return true for all versions up until 0.22.1.
+ */
+ public static synchronized Version version() {
+ // Since we allow 'load' to be called with a parameter, we can not load on
+ // behalf of the user here. Instead, we throw an exception if the library
+ // has not been loaded.
+ if (!loaded) {
+ throw new RuntimeException("'libmesos' not loaded");
+ }
+
+ if (version == null) {
+ // Try to load the libmesos version identifier. If we get an
+ // 'UnsatisfiedLinkError' then this means we are loading a 'libmesos'
with
+ // a version prior to 0.22.1, which is when the 'MAJOR', 'MINOR', and
+ // 'PATCH' version identifiers were introduced.
+ try {
+ version = _version();
+ } catch (UnsatisfiedLinkError error) {
+ System.err.println(
+ "WARNING: using an old version of 'libmesos'" +
+ " without proper version information: " + error.getMessage());
+
+ // If we're using a version of 'libmesos' less than 0.22.1, then we set
+ // the version to 0.0.0.
+ version = new Version(0, 0, 0);
+ }
+ }
+
+ return version;
+ }
+
public static final String VERSION = "@PACKAGE_VERSION@";
+ private static Version version = null;
+
private static boolean loaded = false;
+
+ /**
+ * Native implementation of 'libmesos' version identifier function.
+ */
+ private static native Version _version();
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/9706bb0e/src/java/jni/org_apache_mesos_MesosNativeLibrary.cpp
----------------------------------------------------------------------
diff --git a/src/java/jni/org_apache_mesos_MesosNativeLibrary.cpp
b/src/java/jni/org_apache_mesos_MesosNativeLibrary.cpp
new file mode 100644
index 0000000..39e342f
--- /dev/null
+++ b/src/java/jni/org_apache_mesos_MesosNativeLibrary.cpp
@@ -0,0 +1,26 @@
+#include <jni.h>
+
+#include <mesos/version.hpp>
+
+extern "C" {
+
+/*
+ * Class: org_apache_mesos_MesosNativeLibrary
+ * Method: version
+ * Signature: ()Lorg/apache/mesos/MesosNativeLibrary$Version;
+ */
+JNIEXPORT jobject JNICALL Java_org_apache_mesos_MesosNativeLibrary__1version
+ (JNIEnv* env)
+{
+ jclass clazz = env->FindClass("org/apache/mesos/MesosNativeLibrary$Version");
+ jmethodID _init_ = env->GetMethodID(clazz, "<init>", "(JJJ)V");
+ jobject jversion = env->NewObject(
+ clazz,
+ _init_,
+ (jlong) MESOS_MAJOR_VERSION,
+ (jlong) MESOS_MINOR_VERSION,
+ (jlong) MESOS_PATCH_VERSION);
+ return jversion;
+}
+
+} // extern "C" {
\ No newline at end of file