Skip to content

Commit

Permalink
Slettet referenser till Aiven & ubrukt GET endepunkte i k9sak-route
Browse files Browse the repository at this point in the history
  • Loading branch information
albrektsson committed Oct 6, 2023
1 parent fd804b9 commit e54f439
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 130 deletions.
9 changes: 3 additions & 6 deletions docs/systemcontext.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ graph LR
topic-punsj-til-formidling{{privat-k9punsj-aksjonspunkthendelse-v1}}
topic-punsj-til-los{{privat-k9-dokumenthendelse}}
topic-punsj-til-punsjbolle{{omsorgspenger.k9-rapid-v2}}
onprem-topic-fordel-til-punsj{{onprem:privat-k9-fordel-journalforing-v1}}
aiven-topic-fordel-til-punsj{{aiven:k9saksbehandling.punsjbar-journalpost}}
topic-fordel-til-punsj{{k9saksbehandling.punsjbar-journalpost}}

k9-punsj-frontend --> |punsjer inn papirsoknader| k9-punsj
k9-punsj --> |lagrer, henter, modifiserer soknader, mapper, bunker, journalposter, personer, aksjonspunkt og brev| k9-punsj-db[(k9-punsj-db)]
k9-punsj --> |oppretter/henter fagsaknummer, henter ruting| k9-punsjbolle
k9-punsj --> |henter perioder og inntektsmeldinger | k9-sak
k9-punsj --> |sender søknad| topic-punsj-til-punsjbolle
k9-punsjbolle --> |konsumerer innsendt søknad| topic-punsj-til-punsjbolle
k9-fordel --> |sender punsjbar journalposthendelse| onprem-topic-fordel-til-punsj
k9-punsj .-> |konsumerer punsjbar journalposthendelse| onprem-topic-fordel-til-punsj
k9-fordel --> |sender punsjbar journalposthendelse| aiven-topic-fordel-til-punsj
k9-punsj .-> |konsumerer punsjbar journalposthendelse| aiven-topic-fordel-til-punsj
k9-fordel --> |sender punsjbar journalposthendelse| topic-fordel-til-punsj
k9-punsj .-> |konsumerer punsjbar journalposthendelse| topic-fordel-til-punsj
k9-punsj --> |sender aksjonspunkthendelse| topic-punsj-til-los
k9-los .-> |konsumerer aksjonspunkthendelse| topic-punsj-til-los
k9-punsj --> |sender brevbestilling| topic-punsj-til-formidling
Expand Down
70 changes: 28 additions & 42 deletions src/main/kotlin/no/nav/k9punsj/configuration/KafkaConfig.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package no.nav.k9punsj.configuration

import no.nav.k9punsj.IkkeLokalProfil
import no.nav.k9punsj.IkkeTestProfil
import no.nav.k9punsj.StandardProfil
import org.apache.kafka.clients.CommonClientConfigs
import org.apache.kafka.clients.consumer.ConsumerConfig
import org.apache.kafka.clients.producer.ProducerConfig
import org.apache.kafka.common.config.SslConfigs
import org.apache.kafka.common.security.auth.SecurityProtocol
import org.apache.kafka.common.serialization.StringDeserializer
import org.apache.kafka.common.serialization.StringSerializer
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
Expand All @@ -25,84 +23,72 @@ import java.net.InetAddress
import java.time.Duration

@Configuration
@IkkeTestProfil
@StandardProfil
class KafkaConfig(
@Value("\${kafka.override_truststore_password:}") private val overrideTruststorePassword: String?
) {

@Bean
@Qualifier(AIVEN)
@IkkeLokalProfil
fun aivenKafkaBaseProperties(): Map<String, Any> {
fun kafkaBaseProperties(): Map<String, Any> {
val env = System.getenv()

val truststorePasswordKey: String = if (overrideTruststorePassword.isNullOrEmpty())
AIVEN_KAFKA_CREDSTORE_PASSWORD
else AIVEN_KAFKA_OVERRIDE_TRUSTSTORE_PASSWORD
CREDSTORE_PASSWORD
else OVERRIDE_TRUSTSTORE_PASSWORD

return mapOf(
CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG to env.getValue(AIVEN_KAFKA_BOKERS),
CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG to env.getValue(KAFKA_BOKERS),
CommonClientConfigs.CLIENT_ID_CONFIG to "k9-punsj-${InetAddress.getLocalHost().hostName}",
CommonClientConfigs.SECURITY_PROTOCOL_CONFIG to SecurityProtocol.SSL.name,
SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG to "",
SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG to "jks",
SslConfigs.SSL_KEYSTORE_TYPE_CONFIG to "PKCS12",
SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG to env.getValue(AIVEN_KAFKA_TRUSTSTORE_PATH),
SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG to env.getValue(AIVEN_KAFKA_KEYSTORE_PATH),
SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG to env.getValue(KAFKA_TRUSTSTORE_PATH),
SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG to env.getValue(KAFKA_KEYSTORE_PATH),
SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG to env.getValue(truststorePasswordKey),
SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG to env.getValue(AIVEN_KAFKA_CREDSTORE_PASSWORD)
SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG to env.getValue(CREDSTORE_PASSWORD)
)
}

private fun kafkaConsumerFactory(baseProperties: Map<String, Any>): ConsumerFactory<String, String> =
private fun byggKafkaConsumerFactory(baseProperties: Map<String, Any>): ConsumerFactory<String, String> =
DefaultKafkaConsumerFactory(baseProperties.medConsumerConfig())

private fun kafkaListenerContainerFactory(consumerFactory: ConsumerFactory<String, String>): KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> {
private fun byggKafkaListenerContainerFactory(consumerFactory: ConsumerFactory<String, String>): KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> {
val factory = ConcurrentKafkaListenerContainerFactory<String, String>()
factory.containerProperties.setAuthExceptionRetryInterval(Duration.ofMillis(RETRY_INTERVAL))
factory.setCommonErrorHandler(CommonContainerStoppingErrorHandler())
factory.consumerFactory = consumerFactory
return factory
}

private fun kafkaTemplate(baseProperties: Map<String, Any>): KafkaTemplate<String, String> =
private fun byggKafkaTemplate(baseProperties: Map<String, Any>): KafkaTemplate<String, String> =
KafkaTemplate(DefaultKafkaProducerFactory(baseProperties.medProducerConfig()))

@Bean
@Qualifier(AIVEN)
@IkkeLokalProfil
fun aivenKafkaConsumerFactory(
@Qualifier(AIVEN) baseProperties: Map<String, Any>
) = kafkaConsumerFactory(baseProperties)

@Bean(AIVEN_CONTAINER_FACTORY)
@Qualifier(AIVEN)
@IkkeLokalProfil
fun aivenKafkaListenerContainerFactory(
@Qualifier(AIVEN) consumerFactory: ConsumerFactory<String, String>
fun kafkaConsumerFactory(
baseProperties: Map<String, Any>
) = byggKafkaConsumerFactory(baseProperties)

@Bean
fun kafkaListenerContainerFactory(
consumerFactory: ConsumerFactory<String, String>
): KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> =
kafkaListenerContainerFactory(consumerFactory)
byggKafkaListenerContainerFactory(consumerFactory)

@Bean
@Qualifier(AIVEN)
@IkkeLokalProfil
fun aivenKafkaTemplate(
@Qualifier(AIVEN) baseProperties: Map<String, Any>
): KafkaTemplate<String, String> = kafkaTemplate(baseProperties)
fun kafkaTemplate(
baseProperties: Map<String, Any>
): KafkaTemplate<String, String> = byggKafkaTemplate(baseProperties)

internal companion object {

internal const val AIVEN = "aiven"
internal const val AIVEN_CONTAINER_FACTORY = "aivenKafkaListenerContainerFactory"

private const val RETRY_INTERVAL = 1000L


private const val AIVEN_KAFKA_BOKERS = "KAFKA_BROKERS"
private const val AIVEN_KAFKA_TRUSTSTORE_PATH = "KAFKA_TRUSTSTORE_PATH"
private const val AIVEN_KAFKA_KEYSTORE_PATH = "KAFKA_KEYSTORE_PATH"
private const val AIVEN_KAFKA_CREDSTORE_PASSWORD = "KAFKA_CREDSTORE_PASSWORD"
private const val AIVEN_KAFKA_OVERRIDE_TRUSTSTORE_PASSWORD = "KAFKA_OVERRIDE_TRUSTSTORE_PASSWORD"
private const val KAFKA_BOKERS = "KAFKA_BROKERS"
private const val KAFKA_TRUSTSTORE_PATH = "KAFKA_TRUSTSTORE_PATH"
private const val KAFKA_KEYSTORE_PATH = "KAFKA_KEYSTORE_PATH"
private const val CREDSTORE_PASSWORD = "KAFKA_CREDSTORE_PASSWORD"
private const val OVERRIDE_TRUSTSTORE_PASSWORD = "KAFKA_OVERRIDE_TRUSTSTORE_PASSWORD"

private fun Map<String, Any>.medProducerConfig() = toMutableMap().also {
it[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java
Expand Down
17 changes: 7 additions & 10 deletions src/main/kotlin/no/nav/k9punsj/fordel/KafkaConsumers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package no.nav.k9punsj.fordel
import kotlinx.coroutines.runBlocking
import no.nav.k9punsj.StandardProfil
import no.nav.k9punsj.fordel.FordelPunsjEventDto.Companion.somFordelPunsjEventDto
import no.nav.k9punsj.configuration.KafkaConfig
import org.springframework.kafka.annotation.KafkaListener
import org.springframework.stereotype.Component
import java.io.IOException
Expand All @@ -15,29 +14,27 @@ class KafkaConsumers(
) {

@KafkaListener(
topics = [PUNSJBOLLE_AIVEN_TOPIC],
topics = [PUNSJBOLLE_TOPIC],
groupId = "k9-punsj-1",
properties = ["auto.offset.reset:earliest"],
containerFactory = KafkaConfig.AIVEN_CONTAINER_FACTORY
properties = ["auto.offset.reset:earliest"]
)
@Throws(IOException::class)
fun consumeAivenPunsjbarJournalpost(message: String) {
runBlocking { hendelseMottaker.prosesser(message.somFordelPunsjEventDto(PUNSJBOLLE_AIVEN_TOPIC)) }
fun consumePunsjbarJournalpost(message: String) {
runBlocking { hendelseMottaker.prosesser(message.somFordelPunsjEventDto(PUNSJBOLLE_TOPIC)) }
}

@KafkaListener(
topics = [FORDEL_TOPIC],
groupId = "k9-punsj-1",
properties = ["auto.offset.reset:earliest"],
containerFactory = KafkaConfig.AIVEN_CONTAINER_FACTORY
properties = ["auto.offset.reset:earliest"]
)
@Throws(IOException::class)
fun consumeAivenFordelJournalpost(message: String) {
fun consumeFordelJournalpost(message: String) {
runBlocking { hendelseMottaker.prosesser(message.somFordelPunsjEventDto(FORDEL_TOPIC)) }
}

private companion object {
private const val PUNSJBOLLE_AIVEN_TOPIC = "k9saksbehandling.punsjbar-journalpost"
private const val PUNSJBOLLE_TOPIC = "k9saksbehandling.punsjbar-journalpost"
private const val FORDEL_TOPIC = "k9saksbehandling.fordel-journalforing"
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package no.nav.k9punsj.innsending

import no.nav.k9punsj.StandardProfil
import no.nav.k9punsj.configuration.KafkaConfig.Companion.AIVEN
import org.apache.kafka.clients.CommonClientConfigs
import org.apache.kafka.clients.producer.KafkaProducer
import org.apache.kafka.clients.producer.ProducerConfig
import org.apache.kafka.clients.producer.ProducerRecord
import org.apache.kafka.common.serialization.StringSerializer
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component

@Component
@StandardProfil
class KopierJournalpostInnsendingClient(
@Qualifier(AIVEN) kafkaBaseProperties: Map<String, Any>,
kafkaBaseProperties: Map<String, Any>,
@Value("\${no.nav.kafka.k9_rapid.topic}") private val k9rapidTopic: String
): InnsendingClient {
private val clientId = kafkaBaseProperties.getValue(CommonClientConfigs.CLIENT_ID_CONFIG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import org.springframework.web.bind.annotation.*

@RestController
internal class JournalpostInfoContoller {
@GetMapping(JournalpostInfoRoutes.Urls.HentÅpneJournalposter, produces = ["application/json"])
fun HentÅpneJournalposter(@PathVariable("aktor_id") aktørId: String) {
}

@PostMapping(JournalpostInfoRoutes.Urls.HentÅpneJournalposterPost, produces = ["application/json"], consumes = ["application/json"])
fun HentÅpneJournalposterPost(@RequestBody dto: SøkUferdigJournalposter) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,12 @@ internal class JournalpostInfoRoutes(
private val journalpostService: JournalpostService
) {

private companion object {
private const val AktørIdKey = "aktor_id"
private val logger = LoggerFactory.getLogger(JournalpostInfoRoutes::class.java)
}

internal object Urls {
internal const val HentÅpneJournalposter = "/journalpost/uferdig/{$AktørIdKey}"
internal const val HentÅpneJournalposterPost = "/journalpost/uferdig"
}

@Bean
fun JournalpostInfoRoutes() = K9SakRoutes(authenticationHandler) {
GET("/api${Urls.HentÅpneJournalposter}") { request ->
RequestContext(coroutineContext, request) {
val aktørId = request.aktørId()
val journalpostIder = journalpostService.finnJournalposterPåPersonBareFraFordel(aktørId)
.map { journalpost -> JournalpostIdDto(journalpost.journalpostId) }

return@RequestContext ServerResponse
.ok()
.json()
.bodyValueAndAwait(JournalpostIderDto(journalpostIder))
}
}

POST("/api${Urls.HentÅpneJournalposterPost}") { request ->
RequestContext(coroutineContext, request) {
val dto = request.søkUferdigJournalposter()
Expand All @@ -67,8 +48,6 @@ internal class JournalpostInfoRoutes(
}
}

private fun ServerRequest.aktørId(): String = pathVariable(AktørIdKey)

private suspend fun ServerRequest.søkUferdigJournalposter() =
body(BodyExtractors.toMono(SøkUferdigJournalposter::class.java)).awaitFirst()

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package no.nav.k9punsj.kafka

import no.nav.k9punsj.IkkeTestProfil
import no.nav.k9punsj.configuration.KafkaConfig.Companion.AIVEN
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.kafka.core.KafkaTemplate
import org.springframework.stereotype.Component

@Component
@IkkeTestProfil
class KafkaHendelseProducer(
@Qualifier(AIVEN) private val kafkaTemplate: KafkaTemplate<String, String>
private val kafkaTemplate: KafkaTemplate<String, String>
) : HendelseProducer {
override fun send(topicName: String, data: String, key: String) {
kafkaTemplate.send(topicName, key, data).exceptionally {
Expand Down
42 changes: 15 additions & 27 deletions src/test/kotlin/no/nav/k9punsj/MockKafkaConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import org.apache.kafka.clients.consumer.ConsumerConfig
import org.apache.kafka.clients.producer.ProducerConfig
import org.apache.kafka.common.serialization.StringDeserializer
import org.apache.kafka.common.serialization.StringSerializer
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory
Expand All @@ -23,58 +22,47 @@ import java.time.Duration
class MockKafkaConfig {

@Bean
@Qualifier(AIVEN)
fun aivenKafkaBaseProperties(): Map<String, Any> {
val env = System.getenv()

fun kafkaBaseProperties(): Map<String, Any> {
return mapOf(
CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG to env.getOrDefault(AIVEN_KAFKA_BOKERS, "localhost:9092"),
CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG to "localhost:9092",
CommonClientConfigs.CLIENT_ID_CONFIG to "k9-punsj-lokalt",
)
}

private fun kafkaConsumerFactory(baseProperties: Map<String, Any>): ConsumerFactory<String, String> =
private fun byggKafkaConsumerFactory(baseProperties: Map<String, Any>): ConsumerFactory<String, String> =
DefaultKafkaConsumerFactory(baseProperties.medConsumerConfig())

private fun kafkaListenerContainerFactory(consumerFactory: ConsumerFactory<String, String>): KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> {
private fun byggKafkaListenerContainerFactory(consumerFactory: ConsumerFactory<String, String>): KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> {
val factory = ConcurrentKafkaListenerContainerFactory<String, String>()
factory.containerProperties.setAuthExceptionRetryInterval(Duration.ofMillis(RETRY_INTERVAL))
factory.setCommonErrorHandler(CommonContainerStoppingErrorHandler())
factory.consumerFactory = consumerFactory
return factory
}

private fun kafkaTemplate(baseProperties: Map<String, Any>): KafkaTemplate<String, String> =
private fun byggKafkaTemplate(baseProperties: Map<String, Any>): KafkaTemplate<String, String> =
KafkaTemplate(DefaultKafkaProducerFactory(baseProperties.medProducerConfig()))

@Bean
@Qualifier(AIVEN)
fun aivenKafkaConsumerFactory(
@Qualifier(AIVEN) baseProperties: Map<String, Any>
) = kafkaConsumerFactory(baseProperties)
fun kafkaConsumerFactory(
baseProperties: Map<String, Any>
) = byggKafkaConsumerFactory(baseProperties)

@Bean(AIVEN_CONTAINER_FACTORY)
@Qualifier(AIVEN)
fun aivenKafkaListenerContainerFactory(
@Qualifier(AIVEN) consumerFactory: ConsumerFactory<String, String>
@Bean
fun kafkaListenerContainerFactory(
consumerFactory: ConsumerFactory<String, String>
): KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> =
kafkaListenerContainerFactory(consumerFactory)
byggKafkaListenerContainerFactory(consumerFactory)

@Bean
@Qualifier(AIVEN)
fun aivenKafkaTemplate(
@Qualifier(AIVEN) baseProperties: Map<String, Any>
): KafkaTemplate<String, String> = kafkaTemplate(baseProperties)
fun kafkaTemplate(
baseProperties: Map<String, Any>
): KafkaTemplate<String, String> = byggKafkaTemplate(baseProperties)

internal companion object {

internal const val AIVEN = "aiven"
internal const val AIVEN_CONTAINER_FACTORY = "aivenKafkaListenerContainerFactory"

private const val RETRY_INTERVAL = 1000L

private const val AIVEN_KAFKA_BOKERS = "KAFKA_BROKERS"

private fun Map<String, Any>.medProducerConfig() = toMutableMap().also {
it[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java
it[ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ class PunsjJournalpostInfoRoutesTest {
private val client = TestSetup.client
private val k9sakToken = "Bearer ${no.nav.helse.dusseldorf.testsupport.jws.NaisSts.k9SakToken()}"

@Test
fun `Får en liste med journalpostIder som ikke er ferdig behandlet av punsj`(): Unit = runBlocking {
val res = client.get().uri {
it.pathSegment("api", "journalpost", "uferdig", "1000000000000").build()
}.header(HttpHeaders.AUTHORIZATION, k9sakToken)

val status = res.awaitStatuscode()
assertEquals(HttpStatus.OK, status)
}

@Test
fun `Får en liste med journalpostIder som ikke er ferdig behandlet av punsj post`(): Unit = runBlocking {
val json: JsonB = objectMapper().convertValue(SøkUferdigJournalposter("1000000000000", null))
Expand Down

0 comments on commit e54f439

Please sign in to comment.