You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2016/08/22 19:40:01 UTC

[1/2] mesos git commit: Renamed `JNIMesos` to `V1Mesos` for scheduler shim.

Repository: mesos
Updated Branches:
  refs/heads/master 719375518 -> e3143e756


Renamed `JNIMesos` to `V1Mesos` for scheduler shim.

This change renames `JNIMesos`, v1 implementation for the scheduler
shim to `V1Mesos`. `JNIMesos` was non-intuitive for users considering
the implementation was already in the native code for `V0Mesos` too.
Also, it was a bit confusing that `JNIMesos` referred to using the v1
API under the hood.

Review: https://reviews.apache.org/r/51129/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/04b9498b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/04b9498b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/04b9498b

Branch: refs/heads/master
Commit: 04b9498bc5b5e080095786f4275c202625b3142b
Parents: 7193755
Author: Anand Mazumdar <an...@apache.org>
Authored: Mon Aug 22 11:14:51 2016 -0700
Committer: Anand Mazumdar <an...@apache.org>
Committed: Mon Aug 22 11:14:51 2016 -0700

----------------------------------------------------------------------
 src/Makefile.am                                 |  10 +-
 src/examples/java/V1TestFramework.java          |   6 +-
 .../org_apache_mesos_v1_scheduler_JNIMesos.cpp  | 317 -------------------
 .../org_apache_mesos_v1_scheduler_V1Mesos.cpp   | 317 +++++++++++++++++++
 .../org/apache/mesos/v1/scheduler/JNIMesos.java |  84 -----
 .../org/apache/mesos/v1/scheduler/V1Mesos.java  |  84 +++++
 6 files changed, 409 insertions(+), 409 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/04b9498b/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 83db882..5f77310 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1524,7 +1524,7 @@ MESOS_JAR_SOURCE =							\
   $(srcdir)/java/src/org/apache/mesos/state/State.java			\
   $(srcdir)/java/src/org/apache/mesos/state/Variable.java		\
   $(srcdir)/java/src/org/apache/mesos/state/ZooKeeperState.java		\
-  $(srcdir)/java/src/org/apache/mesos/v1/scheduler/JNIMesos.java		\
+  $(srcdir)/java/src/org/apache/mesos/v1/scheduler/V1Mesos.java		\
   $(srcdir)/java/src/org/apache/mesos/v1/scheduler/Mesos.java		\
   $(srcdir)/java/src/org/apache/mesos/v1/scheduler/Scheduler.java	\
   $(srcdir)/java/src/org/apache/mesos/v1/scheduler/V0Mesos.java
@@ -1571,7 +1571,7 @@ libjava_la_SOURCES =							\
   java/jni/org_apache_mesos_state_LogState.cpp				\
   java/jni/org_apache_mesos_state_Variable.cpp				\
   java/jni/org_apache_mesos_state_ZooKeeperState.cpp			\
-  java/jni/org_apache_mesos_v1_scheduler_JNIMesos.cpp			\
+  java/jni/org_apache_mesos_v1_scheduler_V1Mesos.cpp			\
   java/jni/org_apache_mesos_v1_scheduler_V0Mesos.cpp			\
   jvm/jvm.cpp								\
   jvm/jvm.hpp								\
@@ -1615,7 +1615,7 @@ nodist_libjava_la_SOURCES =						\
   java/jni/org_apache_mesos_state_LogState.h				\
   java/jni/org_apache_mesos_state_Variable.h				\
   java/jni/org_apache_mesos_state_ZooKeeperState.h			\
-  java/jni/org_apache_mesos_v1_scheduler_JNIMesos.h			\
+  java/jni/org_apache_mesos_v1_scheduler_V1Mesos.h			\
   java/jni/org_apache_mesos_v1_scheduler_V0Mesos.h
 
 BUILT_SOURCES += $(nodist_libjava_la_SOURCES)
@@ -1660,10 +1660,10 @@ java/jni/org_apache_mesos_state_ZooKeeperState.h: $(MESOS_JAR)
 	-classpath $(MESOS_JAR):@PROTOBUF_JAR@				\
 	  org.apache.mesos.state.ZooKeeperState
 
-java/jni/org_apache_mesos_v1_scheduler_JNIMesos.h: $(MESOS_JAR)
+java/jni/org_apache_mesos_v1_scheduler_V1Mesos.h: $(MESOS_JAR)
 	$(JAVA_HOME)/bin/javah -d java/jni				\
 	-classpath $(MESOS_JAR):@PROTOBUF_JAR@				\
