-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PS] IndexedMetaData will now only be resolved if config specifies us…
…ing elasticsearch
- Loading branch information
1 parent
1e482a5
commit 1dc14a4
Showing
4 changed files
with
92 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2021 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package osgb.services | ||
|
||
import config.ConfigHelper | ||
import javax.inject.{Inject, Singleton} | ||
import play.api.Configuration | ||
import uk.gov.hmrc.address.services.es.ElasticSettings | ||
|
||
@Singleton | ||
class ElasticSettingsProvider @Inject() (configuration: Configuration, configHelper: ConfigHelper) { | ||
lazy val numShards: Map[String, Int] = configuration.getConfig("elastic.shards").map( | ||
_.entrySet.foldLeft(Map.empty[String, Int])((m, a) => m + (a._1 -> a._2.unwrapped().asInstanceOf[Int])) | ||
).getOrElse(Map.empty[String, Int]) | ||
|
||
lazy val elasticSettings: ElasticSettings = { | ||
val localMode = configHelper.getConfigString("elastic.localMode").exists(_.toBoolean) | ||
val homeDir = configHelper.getConfigString("elastic.homeDir") | ||
val preDelete = configHelper.getConfigString("elastic.preDelete").exists(_.toBoolean) | ||
val clusterName = configHelper.mustGetConfigString("elastic.clusterName") | ||
val connectionString = configHelper.mustGetConfigString("elastic.uri") | ||
val isCluster = configHelper.getConfigString("elastic.isCluster").exists(_.toBoolean) | ||
ElasticSettings(localMode, homeDir, preDelete, connectionString, isCluster, clusterName, numShards) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2021 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package osgb.services | ||
|
||
import javax.inject.{Inject, Singleton} | ||
import uk.gov.hmrc.address.services.es.{ESAdminImpl, ElasticsearchHelper, IndexMetadata} | ||
import uk.gov.hmrc.logging.{LoggerFacade, SimpleLogger} | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
@Singleton | ||
class IndexedMetadataProvider @Inject()(settingsProvider: ElasticSettingsProvider, logger: SimpleLogger, | ||
ec: ExecutionContext) { | ||
|
||
lazy val indexedMetaData: IndexMetadata = { | ||
val numShards = settingsProvider.numShards | ||
val settings = settingsProvider.elasticSettings | ||
|
||
val clients = ElasticsearchHelper.buildClients(settings, new LoggerFacade(play.api.Logger.logger)) | ||
val esImpl = new ESAdminImpl(clients, logger, ec, settings) | ||
new IndexMetadata(esImpl, settings.isCluster, numShards, logger, ec) | ||
} | ||
} |