or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cluster-deployment.mdcluster-management.mdcoarse-grained-scheduling.mdfine-grained-scheduling.mdindex.mdresource-configuration.md
tile.json

cluster-management.mddocs/

Cluster Management

Core cluster management functionality that integrates Spark with Mesos, handling scheduler backend creation and initialization.

Capabilities

MesosClusterManager

The main entry point for Mesos integration in Spark, implementing the ExternalClusterManager interface.

/**
 * Cluster Manager for creation of Mesos scheduler and backend
 */
class MesosClusterManager extends ExternalClusterManager {
  /**
   * Checks if the master URL is a Mesos URL
   * @param masterURL The master URL to check
   * @return true if URL starts with "mesos"
   */
  def canCreate(masterURL: String): Boolean
  
  /**
   * Creates a TaskScheduler for the Spark application
   * @param sc SparkContext instance
   * @param masterURL Mesos master URL
   * @return TaskSchedulerImpl instance
   */
  def createTaskScheduler(sc: SparkContext, masterURL: String): TaskScheduler
  
  /**
   * Creates the appropriate scheduler backend based on configuration
   * @param sc SparkContext instance  
   * @param masterURL Mesos master URL
   * @param scheduler TaskScheduler instance
   * @return SchedulerBackend (coarse-grained or fine-grained)
   * @throws SparkException if I/O encryption is enabled (not supported)
   */
  def createSchedulerBackend(
    sc: SparkContext,
    masterURL: String, 
    scheduler: TaskScheduler
  ): SchedulerBackend
  
  /**
   * Initializes the scheduler with the backend
   * @param scheduler TaskScheduler to initialize
   * @param backend SchedulerBackend to use
   */
  def initialize(scheduler: TaskScheduler, backend: SchedulerBackend): Unit
}

Usage Examples:

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.scheduler.cluster.mesos.MesosClusterManager

// Automatic usage through SparkContext
val conf = new SparkConf()
  .setAppName("MyApp")
  .setMaster("mesos://master:5050")  // Triggers MesosClusterManager usage

val sc = new SparkContext(conf)
// MesosClusterManager.canCreate() returns true for "mesos://" URLs
// createTaskScheduler() and createSchedulerBackend() are called automatically

// Manual usage (not typical)
val clusterManager = new MesosClusterManager()
if (clusterManager.canCreate("mesos://master:5050")) {
  val scheduler = clusterManager.createTaskScheduler(sc, "mesos://master:5050")
  val backend = clusterManager.createSchedulerBackend(sc, "mesos://master:5050", scheduler)
  clusterManager.initialize(scheduler, backend)
}

Configuration Integration

The cluster manager integrates with Spark configuration to determine scheduling mode and security settings.

Key Configuration Properties:

  • spark.mesos.coarse (default: true) - Enables coarse-grained mode
  • spark.io.encryption.enabled - Must be false (I/O encryption not supported)
  • spark.master - Must start with "mesos://" for automatic detection

Scheduling Mode Selection:

// Coarse-grained mode (default)
val conf = new SparkConf()
  .setMaster("mesos://master:5050")
  .set("spark.mesos.coarse", "true")
// Creates MesosCoarseGrainedSchedulerBackend

// Fine-grained mode  
val conf = new SparkConf()
  .setMaster("mesos://master:5050")
  .set("spark.mesos.coarse", "false")
// Creates MesosFineGrainedSchedulerBackend

Error Handling

// I/O encryption validation
if (sc.conf.get(IO_ENCRYPTION_ENABLED)) {
  throw new SparkException("I/O encryption is currently not supported in Mesos.")
}

// URL parsing for Mesos master
val MESOS_REGEX = """mesos://(.*)""".r
val mesosUrl = MESOS_REGEX.findFirstMatchIn(masterURL).get.group(1)

The cluster manager provides the foundation for all Mesos integration in Spark, automatically selecting the appropriate scheduler backend based on configuration and ensuring proper initialization of the scheduling components.