-	  org.apache.mesos.v1.scheduler.JNIMesos
+	  org.apache.mesos.v1.scheduler.V1Mesos
 
 java/jni/org_apache_mesos_v1_scheduler_V0Mesos.h: $(MESOS_JAR)
 	$(JAVA_HOME)/bin/javah -d java/jni				\

http://git-wip-us.apache.org/repos/asf/mesos/blob/04b9498b/src/examples/java/V1TestFramework.java
----------------------------------------------------------------------
diff --git a/src/examples/java/V1TestFramework.java b/src/examples/java/V1TestFramework.java
index a41edbc..ec26919 100644
--- a/src/examples/java/V1TestFramework.java
+++ b/src/examples/java/V1TestFramework.java
@@ -32,10 +32,10 @@ import org.apache.mesos.v1.*;
 
 import org.apache.mesos.v1.Protos.*;
 
-import org.apache.mesos.v1.scheduler.JNIMesos;
 import org.apache.mesos.v1.scheduler.Mesos;
 import org.apache.mesos.v1.scheduler.Scheduler;
 import org.apache.mesos.v1.scheduler.V0Mesos;
+import org.apache.mesos.v1.scheduler.V1Mesos;
 
 import org.apache.mesos.v1.scheduler.Protos.Call;
 import org.apache.mesos.v1.scheduler.Protos.Event;
