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 import akka.persistence.cassandra.query.scaladsl.CassandraReadJournal
22 import com.datastax.oss.driver.api.querybuilder.QueryBuilder.selectFrom
23 import com.typesafe.config.Config
24 import org.make.api.technical.healthcheck.HealthCheck.Status
25 
26 import scala.concurrent.{ExecutionContext, Future}
27 
28 class CassandraHealthCheck(proposalJournal: CassandraReadJournal, config: Config) extends HealthCheck {
29 
30   override val techno: String = "cassandra"
31 
32   val keyspace: String = config.getString("make-api.event-sourcing.proposals.journal.keyspace")
33   val table: String = config.getString("make-api.event-sourcing.proposals.journal.table")
34 
35   override def healthCheck()(implicit ctx: ExecutionContext): Future[Status] = {
36     proposalJournal.session
37       .selectOne(selectFrom(keyspace, table).column("persistence_id").limit(1).build())
38       .map { row =>
39         if (row.isDefined) {
40           Status.OK
41         } else {
42           Status.NOK()
43         }
44       }
45   }
46 }
Line Stmt Id Pos Tree Symbol Tests Code
30 49880 1215 - 1226 Literal <nosymbol> org.scalatest.testsuite "cassandra"
32 41005 1253 - 1323 Apply com.typesafe.config.Config.getString org.scalatest.testsuite CassandraHealthCheck.this.config.getString("make-api.event-sourcing.proposals.journal.keyspace")
33 37597 1346 - 1413 Apply com.typesafe.config.Config.getString org.scalatest.testsuite CassandraHealthCheck.this.config.getString("make-api.event-sourcing.proposals.journal.table")
38 50209 1500 - 1738 ApplyToImplicitArgs scala.concurrent.Future.map org.scalatest.testsuite CassandraHealthCheck.this.proposalJournal.session.selectOne(com.datastax.oss.driver.api.querybuilder.QueryBuilder.selectFrom(CassandraHealthCheck.this.keyspace, CassandraHealthCheck.this.table).column("persistence_id").limit(1).build()).map[org.make.api.technical.healthcheck.HealthCheck.Status](((row: Option[com.datastax.oss.driver.api.core.cql.Row]) => if (row.isDefined) org.make.api.technical.healthcheck.HealthCheck.Status.OK else org.make.api.technical.healthcheck.HealthCheck.Status.NOK.apply(org.make.api.technical.healthcheck.HealthCheck.Status.NOK.apply$default$1)))(ctx)