Skip to content
Snippets Groups Projects
Commit 36b94c46 authored by Leonardo Menezes's avatar Leonardo Menezes
Browse files

fixes show only affected indices

closes #211
parent 3f357250
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,8 @@ package services.overview ...@@ -3,6 +3,8 @@ package services.overview
import _root_.util.DataSize import _root_.util.DataSize
import play.api.libs.json._ import play.api.libs.json._
import scala.collection.mutable
object ClusterOverview { object ClusterOverview {
def apply(clusterSettings: JsValue, health: JsValue, def apply(clusterSettings: JsValue, health: JsValue,
...@@ -16,12 +18,17 @@ object ClusterOverview { ...@@ -16,12 +18,17 @@ object ClusterOverview {
__.read[JsObject].map{ o => o ++ Json.obj( "state" -> JsString(state) ) } __.read[JsObject].map{ o => o ++ Json.obj( "state" -> JsString(state) ) }
) )
val unhealthyIndices = mutable.Set[String]()
val shardMap = (shards.as[JsArray].value.flatMap { val shardMap = (shards.as[JsArray].value.flatMap {
case shard => case shard =>
val index = (shard \ "index").as[String] val index = (shard \ "index").as[String]
val node = (shard \ "node").asOpt[String].getOrElse("unassigned") val node = (shard \ "node").asOpt[String].getOrElse("unassigned")
// TODO: prune node/index from shard? // TODO: prune node/index from shard?
if (node.equals("unassigned"))
unhealthyIndices.add(index)
if ((shard \ "state").as[String].equals("RELOCATING")) { if ((shard \ "state").as[String].equals("RELOCATING")) {
unhealthyIndices.add(index)
val relocation = node.split(" ") val relocation = node.split(" ")
val origin = relocation.head val origin = relocation.head
val target = relocation.last val target = relocation.last
...@@ -42,12 +49,11 @@ object ClusterOverview { ...@@ -42,12 +49,11 @@ object ClusterOverview {
alias => (alias \ "index").as[String] -> (alias \ "alias").as[JsValue] alias => (alias \ "index").as[String] -> (alias \ "alias").as[JsValue]
}.groupBy(_._1).mapValues(a => JsArray(a.map(_._2))) }.groupBy(_._1).mapValues(a => JsArray(a.map(_._2)))
def addAliasAndShards(index: String) = __.json.update { def addAliasAndShards(index: String) = __.json.update {
val aliases = JsObject(Map("aliases" -> aliasesMap.getOrElse(index, JsNull))) val aliases = JsObject(Map("aliases" -> aliasesMap.getOrElse(index, JsNull)))
val shards = JsObject(Map("shards" -> JsObject(shardMap.getOrElse(index, Map())))) val shards = JsObject(Map("shards" -> JsObject(shardMap.getOrElse(index, Map()))))
__.read[JsObject].map { o => o ++ aliases ++ shards } val healthy = JsObject(Map("unhealthy" -> JsBoolean(unhealthyIndices.contains(index))))
__.read[JsObject].map { o => o ++ aliases ++ shards ++ healthy}
} }
var sizeInBytes = 0l var sizeInBytes = 0l
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment