forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-2691] [MESOS] Support for Mesos DockerInfo
This patch adds partial support for running spark on mesos inside of a docker container. Only fine-grained mode is presently supported, and there is no checking done to ensure that the version of libmesos is recent enough to have a DockerInfo structure in the protobuf (other than pinning a mesos version in the pom.xml). Author: Chris Heller <[email protected]> Closes apache#3074 from hellertime/SPARK-2691 and squashes the following commits: d504af6 [Chris Heller] Assist type inference f64885d [Chris Heller] Fix errant line length 17c41c0 [Chris Heller] Base Dockerfile on mesosphere/mesos image 8aebda4 [Chris Heller] Simplfy Docker image docs 1ae7f4f [Chris Heller] Style points 974bd56 [Chris Heller] Convert map to flatMap 5d8bdf7 [Chris Heller] Factor out the DockerInfo construction. 7b75a3d [Chris Heller] Align to styleguide 80108e7 [Chris Heller] Bend to the will of RAT ba77056 [Chris Heller] Explicit RAT exclude abda5e5 [Chris Heller] Wildcard .rat-excludes 2f2873c [Chris Heller] Exclude spark-mesos from RAT a589a5b [Chris Heller] Add example Dockerfile b6825ce [Chris Heller] Remove use of EasyMock eae1b86 [Chris Heller] Move properties under 'spark.mesos.' c184d00 [Chris Heller] Use map on Option to be consistent with non-coarse code fb9501a [Chris Heller] Bumped mesos version to current release fa11879 [Chris Heller] Add listenerBus to EasyMock 882151e [Chris Heller] Changes to scala style b22d42d [Chris Heller] Exclude template from RAT db536cf [Chris Heller] Remove unneeded mocks dea1bd5 [Chris Heller] Force default protocol 7dac042 [Chris Heller] Add test for DockerInfo 5456c0c [Chris Heller] Adjust syntax style 521c194 [Chris Heller] Adjust version info 6e38f70 [Chris Heller] Document Mesos Docker properties 29572ab [Chris Heller] Support all DockerInfo fields b8c0dea [Chris Heller] Support for mesos DockerInfo in coarse-mode. 482a9fd [Chris Heller] Support for mesos DockerInfo in fine-grained mode.
- Loading branch information
1 parent
b4b43df
commit 8f50a07
Showing
9 changed files
with
280 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
spark.mesos.executor.docker.image: <image built from `../docker/spark-mesos/Dockerfile`> | ||
spark.mesos.executor.docker.volumes: /usr/local/lib:/host/usr/local/lib:ro | ||
spark.mesos.executor.home: /opt/spark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
core/src/main/scala/org/apache/spark/scheduler/cluster/mesos/MesosSchedulerBackendUtil.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.scheduler.cluster.mesos | ||
|
||
import org.apache.mesos.Protos.{ContainerInfo, Volume} | ||
import org.apache.mesos.Protos.ContainerInfo.DockerInfo | ||
|
||
import org.apache.spark.{Logging, SparkConf} | ||
|
||
/** | ||
* A collection of utility functions which can be used by both the | ||
* MesosSchedulerBackend and the CoarseMesosSchedulerBackend. | ||
*/ | ||
private[mesos] object MesosSchedulerBackendUtil extends Logging { | ||
/** | ||
* Parse a comma-delimited list of volume specs, each of which | ||
* takes the form [host-dir:]container-dir[:rw|:ro]. | ||
*/ | ||
def parseVolumesSpec(volumes: String): List[Volume] = { | ||
volumes.split(",").map(_.split(":")).flatMap { spec => | ||
val vol: Volume.Builder = Volume | ||
.newBuilder() | ||
.setMode(Volume.Mode.RW) | ||
spec match { | ||
case Array(container_path) => | ||
Some(vol.setContainerPath(container_path)) | ||
case Array(container_path, "rw") => | ||
Some(vol.setContainerPath(container_path)) | ||
case Array(container_path, "ro") => | ||
Some(vol.setContainerPath(container_path) | ||
.setMode(Volume.Mode.RO)) | ||
case Array(host_path, container_path) => | ||
Some(vol.setContainerPath(container_path) | ||
.setHostPath(host_path)) | ||
case Array(host_path, container_path, "rw") => | ||
Some(vol.setContainerPath(container_path) | ||
.setHostPath(host_path)) | ||
case Array(host_path, container_path, "ro") => | ||
Some(vol.setContainerPath(container_path) | ||
.setHostPath(host_path) | ||
.setMode(Volume.Mode.RO)) | ||
case spec => { | ||
logWarning(s"Unable to parse volume specs: $volumes. " | ||
+ "Expected form: \"[host-dir:]container-dir[:rw|:ro](, ...)\"") | ||
None | ||
} | ||
} | ||
} | ||
.map { _.build() } | ||
.toList | ||
} | ||
|
||
/** | ||
* Parse a comma-delimited list of port mapping specs, each of which | ||
* takes the form host_port:container_port[:udp|:tcp] | ||
* | ||
* Note: | ||
* the docker form is [ip:]host_port:container_port, but the DockerInfo | ||
* message has no field for 'ip', and instead has a 'protocol' field. | ||
* Docker itself only appears to support TCP, so this alternative form | ||
* anticipates the expansion of the docker form to allow for a protocol | ||
* and leaves open the chance for mesos to begin to accept an 'ip' field | ||
*/ | ||
def parsePortMappingsSpec(portmaps: String): List[DockerInfo.PortMapping] = { | ||
portmaps.split(",").map(_.split(":")).flatMap { spec: Array[String] => | ||
val portmap: DockerInfo.PortMapping.Builder = DockerInfo.PortMapping | ||
.newBuilder() | ||
.setProtocol("tcp") | ||
spec match { | ||
case Array(host_port, container_port) => | ||
Some(portmap.setHostPort(host_port.toInt) | ||
.setContainerPort(container_port.toInt)) | ||
case Array(host_port, container_port, protocol) => | ||
Some(portmap.setHostPort(host_port.toInt) | ||
.setContainerPort(container_port.toInt) | ||
.setProtocol(protocol)) | ||
case spec => { | ||
logWarning(s"Unable to parse port mapping specs: $portmaps. " | ||
+ "Expected form: \"host_port:container_port[:udp|:tcp](, ...)\"") | ||
None | ||
} | ||
} | ||
} | ||
.map { _.build() } | ||
.toList | ||
} | ||
|
||
/** | ||
* Construct a DockerInfo structure and insert it into a ContainerInfo | ||
*/ | ||
def addDockerInfo( | ||
container: ContainerInfo.Builder, | ||
image: String, | ||
volumes: Option[List[Volume]] = None, | ||
network: Option[ContainerInfo.DockerInfo.Network] = None, | ||
portmaps: Option[List[ContainerInfo.DockerInfo.PortMapping]] = None):Unit = { | ||
|
||
val docker = ContainerInfo.DockerInfo.newBuilder().setImage(image) | ||
|
||
network.foreach(docker.setNetwork) | ||
portmaps.foreach(_.foreach(docker.addPortMappings)) | ||
container.setType(ContainerInfo.Type.DOCKER) | ||
container.setDocker(docker.build()) | ||
volumes.foreach(_.foreach(container.addVolumes)) | ||
} | ||
|
||
/** | ||
* Setup a docker containerizer | ||
*/ | ||
def setupContainerBuilderDockerInfo( | ||
imageName: String, | ||
conf: SparkConf, | ||
builder: ContainerInfo.Builder): Unit = { | ||
val volumes = conf | ||
.getOption("spark.mesos.executor.docker.volumes") | ||
.map(parseVolumesSpec) | ||
val portmaps = conf | ||
.getOption("spark.mesos.executor.docker.portmaps") | ||
.map(parsePortMappingsSpec) | ||
addDockerInfo( | ||
builder, | ||
imageName, | ||
volumes = volumes, | ||
portmaps = portmaps) | ||
logDebug("setupContainerDockerInfo: using docker image: " + imageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This is an example Dockerfile for creating a Spark image which can be | ||
# references by the Spark property 'spark.mesos.executor.docker.image' | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
FROM mesosphere/mesos:0.20.1 | ||
|
||
# Update the base ubuntu image with dependencies needed for Spark | ||
RUN apt-get update && \ | ||
apt-get install -y python libnss3 openjdk-7-jre-headless curl | ||
|
||
RUN mkdir /opt/spark && \ | ||
curl http://www.apache.org/dyn/closer.cgi/spark/spark-1.4.0/spark-1.4.0-bin-hadoop2.4.tgz \ | ||
| tar -xzC /opt | ||
ENV SPARK_HOME /opt/spark | ||
ENV MESOS_NATIVE_JAVA_LIBRARY /usr/local/lib/libmesos.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters