Skip to content

Commit

Permalink
IS-2765: Bruke felles Aiven-cache (#556)
Browse files Browse the repository at this point in the history
  • Loading branch information
geir-waagboe authored Nov 14, 2024
1 parent b3c7148 commit d586056
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 172 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/redis.yaml

This file was deleted.

7 changes: 3 additions & 4 deletions .nais/naiserator-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ spec:
rules:
- application: digdir-krr-proxy
namespace: team-rocket
- application: isdialogmote-redis
- application: ispdfgen
- application: isnarmesteleder
- application: isoppfolgingstilfelle
Expand All @@ -85,19 +84,19 @@ spec:
claims:
extra:
- "NAVident"
redis:
- instance: cache
access: readwrite
tokenx:
enabled: true
envFrom:
- secret: isdialogmote-serviceuser
- secret: isdialogmote-redis-password
- secret: isdialogmote-altinnuser
kafka:
pool: nav-dev
env:
- name: KTOR_ENV
value: production
- name: REDIS_HOST
value: "isdialogmote-redis.teamsykefravr.svc.cluster.local"
- name: DOKARKIV_CLIENT_ID
value: "dev-fss.teamdokumenthandtering.dokarkiv-q1"
- name: DOKARKIV_URL
Expand Down
7 changes: 3 additions & 4 deletions .nais/naiserator-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ spec:
rules:
- application: digdir-krr-proxy
namespace: team-rocket
- application: isdialogmote-redis
- application: ispdfgen
- application: isnarmesteleder
- application: isoppfolgingstilfelle
Expand All @@ -85,19 +84,19 @@ spec:
claims:
extra:
- "NAVident"
redis:
- instance: cache
access: readwrite
tokenx:
enabled: true
envFrom:
- secret: isdialogmote-serviceuser
- secret: isdialogmote-redis-password
- secret: isdialogmote-altinnuser
kafka:
pool: nav-prod
env:
- name: KTOR_ENV
value: "production"
- name: REDIS_HOST
value: "isdialogmote-redis.teamsykefravr.svc.cluster.local"
- name: DOKARKIV_CLIENT_ID
value: "prod-fss.teamdokumenthandtering.dokarkiv"
- name: DOKARKIV_URL
Expand Down
33 changes: 0 additions & 33 deletions .nais/redis-config.yaml

This file was deleted.

35 changes: 0 additions & 35 deletions .nais/redisexporter.yaml

This file was deleted.

17 changes: 9 additions & 8 deletions src/main/kotlin/no/nav/syfo/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ import no.nav.syfo.testdata.reset.kafka.kafkaTestdataResetConsumerConfig
import org.apache.kafka.clients.consumer.KafkaConsumer
import org.apache.kafka.clients.producer.KafkaProducer
import org.slf4j.LoggerFactory
import redis.clients.jedis.JedisPool
import redis.clients.jedis.JedisPoolConfig
import redis.clients.jedis.Protocol
import redis.clients.jedis.*

const val applicationPort = 8080

Expand All @@ -76,14 +74,17 @@ fun main() {
kafkaEsyfovarselConfig(environment.kafka)
),
)