@@ -357,14 +357,14 @@ public class V1TestFramework {
     Mesos mesos;
     if (credentialBuilder != null) {
       mesos = version == 1
-                ? new JNIMesos(scheduler, args[0], credentialBuilder.build())
+                ? new V1Mesos(scheduler, args[0], credentialBuilder.build())
                 : new V0Mesos(scheduler,
                               frameworkBuilder.build(),
                               args[0],
                               credentialBuilder.build());
     } else {
       mesos = version == 1
-                ? new JNIMesos(scheduler, args[0])
+                ? new V1Mesos(scheduler, args[0])
                 : new V0Mesos(scheduler, frameworkBuilder.build(), args[0]);
     }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/04b9498b/src/java/jni/org_apache_mesos_v1_scheduler_JNIMesos.cpp
----------------------------------------------------------------------
diff --git a/src/java/jni/org_apache_mesos_v1_scheduler_JNIMesos.cpp b/src/java/jni/org_apache_mesos_v1_scheduler_JNIMesos.cpp
deleted file mode 100644
index e197b37..0000000
--- a/src/java/jni/org_apache_mesos_v1_scheduler_JNIMesos.cpp
+++ /dev/null
@@ -1,317 +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.
-
-#include <string>
-#include <vector>
-
-#include <process/owned.hpp>
-
-#include <mesos/v1/mesos.hpp>
-
-#include <mesos/v1/scheduler.hpp>
-
-#include <mesos/v1/scheduler/scheduler.hpp>
-
-#include <stout/foreach.hpp>
-#include <stout/lambda.hpp>
-#include <stout/option.hpp>
-#include <stout/result.hpp>
-#include <stout/try.hpp>
-
-#include "jvm/jvm.hpp"
-
-#include "construct.hpp"
-#include "convert.hpp"
-#include "org_apache_mesos_v1_scheduler_JNIMesos.h"
-
-using namespace mesos::v1::scheduler;
-
-using mesos::v1::Credential;
-
-using process::Owned;
-
-using std::string;
-using std::vector;
-
-namespace v1 {
-
-class JNIMesos
-{
-public:
-  JNIMesos(
-      JNIEnv* _env,
-      jweak _jmesos,
-      const string& master,
-      const Option<Credential>& credential)
-    : jvm(nullptr), env(_env), jmesos(_jmesos)
-  {
-    env->GetJavaVM(&jvm);
-
-    mesos.reset(
-        new Mesos(master,
-            mesos::ContentType::PROTOBUF,
-            std::bind(&JNIMesos::connected, this),
-            std::bind(&JNIMesos::disconnected, this),
-            std::bind(&JNIMesos::received_, this, lambda::_1),
-            credential));
-  }
-
-  virtual ~JNIMesos() = default;
-
-  virtual void connected();
-  virtual void disconnected();
-  virtual void received(const Event& event);
-
-  void received_(std::queue<Event> events) {
-    while (!events.empty()) {
-      received(events.front());
-      events.pop();
-    }
-  }
-
-  JavaVM* jvm;
-  JNIEnv* env;
-  jweak jmesos;
-
-  Owned<Mesos> mesos;
-};
-
-
-void JNIMesos::connected()
-{
-  jvm->AttachCurrentThread(JNIENV_CAST(&env), nullptr);
-
-  jclass clazz = env->GetObjectClass(jmesos);
-
-  jfieldID scheduler =
-    env->GetFieldID(clazz, "scheduler",
-                    "Lorg/apache/mesos/v1/scheduler/Scheduler;");
-
-  jobject jscheduler = env->GetObjectField(jmesos, scheduler);
-
-  clazz = env->GetObjectClass(jscheduler);
-
-  // scheduler.connected(mesos);
-  jmethodID connected =
-    env->GetMethodID(clazz, "connected",
-                     "(Lorg/apache/mesos/v1/scheduler/Mesos;)V");
-
-  env->ExceptionClear();
-
-  env->CallVoidMethod(jscheduler, connected, jmesos);
-
-  if (env->ExceptionCheck()) {
-    env->ExceptionDescribe();
-    env->ExceptionClear();
-    jvm->DetachCurrentThread();
-    ABORT("Exception thrown during `connected` call");
-  }
-
-  jvm->DetachCurrentThread();
-}
-
-
-void JNIMesos::disconnected()
-{
-  jvm->AttachCurrentThread(JNIENV_CAST(&env), nullptr);
-
-  jclass clazz = env->GetObjectClass(jmesos);
-
-  jfieldID scheduler =
-    env->GetFieldID(clazz, "scheduler",
-                    "Lorg/apache/mesos/v1/scheduler/Scheduler;");
-
-  jobject jscheduler = env->GetObjectField(jmesos, scheduler);
-
-  clazz = env->GetObjectClass(jscheduler);
-
-  // scheduler.disconnected(mesos);
-  jmethodID disconnected =
-    env->GetMethodID(clazz, "disconnected",
-                     "(Lorg/apache/mesos/v1/scheduler/Mesos;)V");
-
-  env->ExceptionClear();
-
-  env->CallVoidMethod(jscheduler, disconnected, jmesos);
-
-  if (env->ExceptionCheck()) {
-    env->ExceptionDescribe();
-    env->ExceptionClear();
-    jvm->DetachCurrentThread();
-    ABORT("Exception thrown during `disconnected` call");
-  }
-
-  jvm->DetachCurrentThread();
-}
-
-
-void JNIMesos::received(const Event& event)
-{
-  jvm->AttachCurrentThread(JNIENV_CAST(&env), nullptr);
-
-  jclass clazz = env->GetObjectClass(jmesos);
-
-  jfieldID scheduler =
-    env->GetFieldID(clazz, "scheduler",
-                    "Lorg/apache/mesos/v1/scheduler/Scheduler;");
-
-  jobject jscheduler = env->GetObjectField(jmesos, scheduler);
-
-  clazz = env->GetObjectClass(jscheduler);
-
-  // scheduler.received(mesos, event);
-  jmethodID received =
-    env->GetMethodID(clazz, "received",
-                     "(Lorg/apache/mesos/v1/scheduler/Mesos;"
-                     "Lorg/apache/mesos/v1/scheduler/Protos$Event;)V");
-
-  jobject jevent = convert<Event>(env, event);
-
-  env->ExceptionClear();
-
-  env->CallVoidMethod(jscheduler, received, jmesos, jevent);
-
-  if (env->ExceptionCheck()) {
-    env->ExceptionDescribe();
-    env->ExceptionClear();
-    jvm->DetachCurrentThread();
-    ABORT("Exception thrown during `received` call");
-  }
-
-  jvm->DetachCurrentThread();
-}
-
-} // namespace v1 {
-
-
-extern "C" {
-
-/*
- * Class:     org_apache_mesos_v1_JNIMesos
- * Method:    initialize
- * Signature: ()V
- *
- */
-JNIEXPORT void JNICALL Java_org_apache_mesos_v1_scheduler_JNIMesos_initialize
-  (JNIEnv* env, jobject thiz)
-{
-  jclass clazz = env->GetObjectClass(thiz);
-
-  // Create a weak global reference to the Scheduler
-  // instance (we want a global reference so the GC doesn't collect
-  // the instance but we make it weak so the JVM can exit).
-  jweak jmesos = env->NewWeakGlobalRef(thiz);
-
-  // Get out the master passed into the constructor.
-  jfieldID master = env->GetFieldID(clazz, "master", "Ljava/lang/String;");
-  jobject jmaster = env->GetObjectField(thiz, master);
-
-  // Get out the credential passed into the constructor.
-  jfieldID credential =
-    env->GetFieldID(clazz, "credential",
-                    "Lorg/apache/mesos/v1/Protos$Credential;");
-
-  jobject jcredential = env->GetObjectField(thiz, credential);
-
-  Option<Credential> credential_;
-  if (!env->IsSameObject(jcredential, nullptr)) {
-    credential_ = construct<Credential>(env, jcredential);
-  }
-
-  // Create the C++ scheduler and initialize `__mesos`.
-  v1::JNIMesos* mesos =
-    new v1::JNIMesos(env, jmesos, construct<string>(env, jmaster), credential_);
-
-  jfieldID __mesos = env->GetFieldID(clazz, "__mesos", "J");
-  env->SetLongField(thiz, __mesos, (jlong) mesos);
-}
-
-
-/*
- * Class:     org_apache_mesos_v1_JNIMesos
- * Method:    finalize
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_org_apache_mesos_v1_scheduler_JNIMesos_finalize
-  (JNIEnv* env, jobject thiz)
-{
-  jclass clazz = env->GetObjectClass(thiz);
-
-  jfieldID __mesos = env->GetFieldID(clazz, "__mesos", "J");
-  v1::JNIMesos* mesos =
-    (v1::JNIMesos*) env->GetLongField(thiz, __mesos);
-
-  env->DeleteWeakGlobalRef(mesos->jmesos);
-
-  delete mesos;
-}
-
-
-/*
- * Class:     org_apache_mesos_v1_JNIMesos
- * Method:    send
- * Signature: (Lorg/apache/mesos/v1/scheduler/Protos/Call;)V
- */
-JNIEXPORT void JNICALL Java_org_apache_mesos_v1_scheduler_JNIMesos_send
-  (JNIEnv* env, jobject thiz, jobject jcall)
-{
-  // Construct a C++ Call from the Java Call.
-  const Call& call = construct<Call>(env, jcall);
-
-  jclass clazz = env->GetObjectClass(thiz);
-
-  jfieldID __mesos = env->GetFieldID(clazz, "__mesos", "J");
-  v1::JNIMesos* mesos =
-    (v1::JNIMesos*) env->GetLongField(thiz, __mesos);
-
-  // It is possible that `mesos` might not be initialized in some cases due to
-  // a possible race condition. See MESOS-5926 for more details.
-  if (mesos->mesos.get() == nullptr) {
-    LOG(WARNING) << "Ignoring call " << call.type() << " as the library has "
-                 << "not been initialized yet";
-    return;
-  }
-
-  mesos->mesos->send(call);
-}
-
-
-/*
- * Class:     org_apache_mesos_v1_scheduler_JNIMesos
- * Method:    reconnect
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_org_apache_mesos_v1_scheduler_JNIMesos_reconnect
-  (JNIEnv* env, jobject thiz)
-{
-  jclass clazz = env->GetObjectClass(thiz);
-
-  jfieldID __mesos = env->GetFieldID(clazz, "__mesos", "J");
-  v1::JNIMesos* mesos =
-    (v1::JNIMesos*) env->GetLongField(thiz, __mesos);
-
-  // It is possible that `mesos` might not be initialized in some cases due to
-  // a possible race condition. See MESOS-5926 for more details.
-  if (mesos->mesos.get() == nullptr) {
-    LOG(WARNING) << "Ignoring the reconnect request as the library has not "
-                 << "been initialized yet";
-    return;
-  }
-
-  mesos->mesos->reconnect();
-}
-
-} // extern "C" {

http://git-wip-us.apache.org/repos/asf/mesos/blob/04b9498b/src/java/jni/org_apache_mesos_v1_scheduler_V1Mesos.cpp
----------------------------------------------------------------------
diff --git a/src/java/jni/org_apache_mesos_v1_scheduler_V1Mesos.cpp b/src/java/jni/org_apache_mesos_v1_scheduler_V1Mesos.cpp
new file mode 100644
index 0000000..2a5fbd7
--- /dev/null
+++ b/src/java/jni/org_apache_mesos_v1_scheduler_V1Mesos.cpp
@@ -0,0 +1,317 @@
+// 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.
+
+#include <string>
+#include <vector>
+
+#include <process/owned.hpp>
+
+#include <mesos/v1/mesos.hpp>
+
+#include <mesos/v1/scheduler.hpp>
+
+#include <mesos/v1/scheduler/scheduler.hpp>
+
+#include <stout/foreach.hpp>
+#include <stout/lambda.hpp>
+#include <stout/option.hpp>
+#include <stout/result.hpp>
+#include <stout/try.hpp>
+
+#include "jvm/jvm.hpp"
+
+#include "construct.hpp"
+#include "convert.hpp"
+#include "org_apache_mesos_v1_scheduler_V1Mesos.h"
+
+using namespace mesos::v1::scheduler;
+
+using mesos::v1::Credential;
+
+using process::Owned;
+
+using std::string;
+using std::vector;
+
+namespace v1 {
+
+class JNIMesos
+{
+public:
+  JNIMesos(
+      JNIEnv* _env,
+      jweak _jmesos,
+      const string& master,
+      const Option<Credential>& credential)
+    : jvm(nullptr), env(_env), jmesos(_jmesos)
+  {
+    env->GetJavaVM(&jvm);
+
+    mesos.reset(
+        new Mesos(master,
+            mesos::ContentType::PROTOBUF,
+            std::bind(&JNIMesos::connected, this),
+            std::bind(&JNIMesos::disconnected, this),
+            std::bind(&JNIMesos::received_, this, lambda::_1),
+            credential));
+  }
+
+  virtual ~JNIMesos() = default;
+
+  virtual void connected();
+  virtual void disconnected();
+  virtual void received(const Event& event);
+
+  void received_(std::queue<Event> events) {
+    while (!events.empty()) {
+      received(events.front());
+      events.pop();
+    }
+  }
+
+  JavaVM* jvm;
+  JNIEnv* env;
+  jweak jmesos;
+
+  Owned<Mesos> mesos;
+};
+
+
+void JNIMesos::connected()
+{
+  jvm->AttachCurrentThread(JNIENV_CAST(&env), nullptr);
+
+  jclass clazz = env->GetObjectClass(jmesos);
+
+  jfieldID scheduler =
+    env->GetFieldID(clazz, "scheduler",
+                    "Lorg/apache/mesos/v1/scheduler/Scheduler;");
+
+  jobject jscheduler = env->GetObjectField(jmesos, scheduler);
+
+  clazz = env->GetObjectClass(jscheduler);
+
+  // scheduler.connected(mesos);
+  jmethodID connected =
+    env->GetMethodID(clazz, "connected",
+                     "(Lorg/apache/mesos/v1/scheduler/Mesos;)V");
+
+  env->ExceptionClear();
+
+  env->CallVoidMethod(jscheduler, connected, jmesos);
+
+  if (env->ExceptionCheck()) {
+    env->ExceptionDescribe();
+    env->ExceptionClear();
+    jvm->DetachCurrentThread();
+    ABORT("Exception thrown during `connected` call");
+  }
+
+  jvm->DetachCurrentThread();
+}
+
+
+void JNIMesos::disconnected()
+{
+  jvm->AttachCurrentThread(JNIENV_CAST(&env), nullptr);
+
+  jclass clazz = env->GetObjectClass(jmesos);
+
+  jfieldID scheduler =
+    env->GetFieldID(clazz, "scheduler",
+                    "Lorg/apache/mesos/v1/scheduler/Scheduler;");
+
+  jobject jscheduler = env->GetObjectField(jmesos, scheduler);
+
+  clazz = env->GetObjectClass(jscheduler);
+
+  // scheduler.disconnected(mesos);
+  jmethodID disconnected =
+    env->GetMethodID(clazz, "disconnected",
+                     "(Lorg/apache/mesos/v1/scheduler/Mesos;)V");
+
+  env->ExceptionClear();
+
+  env->CallVoidMethod(jscheduler, disconnected, jmesos);
+
+  if (env->ExceptionCheck()) {
+    env->ExceptionDescribe();
+    env->ExceptionClear();
+    jvm->DetachCurrentThread();
+    ABORT("Exception thrown during `disconnected` call");
+  }
+
+  jvm->DetachCurrentThread();
+}
+
+
+void JNIMesos::received(const Event& event)
+{
+  jvm->AttachCurrentThread(JNIENV_CAST(&env), nullptr);
+
+  jclass clazz = env->GetObjectClass(jmesos);
+
+  jfieldID scheduler =
+    env->GetFieldID(clazz, "scheduler",
+                    "Lorg/apache/mesos/v1/scheduler/Scheduler;");
+
+  jobject jscheduler = env->GetObjectField(jmesos, scheduler);
+
+  clazz = env->GetObjectClass(jscheduler);
+
+  // scheduler.received(mesos, event);
+  jmethodID received =
+    env->GetMethodID(clazz, "received",
+                     "(Lorg/apache/mesos/v1/scheduler/Mesos;"
+                     "Lorg/apache/mesos/v1/scheduler/Protos$Event;)V");
+
+  jobject jevent = convert<Event>(env, event);
+
+  env->ExceptionClear();
+
+  env->CallVoidMethod(jscheduler, received, jmesos, jevent);
+
+  if (env->ExceptionCheck()) {
+    env->ExceptionDescribe();
+    env->ExceptionClear();
+    jvm->DetachCurrentThread();
+    ABORT("Exception thrown during `received` call");
+  }
+
+  jvm->DetachCurrentThread();
+}
+
+} // namespace v1 {
+
+
+extern "C" {
+
+/*
+ * Class:     org_apache_mesos_v1_V1Mesos
+ * Method:    initialize
+ * Signature: ()V
+ *
+ */
+JNIEXPORT void JNICALL Java_org_apache_mesos_v1_scheduler_V1Mesos_initialize
+  (JNIEnv* env, jobject thiz)
+{
+  jclass clazz = env->GetObjectClass(thiz);
+
+  // Create a weak global reference to the Scheduler
+  // instance (we want a global reference so the GC doesn't collect
+  // the instance but we make it weak so the JVM can exit).
+  jweak jmesos = env->NewWeakGlobalRef(thiz);
+
+  // Get out the master passed into the constructor.
+  jfieldID master = env->GetFieldID(clazz, "master", "Ljava/lang/String;");
+  jobject jmaster = env->GetObjectField(thiz, master);
+
+  // Get out the credential passed into the constructor.
+  jfieldID credential =
+    env->GetFieldID(clazz, "credential",
+                    "Lorg/apache/mesos/v1/Protos$Credential;");
+
+  jobject jcredential = env->GetObjectField(thiz, credential);
+
+  Option<Credential> credential_;
+  if (!env->IsSameObject(jcredential, nullptr)) {
+    credential_ = construct<Credential>(env, jcredential);
+  }
+
+  // Create the C++ scheduler and initialize `__mesos`.
+  v1::JNIMesos* mesos =
+    new v1::JNIMesos(env, jmesos, construct<string>(env, jmaster), credential_);
+
+  jfieldID __mesos = env->GetFieldID(clazz, "__mesos", "J");
+  env->SetLongField(thiz, __mesos, (jlong) mesos);
+}
+
+
+/*
+ * Class:     org_apache_mesos_v1_V1Mesos
+ * Method:    finalize
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mesos_v1_scheduler_V1Mesos_finalize
+  (JNIEnv* env, jobject thiz)
+{
+  jclass clazz = env->GetObjectClass(thiz);
+
+  jfieldID __mesos = env->GetFieldID(clazz, "__mesos", "J");
+  v1::JNIMesos* mesos =
+    (v1::JNIMesos*) env->GetLongField(thiz, __mesos);
+
+  env->DeleteWeakGlobalRef(mesos->jmesos);
+
+  delete mesos;
+}
+
+
+/*
+ * Class:     org_apache_mesos_v1_V1Mesos
+ * Method:    send
+ * Signature: (Lorg/apache/mesos/v1/scheduler/Protos/Call;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mesos_v1_scheduler_V1Mesos_send
+  (JNIEnv* env, jobject thiz, jobject jcall)
+{
+  // Construct a C++ Call from the Java Call.
+  const Call& call = construct<Call>(env, jcall);
+
+  jclass clazz = env->GetObjectClass(thiz);
+
+  jfieldID __mesos = env->GetFieldID(clazz, "__mesos", "J");
+  v1::JNIMesos* mesos =
+    (v1::JNIMesos*) env->GetLongField(thiz, __mesos);
+
+  // It is possible that `mesos` might not be initialized in some cases due to
+  // a possible race condition. See MESOS-5926 for more details.
+  if (mesos->mesos.get() == nullptr) {
+    LOG(WARNING) << "Ignoring call " << call.type() << " as the library has "
+                 << "not been initialized yet";
+    return;
+  }
+
+  mesos->mesos->send(call);
+}
+
+
+/*
+ * Class:     org_apache_mesos_v1_scheduler_V1Mesos
+ * Method:    reconnect
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mesos_v1_scheduler_V1Mesos_reconnect
+  (JNIEnv* env, jobject thiz)
+{
+  jclass clazz = env->GetObjectClass(thiz);
+
+  jfieldID __mesos = env->GetFieldID(clazz, "__mesos", "J");
+  v1::JNIMesos* mesos =
+    (v1::JNIMesos*) env->GetLongField(thiz, __mesos);
+
+  // It is possible that `mesos` might not be initialized in some cases due to
+  // a possible race condition. See MESOS-5926 for more details.
+  if (mesos->mesos.get() == nullptr) {
+    LOG(WARNING) << "Ignoring the reconnect request as the library has not "
+                 << "been initialized yet";
+    return;
+  }
+
+  mesos->mesos->reconnect();
+}
+
+} // extern "C" {

http://git-wip-us.apache.org/repos/asf/mesos/blob/04b9498b/src/java/src/org/apache/mesos/v1/scheduler/JNIMesos.java
----------------------------------------------------------------------
diff --git a/src/java/src/org/apache/mesos/v1/scheduler/JNIMesos.java b/src/java/src/org/apache/mesos/v1/scheduler/JNIMesos.java
deleted file mode 100644
index fc804a4..0000000
--- a/src/java/src/org/apache/mesos/v1/scheduler/JNIMesos.java
+++ /dev/null
@@ -1,84 +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.mesos.v1.scheduler;
-
-import org.apache.mesos.MesosNativeLibrary;
-
-import org.apache.mesos.v1.Protos.Credential;
-import org.apache.mesos.v1.Protos.FrameworkInfo;
-
-import org.apache.mesos.v1.scheduler.Protos.Call;
-
-/**
- * Concrete implementation of the Mesos interface that connects a Scheduler
- * with a Mesos master. This class is thread-safe.
- * <p>
- * This implementation uses the scheduler library (src/scheduler/scheduler.cpp)
- * based on the V1 Mesos Scheduler API. The library is responsible for
- * invoking the Scheduler callbacks as it communicates with the Mesos master.
- * <p>
- * <p>
- * Note that the scheduler library uses GLOG to do its own logging. GLOG flags
- * can be set via environment variables, prefixing the flag name with
- * "GLOG_", e.g., "GLOG_v=1". For Mesos specific logging flags see
- * src/logging/flags.hpp. Mesos flags can also be set via environment
- * variables, prefixing the flag name with "MESOS_", e.g., "MESOS_QUIET=1".
- * <p>
- * See src/examples/java/V1TestFramework.java for an example of using this.
- */
-public class JNIMesos implements Mesos {
-  static {
-    MesosNativeLibrary.load();
-  }
-
-  public JNIMesos(Scheduler scheduler, String master) {
-    this(scheduler, master, null);
-  }
-
-  public JNIMesos(Scheduler scheduler, String master, Credential credential) {
-    if (scheduler == null) {
-      throw new NullPointerException("Not expecting a null scheduler");
-    }
-
-    if (master == null) {
-      throw new NullPointerException("Not expecting a null master");
-    }
-
-    this.scheduler = scheduler;
-    this.master = master;
-    this.credential = credential;
-
-    initialize();
-  }
-
-  @Override
-  public native void send(Call call);
-
-  @Override
-  public native void reconnect();
-
-  protected native void initialize();
-  protected native void finalize();
-
-  private final Scheduler scheduler;
-  private final String master;
-  private final Credential credential;
-
-  private long __mesos;
-}

http://git-wip-us.apache.org/repos/asf/mesos/blob/04b9498b/src/java/src/org/apache/mesos/v1/scheduler/V1Mesos.java
----------------------------------------------------------------------
diff --git a/src/java/src/org/apache/mesos/v1/scheduler/V1Mesos.java b/src/java/src/org/apache/mesos/v1/scheduler/V1Mesos.java
new file mode 100644
index 0000000..76327e2
--- /dev/null
+++ b/src/java/src/org/apache/mesos/v1/scheduler/V1Mesos.java
@@ -0,0 +1,84 @@
+/**
+ * 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.mesos.v1.scheduler;
+
+import org.apache.mesos.MesosNativeLibrary;
+
+import org.apache.mesos.v1.Protos.Credential;
+import org.apache.mesos.v1.Protos.FrameworkInfo;
+
+import org.apache.mesos.v1.scheduler.Protos.Call;
+
+/**
+ * Concrete implementation of the Mesos interface that connects a Scheduler
+ * with a Mesos master. This class is thread-safe.
+ * <p>
+ * This implementation uses the scheduler library (src/scheduler/scheduler.cpp)
+ * based on the V1 Mesos Scheduler API. The library is responsible for
+ * invoking the Scheduler callbacks as it communicates with the Mesos master.
+ * <p>
+ * <p>
+ * Note that the scheduler library uses GLOG to do its own logging. GLOG flags
+ * can be set via environment variables, prefixing the flag name with
+ * "GLOG_", e.g., "GLOG_v=1". For Mesos specific logging flags see
+ * src/logging/flags.hpp. Mesos flags can also be set via environment
+ * variables, prefixing the flag name with "MESOS_", e.g., "MESOS_QUIET=1".
+ * <p>
+ * See src/examples/java/V1TestFramework.java for an example of using this.
+ */
+public class V1Mesos implements Mesos {
+  static {
+    MesosNativeLibrary.load();
+  }
+
+  public V1Mesos(Scheduler scheduler, String master) {
+    this(scheduler, master, null);
+  }
+
+  public V1Mesos(Scheduler scheduler, String master, Credential credential) {
+    if (scheduler == null) {
+      throw new NullPointerException("Not expecting a null scheduler");
+    }
+
+    if (master == null) {
+      throw new NullPointerException("Not expecting a null master");
+    }
+
+    this.scheduler = scheduler;
+    this.master = master;
+    this.credential = credential;
+
+    initialize();
+  }
+
+  @Override
+  public native void send(Call call);
+
+  @Override
+  public native void reconnect();
+
+  protected native void initialize();
+  protected native void finalize();
+
+  private final Scheduler scheduler;
+  private final String master;
+  private final Credential credential;
+
+  private long __mesos;
+}


[2/2] mesos git commit: Exposed unversioned scheduler/executor protos in Mesos JAR.

Posted by an...@apache.org.
Exposed unversioned scheduler/executor protos in Mesos JAR.

This change exposes the unversioned scheduler/executor protos
in the Mesos JAR. We already used to expose the unversioned
Mesos protos. This is useful for migrating schedulers to use
the new v1 API via the scheduler shim. Otherwise, they would
need to create their own copy of these protobufs even for vetting
the new API via the shim. Note that this only partially resolves
MESOS-6016 and that we would need to tackle the unversioned protobuf
deprecation later eventually.

Review: https://reviews.apache.org/r/51130/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e3143e75
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e3143e75
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e3143e75

Branch: refs/heads/master
Commit: e3143e756fafe343a79cadb10b587fad0e5904d5
Parents: 04b9498
Author: Anand Mazumdar <an...@apache.org>
Authored: Mon Aug 22 11:15:26 2016 -0700
Committer: Anand Mazumdar <an...@apache.org>
Committed: Mon Aug 22 11:15:26 2016 -0700

----------------------------------------------------------------------
 src/Makefile.am | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e3143e75/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 5f77310..9734460 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -328,7 +328,9 @@ CXX_STATE_PROTOS =							\
 
 JAVA_PROTOS =								\
   java/generated/org/apache/mesos/Protos.java				\
-  java/generated/org/apache/mesos/containerizer/Protos.java
+  java/generated/org/apache/mesos/containerizer/Protos.java             \
+  java/generated/org/apache/mesos/executor/Protos.java			\
+  java/generated/org/apache/mesos/scheduler/Protos.java
 
 PYTHON_PROTOS =								\
   python/interface/src/mesos/interface/mesos_pb2.py			\