Skip to content

Commit 39f29bd

Browse files
authored
fjerner leader avhengigheter (#1661)
1 parent 497e84e commit 39f29bd

File tree

8 files changed

+75
-10
lines changed

8 files changed

+75
-10
lines changed

pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,6 @@
260260
<artifactId>logback-syslog4j</artifactId>
261261
<version>1.0.0</version> <!-- August, 2014, men det er den som blir brukt på NAV -->
262262
</dependency>
263-
<dependency>
264-
<groupId>no.nav.familie.felles</groupId>
265-
<artifactId>leader</artifactId>
266-
<version>${felles.version}</version>
267-
</dependency>
268263
<dependency>
269264
<groupId>no.nav.tjenestespesifikasjoner</groupId>
270265
<artifactId>avstemming-v1-tjenestespesifikasjon</artifactId>

src/main/kotlin/no/nav/familie/tilbake/behandling/batch/AutomatiskBehandlingRydderBatch.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package no.nav.familie.tilbake.behandling.batch
22

3-
import no.nav.familie.leader.LeaderClient
43
import no.nav.familie.prosessering.domene.Status
54
import no.nav.familie.prosessering.domene.Task
65
import no.nav.familie.tilbake.behandling.FagsakRepository
76
import no.nav.familie.tilbake.behandling.task.TracableTaskService
87
import no.nav.familie.tilbake.common.repository.findByIdOrThrow
98
import no.nav.familie.tilbake.config.PropertyName
9+
import no.nav.familie.tilbake.leader.LeaderClient
1010
import no.nav.familie.tilbake.log.SecureLog
1111
import org.slf4j.LoggerFactory
1212
import org.springframework.core.env.Environment

src/main/kotlin/no/nav/familie/tilbake/behandling/batch/AutomatiskGjenopptaBehandlingBatch.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package no.nav.familie.tilbake.behandling.batch
22

3-
import no.nav.familie.leader.LeaderClient
43
import no.nav.familie.prosessering.domene.Status
54
import no.nav.familie.prosessering.domene.Task
65
import no.nav.familie.tilbake.behandling.FagsakRepository
76
import no.nav.familie.tilbake.behandling.task.TracableTaskService
87
import no.nav.familie.tilbake.common.repository.findByIdOrThrow
98
import no.nav.familie.tilbake.config.PropertyName
9+
import no.nav.familie.tilbake.leader.LeaderClient
1010
import no.nav.familie.tilbake.log.SecureLog
1111
import org.slf4j.LoggerFactory
1212
import org.springframework.core.env.Environment

src/main/kotlin/no/nav/familie/tilbake/behandling/batch/AutomatiskSaksbehandlingBatch.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package no.nav.familie.tilbake.behandling.batch
22

3-
import no.nav.familie.leader.LeaderClient
43
import no.nav.familie.prosessering.domene.Status
54
import no.nav.familie.tilbake.behandling.FagsakRepository
65
import no.nav.familie.tilbake.behandling.task.TracableTaskService
76
import no.nav.familie.tilbake.common.repository.findByIdOrThrow
7+
import no.nav.familie.tilbake.leader.LeaderClient
88
import no.nav.familie.tilbake.log.SecureLog
99
import org.slf4j.LoggerFactory
1010
import org.springframework.core.env.Environment

src/main/kotlin/no/nav/familie/tilbake/kravgrunnlag/batch/HåndterGamleKravgrunnlagBatch.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package no.nav.familie.tilbake.kravgrunnlag.batch
22

3-
import no.nav.familie.leader.LeaderClient
43
import no.nav.familie.prosessering.domene.Status
54
import no.nav.familie.prosessering.domene.Task
65
import no.nav.familie.tilbake.behandling.FagsystemUtil
@@ -14,6 +13,7 @@ import no.nav.familie.tilbake.kontrakter.tilbakekreving.Ytelsestype.OVERGANGSST
1413
import no.nav.familie.tilbake.kontrakter.tilbakekreving.Ytelsestype.SKOLEPENGER
1514
import no.nav.familie.tilbake.kravgrunnlag.domain.ØkonomiXmlMottatt
1615
import no.nav.familie.tilbake.kravgrunnlag.ØkonomiXmlMottattService
16+
import no.nav.familie.tilbake.leader.LeaderClient
1717
import no.nav.familie.tilbake.log.SecureLog
1818
import org.slf4j.LoggerFactory
1919
import org.springframework.core.env.Environment
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package no.nav.familie.tilbake.leader
2+
3+
object Environment {
4+
@JvmStatic
5+
fun hentLeaderSystemEnv(): String? {
6+
return System.getenv("ELECTOR_GET_URL") ?: return null
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package no.nav.familie.tilbake.leader
2+
3+
import org.slf4j.LoggerFactory
4+
import java.net.InetAddress
5+
import java.net.URI
6+
import java.net.http.HttpClient
7+
import java.net.http.HttpRequest
8+
import java.net.http.HttpResponse
9+
import java.net.http.HttpResponse.BodyHandlers
10+
11+
object LeaderClient {
12+
private val secureLogger = LoggerFactory.getLogger("secureLogger")
13+
14+
/**
15+
* @return Om pod er leader eller ikke. null hvis leadersjekk ikke er implementert på pod
16+
*/
17+
@JvmStatic
18+
fun isLeader(
19+
antallGanger: Int = 3,
20+
forsinkelseIms: Long = 1000,
21+
): Boolean? {
22+
val electorGetUrl = Environment.hentLeaderSystemEnv() ?: return null
23+
24+
val client = HttpClient.newHttpClient()
25+
val request =
26+
HttpRequest
27+
.newBuilder()
28+
.uri(URI.create(electorGetUrl))
29+
.GET()
30+
.build()
31+
32+
val response: HttpResponse<String>? =
33+
retryFunksjon(
34+
antallGanger = antallGanger,
35+
forsinkelseIms = forsinkelseIms,
36+
) { client.send(request, BodyHandlers.ofString()) }
37+
38+
if (response?.body().isNullOrBlank()) return null
39+
40+
val hostname: String = InetAddress.getLocalHost().hostName
41+
return response?.body()?.contains(hostname)
42+
}
43+
44+
private fun <T> retryFunksjon(
45+
antallGanger: Int = 3,
46+
forsinkelseIms: Long = 1000,
47+
funksjon: () -> T,
48+
): T? {
49+
var throwable: Exception? = null
50+
repeat(antallGanger) {
51+
try {
52+
return funksjon()
53+
} catch (e: Exception) {
54+
secureLogger.warn("Kunne ikke hente leader status")
55+
throwable = e
56+
}
57+
Thread.sleep(forsinkelseIms)
58+
}
59+
secureLogger.error("Kunne ikke hente leader status", throwable)
60+
return null
61+
}
62+
}

src/main/kotlin/no/nav/familie/tilbake/micrometer/MålerService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package no.nav.familie.tilbake.micrometer
33
import io.micrometer.core.instrument.Metrics
44
import io.micrometer.core.instrument.MultiGauge
55
import io.micrometer.core.instrument.Tags
6-
import no.nav.familie.leader.LeaderClient
76
import no.nav.familie.prosessering.internal.TaskService
87
import no.nav.familie.tilbake.behandling.domain.Behandlingsresultat
98
import no.nav.familie.tilbake.behandling.domain.Behandlingsresultatstype
109
import no.nav.familie.tilbake.common.fagsystem
1110
import no.nav.familie.tilbake.kontrakter.Fagsystem
11+
import no.nav.familie.tilbake.leader.LeaderClient
1212
import no.nav.familie.tilbake.micrometer.domain.MeldingstellingRepository
1313
import no.nav.familie.tilbake.micrometer.domain.Meldingstype
1414
import org.slf4j.LoggerFactory

0 commit comments

Comments
 (0)