diff --git a/app/models/overview/ClusterOverview.scala b/app/models/overview/ClusterOverview.scala index 4326cf01693ad357c387a209ecee58accb44ad85..45236c04b73d5b124e033fad74bcef5a7e4c452e 100644 --- a/app/models/overview/ClusterOverview.scala +++ b/app/models/overview/ClusterOverview.scala @@ -39,21 +39,20 @@ object ClusterOverview { def buildNodes(masterNodeId: String, nodesInfo: JsValue, nodesStats: JsValue): JsArray = JsArray( - (nodesInfo \ "nodes").as[JsObject].value.map { - case (id, info) => - val stats = (nodesStats \ "nodes" \ id).as[JsObject] + (nodesStats \ "nodes").as[JsObject].value.map { + case (id, stats) => + val info = (nodesInfo \ "nodes" \ id).as[JsObject] Node(id, info, stats, masterNodeId) }.toSeq ) def buildIndices(clusterState: JsValue, indicesStats: JsValue, aliases: JsValue): Seq[JsValue] = { val routingTable = (clusterState \ "routing_table" \ "indices").as[JsObject] - val routingNodes = (clusterState \ "routing_nodes" \ "nodes").as[JsObject] val openIndices = routingTable.value.map { case (index, shards) => val indexStats = (indicesStats \ "indices" \ index).asOpt[JsObject].getOrElse(Json.obj()) val indexAliases = (aliases \ index \ "aliases").asOpt[JsObject].getOrElse(Json.obj()) // 1.4 < does not return aliases obj - Index(index, indexStats, shards, indexAliases, routingNodes) + Index(index, indexStats, shards, indexAliases) }.toSeq val closedIndices = ClosedIndices(clusterState) diff --git a/app/models/overview/Index.scala b/app/models/overview/Index.scala index d44a9b73f523adc0d22edf255c16ec4aba453f8a..5b6573a53500f536e1ff06e6df7a71a9a7fb5d7b 100644 --- a/app/models/overview/Index.scala +++ b/app/models/overview/Index.scala @@ -4,23 +4,22 @@ import play.api.libs.json._ object Index { - def apply(name: String, stats: JsValue, shards: JsValue, aliases: JsObject, routingNodes: JsValue): JsValue = { + def apply(name: String, stats: JsValue, routingTable: JsValue, aliases: JsObject): JsValue = { + var unhealthy = false + var numReplicas = 0 + var numShards = 0 - val unassignedShards = (shards \ "shards").as[JsObject].values.flatMap { - case JsArray(shards) => - shards.filter { shard => - (shard \ "node").asOpt[String].isEmpty - } - case _ => Nil - } + val shardMap = (routingTable \ "shards").as[JsObject].value.toSeq.flatMap { case (num, shards) => + numShards = Math.max(numShards, num.toInt + 1) // shard num is 0 based - val shardsAllocation = routingNodes.as[JsObject].value.mapValues { - case JsArray(shards) => JsArray(shards.filter { shard => (shard \ "index").as[String].equals(name) }) - case _ => JsArray() - }.toSeq ++ Seq("unassigned" -> JsArray(unassignedShards.toSeq)) + val shardInstances = shards.as[JsArray].value + numReplicas = shardInstances.length - 1 - val numShards = (shards \ "shards").as[JsObject].keys.size - val numReplicas = (shards \ "shards" \ "0").as[JsArray].value.size - 1 + shardInstances.map { shard => + unhealthy = unhealthy && (shard \ "state").as[String].equals("STARTED") + (shard \ "node").asOpt[String].getOrElse("unassigned") -> shard + } + }.groupBy(_._1).mapValues(v => JsArray(v.map(_._2))) val special = name.startsWith(".") @@ -28,7 +27,7 @@ object Index { "name" -> JsString(name), "closed" -> JsBoolean(false), "special" -> JsBoolean(special), - "unhealthy" -> JsBoolean(unhealthyIndex(shardsAllocation)), + "unhealthy" -> JsBoolean(unhealthy), "doc_count" -> (stats \ "primaries" \ "docs" \ "count").asOpt[JsNumber].getOrElse(JsNumber(0)), "deleted_docs" -> (stats \ "primaries" \ "docs" \ "deleted").asOpt[JsNumber].getOrElse(JsNumber(0)), "size_in_bytes" -> (stats \ "primaries" \ "store" \ "size_in_bytes").asOpt[JsNumber].getOrElse(JsNumber(0)), @@ -36,14 +35,8 @@ object Index { "aliases" -> JsArray(aliases.keys.map(JsString(_)).toSeq), // 1.4 < does not return aliases obj "num_shards" -> JsNumber(numShards), "num_replicas" -> JsNumber(numReplicas), - "shards" -> JsObject(shardsAllocation) + "shards" -> JsObject(shardMap) )) } - private def unhealthyIndex(shardAllocation: Seq[(String, JsArray)]): Boolean = - shardAllocation.exists { - case ("unassigned", _) => true - case (_, JsArray(shards)) => shards.exists(!_.\("state").as[String].equals("STARTED")) - } - } diff --git a/app/models/overview/Node.scala b/app/models/overview/Node.scala index 0086ee53fc7bce8d2acaf1761030ec076a9726d7..dd95c103d484a0dcd68e5f98c5fafd36a013e8e2 100644 --- a/app/models/overview/Node.scala +++ b/app/models/overview/Node.scala @@ -6,18 +6,18 @@ import play.api.libs.json._ object Node { def apply(id: String, info: JsValue, stats: JsValue, masterNodeId: String) = { - val nodeRoles = NodeRoles(info) + val nodeRoles = NodeRoles(stats) // AWS nodes return no host/ip info - val host = (info \ "host").asOpt[JsString].getOrElse(JsNull) - val ip = (info \ "ip").asOpt[JsString].getOrElse(JsNull) + val host = (stats \ "host").asOpt[JsString].getOrElse(JsNull) + val ip = (stats \ "ip").asOpt[JsString].getOrElse(JsNull) val jvmVersion = (info \ "jvm" \ "version").asOpt[JsString].getOrElse(JsNull) Json.obj( "id" -> JsString(id), "current_master" -> JsBoolean(id.equals(masterNodeId)), - "name" -> (info \ "name").as[JsString], + "name" -> (stats \ "name").as[JsString], "host" -> host, "ip" -> ip, "es_version" -> (info \ "version").as[JsString], diff --git a/app/services/overview/OverviewDataService.scala b/app/services/overview/OverviewDataService.scala index 9a5bbea736499ba62bd80fe439b367e5c7232577..2153f2b2edf692c3868960d3cb83e6ffb54455db 100644 --- a/app/services/overview/OverviewDataService.scala +++ b/app/services/overview/OverviewDataService.scala @@ -14,7 +14,7 @@ class OverviewDataService @Inject()(client: ElasticClient) { def overview(target: ElasticServer): Future[JsValue] = { val apis = Seq( - "_cluster/state/master_node,routing_table,routing_nodes,blocks", + "_cluster/state/master_node,routing_table,blocks", "_nodes/stats/jvm,fs,os,process?human=true", "_stats/docs,store", "_cluster/settings", @@ -22,26 +22,21 @@ class OverviewDataService @Inject()(client: ElasticClient) { "_cluster/health", s"_nodes/_all/os,jvm?human=true" ) - - val start = System.currentTimeMillis() Future.sequence(apis.map(client.executeRequest("GET", _, None, target))).map { responses => responses.zipWithIndex.find(_._1.isInstanceOf[Error]) match { - case Some((failed, idx)) => - throw RequestFailedException(apis(idx), failed.status, failed.body.toString()) + case Some((response, idx)) => + throw RequestFailedException(apis(idx), response.status, response.body.toString()) case None => - val end = System.currentTimeMillis() - val overview = ClusterOverview( - responses(0).body, - responses(1).body, - responses(2).body, - responses(3).body, - responses(4).body, - responses(5).body, - responses(6).body + ClusterOverview( + responses(0).body, // cluster state + responses(1).body, // nodes stats + responses(2).body, // index stats + responses(3).body, // cluster settings + responses(4).body, // aliases + responses(5).body, // cluster health + responses(6).body // nodes ) - println(s"Requesting took [${end - start}]") - overview } } } diff --git a/test/models/overview/ClusterInitializingShards.scala b/test/models/overview/ClusterInitializingShards.scala index 2c62fc90601745faa3e6323c8dc8206d3b3bd625..363c2f93ed8aa60c15c1262526431e071411de81 100644 --- a/test/models/overview/ClusterInitializingShards.scala +++ b/test/models/overview/ClusterInitializingShards.scala @@ -151,140 +151,6 @@ object ClusterInitializingShards { | } | } | } - | }, - | "routing_nodes" : { - | "unassigned" : [ { - | "state" : "UNASSIGNED", - | "primary" : false, - | "node" : null, - | "relocating_node" : null, - | "shard" : 4, - | "index" : "hello", - | "version" : 10, - | "unassigned_info" : { - | "reason" : "REPLICA_ADDED", - | "at" : "2016-03-19T14:13:39.833Z" - | } - | } ], - | "nodes" : { - | "VOiMU2k5SuStH3-X1uuBGw" : [ { - | "state" : "INITIALIZING", - | "primary" : false, - | "node" : "VOiMU2k5SuStH3-X1uuBGw", - | "relocating_node" : null, - | "shard" : 1, - | "index" : "hello", - | "version" : 16, - | "allocation_id" : { - | "id" : "rNdtAPz_RhKVBp6dpAH1cw" - | }, - | "unassigned_info" : { - | "reason" : "REPLICA_ADDED", - | "at" : "2016-03-19T14:13:39.833Z" - | } - | }, { - | "state" : "STARTED", - | "primary" : true, - | "node" : "VOiMU2k5SuStH3-X1uuBGw", - | "relocating_node" : null, - | "shard" : 2, - | "index" : "hello", - | "version" : 15, - | "allocation_id" : { - | "id" : "rN62kibSRZq0RxcwxEHKKw" - | } - | }, { - | "state" : "INITIALIZING", - | "primary" : false, - | "node" : "VOiMU2k5SuStH3-X1uuBGw", - | "relocating_node" : null, - | "shard" : 3, - | "index" : "hello", - | "version" : 11, - | "allocation_id" : { - | "id" : "NhG91IW6RCW1KAbSx67O9g" - | }, - | "unassigned_info" : { - | "reason" : "REPLICA_ADDED", - | "at" : "2016-03-19T14:13:39.833Z" - | } - | }, { - | "state" : "STARTED", - | "primary" : true, - | "node" : "VOiMU2k5SuStH3-X1uuBGw", - | "relocating_node" : null, - | "shard" : 0, - | "index" : "hello", - | "version" : 17, - | "allocation_id" : { - | "id" : "13mrI6FhRjGEk7xG7xYJvg" - | } - | } ], - | "cPsT9o5FQ3WRnvqSTXHiVQ" : [ { - | "state" : "STARTED", - | "primary" : true, - | "node" : "cPsT9o5FQ3WRnvqSTXHiVQ", - | "relocating_node" : null, - | "shard" : 1, - | "index" : "hello", - | "version" : 16, - | "allocation_id" : { - | "id" : "hlwc94lZRvOoBoaxyEWIGg" - | } - | }, { - | "state" : "STARTED", - | "primary" : true, - | "node" : "cPsT9o5FQ3WRnvqSTXHiVQ", - | "relocating_node" : null, - | "shard" : 4, - | "index" : "hello", - | "version" : 10, - | "allocation_id" : { - | "id" : "Kyne0gDVQEasq9VxUUsxbg" - | } - | }, { - | "state" : "INITIALIZING", - | "primary" : false, - | "node" : "cPsT9o5FQ3WRnvqSTXHiVQ", - | "relocating_node" : null, - | "shard" : 2, - | "index" : "hello", - | "version" : 15, - | "allocation_id" : { - | "id" : "2G3Hs3CnT5uvhpeOmHZyYg" - | }, - | "unassigned_info" : { - | "reason" : "REPLICA_ADDED", - | "at" : "2016-03-19T14:13:39.833Z" - | } - | }, { - | "state" : "STARTED", - | "primary" : true, - | "node" : "cPsT9o5FQ3WRnvqSTXHiVQ", - | "relocating_node" : null, - | "shard" : 3, - | "index" : "hello", - | "version" : 11, - | "allocation_id" : { - | "id" : "b4Gdtk7uTuSINaZ_YdaJdg" - | } - | }, { - | "state" : "INITIALIZING", - | "primary" : false, - | "node" : "cPsT9o5FQ3WRnvqSTXHiVQ", - | "relocating_node" : null, - | "shard" : 0, - | "index" : "hello", - | "version" : 17, - | "allocation_id" : { - | "id" : "FbfzrPiySEaOzGMRZRDf7w" - | }, - | "unassigned_info" : { - | "reason" : "REPLICA_ADDED", - | "at" : "2016-03-19T14:13:39.833Z" - | } - | } ] - | } | } |} """.stripMargin diff --git a/test/models/overview/ClusterRelocatingShards.scala b/test/models/overview/ClusterRelocatingShards.scala index 4a0974e794dbb985a823b08ea27f02eaf11f070c..bcd8a51279b70339b292457e49c60232b53c8e1b 100644 --- a/test/models/overview/ClusterRelocatingShards.scala +++ b/test/models/overview/ClusterRelocatingShards.scala @@ -136,154 +136,6 @@ object ClusterRelocatingShards extends ClusterStub { | } | } | } - | }, - | "routing_nodes" : { - | "unassigned" : [ ], - | "nodes" : { - | "VOiMU2k5SuStH3-X1uuBGw" : [ { - | "state" : "RELOCATING", - | "primary" : false, - | "node" : "VOiMU2k5SuStH3-X1uuBGw", - | "relocating_node" : "xIcHb7CPRH-_m4VGCtBV-w", - | "shard" : 1, - | "index" : "hello", - | "version" : 18, - | "expected_shard_size_in_bytes" : 407699, - | "allocation_id" : { - | "id" : "rNdtAPz_RhKVBp6dpAH1cw", - | "relocation_id" : "avGC6WQeTzqRnQyBE9O_bQ" - | } - | }, { - | "state" : "STARTED", - | "primary" : false, - | "node" : "VOiMU2k5SuStH3-X1uuBGw", - | "relocating_node" : null, - | "shard" : 4, - | "index" : "hello", - | "version" : 12, - | "allocation_id" : { - | "id" : "A4Dfk71HTriXU1OVBFQIeA" - | } - | }, { - | "state" : "STARTED", - | "primary" : true, - | "node" : "VOiMU2k5SuStH3-X1uuBGw", - | "relocating_node" : null, - | "shard" : 2, - | "index" : "hello", - | "version" : 16, - | "allocation_id" : { - | "id" : "rN62kibSRZq0RxcwxEHKKw" - | } - | }, { - | "state" : "STARTED", - | "primary" : false, - | "node" : "VOiMU2k5SuStH3-X1uuBGw", - | "relocating_node" : null, - | "shard" : 3, - | "index" : "hello", - | "version" : 12, - | "allocation_id" : { - | "id" : "NhG91IW6RCW1KAbSx67O9g" - | } - | }, { - | "state" : "STARTED", - | "primary" : true, - | "node" : "VOiMU2k5SuStH3-X1uuBGw", - | "relocating_node" : null, - | "shard" : 0, - | "index" : "hello", - | "version" : 19, - | "allocation_id" : { - | "id" : "13mrI6FhRjGEk7xG7xYJvg" - | } - | } ], - | "xIcHb7CPRH-_m4VGCtBV-w" : [ { - | "state" : "INITIALIZING", - | "primary" : false, - | "node" : "xIcHb7CPRH-_m4VGCtBV-w", - | "relocating_node" : "VOiMU2k5SuStH3-X1uuBGw", - | "shard" : 1, - | "index" : "hello", - | "version" : 18, - | "expected_shard_size_in_bytes" : 407699, - | "allocation_id" : { - | "id" : "avGC6WQeTzqRnQyBE9O_bQ", - | "relocation_id" : "rNdtAPz_RhKVBp6dpAH1cw" - | } - | }, { - | "state" : "INITIALIZING", - | "primary" : false, - | "node" : "xIcHb7CPRH-_m4VGCtBV-w", - | "relocating_node" : "cPsT9o5FQ3WRnvqSTXHiVQ", - | "shard" : 0, - | "index" : "hello", - | "version" : 19, - | "expected_shard_size_in_bytes" : 405582, - | "allocation_id" : { - | "id" : "fU5MEf2SSyGi40BscFJQsw", - | "relocation_id" : "FbfzrPiySEaOzGMRZRDf7w" - | } - | } ], - | "cPsT9o5FQ3WRnvqSTXHiVQ" : [ { - | "state" : "STARTED", - | "primary" : true, - | "node" : "cPsT9o5FQ3WRnvqSTXHiVQ", - | "relocating_node" : null, - | "shard" : 1, - | "index" : "hello", - | "version" : 18, - | "allocation_id" : { - | "id" : "hlwc94lZRvOoBoaxyEWIGg" - | } - | }, { - | "state" : "STARTED", - | "primary" : true, - | "node" : "cPsT9o5FQ3WRnvqSTXHiVQ", - | "relocating_node" : null, - | "shard" : 4, - | "index" : "hello", - | "version" : 12, - | "allocation_id" : { - | "id" : "Kyne0gDVQEasq9VxUUsxbg" - | } - | }, { - | "state" : "STARTED", - | "primary" : false, - | "node" : "cPsT9o5FQ3WRnvqSTXHiVQ", - | "relocating_node" : null, - | "shard" : 2, - | "index" : "hello", - | "version" : 16, - | "allocation_id" : { - | "id" : "2G3Hs3CnT5uvhpeOmHZyYg" - | } - | }, { - | "state" : "STARTED", - | "primary" : true, - | "node" : "cPsT9o5FQ3WRnvqSTXHiVQ", - | "relocating_node" : null, - | "shard" : 3, - | "index" : "hello", - | "version" : 12, - | "allocation_id" : { - | "id" : "b4Gdtk7uTuSINaZ_YdaJdg" - | } - | }, { - | "state" : "RELOCATING", - | "primary" : false, - | "node" : "cPsT9o5FQ3WRnvqSTXHiVQ", - | "relocating_node" : "xIcHb7CPRH-_m4VGCtBV-w", - | "shard" : 0, - | "index" : "hello", - | "version" : 19, - | "expected_shard_size_in_bytes" : 405582, - | "allocation_id" : { - | "id" : "FbfzrPiySEaOzGMRZRDf7w", - | "relocation_id" : "fU5MEf2SSyGi40BscFJQsw" - | } - | } ] - | } | } |} """.stripMargin diff --git a/test/models/overview/ClusterWithData.scala b/test/models/overview/ClusterWithData.scala index 304260df8ff63aeb2e34e3d59d878878ac071663..3a7a14d077a412159523998c5b5a8ab4178a61a3 100644 --- a/test/models/overview/ClusterWithData.scala +++ b/test/models/overview/ClusterWithData.scala @@ -127,99 +127,6 @@ trait ClusterWithData extends ClusterStub { | } | } | } - | }, - | "routing_nodes": { - | "unassigned": [], - | "nodes": { - | "MoDcZdJkQGK2RpYTvJhQlA": [ - | { - | "state": "STARTED", - | "primary": false, - | "node": "MoDcZdJkQGK2RpYTvJhQlA", - | "relocating_node": null, - | "shard": 0, - | "index": "bar", - | "version": 3, - | "allocation_id": { - | "id": "ns_A3bOnS26LHP9aMMoNqQ" - | } - | }, - | { - | "state": "STARTED", - | "primary": true, - | "node": "MoDcZdJkQGK2RpYTvJhQlA", - | "relocating_node": null, - | "shard": 4, - | "index": ".foobar", - | "version": 2, - | "allocation_id": { - | "id": "w30rCs_vRIeWWNdPD6yinA" - | } - | }, - | { - | "state": "STARTED", - | "primary": true, - | "node": "MoDcZdJkQGK2RpYTvJhQlA", - | "relocating_node": null, - | "shard": 2, - | "index": ".foobar", - | "version": 2, - | "allocation_id": { - | "id": "9i-1Ze0iTyyGreKtd6uNlQ" - | } - | }, - | { - | "state": "STARTED", - | "primary": true, - | "node": "MoDcZdJkQGK2RpYTvJhQlA", - | "relocating_node": null, - | "shard": 0, - | "index": ".foobar", - | "version": 2, - | "allocation_id": { - | "id": "av2CBQ7ZR6mpYP4hN45SFQ" - | } - | } - | ], - | "cPsT9o5FQ3WRnvqSTXHiVQ": [ - | { - | "state": "STARTED", - | "primary": true, - | "node": "cPsT9o5FQ3WRnvqSTXHiVQ", - | "relocating_node": null, - | "shard": 0, - | "index": "bar", - | "version": 3, - | "allocation_id": { - | "id": "KpTuITnDRju5huuD7K42JQ" - | } - | }, - | { - | "state": "STARTED", - | "primary": true, - | "node": "cPsT9o5FQ3WRnvqSTXHiVQ", - | "relocating_node": null, - | "shard": 1, - | "index": ".foobar", - | "version": 2, - | "allocation_id": { - | "id": "WA41NgmPRdyuV1Bdf3xAIw" - | } - | }, - | { - | "state": "STARTED", - | "primary": true, - | "node": "cPsT9o5FQ3WRnvqSTXHiVQ", - | "relocating_node": null, - | "shard": 3, - | "index": ".foobar", - | "version": 2, - | "allocation_id": { - | "id": "QqhRDD_DST6P0By3QaKjug" - | } - | } - | ] - | } | } |} """.stripMargin diff --git a/test/models/overview/ClusterWithoutData.scala b/test/models/overview/ClusterWithoutData.scala index 2398e93aa5b3931e5f5f8c6a0c5afe1a5a0d8da8..c0c44f4b0e9b5bb4ff0e8ea499e91e4cc1e84ef0 100644 --- a/test/models/overview/ClusterWithoutData.scala +++ b/test/models/overview/ClusterWithoutData.scala @@ -16,19 +16,6 @@ object ClusterWithoutData extends ClusterStub { | "indices":{ | | } - | }, - | "routing_nodes":{ - | "unassigned":[ - | - | ], - | "nodes":{ - | "MoDcZdJkQGK2RpYTvJhQlA":[ - | - | ], - | "cPsT9o5FQ3WRnvqSTXHiVQ":[ - | - | ] - | } | } |} """.stripMargin diff --git a/test/models/overview/NodeStats.scala b/test/models/overview/NodeStats.scala index f813ba2b3eede5cc5db61ff2657876a57ae4d5b7..e0ea5b58f8811d7fd541a58de6eca2b45358bf15 100644 --- a/test/models/overview/NodeStats.scala +++ b/test/models/overview/NodeStats.scala @@ -11,10 +11,7 @@ object NodeStats { | "name":"Solara", | "transport_address":"127.0.0.1:9301", | "host":"127.0.0.1", - | "ip":[ - | "127.0.0.1:9301", - | "NONE" - | ], + | "ip": "127.0.0.1", | "os":{ | "timestamp":1458346589015, | "load_average":3.17138671875,