in discovery-marathon-api/src/main/scala/org/apache/pekko/discovery/marathon/MarathonApiServiceDiscovery.scala [41:79]
private[marathon] def targets(appList: AppList, portName: String): Seq[ResolvedTarget] = {
def dockerContainerPort(app: App) =
app.container
.flatMap(_.docker)
.flatMap(_.portMappings)
.getOrElse(Seq.empty)
.zipWithIndex
.find(_._1.name.contains(portName))
.map(_._2)
def appContainerPort(app: App) =
app.container
.flatMap(_.portMappings)
.getOrElse(Seq.empty)
.zipWithIndex
.find(_._1.name.contains(portName))
.map(_._2)
def appPort(app: App) =
app.portDefinitions.getOrElse(Seq.empty).zipWithIndex.find(_._1.name.contains(portName)).map(_._2)
// Tasks in the API don't have port names, so we have to look to the app to get the position we use
def portIndex(app: App) =
dockerContainerPort(app).orElse(appContainerPort(app)).orElse(appPort(app))
for {
app <- appList.apps
task <- app.tasks.getOrElse(Seq.empty)
portNumber <- portIndex(app)
taskHost <- task.host
taskPorts <- task.ports
taskPekkoManagementPort <- taskPorts.lift(portNumber)
} yield {
ResolvedTarget(
host = taskHost,
port = Some(taskPekkoManagementPort),
address = Try(InetAddress.getByName(taskHost)).toOption)
}
}