Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit a14d135

Browse files
committed
[Lift] app to JVM 12, with updated Kotlin, ES client and Spring-Boot
Also add missing prometheus actuator provider, which should fix missing metrics and warnings during deploy.
1 parent 4c9ba36 commit a14d135

File tree

4 files changed

+30
-32
lines changed

4 files changed

+30
-32
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM navikt/java:8
1+
FROM navikt/java:12
22
COPY target/pam-ontologi-indexer-*.jar /app/app.jar
33

44
EXPOSE 9023

pom.xml

+12-9
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,17 @@
1414
<parent>
1515
<groupId>org.springframework.boot</groupId>
1616
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>2.1.4.RELEASE</version>
18-
<relativePath/> <!-- lookup parent from repository -->
17+
<version>2.1.7.RELEASE</version>
1918
</parent>
2019

2120
<properties>
2221
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2322
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24-
<java.version>1.8</java.version>
25-
<maven.compiler.source>1.8</maven.compiler.source>
26-
<maven.compiler.target>1.8</maven.compiler.target>
27-
<kotlin.version>1.3.31</kotlin.version>
28-
<elasticsearch.version>6.2.2</elasticsearch.version>
23+
<java.version>12</java.version>
24+
<kotlin.version>1.3.41</kotlin.version>
25+
<elasticsearch.version>6.5.4</elasticsearch.version>
2926
<wiremock.version>2.7.1</wiremock.version>
30-
<logstash-logback-encoder.version>4.10</logstash-logback-encoder.version>
27+
<logstash-logback-encoder.version>6.1</logstash-logback-encoder.version>
3128
</properties>
3229

3330
<dependencies>
@@ -37,11 +34,13 @@
3734
</dependency>
3835
<dependency>
3936
<groupId>org.jetbrains.kotlin</groupId>
40-
<artifactId>kotlin-stdlib-jdk8</artifactId>
37+
<artifactId>kotlin-stdlib</artifactId>
38+
<version>${kotlin.version}</version>
4139
</dependency>
4240
<dependency>
4341
<groupId>org.jetbrains.kotlin</groupId>
4442
<artifactId>kotlin-reflect</artifactId>
43+
<version>${kotlin.version}</version>
4544
</dependency>
4645

4746
<dependency>
@@ -82,6 +81,10 @@
8281
<groupId>org.springframework.boot</groupId>
8382
<artifactId>spring-boot-starter-actuator</artifactId>
8483
</dependency>
84+
<dependency>
85+
<groupId>io.micrometer</groupId>
86+
<artifactId>micrometer-registry-prometheus</artifactId>
87+
</dependency>
8588
<dependency>
8689
<groupId>com.fasterxml.jackson.module</groupId>
8790
<artifactId>jackson-module-kotlin</artifactId>

src/main/kotlin/no/nav/arbeid/pam/ontologindexer/es/ElasticsearchIndexClient.kt

+16-21
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,34 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest
1010
import org.elasticsearch.action.bulk.BulkRequest
1111
import org.elasticsearch.action.bulk.BulkResponse
1212
import org.elasticsearch.action.index.IndexRequest
13-
import org.elasticsearch.client.ResponseException
14-
import org.elasticsearch.client.RestClientBuilder
15-
import org.elasticsearch.client.RestHighLevelClient
13+
import org.elasticsearch.client.*
1614
import org.elasticsearch.common.xcontent.XContentType
1715
import org.slf4j.LoggerFactory
1816
import org.springframework.beans.factory.annotation.Autowired
1917
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
2018
import org.springframework.stereotype.Service
2119
import java.io.IOException
22-
import kotlin.streams.toList
20+
import java.util.stream.Collectors.toList
2321

