Repository: incubator-myriad Updated Branches: refs/heads/upgrademesos1.5 [created] 16467f39d
http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/b5b468b9/myriad-commons/src/main/java/org/apache/mesos/v1/scheduler/Scheduler.java ---------------------------------------------------------------------- diff --git a/myriad-commons/src/main/java/org/apache/mesos/v1/scheduler/Scheduler.java b/myriad-commons/src/main/java/org/apache/mesos/v1/scheduler/Scheduler.java new file mode 100644 index 0000000..002acef --- /dev/null +++ b/myriad-commons/src/main/java/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); +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/b5b468b9/myriad-commons/src/main/java/org/apache/mesos/v1/scheduler/V0Mesos.java ---------------------------------------------------------------------- diff --git a/myriad-commons/src/main/java/org/apache/mesos/v1/scheduler/V0Mesos.java b/myriad-commons/src/main/java/org/apache/mesos/v1/scheduler/V0Mesos.java new file mode 100644 index 0000000..753de63 --- /dev/null +++ b/myriad-commons/src/main/java/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; +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/b5b468b9/myriad-commons/src/main/java/org/apache/mesos/v1/scheduler/V1Mesos.java ---------------------------------------------------------------------- diff --git a/myriad-commons/src/main/java/org/apache/mesos/v1/scheduler/V1Mesos.java b/myriad-commons/src/main/java/org/apache/mesos/v1/scheduler/V1Mesos.java new file mode 100644 index 0000000..59a0a35 --- /dev/null +++ b/myriad-commons/src/main/java/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; +}