Added v1 Scheduler/Mesos interface in Java. This change adds an interface for the v1 Scheduler + Mesos interface that the schedulers can use to connect to Mesos.
Review: https://reviews.apache.org/r/50250 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/c1ba4a5a Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c1ba4a5a Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c1ba4a5a Branch: refs/heads/master Commit: c1ba4a5a2dc41e6b19b08ef8f62af8b62bc2a481 Parents: 07a1802 Author: Anand Mazumdar <an...@apache.org> Authored: Tue Jul 19 19:36:22 2016 -0700 Committer: Anand Mazumdar <an...@apache.org> Committed: Tue Aug 2 08:25:48 2016 -0700 ---------------------------------------------------------------------- src/Makefile.am | 5 +- .../org/apache/mesos/v1/scheduler/Mesos.java | 58 ++++++++++++++++++++ .../apache/mesos/v1/scheduler/Scheduler.java | 53 ++++++++++++++++++ 3 files changed, 115 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/c1ba4a5a/src/Makefile.am ---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index 5eabc33..fa4dea2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1515,7 +1515,10 @@ MESOS_JAR_SOURCE = \ $(srcdir)/java/src/org/apache/mesos/state/LogState.java \ $(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/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 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/c1ba4a5a/src/java/src/org/apache/mesos/v1/scheduler/Mesos.java ---------------------------------------------------------------------- diff --git a/src/java/src/org/apache/mesos/v1/scheduler/Mesos.java b/src/java/src/org/apache/mesos/v1/scheduler/Mesos.java new file mode 100644 index 0000000..db0116a --- /dev/null +++ b/src/java/src/org/apache/mesos/v1/scheduler/Mesos.java @@ -0,0 +1,58 @@ +/** + * 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.v1.scheduler.Protos.Call; + +/** + * Abstract interface for connecting a scheduler to Mesos. This interface + * is used to send Call's to Mesos (e.g., launch tasks, kill tasks, etc.). + */ +public interface Mesos { + /** + * Sends a Call to the Mesos master. The scheduler should only invoke this + * method once it has received the 'connected' callback. Otherwise, all calls + * would be dropped while disconnected. + * + * Some local validation of calls is performed which may generate + * events without ever being sent to the master. + * + * These comments are copied from include/mesos/v1/scheduler.hpp and should + * be kept in sync. + */ + void send(Call call); + + /** + * Force a reconnection with the Mesos master. + * + * In the case of a one-way network partition, the connection between the + * scheduler and master might not necessarily break. If the scheduler detects + * a partition, due to lack of `HEARTBEAT` events (e.g., 5) within a time + * window, it can explicitly ask the library to force a reconnection with + * the master. + * + * This call would be ignored if the scheduler is already disconnected with + * the master (e.g., no new master has been elected). Otherwise, the scheduler + * would get a 'disconnected' callback followed by a 'connected' callback. + * + * These comments are copied from include/mesos/v1/scheduler.hpp and should + * be kept in sync. + */ + void reconnect(); +} http://git-wip-us.apache.org/repos/asf/mesos/blob/c1ba4a5a/src/java/src/org/apache/mesos/v1/scheduler/Scheduler.java ---------------------------------------------------------------------- diff --git a/src/java/src/org/apache/mesos/v1/scheduler/Scheduler.java b/src/java/src/org/apache/mesos/v1/scheduler/Scheduler.java new file mode 100644 index 0000000..28efaff --- /dev/null +++ b/src/java/src/org/apache/mesos/v1/scheduler/Scheduler.java @@ -0,0 +1,53 @@ +/** + * 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.v1.scheduler.Protos.Event; + +/** + * Callback interface to be implemented by schedulers. + * Note that only one callback will be invoked at a time, + * so it is not recommended that you block within a callback because + * it may cause a deadlock. + * <p> + * Each callback includes a reference to the Mesos interface that was + * used to run this scheduler. The reference will not change for the + * duration of a scheduler from the time it is instantiated. + * This is intended for convenience so that a scheduler doesn't need to + * store a reference to the interface itself. + */ + +public interface Scheduler { + /** + * Invoked when a connection is established with the master upon a + * master (re-)detection. + */ + void connected(Mesos mesos); + + /** + * Invoked when no master is detected or when the existing persistent + * connection is interrupted. + */ + void disconnected(Mesos mesos); + + /** + * Invoked when a new event is received from the Mesos master. + */ + void received(Mesos mesos, Event event); +}