2422
/**
2523
* Elasticsearch client implementation.
2624
* <br></br><br></br>
2725
* Note that in cases where parameters are used as part of an index name, the value(s) are converted to lower case before being used.
2826
*/
29-
@ConditionalOnProperty(prefix = "elasticsearch", name = ["usemock"], havingValue = "false", matchIfMissing = true)
3027
@Service
3128
class ElasticsearchIndexClient @Autowired
32-
constructor(client: RestClientBuilder,
33-
private val objectMapper: ObjectMapper) : RestHighLevelClient(client) {
29+
constructor(elasticClientBuilder: RestClientBuilder,
30+
private val objectMapper: ObjectMapper) : RestHighLevelClient(elasticClientBuilder) {
3431

3532
val isHealthy: Boolean
3633
@Throws(IOException::class)
37-
get() = super.ping()
34+
get() = super.ping(RequestOptions.DEFAULT)
3835

3936
@Throws(IOException::class)
4037
fun createIndex(index: String, settings: String) {
4138

4239
val lowerCaseIndex = index.toLowerCase()
43-
indices().create(CreateIndexRequest(lowerCaseIndex).source(settings, XContentType.JSON))
40+
indices().create(CreateIndexRequest(lowerCaseIndex).source(settings, XContentType.JSON), RequestOptions.DEFAULT)
4441

4542
}
4643

@@ -50,7 +47,7 @@ constructor(client: RestClientBuilder,
5047
val lowerCaseIndices = indices.map { it.toLowerCase() }.toTypedArray()
5148

5249
if (lowerCaseIndices.isNotEmpty()) {
53-
indices().delete(DeleteIndexRequest(*lowerCaseIndices))
50+
indices().delete(DeleteIndexRequest(*lowerCaseIndices), RequestOptions.DEFAULT)
5451
}
5552
}
5653

@@ -59,7 +56,7 @@ constructor(client: RestClientBuilder,
5956

6057
val lowerCaseIndex = index.toLowerCase()
6158
try {
62-
lowLevelClient.performRequest("GET", "/$lowerCaseIndex")
59+
lowLevelClient.performRequest(Request("GET", "/$lowerCaseIndex"))
6360
return true
6461
} catch (e: ResponseException) {
6562
LOG.debug("Exception while calling indexExists" + e.message)
@@ -79,12 +76,10 @@ constructor(client: RestClientBuilder,
7976
" { \"add\" : { \"index\" : \"" + lowerCaseAlias + indexDatestamp + "\", \"alias\" : \"" + lowerCaseAlias + "\" } }\n" +
8077
" ]\n" +
8178
"}"
82-
lowLevelClient.performRequest(
83-
"POST",
84-
"/_aliases",
85-
emptyMap(),
86-
NStringEntity(jsonString, ContentType.APPLICATION_JSON)
87-
)
79+
80+
lowLevelClient.performRequest(Request("POST", "/_aliases").apply {
81+
this.entity = NStringEntity(jsonString, ContentType.APPLICATION_JSON)
82+
})
8883

8984
}
9085

@@ -106,8 +101,8 @@ constructor(client: RestClientBuilder,
106101
fun fetchIndexDocCount(index: String): Int {
107102

108103
val lowerCaseIndex = index.toLowerCase()
109-
lowLevelClient.performRequest("POST", "/$lowerCaseIndex/_refresh")
110-
val response = lowLevelClient.performRequest("GET", "/_cat/indices/$lowerCaseIndex")
104+
lowLevelClient.performRequest(Request("POST", "/$lowerCaseIndex/_refresh"))
105+
val response = lowLevelClient.performRequest(Request("GET", "/_cat/indices/$lowerCaseIndex"))
111106
val line = EntityUtils.toString(response.entity)
112107
return Integer.parseInt(line.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[6])
113108

@@ -117,15 +112,15 @@ constructor(client: RestClientBuilder,
117112
fun fetchAllIndicesStartingWith(name: String): List<String> {
118113

119114
val lowerCaseName = name.toLowerCase()
120-
val response = lowLevelClient.performRequest("GET", "/_cat/indices/$lowerCaseName*")
115+
val response = lowLevelClient.performRequest(Request("GET", "/_cat/indices/$lowerCaseName*"))
121116

122117
return response.entity.content.bufferedReader().lines().filter {
123118
!it.trim().isEmpty()
124119
}.map {
125120
it.split("\\s+".toRegex())[2]
126121
}.filter {
127122
it.startsWith(lowerCaseName) // Extra sanity check
128-
}.toList()
123+
}.collect(toList())
129124
}
130125

131126
companion object {

src/main/kotlin/no/nav/arbeid/pam/ontologindexer/scheduler/OntologiScheduler.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class OntologiScheduler {
1818
@Scheduled(cron = CRON_INDEXER)
1919
fun leggInnStillingstitler() {
2020

21-
LOGGER.info("leggInnStillingstitler scheduled job startet cron:$CRON_INDEXER")
21+
LOGGER.info("leggInnStillingstitler scheduled job startet cron: $CRON_INDEXER")
2222
jobbtittelIndexerService.indekser()
2323
LOGGER.info("leggInnStillingstitler scheduled job avsluttet")
2424

0 commit comments

Comments
 (0)