1 /* 2 * Make.org Core API 3 * Copyright (C) 2018 Make.org 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation, either version 3 of the 8 * License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Affero General Public License for more details. 14 * 15 * You should have received a copy of the GNU Affero General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package org.make.api.technical.healthcheck 21 22 import com.sksamuel.elastic4s.Index 23 import com.sksamuel.elastic4s.ElasticDsl._ 24 import org.make.api.technical.elasticsearch._ 25 import org.make.api.technical.healthcheck.HealthCheck.Status 26 27 import scala.concurrent.{ExecutionContext, Future} 28 29 class ElasticsearchHealthCheck( 30 elasticsearchConfiguration: ElasticsearchConfiguration, 31 elasticsearchClient: ElasticsearchClient 32 ) extends HealthCheck { 33 34 override val techno: String = "elasticsearch" 35 36 private val proposalAlias: Index = 37 elasticsearchConfiguration.proposalAliasName 38 39 override def healthCheck()(implicit ctx: ExecutionContext): Future[Status] = { 40 elasticsearchClient.client 41 .executeAsFuture(search(proposalAlias).bool(must(matchAllQuery())).limit(1)) 42 .map { response => 43 if (response.totalHits > 0) { 44 Status.OK 45 } else { 46 Status.NOK(Some("Unexpected result in elasticsearch health check: expected result greater than 0")) 47 } 48 } 49 } 50 51 }
| Line | Stmt Id | Pos | Tree | Symbol | Tests | Code |
|---|---|---|---|---|---|---|
| 34 | 48297 | 1218 - 1233 | Literal | <nosymbol> | org.scalatest.testsuite | "elasticsearch" |
| 37 | 44134 | 1276 - 1320 | ApplyImplicitView | com.sksamuel.elastic4s.Index.toIndex | org.scalatest.testsuite | elastic4s.this.Index.toIndex(ElasticsearchHealthCheck.this.elasticsearchConfiguration.proposalAliasName) |
| 42 | 36632 | 1407 - 1744 | ApplyToImplicitArgs | scala.concurrent.Future.map | org.scalatest.testsuite | org.make.api.technical.elasticsearch.`package`.RichHttpClient(ElasticsearchHealthCheck.this.elasticsearchClient.client).executeAsFuture[com.sksamuel.elastic4s.requests.searches.SearchRequest, com.sksamuel.elastic4s.requests.searches.SearchResponse](com.sksamuel.elastic4s.ElasticDsl.search(ElasticsearchHealthCheck.this.proposalAlias).bool(com.sksamuel.elastic4s.ElasticDsl.must(com.sksamuel.elastic4s.ElasticDsl.matchAllQuery())).limit(1))(com.sksamuel.elastic4s.ElasticDsl.SearchHandler, ctx, scala.reflect.ManifestFactory.classType[com.sksamuel.elastic4s.requests.searches.SearchResponse](classOf[com.sksamuel.elastic4s.requests.searches.SearchResponse])).map[org.make.api.technical.healthcheck.HealthCheck.Status](((response: com.sksamuel.elastic4s.requests.searches.SearchResponse) => if (response.totalHits.>(0)) org.make.api.technical.healthcheck.HealthCheck.Status.OK else org.make.api.technical.healthcheck.HealthCheck.Status.NOK.apply(scala.Some.apply[String]("Unexpected result in elasticsearch health check: expected result greater than 0"))))(ctx) |