val redisConfig = environment.redisConfig
val cache = RedisStore(
JedisPool(
JedisPoolConfig(),
environment.redisHost,
environment.redisPort,
Protocol.DEFAULT_TIMEOUT,
environment.redisSecret
HostAndPort(redisConfig.host, redisConfig.port),
DefaultJedisClientConfig.builder()
.ssl(redisConfig.ssl)
.user(redisConfig.redisUsername)
.password(redisConfig.redisPassword)
.database(redisConfig.redisDB)
.build()
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package no.nav.syfo.application

import io.ktor.server.application.*
import no.nav.syfo.application.cache.RedisConfig
import java.net.URI
import java.time.LocalDate

data class Environment(
Expand All @@ -27,9 +29,12 @@ data class Environment(
aivenTruststoreLocation = getEnvVar("KAFKA_TRUSTSTORE_PATH"),
aivenKeystoreLocation = getEnvVar("KAFKA_KEYSTORE_PATH"),
),
val redisHost: String = getEnvVar("REDIS_HOST"),
val redisPort: Int = getEnvVar("REDIS_PORT", "6379").toInt(),
val redisSecret: String = getEnvVar("REDIS_PASSWORD"),
val redisConfig: RedisConfig = RedisConfig(
redisUri = URI(getEnvVar("REDIS_URI_CACHE")),
redisDB = 7, // se https://github.com/navikt/istilgangskontroll/blob/master/README.md
redisUsername = getEnvVar("REDIS_USERNAME_CACHE"),
redisPassword = getEnvVar("REDIS_PASSWORD_CACHE"),
),
val isdialogmoteDbHost: String = getEnvVar("NAIS_DATABASE_ISDIALOGMOTE_ISDIALOGMOTE_DB_HOST"),
val isdialogmoteDbPort: String = getEnvVar("NAIS_DATABASE_ISDIALOGMOTE_ISDIALOGMOTE_DB_PORT"),
val isdialogmoteDbName: String = getEnvVar("NAIS_DATABASE_ISDIALOGMOTE_ISDIALOGMOTE_DB_DATABASE"),
Expand Down
14 changes: 14 additions & 0 deletions src/main/kotlin/no/nav/syfo/application/cache/RedisConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package no.nav.syfo.application.cache

import java.net.URI

class RedisConfig(
val redisUri: URI,
val redisDB: Int,
val redisUsername: String,
val redisPassword: String,
val ssl: Boolean = true
) {
val host: String = redisUri.host
val port: Int = redisUri.port
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import kotlinx.coroutines.runBlocking
import no.altinn.schemas.services.intermediary.receipt._2009._10.ReceiptExternal
import no.altinn.schemas.services.intermediary.receipt._2009._10.ReceiptStatusEnum
import no.altinn.services.serviceengine.correspondence._2009._10.ICorrespondenceAgencyExternalBasic
import no.nav.syfo.application.cache.RedisStore
import no.nav.syfo.brev.arbeidstaker.domain.ArbeidstakerBrevDTO
import no.nav.syfo.brev.arbeidstaker.domain.ArbeidstakerResponsDTO
import no.nav.syfo.brev.esyfovarsel.ArbeidstakerHendelse
Expand Down Expand Up @@ -47,9 +46,6 @@ import org.amshove.kluent.shouldBeNull
import org.amshove.kluent.shouldNotBeNull
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import redis.clients.jedis.JedisPool
import redis.clients.jedis.JedisPoolConfig
import redis.clients.jedis.Protocol
import java.time.LocalDateTime
import java.util.*

Expand All @@ -74,15 +70,6 @@ class ArbeidstakerBrevApiSpek : Spek({
externalMockEnvironment = externalMockEnvironment,
altinnMock = altinnMock,
)
val cache = RedisStore(
JedisPool(
JedisPoolConfig(),
externalMockEnvironment.environment.redisHost,
externalMockEnvironment.environment.redisPort,
Protocol.DEFAULT_TIMEOUT,
externalMockEnvironment.environment.redisSecret
)
)
val tokendingsClient = TokendingsClient(
tokenxClientId = externalMockEnvironment.environment.tokenxClientId,
tokenxEndpoint = externalMockEnvironment.environment.tokenxEndpoint,
Expand All @@ -92,14 +79,14 @@ class ArbeidstakerBrevApiSpek : Spek({
aadAppClient = externalMockEnvironment.environment.aadAppClient,
aadAppSecret = externalMockEnvironment.environment.aadAppSecret,
aadTokenEndpoint = externalMockEnvironment.environment.aadTokenEndpoint,
redisStore = cache,
redisStore = externalMockEnvironment.redisCache,
)
val oppfolgingstilfelleClient = OppfolgingstilfelleClient(
azureAdV2Client = azureAdV2Client,
tokendingsClient = tokendingsClient,
isoppfolgingstilfelleClientId = externalMockEnvironment.environment.isoppfolgingstilfelleClientId,
isoppfolgingstilfelleBaseUrl = externalMockEnvironment.environment.isoppfolgingstilfelleUrl,
cache = cache,
cache = externalMockEnvironment.redisCache,
)
val arbeidstakerVarselService = ArbeidstakerVarselService(
esyfovarselProducer = esyfovarselProducer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import kotlinx.coroutines.runBlocking
import no.altinn.schemas.services.intermediary.receipt._2009._10.ReceiptExternal
import no.altinn.schemas.services.intermediary.receipt._2009._10.ReceiptStatusEnum
import no.altinn.services.serviceengine.correspondence._2009._10.ICorrespondenceAgencyExternalBasic
import no.nav.syfo.application.cache.RedisStore
import no.nav.syfo.brev.arbeidstaker.ArbeidstakerVarselService
import no.nav.syfo.brev.arbeidstaker.domain.ArbeidstakerResponsDTO
import no.nav.syfo.brev.domain.BrevType
Expand Down Expand Up @@ -50,9 +49,6 @@ import org.amshove.kluent.shouldBeNull
import org.amshove.kluent.shouldNotBeNull
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import redis.clients.jedis.JedisPool
import redis.clients.jedis.JedisPoolConfig
import redis.clients.jedis.Protocol
import java.time.LocalDateTime
import java.util.*

Expand All @@ -78,15 +74,6 @@ object NarmesteLederBrevSpek : Spek({
altinnMock = altinnMock,
esyfovarselProducer = esyfovarselProducerMock,
)
val cache = RedisStore(
JedisPool(
JedisPoolConfig(),
externalMockEnvironment.environment.redisHost,
externalMockEnvironment.environment.redisPort,
Protocol.DEFAULT_TIMEOUT,
externalMockEnvironment.environment.redisSecret
)
)
val tokendingsClient = TokendingsClient(
tokenxClientId = externalMockEnvironment.environment.tokenxClientId,
tokenxEndpoint = externalMockEnvironment.environment.tokenxEndpoint,
Expand All @@ -96,14 +83,14 @@ object NarmesteLederBrevSpek : Spek({
aadAppClient = externalMockEnvironment.environment.aadAppClient,
aadAppSecret = externalMockEnvironment.environment.aadAppSecret,
aadTokenEndpoint = externalMockEnvironment.environment.aadTokenEndpoint,
redisStore = cache,
redisStore = externalMockEnvironment.redisCache,
)
val oppfolgingstilfelleClient = OppfolgingstilfelleClient(
azureAdV2Client = azureAdV2Client,
tokendingsClient = tokendingsClient,
isoppfolgingstilfelleClientId = externalMockEnvironment.environment.isoppfolgingstilfelleClientId,
isoppfolgingstilfelleBaseUrl = externalMockEnvironment.environment.isoppfolgingstilfelleUrl,
cache = cache,
cache = externalMockEnvironment.redisCache,
)
val arbeidstakerVarselService = ArbeidstakerVarselService(
esyfovarselProducer = esyfovarselProducer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ object IdenthendelseServiceSpek : Spek({
redisStore = RedisStore(
JedisPool(
JedisPoolConfig(),
externalMockEnvironment.environment.redisHost,
externalMockEnvironment.environment.redisPort,
externalMockEnvironment.environment.redisConfig.host,
externalMockEnvironment.environment.redisConfig.port,
Protocol.DEFAULT_TIMEOUT,
externalMockEnvironment.environment.redisSecret
)
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package no.nav.syfo.testhelper

import io.ktor.server.netty.*
import no.nav.syfo.application.ApplicationState
import no.nav.syfo.application.cache.RedisStore
import no.nav.syfo.testhelper.mock.*
import java.util.*

Expand Down Expand Up @@ -47,7 +48,7 @@ class ExternalMockEnvironment private constructor() {
narmestelederUrl = narmesteLederMock.url,
pdlUrl = pdlMock.url,
)
val redisServer = testRedis(environment)
lateinit var redisCache: RedisStore

val wellKnownSelvbetjening = wellKnownSelvbetjeningMock()
val wellKnownVeilederV2 = wellKnownVeilederV2Mock()
Expand All @@ -67,13 +68,11 @@ class ExternalMockEnvironment private constructor() {

fun ExternalMockEnvironment.startExternalMocks() {
this.externalApplicationMockMap.start()
this.redisServer.start()
}

fun ExternalMockEnvironment.stopExternalMocks() {
this.externalApplicationMockMap.stop()
this.database.stop()
this.redisServer.stop()
}

fun HashMap<String, NettyApplicationEngine>.start() {
Expand Down
Loading

0 comments on commit d586056

Please sign in to comment.