> For the complete documentation index, see [llms.txt](https://nag-9-s.gitbook.io/spark-workshop/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nag-9-s.gitbook.io/spark-workshop/exercises/spark-exercise-custom-externalclustermanager.md).

# spark-exercise-custom-ExternalClusterManager

## Goal

The goal of the exercise is to register a custom `ExternalClusterManager` so `scalania` master URL is supported and the following works:

```
$ ./bin/spark-shell --master scalania
Error: Master must either be yarn or start with spark, mesos, local
Run with --help for usage help or --verbose for debug output
```

## Steps

1. Create a brand new Scala/sbt project
   * Use the one and only IntelliJ IDEA
   * Project name: `spark-external-cluster-manager`
2. Add `libraryDependencies` for Spark 2.0.0 (RC5)
   * See <https://gist.github.com/jborkowski/a77d9cc88067feea24261479afcc4ee1>
3. ScalaTest
   * Follow Spark's own  [ExternalClusterManagerSuite](https://github.com/apache/spark/blob/master/core/src/test/scala/org/apache/spark/scheduler/ExternalClusterManagerSuite.scala)

## Hints

1. The custom Cluster Manager should extend [ExternalClusterManager](https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/scheduler/ExternalClusterManager.scala)
2. The cluster manager support is loaded by [ServiceLoader.load](http://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html#load-java.lang.Class-). See [the code in Spark](https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/SparkContext.scala#L2524-L2534)
3. See [how and where the loading happens in Spark](https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/SparkContext.scala#L2506-L2520).

## Solution

See a complete Scala/sbt project in [spark-external-cluster-manager](https://github.com/nag9s/spark-workshop/tree/4973b189efc4a33ce007789116ae9ad30914ea24/solutions/spark-external-cluster-manager/README.md). It is a work in progress work.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nag-9-s.gitbook.io/spark-workshop/exercises/spark-exercise-custom-externalclustermanager.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
