Coder Social home page Coder Social logo

akka-mesos's Introduction

akka-mesos

Build Status

Non-blocking driver for Apache Mesos based on Akka.

Usage

Registering a Framework with Mesos

import akka.actor.ActorSystem
import akka.libprocess.PID
import akka.mesos.Mesos
import akka.mesos.protos.FrameworkInfo

implicit val system = ActorSystem("Mesos", config)

val frameworkInfo = FrameworkInfo(
  name = "ExampleFramework",
  user = "user",
  failoverTimeout = Some(5.minutes),
  checkpoint = Some(true)
)

val framework = Mesos(system).registerFramework(Success(PID("127.0.0.1", 5050, "master")), frameworkInfo)

The registerFramework method returns a Framework object. This object contains a SchedulerDriver and a Source[SchedulerMessage]. The SchedulerDriver can be used to send scheduling messages to Mesos, while the Source[SchedulerMessages] contains the scheduling messages that Mesos sends to the framework.

Example

import akka.mesos.protos.TaskInfo
import akka.mesos.scheduler.SchedulerPublisher.{ StatusUpdate, ResourceOffers }
import akka.stream.ActorFlowMaterializer

// necessary to process the message stream
implicit val materializer = ActorFlowMaterializer()

// process incoming messages with the given function
framework.schedulerMessages.runForeach {
  case ResourceOffers(offers) =>
    // create a TaskInfo
    val taskInfo = TaskInfo(...)

    // find a matching offer
    val matchingOffer = offer.find(...)

    // if a matching offer is found, start the task with the offer
    matchingOffer.foreach { offer =>
      driver.launchTasks(Seq(task), Seq(offer.id))
    }

    // don't forget to decline the offers that didn't match
    (offers diff matchingOffer.toSeq).foreach { offer =>
      driver.declineOffer(offer.id)
    }

  case StatusUpdate(update) =>
    println(s"Task ${update.status.taskId} id now ${update.status.state}")
    // Status updates must be acknowledged so Mesos knows, that we
    // received and sucessfully processed this message. Otherwise
    // Mesos would keep sending this message
    framework.driver.acknowledgeStatusUpdate(update)

  case _ => // We are not interested in other messages for now
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.