Move Views config into component
This commit is contained in:
@@ -15,8 +15,8 @@ import fr.dcproject.component.article.routes.getOneArticle
|
||||
import fr.dcproject.component.article.routes.upsertArticle
|
||||
import fr.dcproject.component.auth.ForbiddenException
|
||||
import fr.dcproject.component.auth.routes.authLogin
|
||||
import fr.dcproject.component.auth.routes.authRegister
|
||||
import fr.dcproject.component.auth.routes.authPasswordless
|
||||
import fr.dcproject.component.auth.routes.authRegister
|
||||
import fr.dcproject.component.auth.user
|
||||
import fr.dcproject.component.citizen.routes.changeMyPassword
|
||||
import fr.dcproject.component.citizen.routes.findCitizen
|
||||
@@ -29,6 +29,7 @@ import fr.dcproject.component.comment.generic.routes.createCommentChildren
|
||||
import fr.dcproject.component.comment.generic.routes.editComment
|
||||
import fr.dcproject.component.comment.generic.routes.getChildrenComments
|
||||
import fr.dcproject.component.comment.generic.routes.getOneComment
|
||||
import fr.dcproject.component.views.ConfigViews
|
||||
import fr.dcproject.component.workgroup.routes.CreateWorkgroup.createWorkgroup
|
||||
import fr.dcproject.component.workgroup.routes.DeleteWorkgroup.deleteWorkgroup
|
||||
import fr.dcproject.component.workgroup.routes.EditWorkgroup.editWorkgroup
|
||||
@@ -37,22 +38,20 @@ import fr.dcproject.component.workgroup.routes.GetWorkgroups.getWorkgroups
|
||||
import fr.dcproject.component.workgroup.routes.members.AddMemberToWorkgroup.addMemberToWorkgroup
|
||||
import fr.dcproject.component.workgroup.routes.members.DeleteMembersOfWorkgroup.deleteMemberOfWorkgroup
|
||||
import fr.dcproject.component.workgroup.routes.members.UpdateMemberOfWorkgroup.updateMemberOfWorkgroup
|
||||
import fr.dcproject.elasticsearch.configElasticIndexes
|
||||
import fr.dcproject.event.EventNotification
|
||||
import fr.dcproject.event.EventSubscriber
|
||||
import fr.dcproject.routes.*
|
||||
import fr.dcproject.security.voter.*
|
||||
import fr.dcproject.security.voter.OpinionChoiceVoter
|
||||
import fr.dcproject.security.voter.OpinionVoter
|
||||
import fr.ktorVoter.AuthorizationVoter
|
||||
import fr.ktorVoter.VoterException
|
||||
import fr.postgresjson.migration.Migrations
|
||||
import io.ktor.application.*
|
||||
import io.ktor.auth.*
|
||||
import io.ktor.auth.jwt.*
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.engine.jetty.Jetty
|
||||
import io.ktor.features.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.http.auth.*
|
||||
import io.ktor.jackson.*
|
||||
import io.ktor.locations.*
|
||||
import io.ktor.response.*
|
||||
@@ -67,7 +66,6 @@ import org.koin.ktor.ext.Koin
|
||||
import org.koin.ktor.ext.get
|
||||
import org.slf4j.event.Level
|
||||
import java.time.Duration
|
||||
import java.util.*
|
||||
import java.util.concurrent.CompletionException
|
||||
|
||||
fun main(args: Array<String>): Unit = EngineMain.main(args)
|
||||
@@ -104,7 +102,7 @@ fun Application.module(env: Env = PROD) {
|
||||
}
|
||||
}
|
||||
|
||||
configElasticIndexes(get())
|
||||
ConfigViews.createEsIndexForViews(get())
|
||||
|
||||
install(WebSockets) {
|
||||
pingPeriod = Duration.ofSeconds(60) // Disabled (null) by default
|
||||
|
||||
@@ -5,7 +5,7 @@ import fr.dcproject.entity.ViewAggregation
|
||||
import fr.dcproject.utils.contentToString
|
||||
import fr.dcproject.utils.getJsonField
|
||||
import fr.dcproject.utils.toIso
|
||||
import fr.dcproject.views.ViewManager
|
||||
import fr.dcproject.component.views.ViewManager
|
||||
import org.elasticsearch.client.Request
|
||||
import org.elasticsearch.client.Response
|
||||
import org.elasticsearch.client.RestClient
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.dcproject.views
|
||||
package fr.dcproject.component.views
|
||||
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.entity.ViewAggregation
|
||||
@@ -1,45 +1,46 @@
|
||||
package fr.dcproject.elasticsearch
|
||||
package fr.dcproject.component.views
|
||||
|
||||
import org.elasticsearch.client.Request
|
||||
import org.elasticsearch.client.RestClient
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
fun waitElasticsearchIsUp(client: RestClient) {
|
||||
val logger: Logger = LoggerFactory.getLogger("fr.dcproject.elasticsearch")
|
||||
val request = Request("GET", "/_cluster/health")
|
||||
repeat(5*60 / 2) { // 5 minutes
|
||||
runCatching {
|
||||
client.performRequest(request).statusLine.statusCode
|
||||
}.onSuccess {
|
||||
if (it == 200) {
|
||||
logger.debug("Elasticsearch is Ready! Continue...")
|
||||
return
|
||||
} else {
|
||||
logger.debug("sleep 2s and retry...")
|
||||
object ConfigViews {
|
||||
private fun waitElasticsearchIsUp(client: RestClient) {
|
||||
val logger: Logger = LoggerFactory.getLogger("fr.dcproject.elasticsearch")
|
||||
val request = Request("GET", "/_cluster/health")
|
||||
repeat(5*60 / 2) { // 5 minutes
|
||||
runCatching {
|
||||
client.performRequest(request).statusLine.statusCode
|
||||
}.onSuccess {
|
||||
if (it == 200) {
|
||||
logger.debug("Elasticsearch is Ready! Continue...")
|
||||
return
|
||||
} else {
|
||||
logger.debug("sleep 2s and retry...")
|
||||
Thread.sleep(2000)
|
||||
}
|
||||
}.onFailure {
|
||||
logger.debug("${it.message}, sleep 2s and retry...")
|
||||
Thread.sleep(2000)
|
||||
}
|
||||
}.onFailure {
|
||||
logger.debug("${it.message}, sleep 2s and retry...")
|
||||
Thread.sleep(2000)
|
||||
}
|
||||
error("Elasticsearch is not ready")
|
||||
}
|
||||
error("Elasticsearch is not ready")
|
||||
}
|
||||
|
||||
fun configElasticIndexes(client: RestClient) {
|
||||
waitElasticsearchIsUp(client)
|
||||
fun createEsIndexForViews(client: RestClient) {
|
||||
waitElasticsearchIsUp(client)
|
||||
|
||||
/* Create index if not exist */
|
||||
client.run {
|
||||
if (performRequest(Request("HEAD", "/views?include_type_name=false")).statusLine.statusCode == 404) {
|
||||
Request(
|
||||
"PUT",
|
||||
"/views?include_type_name=false"
|
||||
).apply {
|
||||
//language=JSON
|
||||
setJsonEntity(
|
||||
"""
|
||||
/* Create index if not exist */
|
||||
client.run {
|
||||
if (performRequest(Request("HEAD", "/views?include_type_name=false")).statusLine.statusCode == 404) {
|
||||
Request(
|
||||
"PUT",
|
||||
"/views?include_type_name=false"
|
||||
).apply {
|
||||
//language=JSON
|
||||
setJsonEntity(
|
||||
"""
|
||||
{
|
||||
"settings": {
|
||||
"number_of_shards": 5
|
||||
@@ -74,9 +75,10 @@ fun configElasticIndexes(client: RestClient) {
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}.let {
|
||||
performRequest(it)
|
||||
)
|
||||
}.let {
|
||||
performRequest(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user