package main import ( "context" "fmt" "github.com/mesos/mesos-go/auth" "github.com/mesos/mesos-go/auth/sasl" "github.com/mesos/mesos-go/driver" "github.com/mesos/mesos-go/driver/executor" "github.com/mesos/mesos-go/mesosproto" "log" "os" ) type MyScheduler struct {} func (sched *MyScheduler) Registered(driver driver.Driver, frameworkId *mesosproto.FrameworkID, masterInfo *mesosproto.MasterInfo) { log.Printf("Registered with framework ID %s\n", frameworkId.GetValue()) } func (sched *MyScheduler) LaunchTasks(driver driver.Driver, tasks []*mesosproto.TaskInfo, offers []*mesosproto.Offer) { log.Printf("Launching %d tasks\n", len(tasks)) for _, offer := range offers { for _, task := range tasks { // Launch the task on the offer _, err := driver.AcceptOffers(context.Background(), []*mesosproto.OfferID{offer.Id}, []*mesosproto.Offer_Operation{ &mesosproto.Offer_Operation{ Type: mesosproto.Offer_Operation_LAUNCH, Launch: &mesosproto.Offer_Operation_Launch{ TaskInfos: []*mesosproto.TaskInfo{task}, }, }, }, &mesosproto.Filters{}) if err != nil { log.Printf("Error launching task: %v\n", err) } else { log.Printf("Launched task %s on offer %s\n", task.TaskId.GetValue(), offer.Id.GetValue()) } } } } func (sched *MyScheduler) StatusUpdate(driver driver.Driver, status *mesosproto.TaskStatus) { log.Printf("Received status update from task %s in state %s\n", status.TaskId.GetValue(), status.State.String()) } func (sched *MyScheduler) Error(driver driver.Driver, err string) { log.Printf("Error: %s", err) } func main() { config := driver.DriverConfig{ Framework: &mesosproto.FrameworkInfo{ User: proto.String("root"), Name: proto.String("my-framework"), }, Executor: &mesosproto.ExecutorInfo{ ExecutorId: &mesosproto.ExecutorID{Value: proto.String("default")}, Command: &mesosproto.CommandInfo{ Value: proto.String("echo 'Hello, Mesos!'"), }, }, Credential: &mesosproto.Credential{ Principal: proto.String("principal"), Secret: proto.String("secret"), PrincipalSecretProvider: auth.NewPrincipalSecretProvider( &auth.CramMD5Authenticator{ Authenticatee: sasl.NewEncryptingAuthenticator( sasl.NewPlainAuthenticator().NewCramMD5Client(), ), Secrets: auth.NewInMemorySecretsProvider("principal", "secret"), }, ), }, Scheduler: &MyScheduler{}, Master: "127.0.0.1:5050", } driver, err := driver.NewMesosSchedulerDriver(config) if err != nil { log.Fatalf("Unable to create Mesos driver: %v\n", err) } if status, err := driver.Run(); err != nil { log.Fatal("Mesos driver failed with status", status, ":", err) } os.Exit(int(status)) }In this example, the MyScheduler implementation of the Scheduler interface is used to launch a set of tasks on available agents. The example code creates a new instance of the MesosSchedulerDriver, which is used to connect to the Mesos master and interact with the Mesos framework. Overall, the example code demonstrates how to use the LaunchTasks method of the SchedulerDriver interface to instruct Mesos to launch a set of tasks on agents. The code also shows how to register a scheduler and handle status updates and errors. The underlying package library used here is the github.com.mesos.mesos-go.scheduler package.