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/02 15:42:49 UTC

[7/7] mesos git commit: Added java implementations for the V0/V1 implementation for Mesos.

Added java implementations for the V0/V1 implementation for Mesos.

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


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

Branch: refs/heads/master
Commit: 5855532668ab2a5f23914b26ccee70d7a5068302
Parents: c1ba4a5
Author: Anand Mazumdar <an...@apache.org>
Authored: Tue Jul 19 19:56:50 2016 -0700
Committer: Anand Mazumdar <an...@apache.org>
Committed: Tue Aug 2 08:25:48 2016 -0700

----------------------------------------------------------------------
 src/Makefile.am                                 |  3 +-
 .../org/apache/mesos/v1/scheduler/JNIMesos.java | 84 ++++++++++++++++++++
 .../org/apache/mesos/v1/scheduler/V0Mesos.java  | 84 ++++++++++++++++++++
 3 files changed, 170 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/58555326/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index fa4dea2..3a743e4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1518,7 +1518,8 @@ MESOS_JAR_SOURCE =							\
   $(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/Mesos.java		\
-  $(srcdir)/java/src/org/apache/mesos/v1/scheduler/Scheduler.java
+  $(srcdir)/java/src/org/apache/mesos/v1/scheduler/Scheduler.java	\
+  $(srcdir)/java/src/org/apache/mesos/v1/scheduler/V0Mesos.java
 MESOS_JAR_GENERATED = $(JAVA_PROTOS) $(V1_JAVA_PROTOS)			\
   java/generated/org/apache/mesos/MesosNativeLibrary.java
 EXTRA_DIST += $(MESOS_JAR_SOURCE)					\

http://git-wip-us.apache.org/repos/asf/mesos/blob/58555326/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
new file mode 100644
index 0000000..fc804a4
--- /dev/null
+++ b/src/java/src/org/apache/mesos/v1/scheduler/JNIMesos.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 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/58555326/src/java/src/org/apache/mesos/v1/scheduler/V0Mesos.java
----------------------------------------------------------------------
diff --git a/src/java/src/org/apache/mesos/v1/scheduler/V0Mesos.java b/src/java/src/org/apache/mesos/v1/scheduler/V0Mesos.java
new file mode 100644
index 0000000..fc262e1
--- /dev/null
+++ b/src/java/src/org/apache/mesos/v1/scheduler/V0Mesos.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;
+import org.apache.mesos.v1.scheduler.Protos.Event;
+
+/**
+ * This implementation acts as an adapter from the v0 (driver + scheduler)
+ * to the v1 Scheduler interface. It uses the MesosSchedulerDriver under
+ * the hood for interacting with Mesos. This class is thread-safe.
+ */
+public class V0Mesos implements Mesos {
+  static {
+    MesosNativeLibrary.load();
+  }
+
+  public V0Mesos(Scheduler scheduler, FrameworkInfo framework, String master) {
+    this(scheduler, framework, master, null);
+  }
+
+  public V0Mesos(Scheduler scheduler,
+                 FrameworkInfo framework,
+                 String master,
+                 Credential credential) {
+    if (scheduler == null) {
+      throw new NullPointerException("Not expecting a null scheduler");
+    }
+
+    if (framework == null) {
+      throw new NullPointerException("Not expecting a null framework");
+    }
+
+    if (master == null) {
+      throw new NullPointerException("Not expecting a null master");
+    }
+
+    this.scheduler = scheduler;
+    this.framework = framework;
+    this.master = master;
+    this.credential = credential;
+
+    initialize();
+  }
+
+  @Override
+  public native void send(Call call);
+
+  // This is currently a no-op for the driver as it does not expose semantics
+  // to force reconnection.
+  @Override
+  public void reconnect() {}
+
+  protected native void initialize();
+  protected native void finalize();
+
+  private final Scheduler scheduler;
+  private final FrameworkInfo framework;
+  private final String master;
+  private final Credential credential;
+
+  private long __mesos;
+}