| 1 | /** |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | package scheduler |
| 20 | |
| 21 | import ( |
| 22 | mesos "github.com/mesos/mesos-go/api/v0/mesosproto" |
| 23 | ) |
| 24 | |
| 25 | // Interface for connecting a scheduler to Mesos. This |
| 26 | // interface is used both to manage the scheduler's lifecycle (start |
| 27 | // it, stop it, or wait for it to finish) and to interact with Mesos |
| 28 | // (e.g., launch tasks, kill tasks, etc.). |
| 29 | // See the MesosSchedulerDriver type for a concrete |
| 30 | // impl of a SchedulerDriver. |
| 31 | type SchedulerDriver interface { |
| 32 | // Starts the scheduler driver. This needs to be called before any |
| 33 | // other driver calls are made. |
| 34 | Start() (mesos.Status, error) |
| 35 | |
| 36 | // Stops the scheduler driver. If the 'failover' flag is set to |
| 37 | // false then it is expected that this framework will never |
| 38 | // reconnect to Mesos and all of its executors and tasks can be |
| 39 | // terminated. Otherwise, all executors and tasks will remain |
| 40 | // running (for some framework specific failover timeout) allowing the |
| 41 | // scheduler to reconnect (possibly in the same process, or from a |
| 42 | // different process, for example, on a different machine). |
| 43 | Stop(failover bool) (mesos.Status, error) |
| 44 | |
| 45 | // Aborts the driver so that no more callbacks can be made to the |
| 46 | // scheduler. The semantics of abort and stop have deliberately been |
| 47 | // separated so that code can detect an aborted driver (i.e., via |
| 48 | // the return status of SchedulerDriver::join, see below), and |
| 49 | // instantiate and start another driver if desired (from within the |
| 50 | // same process). Note that 'Stop()' is not automatically called |
| 51 | // inside 'Abort()'. |
| 52 | Abort() (mesos.Status, error) |
| 53 | |
| 54 | // Waits for the driver to be stopped or aborted, possibly |
| 55 | // _blocking_ the current thread indefinitely. The return status of |
| 56 | // this function can be used to determine if the driver was aborted |
| 57 | // (see mesos.proto for a description of Status). |
| 58 | Join() (mesos.Status, error) |
| 59 | |
| 60 | // Starts and immediately joins (i.e., blocks on) the driver. |
| 61 | Run() (mesos.Status, error) |
| 62 | |
| 63 | // Requests resources from Mesos (see mesos.proto for a description |
| 64 | // of Request and how, for example, to request resources |
| 65 | // from specific slaves). Any resources available are offered to the |
| 66 | // framework via Scheduler.ResourceOffers callback, asynchronously. |
| 67 | RequestResources(requests []*mesos.Request) (mesos.Status, error) |
| 68 | |
| 69 | // AcceptOffers utilizes the new HTTP API to send a Scheduler Call Message |
| 70 | // to the Mesos Master. Valid operation types are LAUNCH, RESERVE, UNRESERVE, |
| 71 | // CREATE, DESTROY, and more. |
| 72 | AcceptOffers(offerIDs []*mesos.OfferID, operations []*mesos.Offer_Operation, filters *mesos.Filters) (mesos.Status, error) |
| 73 | |
| 74 | // Launches the given set of tasks. Any resources remaining (i.e., |
| 75 | // not used by the tasks or their executors) will be considered |
| 76 | // declined. The specified filters are applied on all unused |
| 77 | // resources (see mesos.proto for a description of Filters). |
| 78 | // Available resources are aggregated when mutiple offers are |
| 79 | // provided. Note that all offers must belong to the same slave. |
| 80 | // Invoking this function with an empty collection of tasks declines |
| 81 | // offers in their entirety (see Scheduler::declineOffer). |
| 82 | LaunchTasks(offerIDs []*mesos.OfferID, tasks []*mesos.TaskInfo, filters *mesos.Filters) (mesos.Status, error) |
| 83 | |
| 84 | // Kills the specified task. Note that attempting to kill a task is |
| 85 | // currently not reliable. If, for example, a scheduler fails over |
| 86 | // while it was attempting to kill a task it will need to retry in |
| 87 | // the future. Likewise, if unregistered / disconnected, the request |
| 88 | // will be dropped (these semantics may be changed in the future). |
| 89 | KillTask(taskID *mesos.TaskID) (mesos.Status, error) |
| 90 | |
| 91 | // Declines an offer in its entirety and applies the specified |
| 92 | // filters on the resources (see mesos.proto for a description of |
| 93 | // Filters). Note that this can be done at any time, it is not |
| 94 | // necessary to do this within the Scheduler::resourceOffers |
| 95 | // callback. |
| 96 | DeclineOffer(offerID *mesos.OfferID, filters *mesos.Filters) (mesos.Status, error) |
| 97 | |
| 98 | // Removes all filters previously set by the framework (via |
| 99 | // LaunchTasks()). This enables the framework to receive offers from |
| 100 | // those filtered slaves. |
| 101 | ReviveOffers() (mesos.Status, error) |
| 102 | |
| 103 | // Sends a message from the framework to one of its executors. These |
| 104 | // messages are best effort; do not expect a framework message to be |
| 105 | // retransmitted in any reliable fashion. |
| 106 | SendFrameworkMessage(executorID *mesos.ExecutorID, slaveID *mesos.SlaveID, data string) (mesos.Status, error) |
| 107 | |
| 108 | // Allows the framework to query the status for non-terminal tasks. |
| 109 | // This causes the master to send back the latest task status for |
| 110 | // each task in 'statuses', if possible. Tasks that are no longer |
| 111 | // known will result in a TASK_LOST update. If statuses is empty, |
| 112 | // then the master will send the latest status for each task |
| 113 | // currently known. |
| 114 | ReconcileTasks(statuses []*mesos.TaskStatus) (mesos.Status, error) |
| 115 | } |
| 116 | |
| 117 | // Scheduler a type with callback attributes to be provided by frameworks |
| 118 | // schedulers. |
| 119 | // |
| 120 | // Each callback includes a reference to the scheduler driver that was |
| 121 | // used to run this scheduler. The pointer will not change for the |
| 122 | // duration of a scheduler (i.e., from the point you do |
| 123 | // SchedulerDriver.Start() to the point that SchedulerDriver.Stop() |
| 124 | // returns). This is intended for convenience so that a scheduler |
| 125 | // doesn't need to store a reference to the driver itself. |
| 126 | type Scheduler interface { |
| 127 | |
| 128 | // Invoked when the scheduler successfully registers with a Mesos |
| 129 | // master. A unique ID (generated by the master) used for |
| 130 | // distinguishing this framework from others and MasterInfo |
| 131 | // with the ip and port of the current master are provided as arguments. |
| 132 | Registered(SchedulerDriver, *mesos.FrameworkID, *mesos.MasterInfo) |
| 133 | |
| 134 | // Invoked when the scheduler re-registers with a newly elected Mesos master. |
| 135 | // This is only called when the scheduler has previously been registered. |
| 136 | // MasterInfo containing the updated information about the elected master |
| 137 | // is provided as an argument. |
| 138 | Reregistered(SchedulerDriver, *mesos.MasterInfo) |
| 139 | |
| 140 | // Invoked when the scheduler becomes "disconnected" from the master |
| 141 | // (e.g., the master fails and another is taking over). |
| 142 | Disconnected(SchedulerDriver) |
| 143 | |
| 144 | // Invoked when resources have been offered to this framework. A |
| 145 | // single offer will only contain resources from a single slave. |
| 146 | // Resources associated with an offer will not be re-offered to |
| 147 | // _this_ framework until either (a) this framework has rejected |
| 148 | // those resources (see SchedulerDriver::launchTasks) or (b) those |
| 149 | // resources have been rescinded (see Scheduler::offerRescinded). |
| 150 | // Note that resources may be concurrently offered to more than one |
| 151 | // framework at a time (depending on the allocator being used). In |
| 152 | // that case, the first framework to launch tasks using those |
| 153 | // resources will be able to use them while the other frameworks |
| 154 | // will have those resources rescinded (or if a framework has |
| 155 | // already launched tasks with those resources then those tasks will |
| 156 | // fail with a TASK_LOST status and a message saying as much). |
| 157 | ResourceOffers(SchedulerDriver, []*mesos.Offer) |
| 158 | |
| 159 | // Invoked when an offer is no longer valid (e.g., the slave was |
| 160 | // lost or another framework used resources in the offer). If for |
| 161 | // whatever reason an offer is never rescinded (e.g., dropped |
| 162 | // message, failing over framework, etc.), a framwork that attempts |
| 163 | // to launch tasks using an invalid offer will receive TASK_LOST |
| 164 | // status updates for those tasks (see Scheduler::resourceOffers). |
| 165 | OfferRescinded(SchedulerDriver, *mesos.OfferID) |
| 166 | |
| 167 | // Invoked when the status of a task has changed (e.g., a slave is |
| 168 | // lost and so the task is lost, a task finishes and an executor |
| 169 | // sends a status update saying so, etc). Note that returning from |
| 170 | // this callback _acknowledges_ receipt of this status update! If |
| 171 | // for whatever reason the scheduler aborts during this callback (or |
| 172 | // the process exits) another status update will be delivered (note, |
| 173 | // however, that this is currently not true if the slave sending the |
| 174 | // status update is lost/fails during that time). |
| 175 | StatusUpdate(SchedulerDriver, *mesos.TaskStatus) |
| 176 | |
| 177 | // Invoked when an executor sends a message. These messages are best |
| 178 | // effort; do not expect a framework message to be retransmitted in |
| 179 | // any reliable fashion. |
| 180 | FrameworkMessage(SchedulerDriver, *mesos.ExecutorID, *mesos.SlaveID, string) |
| 181 | |
| 182 | // Invoked when a slave has been determined unreachable (e.g., |
| 183 | // machine failure, network partition). Most frameworks will need to |
| 184 | // reschedule any tasks launched on this slave on a new slave. |
| 185 | SlaveLost(SchedulerDriver, *mesos.SlaveID) |
| 186 | |
| 187 | // Invoked when an executor has exited/terminated. Note that any |
| 188 | // tasks running will have TASK_LOST status updates automagically |
| 189 | // generated. |
| 190 | ExecutorLost(SchedulerDriver, *mesos.ExecutorID, *mesos.SlaveID, int) |
| 191 | |
| 192 | // Invoked when there is an unrecoverable error in the scheduler or |
| 193 | // scheduler driver. The driver will be aborted BEFORE invoking this |
| 194 | // callback. |
| 195 | Error(SchedulerDriver, string) |
| 196 | } |