本文整理汇总了Scala中org.apache.mesos.SchedulerDriver类的典型用法代码示例。如果您正苦于以下问题:Scala SchedulerDriver类的具体用法?Scala SchedulerDriver怎么用?Scala SchedulerDriver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SchedulerDriver类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: SimulatedSchedulerDriverFactory
//设置package包名称以及导入依赖的类
package mesosphere.mesos.simulation
import javax.inject.Inject
import mesosphere.marathon.{ MarathonScheduler, MarathonSchedulerDriverHolder, SchedulerDriverFactory }
import org.apache.mesos.SchedulerDriver
class SimulatedSchedulerDriverFactory @Inject() (
holder: MarathonSchedulerDriverHolder,
newScheduler: MarathonScheduler)
extends SchedulerDriverFactory {
override def createDriver(): SchedulerDriver = {
val driver = SimulatedDriverWiring.createDriver(newScheduler)
holder.driver = Some(driver)
driver
}
}
开发者ID:xiaozai512,项目名称:marathon,代码行数:19,代码来源:SimulatedSchedulerDriverFactory.scala
示例2: SimulatedDriverWiring
//设置package包名称以及导入依赖的类
package mesosphere.mesos.simulation
import akka.actor.Props
import org.apache.mesos.{ Scheduler, SchedulerDriver }
private class SimulatedDriverWiring(scheduler: Scheduler) {
private lazy val schedulerActorProps = Props(new SchedulerActor(scheduler))
private lazy val driverActorProps = Props(new DriverActor(schedulerActorProps))
lazy val driver = new SimulatedDriver(driverActorProps)
}
object SimulatedDriverWiring {
def createDriver(scheduler: Scheduler): SchedulerDriver = {
new SimulatedDriverWiring(scheduler).driver
}
}
开发者ID:xiaozai512,项目名称:marathon,代码行数:18,代码来源:SimulatedDriverWiring.scala
示例3: SchedulerActor
//设置package包名称以及导入依赖的类
package mesosphere.mesos.simulation
import akka.actor.{ Actor, Stash }
import akka.event.LoggingReceive
import mesosphere.marathon.stream._
import org.apache.mesos.Protos.{ FrameworkID, MasterInfo, Offer, TaskStatus }
import org.apache.mesos.{ Scheduler, SchedulerDriver }
import org.slf4j.LoggerFactory
import scala.collection.immutable.Seq
object SchedulerActor {
private val log = LoggerFactory.getLogger(getClass)
case class Registered(
frameworkId: FrameworkID,
master: MasterInfo)
case class ResourceOffers(offers: Seq[Offer])
}
class SchedulerActor(scheduler: Scheduler) extends Actor with Stash {
import SchedulerActor._
var driverOpt: Option[SchedulerDriver] = None
def receive: Receive = waitForDriver
def waitForDriver: Receive = LoggingReceive.withLabel("waitForDriver") {
case driver: SchedulerDriver =>
log.info("received driver")
driverOpt = Some(driver)
context.become(handleCmds(driver))
unstashAll()
case _ => stash()
}
def handleCmds(driver: SchedulerDriver): Receive = LoggingReceive.withLabel("handleCmds") {
case Registered(frameworkId, masterInfo) =>
scheduler.registered(driver, frameworkId, masterInfo)
case ResourceOffers(offers) =>
scheduler.resourceOffers(driver, offers)
case status: TaskStatus =>
scheduler.statusUpdate(driver, status)
}
override def postStop(): Unit = {
driverOpt.foreach { driver => scheduler.disconnected(driver) }
}
}
开发者ID:xiaozai512,项目名称:marathon,代码行数:54,代码来源:SchedulerActor.scala
示例4: createDriver
//设置package包名称以及导入依赖的类
package mesosphere.marathon
import javax.inject.Inject
import mesosphere.chaos.http.HttpConf
import mesosphere.marathon.storage.repository.FrameworkIdRepository
import org.apache.mesos.{ Scheduler, SchedulerDriver }
import org.slf4j.LoggerFactory
import scala.concurrent.Await
trait SchedulerDriverFactory {
def createDriver(): SchedulerDriver
}
class MesosSchedulerDriverFactory @Inject() (
holder: MarathonSchedulerDriverHolder,
config: MarathonConf,
httpConfig: HttpConf,
frameworkIdRepository: FrameworkIdRepository,
scheduler: Scheduler)
extends SchedulerDriverFactory {
private[this] val log = LoggerFactory.getLogger(getClass.getName)
log.debug("using scheduler " + scheduler)
override def createDriver(): SchedulerDriver = {
implicit val zkTimeout = config.zkTimeoutDuration
val frameworkId = Await.result(frameworkIdRepository.get(), zkTimeout).map(_.toProto)
val driver = MarathonSchedulerDriver.newDriver(config, httpConfig, scheduler, frameworkId)
holder.driver = Some(driver)
driver
}
}
开发者ID:xiaozai512,项目名称:marathon,代码行数:38,代码来源:SchedulerDriverFactory.scala
示例5: resourceOffers
//设置package包名称以及导入依赖的类
package com.example
import org.apache.mesos.Protos.Offer
import org.apache.mesos.{Scheduler, SchedulerDriver}
import org.apache.mesos.{SchedulerDriver, Scheduler}
import org.apache.mesos.Protos._
import scala.collection.JavaConverters._
import scala.collection.mutable
override def resourceOffers(driver: SchedulerDriver, offers: java.util.List[Offer]) {
//for every available offer run tasks
for (offer <- offers.asScala) {
println(s"offer $offer")
_tasks.dequeueFirst(value => true) map (cmdString => {
val cmd = CommandInfo.newBuilder
.setValue(cmdString)
//our task will use one cpu
val cpus = Resource.newBuilder.
setType(org.apache.mesos.Protos.Value.Type.SCALAR)
.setName("cpus")
.setScalar(org.apache.mesos.Protos.Value.Scalar.newBuilder.setValue(1.0))
.setRole("*")
.build
//generate random task id
val id = "task" + System.currentTimeMillis()
//create task with given command
val task = TaskInfo.newBuilder
.setCommand(cmd)
.setName(id)
.setTaskId(TaskID.newBuilder.setValue(id))
.addResources(cpus)
.setSlaveId(offer.getSlaveId)
.build
driver.launchTasks(offer.getId, List(task).asJava)
})
}
}
def submitTasks(tasks: String*) = {
this.synchronized {
this._tasks.enqueue(tasks: _*)
}
}
override def reregistered(driver: SchedulerDriver, masterInfo: MasterInfo) {}
override def registered(driver: SchedulerDriver, frameworkId: FrameworkID, masterInfo: MasterInfo) {}
}
开发者ID:rahulkumar-aws,项目名称:Mesos-HelloWorld,代码行数:54,代码来源:SigScheduler.scala
示例6: GoCDScheduler
//设置package包名称以及导入依赖的类
package com.github.roberveral.mesosgocd.scheduler
import java.util
import com.github.roberveral.mesosgocd.spec.Task
import com.github.roberveral.mesosgocd.utils.OfferUtils
import org.apache.mesos.Protos
import org.apache.mesos.{Scheduler, SchedulerDriver}
import mesosphere.mesos.protos.Implicits._
import com.github.roberveral.mesosgocd.spec.Implicits._
import scala.collection.JavaConverters._
class GoCDScheduler(task: Task) extends Scheduler with OfferUtils {
override def offerRescinded(schedulerDriver: SchedulerDriver, offerID: Protos.OfferID): Unit = {}
override def disconnected(schedulerDriver: SchedulerDriver): Unit = {}
override def reregistered(schedulerDriver: SchedulerDriver, masterInfo: Protos.MasterInfo): Unit = {}
override def slaveLost(schedulerDriver: SchedulerDriver, slaveID: Protos.SlaveID): Unit = {}
override def error(schedulerDriver: SchedulerDriver, s: String): Unit = {}
override def statusUpdate(schedulerDriver: SchedulerDriver, taskStatus: Protos.TaskStatus): Unit =
println(s"received status update $taskStatus")
override def frameworkMessage(schedulerDriver: SchedulerDriver,
executorID: Protos.ExecutorID,
slaveID: Protos.SlaveID,
bytes: Array[Byte]): Unit = {}
override def resourceOffers(schedulerDriver: SchedulerDriver, list: util.List[Protos.Offer]): Unit = {
// https://github.com/apache/mesos/blob/1.2.0/include/mesos/mesos.proto
val receivedOffers = list.asScala
// Select a valid offer for the task to run
val optionalAcceptOffer = receivedOffers.find(checkOffer(task, _))
// If there is a valid offer, get the remaining offers
val remainingOffers = receivedOffers diff optionalAcceptOffer.toList
// Launche the task by accepting the offer
optionalAcceptOffer.foreach(offer =>
schedulerDriver.launchTasks(List(offer.getId).asJava,
List(taskToProto(task).setSlaveId(offer.getSlaveId).build()).asJava))
// Decline the other offers
remainingOffers foreach(offer => schedulerDriver.declineOffer(offer.getId))
}
override def registered(schedulerDriver: SchedulerDriver,
frameworkID: Protos.FrameworkID,
masterInfo: Protos.MasterInfo): Unit =
println(s"Framework registered with ID: $frameworkID")
override def executorLost(schedulerDriver: SchedulerDriver,
executorID: Protos.ExecutorID,
slaveID: Protos.SlaveID,
i: Int): Unit = {}
}
开发者ID:roberveral,项目名称:mesos-gocd,代码行数:59,代码来源:GoCDScheduler.scala
注:本文中的org.apache.mesos.SchedulerDriver类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论