├── project ├── build.properties └── plugins.sbt ├── http ├── src │ └── main │ │ ├── resources │ │ ├── META-INF │ │ │ ├── resources │ │ │ │ └── webjars │ │ │ │ │ └── static │ │ │ │ │ └── hello.txt │ │ │ └── services │ │ │ │ └── mesosphere.marathon.plugin.http.HttpRequestHandler │ │ └── mesosphere │ │ │ └── marathon │ │ │ └── example │ │ │ └── plugin │ │ │ └── http │ │ │ └── plugin-conf.json │ │ └── scala │ │ └── mesosphere │ │ └── marathon │ │ └── example │ │ └── plugin │ │ └── http │ │ └── WebJarHandler.scala ├── build.sbt └── README.md ├── .arcconfig ├── auth ├── src │ └── main │ │ ├── resources │ │ ├── META-INF │ │ │ └── services │ │ │ │ ├── mesosphere.marathon.plugin.auth.Authenticator │ │ │ │ └── mesosphere.marathon.plugin.auth.Authorizer │ │ └── mesosphere │ │ │ └── marathon │ │ │ └── example │ │ │ └── plugin │ │ │ └── auth │ │ │ └── plugin-conf.json │ │ └── scala │ │ └── mesosphere │ │ └── marathon │ │ └── example │ │ └── plugin │ │ └── auth │ │ ├── ExampleAuthorizer.scala │ │ ├── ExampleIdentity.scala │ │ ├── Permission.scala │ │ └── ExampleAuthenticator.scala ├── build.sbt └── README.md ├── javaauth ├── src │ └── main │ │ ├── resources │ │ ├── META-INF │ │ │ └── services │ │ │ │ ├── mesosphere.marathon.plugin.auth.Authorizer │ │ │ │ └── mesosphere.marathon.plugin.auth.Authenticator │ │ └── mesosphere │ │ │ └── marathon │ │ │ └── example │ │ │ └── plugin │ │ │ └── javaauth │ │ │ └── plugin-conf.json │ │ └── java │ │ └── mesosphere │ │ └── marathon │ │ └── example │ │ └── plugin │ │ └── javaauth │ │ ├── JavaIdentity.java │ │ ├── Action.java │ │ ├── JavaAuthorizer.java │ │ └── JavaAuthenticator.java ├── build.sbt └── README.md ├── env ├── src │ ├── main │ │ ├── resources │ │ │ ├── META-INF │ │ │ │ └── services │ │ │ │ │ └── mesosphere.marathon.plugin.task.RunSpecTaskProcessor │ │ │ └── mesosphere │ │ │ │ └── marathon │ │ │ │ └── example │ │ │ │ └── plugin │ │ │ │ └── env │ │ │ │ └── plugin-conf.json │ │ └── scala │ │ │ └── mesosphere │ │ │ └── marathon │ │ │ └── example │ │ │ └── plugin │ │ │ └── env │ │ │ └── EnvVarExtenderPlugin.scala │ └── test │ │ └── scala │ │ └── EnvVarExtenderPluginTest.scala ├── build.sbt └── README.md ├── label ├── src │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── services │ │ │ │ └── mesosphere.marathon.plugin.validation.RunSpecValidator │ │ └── scala │ │ │ └── mesosphere │ │ │ └── marathon │ │ │ └── example │ │ │ └── plugin │ │ │ └── label │ │ │ └── LabelValidatorPlugin.scala │ └── test │ │ └── scala │ │ └── LabelValidatorPluginTest.scala ├── build.sbt └── README.md ├── executorid ├── src │ ├── main │ │ ├── resources │ │ │ ├── META-INF │ │ │ │ └── services │ │ │ │ │ └── mesosphere.marathon.plugin.task.RunSpecTaskProcessor │ │ │ └── mesosphere │ │ │ │ └── marathon │ │ │ │ └── example │ │ │ │ └── plugin │ │ │ │ └── executorid │ │ │ │ └── plugin-conf.json │ │ └── scala │ │ │ └── mesosphere │ │ │ └── marathon │ │ │ └── example │ │ │ └── plugin │ │ │ └── executorid │ │ │ └── ExecutorIdExtenderPlugin.scala │ └── test │ │ └── scala │ │ └── mesosphere │ │ └── marathon │ │ └── example │ │ └── plugin │ │ └── executorid │ │ └── ExecutorIdExtenderPluginTest.scala ├── build.sbt └── README.md ├── .gitignore ├── project.sbt ├── README.md └── LICENSE /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version = 0.13.8 -------------------------------------------------------------------------------- /http/src/main/resources/META-INF/resources/webjars/static/hello.txt: -------------------------------------------------------------------------------- 1 | Hello World! 2 | -------------------------------------------------------------------------------- /.arcconfig: -------------------------------------------------------------------------------- 1 | { 2 | "phabricator.uri": "https://phabricator.mesosphere.com", 3 | "repository.callsign": "marathon-example-plugins" 4 | } 5 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | logLevel := Level.Warn 2 | 3 | addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.7.5") // for sbt-0.13.x or higher 4 | 5 | -------------------------------------------------------------------------------- /auth/src/main/resources/META-INF/services/mesosphere.marathon.plugin.auth.Authenticator: -------------------------------------------------------------------------------- 1 | mesosphere.marathon.example.plugin.auth.ExampleAuthenticator -------------------------------------------------------------------------------- /auth/src/main/resources/META-INF/services/mesosphere.marathon.plugin.auth.Authorizer: -------------------------------------------------------------------------------- 1 | mesosphere.marathon.example.plugin.auth.ExampleAuthorizer 2 | -------------------------------------------------------------------------------- /http/src/main/resources/META-INF/services/mesosphere.marathon.plugin.http.HttpRequestHandler: -------------------------------------------------------------------------------- 1 | mesosphere.marathon.example.plugin.http.WebJarHandler -------------------------------------------------------------------------------- /javaauth/src/main/resources/META-INF/services/mesosphere.marathon.plugin.auth.Authorizer: -------------------------------------------------------------------------------- 1 | mesosphere.marathon.example.plugin.javaauth.JavaAuthorizer -------------------------------------------------------------------------------- /env/src/main/resources/META-INF/services/mesosphere.marathon.plugin.task.RunSpecTaskProcessor: -------------------------------------------------------------------------------- 1 | mesosphere.marathon.example.plugin.env.EnvVarExtenderPlugin -------------------------------------------------------------------------------- /javaauth/src/main/resources/META-INF/services/mesosphere.marathon.plugin.auth.Authenticator: -------------------------------------------------------------------------------- 1 | mesosphere.marathon.example.plugin.javaauth.JavaAuthenticator -------------------------------------------------------------------------------- /label/src/main/resources/META-INF/services/mesosphere.marathon.plugin.validation.RunSpecValidator: -------------------------------------------------------------------------------- 1 | mesosphere.marathon.example.plugin.label.LabelValidatorPlugin 2 | -------------------------------------------------------------------------------- /executorid/src/main/resources/META-INF/services/mesosphere.marathon.plugin.task.RunSpecTaskProcessor: -------------------------------------------------------------------------------- 1 | mesosphere.marathon.example.plugin.executorid.ExecutorIdExtenderPlugin -------------------------------------------------------------------------------- /http/build.sbt: -------------------------------------------------------------------------------- 1 | name := "http-plugin" 2 | 3 | version := "1.0" 4 | 5 | resolvers += "Mesosphere Public Repo" at "http://downloads.mesosphere.io/maven" 6 | 7 | libraryDependencies ++= Seq( 8 | "mesosphere.marathon" %% "plugin-interface" % "1.6.325" % "provided" 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /javaauth/build.sbt: -------------------------------------------------------------------------------- 1 | name := "java-auth-plugin" 2 | 3 | version := "1.0" 4 | 5 | resolvers += "Mesosphere Public Repo" at "http://downloads.mesosphere.io/maven" 6 | 7 | libraryDependencies ++= Seq( 8 | "mesosphere.marathon" %% "plugin-interface" % "1.6.325" % "provided" 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | 4 | # sbt specific 5 | .cache 6 | .history 7 | .lib/ 8 | dist/* 9 | target/ 10 | lib_managed/ 11 | src_managed/ 12 | project/boot/ 13 | project/plugins/project/ 14 | .idea/ 15 | */project/ 16 | 17 | # Scala-IDE specific 18 | .scala_dependencies 19 | .worksheet 20 | -------------------------------------------------------------------------------- /env/build.sbt: -------------------------------------------------------------------------------- 1 | name := "env-plugin" 2 | 3 | version := "1.0" 4 | 5 | resolvers += "Mesosphere Public Repo" at "http://downloads.mesosphere.io/maven" 6 | 7 | libraryDependencies ++= Seq( 8 | "mesosphere.marathon" %% "plugin-interface" % "1.6.325" % "provided", 9 | "org.scalatest" %% "scalatest" % "3.0.1" % "test" 10 | ) 11 | -------------------------------------------------------------------------------- /auth/build.sbt: -------------------------------------------------------------------------------- 1 | name := "auth-plugin" 2 | 3 | version := "1.0" 4 | 5 | resolvers += "Mesosphere Public Repo" at "http://downloads.mesosphere.io/maven" 6 | 7 | libraryDependencies ++= Seq( 8 | "mesosphere.marathon" %% "plugin-interface" % "1.6.325" % "provided", 9 | "com.typesafe.scala-logging" %% "scala-logging" % "3.7.2" % "provided" 10 | ) 11 | -------------------------------------------------------------------------------- /executorid/src/main/resources/mesosphere/marathon/example/plugin/executorid/plugin-conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": { 3 | "executorIdExtender": { 4 | "plugin": "mesosphere.marathon.plugin.task.RunSpecTaskProcessor", 5 | "implementation": "mesosphere.marathon.example.plugin.executorid.ExecutorIdExtenderPlugin", 6 | "configuration": { 7 | } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /label/build.sbt: -------------------------------------------------------------------------------- 1 | name := "label-plugin" 2 | 3 | version := "1.0" 4 | 5 | resolvers += "Mesosphere Public Repo" at "http://downloads.mesosphere.io/maven" 6 | 7 | libraryDependencies ++= Seq( 8 | "mesosphere.marathon" %% "plugin-interface" % "1.6.325" % "provided", 9 | "com.typesafe.scala-logging" %% "scala-logging" % "3.7.2" % "provided", 10 | "org.scalatest" %% "scalatest" % "3.0.1" % "test" 11 | ) 12 | -------------------------------------------------------------------------------- /executorid/build.sbt: -------------------------------------------------------------------------------- 1 | name := "executorid-plugin" 2 | 3 | version := "1.0" 4 | 5 | resolvers += "Mesosphere Public Repo" at "http://downloads.mesosphere.io/maven" 6 | 7 | libraryDependencies ++= Seq( 8 | "mesosphere.marathon" %% "plugin-interface" % "1.7.50" % "provided", 9 | "com.typesafe.scala-logging" %% "scala-logging" % "3.7.2" % "provided", 10 | "org.scalatest" %% "scalatest" % "3.0.1" % "test" 11 | ) 12 | -------------------------------------------------------------------------------- /label/README.md: -------------------------------------------------------------------------------- 1 | # Label Example Plugin 2 | 3 | Checks the container labels for labels known to be DCOS Framework services and rejects them. 4 | For this example it includes "DCOS_PACKAGE_FRAMEWORK_NAME" and "DCOS_SERVICE_NAME". 5 | 6 | ## Usage 7 | 8 | See the [plugin configuration file](https://github.com/mesosphere/marathon-example-plugins/blob/master/env/src/main/resources/mesosphere/marathon/example/plugin/label/plugin-conf.json) 9 | -------------------------------------------------------------------------------- /http/src/main/resources/mesosphere/marathon/example/plugin/http/plugin-conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": { 3 | "webjar": { 4 | "plugin": "mesosphere.marathon.plugin.http.HttpRequestHandler", 5 | "implementation": "mesosphere.marathon.example.plugin.http.WebJarHandler", 6 | "tags": ["webjar", "test"], 7 | "info": { 8 | "test": true, 9 | "arr": [1,2,3,4,5,6] 10 | } 11 | } 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /env/README.md: -------------------------------------------------------------------------------- 1 | # Env Example Plugin 2 | 3 | Set environment variables in a JSON file and add them in the builder configuration. 4 | These variables will be applied on every tasks and overwrite the environment variables previously set that have the same name. 5 | 6 | ## Usage 7 | 8 | See the [plugin configuration file](https://github.com/mesosphere/marathon-example-plugins/blob/master/env/src/main/resources/mesosphere/marathon/example/plugin/env/plugin-conf.json) 9 | -------------------------------------------------------------------------------- /env/src/main/resources/mesosphere/marathon/example/plugin/env/plugin-conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": { 3 | "envVarExtender": { 4 | "plugin": "mesosphere.marathon.plugin.task.RunSpecTaskProcessor", 5 | "implementation": "mesosphere.marathon.example.plugin.env.EnvVarExtenderPlugin", 6 | "configuration": { 7 | "env": { 8 | "foo": "bar", 9 | "key": "value" 10 | } 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /javaauth/src/main/java/mesosphere/marathon/example/plugin/javaauth/JavaIdentity.java: -------------------------------------------------------------------------------- 1 | package mesosphere.marathon.example.plugin.javaauth; 2 | 3 | 4 | import mesosphere.marathon.plugin.auth.Identity; 5 | 6 | class JavaIdentity implements Identity { 7 | 8 | private final String name; 9 | 10 | public JavaIdentity(String name) { 11 | this.name = name; 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /auth/README.md: -------------------------------------------------------------------------------- 1 | # Auth Example Plugin 2 | 3 | This authorization plugin is based on HTTP basic authentication. 4 | 5 | ## Usage 6 | 7 | See the [plugin configuration file](https://github.com/mesosphere/marathon-example-plugins/blob/master/auth/src/main/resources/mesosphere/marathon/example/plugin/auth/plugin-conf.json). 8 | You can configure username + password + permissions for all users. 9 | The permissions are based on the app/group path on which an action is 10 | performed. 11 | -------------------------------------------------------------------------------- /http/src/main/scala/mesosphere/marathon/example/plugin/http/WebJarHandler.scala: -------------------------------------------------------------------------------- 1 | package mesosphere.marathon.example.plugin.http 2 | 3 | import mesosphere.marathon.plugin.http.{HttpRequest, HttpRequestHandlerBase, HttpResponse} 4 | 5 | class WebJarHandler extends HttpRequestHandlerBase { 6 | 7 | override def serve(request: HttpRequest, response: HttpResponse): Unit = request.method match { 8 | case "GET" => serveResource("/META-INF/resources/webjars/static/" + request.requestPath, response) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /javaauth/src/main/resources/mesosphere/marathon/example/plugin/javaauth/plugin-conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": { 3 | "authorization": { 4 | "plugin": "mesosphere.marathon.plugin.auth.Authorizer", 5 | "implementation": "mesosphere.marathon.example.plugin.javaauth.JavaAuthorizer" 6 | }, 7 | "authentication": { 8 | "plugin": "mesosphere.marathon.plugin.auth.Authenticator", 9 | "implementation": "mesosphere.marathon.example.plugin.javaauth.JavaAuthenticator" 10 | } 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /javaauth/README.md: -------------------------------------------------------------------------------- 1 | # JavaAuth Example Plugin 2 | 3 | This authorization plugin is based on HTTP basic authentication. 4 | The purpose of this plugin is to make sure, that a Java based plugin works as well. 5 | 6 | ## Usage 7 | 8 | See the [plugin configuration file](https://github.com/mesosphere/marathon-example-plugins/blob/master/javaauth/src/main/resources/mesosphere/marathon/example/plugin/javaauth/plugin-conf.json). 9 | It allows access if username and password are the same with this permissions: 10 | 11 | - Creation is always allowed 12 | - View is always allowed 13 | - Update is allowed only, if the username is ernie 14 | - Deletion is allowed only on path /test (recursively) 15 | - KillTask is not allowed 16 | -------------------------------------------------------------------------------- /project.sbt: -------------------------------------------------------------------------------- 1 | 2 | organization in Global := "mesosphere.marathon" 3 | 4 | name in Global := "example-plugins" 5 | 6 | scalaVersion in Global := "2.12.7" 7 | 8 | resolvers += Resolver.sonatypeRepo("releases") 9 | 10 | lazy val plugins = project.in(file(".")) 11 | .aggregate(auth, javaauth, http, env, label, executorid) 12 | .dependsOn(auth) 13 | .dependsOn(javaauth) 14 | .dependsOn(http) 15 | .dependsOn(env) 16 | .dependsOn(label) 17 | .dependsOn(executorid) 18 | 19 | lazy val auth = project 20 | 21 | lazy val javaauth = project 22 | 23 | lazy val http = project 24 | 25 | lazy val env = project 26 | 27 | lazy val label = project 28 | 29 | lazy val executorid = project 30 | 31 | packAutoSettings 32 | 33 | packExcludeJars := Seq("scala-.*\\.jar") 34 | -------------------------------------------------------------------------------- /auth/src/main/scala/mesosphere/marathon/example/plugin/auth/ExampleAuthorizer.scala: -------------------------------------------------------------------------------- 1 | package mesosphere.marathon.example.plugin.auth 2 | 3 | import mesosphere.marathon.plugin.auth._ 4 | import mesosphere.marathon.plugin.http._ 5 | 6 | class ExampleAuthorizer extends Authorizer { 7 | 8 | override def handleNotAuthorized(principal: Identity, response: HttpResponse): Unit = { 9 | response.status(403) 10 | response.body("application/json", s"""{"message": "Not Authorized to perform this action!"}""".getBytes("UTF-8")) 11 | } 12 | 13 | override def isAuthorized[R](principal: Identity, 14 | action: AuthorizedAction[R], 15 | resource: R): Boolean = { 16 | principal match { 17 | case identity: ExampleIdentity => identity.isAllowed(action, resource) 18 | case _ => false 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /javaauth/src/main/java/mesosphere/marathon/example/plugin/javaauth/Action.java: -------------------------------------------------------------------------------- 1 | package mesosphere.marathon.example.plugin.javaauth; 2 | 3 | import mesosphere.marathon.plugin.auth.*; 4 | 5 | /** 6 | * Enumeration for handling AuthorizedActions more easily in Java. 7 | */ 8 | public enum Action { 9 | 10 | CreateAppOrGroup(CreateGroup$.MODULE$), 11 | UpdateAppOrGroup(UpdateGroup$.MODULE$), 12 | DeleteAppOrGroup(DeleteGroup$.MODULE$), 13 | ViewAppOrGroup(ViewGroup$.MODULE$), 14 | KillTask(DeleteGroup$.MODULE$); 15 | 16 | public static Action byAction(AuthorizedAction action) { 17 | for (Action a : values()) { 18 | if (a.action.equals(action)) { 19 | return a; 20 | } 21 | } 22 | throw new IllegalArgumentException("Unknown Action: " + action); 23 | } 24 | 25 | private final AuthorizedAction action; 26 | Action(AuthorizedAction action) { 27 | this.action = action; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /auth/src/main/scala/mesosphere/marathon/example/plugin/auth/ExampleIdentity.scala: -------------------------------------------------------------------------------- 1 | package mesosphere.marathon.example.plugin.auth 2 | 3 | import com.typesafe.scalalogging.StrictLogging 4 | import mesosphere.marathon.plugin.auth._ 5 | import play.api.libs.functional.syntax._ 6 | import play.api.libs.json._ 7 | 8 | 9 | case class ExampleIdentity(username: String, password: String, permissions: Seq[Permission]) extends Identity with StrictLogging { 10 | 11 | def isAllowed[R](action: AuthorizedAction[R], resource: R): Boolean = { 12 | val permit = permissions.find { permission => 13 | permission.eligible(action) && permission.isAllowed(resource) 14 | } 15 | permit match { 16 | case Some(p) => logger.info(s"Found permit: $p") 17 | case None => logger.error(s"$username is not allowed for action $action on resource $resource") 18 | } 19 | permit.isDefined 20 | } 21 | } 22 | 23 | object ExampleIdentity { 24 | implicit val identityRead: Reads[ExampleIdentity] = ( 25 | (__ \ "user").read[String] ~ 26 | (__ \ "password").read[String] ~ 27 | (__ \ "permissions").read[Seq[PathPermission]] 28 | ) ((name, pass, permissions) => ExampleIdentity(name, pass, permissions)) 29 | } 30 | 31 | -------------------------------------------------------------------------------- /env/src/test/scala/EnvVarExtenderPluginTest.scala: -------------------------------------------------------------------------------- 1 | package mesosphere.marathon.example.plugin.env 2 | 3 | import mesosphere.marathon.plugin.ApplicationSpec 4 | import org.apache.mesos.Protos 5 | import org.scalatest.{FlatSpec, Matchers} 6 | import play.api.libs.json.{JsObject, Json} 7 | 8 | 9 | class EnvVarExtenderPluginTest extends FlatSpec with Matchers { 10 | "Initialization with a configuration" should "work" in { 11 | val f = new Fixture 12 | f.envVarExtender.envVariables should be(Map("foo" -> "bar", "key" -> "value")) 13 | } 14 | 15 | "Applying the plugin" should "work" in { 16 | val f = new Fixture 17 | val runSpec: ApplicationSpec = null 18 | val builder = Protos.TaskInfo.newBuilder() 19 | f.envVarExtender.taskInfo(runSpec, builder) 20 | builder.getCommand.getEnvironment.getVariablesList.get(0).getName should be("foo") 21 | } 22 | 23 | class Fixture { 24 | val json = 25 | """{ 26 | | "env": { 27 | | "foo": "bar", 28 | | "key": "value" 29 | | } 30 | |} 31 | """.stripMargin 32 | val config = Json.parse(json).as[JsObject] 33 | val envVarExtender = new EnvVarExtenderPlugin() 34 | envVarExtender.initialize(Map.empty, config) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /http/README.md: -------------------------------------------------------------------------------- 1 | # Http Example Plugin 2 | 3 | This http handler plugin allows the handling of basic http request/response cycles. 4 | 5 | ## Usage 6 | 7 | Start up Marathon according to the example project [README.md](../README.md) file, using the [plugin configuration file](https://github.com/mesosphere/marathon-example-plugins/blob/master/http/src/main/resources/mesosphere/marathon/example/plugin/http/plugin-conf.json) configuration file. This plugin example implements the [HttpRequestHandlerBase](https://github.com/mesosphere/marathon/blob/master/plugin-interface/src/main/scala/mesosphere/marathon/plugin/http/HttpRequestHandlerBase.scala) plugin with [WebJarHandler](https://github.com/mesosphere/marathon-example-plugins/blob/master/http/src/main/scala/mesosphere/marathon/example/plugin/http/WebJarHandler.scala). The implementation of the WebJarHandler class will serve static content that is placed under the [/META-INF/resources/webjars/static](https://github.com/mesosphere/marathon-example-plugins/blob/master/http/src/main/scala/mesosphere/marathon/example/plugin/http/WebJarHandler.scala#L11) folder. 8 | 9 | It will serve the contents via: http://localhost:8080/v2/plugins/webjar/hello.txt where webjar is it's pluginid defined in the [plugin configuration](https://github.com/mesosphere/marathon-example-plugins/blob/master/http/src/main/resources/mesosphere/marathon/example/plugin/http/plugin-conf.json#L3). 10 | -------------------------------------------------------------------------------- /label/src/main/scala/mesosphere/marathon/example/plugin/label/LabelValidatorPlugin.scala: -------------------------------------------------------------------------------- 1 | package mesosphere.marathon.example.plugin.label 2 | 3 | 4 | import com.wix.accord._ 5 | import mesosphere.marathon.plugin.validation.RunSpecValidator 6 | import mesosphere.marathon.plugin.{ApplicationSpec, RunSpec} 7 | 8 | 9 | class LabelValidatorPlugin extends RunSpecValidator { 10 | override def apply(runSpec: RunSpec): Result = runSpec match { 11 | case app: ApplicationSpec => DCOSServiceLabelValidator.appIsValid(app) 12 | case _ => Success 13 | } 14 | } 15 | 16 | /** 17 | * DCOS uses the labels DCOS_PACKAGE_FRAMEWORK_NAME and DCOS_SERVICE_NAME for frameworks and services. This validator 18 | * rejects those labels. IF they exist we fail, otherwise we succeed. 19 | * This ensures the marathon that uses this plugin will never launch what is intended to be a DCOS service. 20 | */ 21 | object DCOSServiceLabelValidator { 22 | 23 | val forbiddenLabels = List("DCOS_PACKAGE_FRAMEWORK_NAME", "DCOS_SERVICE_NAME") 24 | 25 | protected[ label ] lazy val appIsValid = new Validator[ ApplicationSpec ] { 26 | def apply(app: ApplicationSpec): Result = { 27 | if (app.labels.keySet.exists(forbiddenLabels.contains)) 28 | Failure(Set(RuleViolation(app.labels, s"An App label contains one or more DCOS LABELs ${forbiddenLabels} which is restricted"))) 29 | else Success 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /env/src/main/scala/mesosphere/marathon/example/plugin/env/EnvVarExtenderPlugin.scala: -------------------------------------------------------------------------------- 1 | package mesosphere.marathon.example.plugin.env 2 | 3 | import mesosphere.marathon.plugin.{ApplicationSpec, PodSpec} 4 | import mesosphere.marathon.plugin.task._ 5 | import mesosphere.marathon.plugin.plugin.PluginConfiguration 6 | import org.apache.mesos.Protos 7 | import org.apache.mesos.Protos.{ExecutorInfo, TaskGroupInfo, TaskInfo} 8 | 9 | class EnvVarExtenderPlugin extends RunSpecTaskProcessor with PluginConfiguration { 10 | private[env] var envVariables = Map.empty[String, String] 11 | 12 | def initialize(marathonInfo: Map[String, Any], configuration: play.api.libs.json.JsObject): Unit = { 13 | envVariables = (configuration \ "env").as[Map[String, String]] 14 | } 15 | 16 | override def taskInfo(appSpec: ApplicationSpec, builder: TaskInfo.Builder): Unit = { 17 | val envBuilder = builder.getCommand.getEnvironment.toBuilder 18 | envVariables.foreach { 19 | case (key, value) => 20 | val envVariable = Protos.Environment.Variable.newBuilder() 21 | envVariable.setName(key) 22 | envVariable.setValue(value) 23 | envBuilder.addVariables(envVariable) 24 | } 25 | val commandBuilder = builder.getCommand.toBuilder 26 | commandBuilder.setEnvironment(envBuilder) 27 | builder.setCommand(commandBuilder) 28 | } 29 | 30 | override def taskGroup(podSpec: PodSpec, executor: ExecutorInfo.Builder, taskGroup: TaskGroupInfo.Builder): Unit = ??? 31 | } 32 | -------------------------------------------------------------------------------- /auth/src/main/scala/mesosphere/marathon/example/plugin/auth/Permission.scala: -------------------------------------------------------------------------------- 1 | package mesosphere.marathon.example.plugin.auth 2 | 3 | import mesosphere.marathon.plugin.RunSpec 4 | import mesosphere.marathon.plugin.Group 5 | import mesosphere.marathon.plugin.auth._ 6 | import play.api.libs.functional.syntax._ 7 | import play.api.libs.json._ 8 | 9 | trait Permission { 10 | def eligible[R](action: AuthorizedAction[R]): Boolean 11 | def isAllowed[R](resource: R): Boolean 12 | } 13 | 14 | object Permission { 15 | 16 | private def actionByName(name: String): Seq[AuthorizedAction[_]] = name match { 17 | case "create" => Seq(CreateRunSpec, CreateGroup) 18 | case "update" => Seq(UpdateRunSpec, UpdateGroup) 19 | case "delete" => Seq(DeleteRunSpec, DeleteGroup) 20 | case "view" => Seq(ViewRunSpec, ViewGroup) 21 | } 22 | 23 | implicit lazy val permissionReads: Reads[PathPermission] = ( 24 | (__ \ "allowed").read[String].map(actionByName) ~ 25 | (__ \ "on").read[String] 26 | )(PathPermission) 27 | 28 | } 29 | 30 | case class PathPermission(allowed: Seq[AuthorizedAction[_]], on: String) extends Permission { 31 | 32 | override def eligible[R](requested: AuthorizedAction[R]): Boolean = allowed.contains(requested) 33 | override def isAllowed[R](resource: R): Boolean = resource match { 34 | case app: RunSpec => app.id.toString.startsWith(on) 35 | case group: Group => group.id.toString.startsWith(on) 36 | case _ => false 37 | } 38 | override def toString: String = s"Permission(allow: $allowed, on: $on)" 39 | } 40 | 41 | -------------------------------------------------------------------------------- /auth/src/main/resources/mesosphere/marathon/example/plugin/auth/plugin-conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": { 3 | "authorization": { 4 | "plugin": "mesosphere.marathon.plugin.auth.Authorizer", 5 | "implementation": "mesosphere.marathon.example.plugin.auth.ExampleAuthorizer" 6 | }, 7 | "authentication": { 8 | "plugin": "mesosphere.marathon.plugin.auth.Authenticator", 9 | "implementation": "mesosphere.marathon.example.plugin.auth.ExampleAuthenticator", 10 | "configuration": { 11 | "users": [ 12 | { 13 | "user": "ernie", 14 | "password": "ernie", 15 | "permissions": [ 16 | { "allowed": "create", "on": "/dev/" }, 17 | { "allowed": "update", "on": "/dev/" }, 18 | { "allowed": "delete", "on": "/dev/" }, 19 | { "allowed": "view", "on": "/dev/" } 20 | ] 21 | }, 22 | { 23 | "user": "bert", 24 | "password": "bert", 25 | "permissions": [ 26 | { "allowed": "create", "on": "/prod/" }, 27 | { "allowed": "update", "on": "/prod/" }, 28 | { "allowed": "delete", "on": "/prod/" }, 29 | { "allowed": "view", "on": "/prod/" } 30 | ] 31 | }, 32 | { 33 | "user": "admin", 34 | "password": "admin", 35 | "permissions": [ 36 | { "allowed": "create", "on": "/" }, 37 | { "allowed": "update", "on": "/" }, 38 | { "allowed": "delete", "on": "/" }, 39 | { "allowed": "view", "on": "/" } 40 | ] 41 | } 42 | ] 43 | } 44 | } 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /javaauth/src/main/java/mesosphere/marathon/example/plugin/javaauth/JavaAuthorizer.java: -------------------------------------------------------------------------------- 1 | package mesosphere.marathon.example.plugin.javaauth; 2 | 3 | import mesosphere.marathon.plugin.PathId; 4 | import mesosphere.marathon.plugin.auth.AuthorizedAction; 5 | import mesosphere.marathon.plugin.auth.Authorizer; 6 | import mesosphere.marathon.plugin.auth.Identity; 7 | import mesosphere.marathon.plugin.http.HttpRequest; 8 | import mesosphere.marathon.plugin.http.HttpResponse; 9 | 10 | public class JavaAuthorizer implements Authorizer { 11 | 12 | @Override 13 | public boolean isAuthorized(Identity principal, AuthorizedAction action, Resource resource) { 14 | return principal instanceof JavaIdentity && 15 | resource instanceof PathId && 16 | isAuthorized((JavaIdentity) principal, Action.byAction(action), (PathId) resource); 17 | 18 | } 19 | 20 | private boolean isAuthorized(JavaIdentity principal, Action action, PathId path) { 21 | switch (action) { 22 | case CreateAppOrGroup: 23 | return true; 24 | case UpdateAppOrGroup: 25 | return principal.getName().contains("ernie"); 26 | case DeleteAppOrGroup: 27 | return path.toString().startsWith("/test"); 28 | case ViewAppOrGroup: 29 | return true; 30 | case KillTask: 31 | return false; 32 | default: 33 | return false; 34 | } 35 | } 36 | 37 | @Override 38 | public void handleNotAuthorized(Identity principal, HttpResponse response) { 39 | response.status(403); 40 | response.body("application/json", "{\"problem\": \"Not Authorized to perform this action!\"}".getBytes()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Example plugins for Marathon 2 | 3 | ## Marathon Plugin Dependency 4 | 5 | The Marathon plugin interface is needed to compile this package. 6 | 7 | ## Package 8 | 9 | To build the package run this command: 10 | `sbt clean pack` 11 | This will compile and package all plugins. 12 | The resulting jars with all dependencies are put into the directory: `target/pack/lib`. 13 | This directory can be used directly as plugin directory for Marathon. 14 | 15 | # Using a Plugin 16 | 1. Run `sbt clean pack` in the repository's root directory. 17 | 2. Locate the Plugin configuration file (look at the Plugin's README.md 18 | for a hint)). 19 | 3. Start Marathon with the following flags: `--plugin_dir target/pack/lib --plugin_conf ` 20 | 21 | ## Plugins 22 | 23 | ### auth 24 | 25 | Example Authentication and Authorization Plugin (Scala based). 26 | See [README.md](https://github.com/mesosphere/marathon-example-plugins/blob/master/auth/README.md) in the auth plugin directory. 27 | 28 | ### javaauth 29 | 30 | Example Authentication and Authorization Plugin (Java based). 31 | See [README.md](https://github.com/mesosphere/marathon-example-plugins/blob/master/javaauth/README.md) in the javaauth directory. 32 | 33 | ### env 34 | 35 | Example Environment Variables Configuration. 36 | See [README.md](https://github.com/mesosphere/marathon-example-plugins/blob/master/env/README.md) in the env plugin directory. 37 | 38 | ### label 39 | 40 | Example validation of runspec for specific labels. 41 | See [README.md](https://github.com/mesosphere/marathon-example-plugins/blob/master/label/README.md) in the label plugin directory. 42 | 43 | ### executorid 44 | Example plugin to set the executor Id. 45 | See [README.md](https://github.com/mesosphere/marathon-example-plugins/blob/master/executorid/README.md) in the executorid plugin directory. -------------------------------------------------------------------------------- /executorid/README.md: -------------------------------------------------------------------------------- 1 | # ExecutorID example plugin 2 | 3 | Currently marathon generates a unique ExecutorID for all tasks thus starting a new executor process for every task (1-1 relationship). This is completely sufficient for the 99% of all use cases but sometimes a user might want to reuse the same executor instance for multiple tasks (1-n relationship). This is achieved by setting the same `TaskInfo.ExecutorInfo.ExecutorID` for all the tasks that should share an executor. This plugin when given an application with a custom executor and a label with a key `MARATHON_EXECUTOR_ID` and a value of the executor Id will use it to override the `TaskInfo.ExecutorInfo.ExecutorID`. 4 | 5 | **Note:** all application sharing the same executor Id will share the same executor instance allowing to save resources. The downfall is that all the tasks started with the same executor id must have identical `TaskInfo.ExecutorInfo`. Among other things that means environment variables must be identical. Since marathon would automatically generate per-task environment variables like `MARATHON_APP_VERSION`, `MESOS_TASK_ID` or `PORTx` this will not work. For this reason this plugin removes all the environment variables. It is possible to be more selective and remove only those environment variables that change from task to task but that's too much hustle for this simple plugin. 6 | 7 | ## Usage 8 | A simple app definition setting the executor Id `custom-executor` looks like: 9 | ``` 10 | { 11 | "id": "sleep", 12 | "cmd": "sleep 232323", 13 | "cpus": 0.01, 14 | "mem": 32, 15 | "disk": 0, 16 | "instances": 1, 17 | "executor": "/path/to/custom/executor-binary", 18 | "labels": { 19 | "MARATHON_EXECUTOR_ID": "custom-executor" 20 | } 21 | } 22 | ``` 23 | See the [plugin configuration file](https://github.com/mesosphere/marathon-example-plugins/blob/master/executorid/src/main/resources/mesosphere/marathon/example/plugin/executorid/plugin-conf.json) 24 | -------------------------------------------------------------------------------- /auth/src/main/scala/mesosphere/marathon/example/plugin/auth/ExampleAuthenticator.scala: -------------------------------------------------------------------------------- 1 | package mesosphere.marathon.example.plugin.auth 2 | 3 | import java.util.Base64 4 | 5 | import mesosphere.marathon.plugin.auth.{ Authenticator, Identity } 6 | import mesosphere.marathon.plugin.http.{ HttpRequest, HttpResponse } 7 | import mesosphere.marathon.plugin.plugin.PluginConfiguration 8 | import play.api.libs.json.JsObject 9 | 10 | import scala.concurrent.Future 11 | 12 | class ExampleAuthenticator extends Authenticator with PluginConfiguration { 13 | 14 | import scala.concurrent.ExecutionContext.Implicits.global 15 | 16 | override def handleNotAuthenticated(request: HttpRequest, response: HttpResponse): Unit = { 17 | response.status(401) 18 | response.header("WWW-Authenticate", """Basic realm="Marathon Example Authentication"""") 19 | response.body("application/json", """{"message": "Not Authenticated!"}""".getBytes("UTF-8")) 20 | } 21 | 22 | override def authenticate(request: HttpRequest): Future[Option[Identity]] = Future { 23 | 24 | def basicAuth(header: String): Option[(String, String)] = { 25 | val BasicAuthRegex = "Basic (.+)".r 26 | val UserPassRegex = "([^:]+):(.+)".r 27 | header match { 28 | case BasicAuthRegex(encoded) => 29 | val decoded = new String(Base64.getDecoder.decode(encoded)) 30 | val UserPassRegex(username, password) = decoded 31 | Some(username->password) 32 | case _ => None 33 | } 34 | } 35 | 36 | for { 37 | auth <- request.header("Authorization").headOption 38 | (username, password) <- basicAuth(auth) 39 | identity <- identities.get(username) if identity.password == password 40 | } yield identity 41 | 42 | } 43 | 44 | private var identities = Map.empty[String, ExampleIdentity] 45 | 46 | override def initialize(marathonInfo: Map[String, Any], configuration: JsObject): Unit = { 47 | //read all identities from the configuration 48 | identities = (configuration \ "users").as[Seq[ExampleIdentity]].map(id => id.username -> id).toMap 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /label/src/test/scala/LabelValidatorPluginTest.scala: -------------------------------------------------------------------------------- 1 | package mesosphere.marathon.example.plugin.label 2 | 3 | 4 | import mesosphere.marathon.plugin._ 5 | import org.scalatest.{FlatSpec, Matchers} 6 | 7 | 8 | class LabelValidatorPluginTest extends FlatSpec with Matchers { 9 | 10 | "plugin with pod spec" should "work" in { 11 | val pod = FakePodSpec(labels = Map("BOGUS_LABEL" -> "foo")) 12 | val labelValidator = new LabelValidatorPlugin() 13 | labelValidator.apply(pod).isSuccess shouldBe true 14 | } 15 | 16 | "plugin with app spec no labels" should "work" in { 17 | val app = FakeAppSpec(labels = Map("BOGUS_LABEL" -> "foo")) 18 | val labelValidator = new LabelValidatorPlugin() 19 | labelValidator.apply(app).isSuccess shouldBe true 20 | } 21 | 22 | "plugin with app spec with restricted label" should "fail" in { 23 | val app = FakeAppSpec(labels = Map("DCOS_PACKAGE_FRAMEWORK_NAME" -> "foo")) 24 | val labelValidator = new LabelValidatorPlugin() 25 | labelValidator.apply(app).isFailure shouldBe true 26 | } 27 | } 28 | 29 | case class FakePath(path: List[ String ] = List("fake")) extends PathId { 30 | override def toString: String = path.toSeq.reverse.mkString(".") 31 | } 32 | 33 | case class FakeAppSpec( 34 | id: PathId = FakePath(), 35 | user: Option[String] = None, 36 | env: Map[String, EnvVarValue] = Map.empty, 37 | labels: Map[String, String] = Map.empty, 38 | acceptedResourceRoles: Set[String] = Set.empty, 39 | secrets: Map[String, Secret] = Map.empty, 40 | networks: Seq[NetworkSpec] = Seq.empty, 41 | volumeMounts: Seq[VolumeMountSpec] = Seq.empty, 42 | volumes: Seq[VolumeSpec] = Seq.empty 43 | ) extends ApplicationSpec 44 | 45 | 46 | case class FakePodSpec( 47 | id: PathId = FakePath(), 48 | acceptedResourceRoles: Set[String] = Set.empty, 49 | secrets: Map[String, Secret] = Map.empty, 50 | env: Map[String, EnvVarValue] = Map.empty, 51 | containers: Seq[ContainerSpec] = Seq.empty, 52 | networks: Seq[NetworkSpec] = Seq.empty, 53 | labels: Map[String, String] = Map.empty, 54 | volumeMounts: Seq[VolumeMountSpec] = Seq.empty, 55 | volumes: Seq[VolumeSpec] = Seq.empty 56 | ) extends PodSpec 57 | -------------------------------------------------------------------------------- /javaauth/src/main/java/mesosphere/marathon/example/plugin/javaauth/JavaAuthenticator.java: -------------------------------------------------------------------------------- 1 | package mesosphere.marathon.example.plugin.javaauth; 2 | 3 | import java.util.Base64; 4 | import java.util.concurrent.Executors; 5 | 6 | import akka.dispatch.ExecutionContexts; 7 | import akka.dispatch.Futures; 8 | import mesosphere.marathon.plugin.auth.Authenticator; 9 | import mesosphere.marathon.plugin.auth.Identity; 10 | import mesosphere.marathon.plugin.http.HttpRequest; 11 | import mesosphere.marathon.plugin.http.HttpResponse; 12 | import scala.Option; 13 | import scala.concurrent.ExecutionContext; 14 | import scala.concurrent.Future; 15 | 16 | public class JavaAuthenticator implements Authenticator { 17 | 18 | private final ExecutionContext EC = ExecutionContexts.fromExecutorService(Executors.newSingleThreadExecutor()); 19 | 20 | @Override 21 | public Future> authenticate(HttpRequest request) { 22 | return Futures.future(() -> Option.apply(doAuth(request)), EC); 23 | } 24 | 25 | private Identity doAuth(HttpRequest request) { 26 | try { 27 | Option header = request.header("Authorization").headOption(); 28 | if (header.isDefined() && header.get().startsWith("Basic ")) { 29 | String encoded = header.get().replaceFirst("Basic ", ""); 30 | String decoded = new String(Base64.getDecoder().decode(encoded), "UTF-8"); 31 | String[] userPass = decoded.split(":", 2); 32 | if (userPass.length == 2) { 33 | return doAuth(userPass[0], userPass[1]); 34 | } 35 | } 36 | } catch (Exception ex) { /* do not authenticate in case of exception */ } 37 | return null; 38 | } 39 | 40 | /** 41 | * Authenticate, if the username matches the password. 42 | */ 43 | private Identity doAuth(String username, String password) { 44 | if (username.equals(password)) { 45 | return new JavaIdentity(username); 46 | } else { 47 | return null; 48 | } 49 | } 50 | 51 | 52 | @Override 53 | public void handleNotAuthenticated(HttpRequest request, HttpResponse response) { 54 | response.status(401); 55 | response.header("WWW-Authenticate", "Basic realm=\"Marathon: Username==Password\""); 56 | response.body("application/json", "{\"problem\": \"Not Authenticated!\"}".getBytes()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /executorid/src/main/scala/mesosphere/marathon/example/plugin/executorid/ExecutorIdExtenderPlugin.scala: -------------------------------------------------------------------------------- 1 | package mesosphere.marathon.example.plugin.executorid 2 | 3 | import com.typesafe.scalalogging.StrictLogging 4 | import mesosphere.marathon.plugin.{ApplicationSpec, PodSpec} 5 | import mesosphere.marathon.plugin.plugin.PluginConfiguration 6 | import mesosphere.marathon.plugin.task.RunSpecTaskProcessor 7 | import org.apache.mesos.Protos._ 8 | import play.api.libs.json.JsObject 9 | 10 | import scala.collection.JavaConverters._ 11 | 12 | class ExecutorIdExtenderPlugin extends RunSpecTaskProcessor with PluginConfiguration with StrictLogging { 13 | 14 | val ExecutorIdLabel = "MARATHON_EXECUTOR_ID" 15 | 16 | override def taskInfo(appSpec: ApplicationSpec, builder: TaskInfo.Builder): Unit = { 17 | // If custom executor is used 18 | if (builder.hasExecutor && builder.getExecutor.hasCommand) { 19 | val labels = builder.getLabels.getLabelsList.asScala 20 | 21 | // ... and there is MARATHON_EXECUTOR_ID label set 22 | labels.find(_.getKey == ExecutorIdLabel).foreach {label => 23 | // Set the executorID from the MARATHON_EXECUTOR_ID label 24 | val executorId = label.getValue 25 | val executorBuilder = builder.getExecutor.toBuilder 26 | executorBuilder.setExecutorId(ExecutorID.newBuilder.setValue(executorId)) 27 | 28 | // An executor id of the executor to launch this application. Note that all application sharing the same 29 | // executor id will share the same executor instance allowing to save resources. The downfall is that all 30 | // the apps started with the same executo id must have identical `TaskInfo.ExecutorInfo`. Among other things that 31 | // means environment variables must be identical. Since marathon would automatically generate per-task environment 32 | // variables like `MARATHON_APP_VERSION`, `MESOS_TASK_ID` or `PORTx` this will not work. 33 | // For this reason we just remove all the environment variables. It is possible to be more selective and remove 34 | // only those environment variables that change from task to task but that's too much hustle for this simple plugin. 35 | val commandBuilder = executorBuilder.getCommand.toBuilder 36 | commandBuilder.clearEnvironment() 37 | executorBuilder.setCommand(commandBuilder) 38 | 39 | builder.setExecutor(executorBuilder) 40 | } 41 | } 42 | } 43 | 44 | override def taskGroup(podSpec: PodSpec, executor: ExecutorInfo.Builder, taskGroup: TaskGroupInfo.Builder): Unit = {} 45 | 46 | override def initialize(marathonInfo: Map[String, Any], configuration: JsObject): Unit = { 47 | logger.info(s"ExecutorIdExtenderPlugin successfully initialized") 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /executorid/src/test/scala/mesosphere/marathon/example/plugin/executorid/ExecutorIdExtenderPluginTest.scala: -------------------------------------------------------------------------------- 1 | package mesosphere.marathon.example.plugin.executorid 2 | 3 | import com.typesafe.scalalogging.StrictLogging 4 | import org.apache.mesos.Protos.Environment.Variable 5 | import org.apache.mesos.Protos._ 6 | import org.scalatest.{GivenWhenThen, Matchers, WordSpec} 7 | 8 | class ExecutorIdExtenderPluginTest extends WordSpec with Matchers with GivenWhenThen with StrictLogging { 9 | 10 | "Given an MARATHON_EXECUTOR_ID label an executorID should be injected" in { 11 | val f = new Fixture 12 | 13 | Given("a TaskInfo with a MARATHON_EXECUTOR_ID label") 14 | val taskInfo = TaskInfo.newBuilder. 15 | setExecutor(ExecutorInfo.newBuilder. 16 | setCommand(CommandInfo.newBuilder. 17 | setEnvironment(Environment.newBuilder.addVariables( 18 | Variable.newBuilder.setName("foo").setValue("bar") 19 | ) 20 | )). 21 | setExecutorId(ExecutorID.newBuilder.setValue("task.12345")) 22 | ). 23 | setLabels(Labels.newBuilder.addLabels(Label.newBuilder. 24 | setKey(f.plugin.ExecutorIdLabel) 25 | .setValue("customer-executor-id") 26 | )) 27 | 28 | When("handled by the plugin") 29 | f.plugin.taskInfo(null, taskInfo) 30 | 31 | Then("ExecutorInfo.ExecutorId should be changed") 32 | taskInfo.getExecutor.getExecutorId.getValue shouldBe "customer-executor-id" 33 | 34 | And("Environment variables should be removed") 35 | taskInfo.getExecutor.getCommand.getEnvironment.getVariablesCount shouldBe 0 36 | } 37 | 38 | "Given no MARATHON_EXECUTOR_ID label an executorID should be untouched" in { 39 | val f = new Fixture 40 | 41 | Given("a TaskInfo with a MARATHON_EXECUTOR_ID label") 42 | val taskInfo = TaskInfo.newBuilder. 43 | setExecutor(ExecutorInfo.newBuilder. 44 | setCommand(CommandInfo.newBuilder. 45 | setEnvironment(Environment.newBuilder.addVariables( 46 | Variable.newBuilder.setName("foo").setValue("bar") 47 | ) 48 | )). 49 | setExecutorId(ExecutorID.newBuilder.setValue("task.12345")) 50 | ). 51 | setLabels(Labels.newBuilder.addLabels(Label.newBuilder. 52 | setKey("baz") 53 | .setValue("wof") 54 | )) 55 | 56 | When("handled by the plugin") 57 | f.plugin.taskInfo(null, taskInfo) 58 | 59 | Then("ExecutorInfo.ExecutorId should stay the same") 60 | taskInfo.getExecutor.getExecutorId.getValue shouldBe "task.12345" 61 | 62 | And("environment variables should be kept") 63 | taskInfo.getExecutor.getCommand.getEnvironment.getVariablesCount shouldBe 1 64 | } 65 | 66 | class Fixture { 67 | val plugin = new ExecutorIdExtenderPlugin() 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------