Skip to content

Commit

Permalink
Oppdatert bekreftelse etter rename av avro-meldinger, lagt til github…
Browse files Browse the repository at this point in the history
… action for bekreftelse-api
  • Loading branch information
naviktthomas committed Sep 16, 2024
1 parent dbaa15a commit 9257f5c
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 57 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/bekreftelse-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Bekreftelse API

on:
push:
branches:
- main
- dev/*
paths:
- 'apps/bekreftelse-api/**'
- 'lib/**'
- 'domain/**'
- '.github/workflows/bekreftelse-api.yaml'
- 'gradle/**'
- 'settings.gradle.kts'
- 'gradle.properties'
- 'gradlew'
- 'gradlew.bat'

env:
MODULE: bekreftelse-api
IMAGE: europe-north1-docker.pkg.dev/${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}/paw/paw-arbeidssoeker-bekreftelse-api
jobs:
build:
name: Build
permissions:
contents: read
id-token: write
packages: write
runs-on: ubuntu-latest
outputs:
image: ${{ steps.docker-build-push.outputs.image }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: gradle
- name: Set version
run: echo "VERSION=$(date +'%y.%m.%d').${{ github.run_number }}-${{ github.run_attempt }}" >> $GITHUB_ENV
- name: Login GAR
uses: nais/login@v0
with:
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
team: paw
- name: Build and push image with Gradle
id: docker-build-push
working-directory: ./
env:
ORG_GRADLE_PROJECT_githubPassword: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "image=${{ env.IMAGE }}:${{ env.VERSION }}" >> $GITHUB_OUTPUT
echo -Pversion=${{ env.VERSION }} -Pimage=${{ env.IMAGE }} :apps:${{ env.MODULE }}:build :apps:${{ env.MODULE }}:jib
./gradlew -Pversion=${{ env.VERSION }} -Pimage=${{ env.IMAGE }} :apps:${{ env.MODULE }}:build :apps:${{ env.MODULE }}:jib
echo "DIGEST=$(cat ./apps/${{ env.MODULE }}/build/jib-image.digest)" >> $GITHUB_ENV
- name: Attest and sign image
uses: nais/[email protected]
with:
image_ref: ${{ env.IMAGE }}@${{ env.DIGEST }}

deploy-dev:
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/dev')
name: Deploy to dev-gcp
needs:
- build
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy to GCP
uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: dev-gcp
RESOURCE: ./apps/${{ env.MODULE }}/nais/nais-dev.yaml
VAR: image=${{ needs.build.outputs.image }}

# deploy-prod:
# if: github.ref == 'refs/heads/main'
# name: Deploy to prod-gcp
# needs:
# - build
# - deploy-dev
# permissions:
# contents: read
# id-token: write
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Deploy to GCP
# uses: nais/deploy/actions/deploy@v2
# env:
# TEAM: paw
# CLUSTER: prod-gcp
# RESOURCE: ./apps/${{ env.MODULE }}/nais/nais-prod.yaml
# VAR: image=${{ needs.build.outputs.image }}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fun Application.module(
) {
configureMetrics(dependencies.prometheusMeterRegistry)
configureHTTP()
configureAuthentication(applicationConfig.authProviders)
configureAuthentication(applicationConfig)
configureLogging()
configureSerialization()
configureTracing()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ package no.nav.paw.bekreftelse.api.kafka

import no.nav.paw.bekreftelse.api.config.ApplicationConfig
import no.nav.paw.bekreftelse.api.model.BekreftelseRequest
import no.nav.paw.bekreftelse.api.utils.buildMeldingSerde
import no.nav.paw.bekreftelse.api.utils.buildBekreftelseSerde
import no.nav.paw.bekreftelse.api.utils.logger
import no.nav.paw.bekreftelse.internehendelser.BekreftelseTilgjengelig
import no.nav.paw.bekreftelse.melding.v1.Bekreftelse
import no.nav.paw.config.kafka.KafkaFactory
import no.nav.paw.config.kafka.sendDeferred
import no.nav.paw.rapportering.melding.v1.Melding
import org.apache.kafka.clients.producer.Producer
import org.apache.kafka.clients.producer.ProducerRecord
import org.apache.kafka.common.serialization.LongSerializer

class BekreftelseProducer(
private val applicationConfig: ApplicationConfig,
) {
private lateinit var producer: Producer<Long, Melding>
private val meldingSerde = buildMeldingSerde()
private lateinit var producer: Producer<Long, Bekreftelse>
private val bekreftelseSerde = buildBekreftelseSerde()

init {
initializeProducer()
Expand All @@ -25,14 +25,14 @@ class BekreftelseProducer(
private fun initializeProducer() {
val kafkaFactory = KafkaFactory(applicationConfig.kafkaClients)
producer =
kafkaFactory.createProducer<Long, Melding>(
kafkaFactory.createProducer<Long, Bekreftelse>(
clientId = applicationConfig.kafkaTopology.producerId,
keySerializer = LongSerializer::class,
valueSerializer = meldingSerde.serializer()::class
valueSerializer = bekreftelseSerde.serializer()::class
)
}

suspend fun produceMessage(key: Long, message: Melding) {
suspend fun produceMessage(key: Long, message: Bekreftelse) {
val topic = applicationConfig.kafkaTopology.bekreftelseTopic
val record = ProducerRecord(topic, key, message)
val recordMetadata = producer.sendDeferred(record).await()
Expand All @@ -44,7 +44,7 @@ class BekreftelseProducer(
}
}

fun createMelding(state: BekreftelseTilgjengelig, bekreftelse: BekreftelseRequest): Melding = TODO()
fun createMelding(state: BekreftelseTilgjengelig, bekreftelse: BekreftelseRequest): Bekreftelse = TODO()
//Melding.newBuilder()
// .setId(ApplicationInfo.id)
// .setNamespace("paw")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@ package no.nav.paw.bekreftelse.api.plugins

import io.ktor.server.application.Application
import io.ktor.server.auth.authentication
import no.nav.paw.bekreftelse.api.config.AuthProviders
import no.nav.paw.bekreftelse.api.config.ApplicationConfig
import no.nav.security.token.support.v2.IssuerConfig
import no.nav.security.token.support.v2.RequiredClaims
import no.nav.security.token.support.v2.TokenSupportConfig
import no.nav.security.token.support.v2.tokenValidationSupport

fun Application.configureAuthentication(authProviders: AuthProviders) =
authentication {
authProviders.forEach { provider ->
tokenValidationSupport(
name = provider.name,
requiredClaims = RequiredClaims(
provider.name,
provider.claims.map.toTypedArray(),
provider.claims.combineWithOr
),
config = TokenSupportConfig(
IssuerConfig(
name = provider.name,
discoveryUrl = provider.discoveryUrl,
acceptedAudience = listOf(provider.clientId)
fun Application.configureAuthentication(applicationConfig: ApplicationConfig) {
with(applicationConfig) {
authentication {
authProviders.forEach { provider ->
tokenValidationSupport(
name = provider.name,
requiredClaims = RequiredClaims(
provider.name,
provider.claims.map.toTypedArray(),
provider.claims.combineWithOr
),
config = TokenSupportConfig(
IssuerConfig(
name = provider.name,
discoveryUrl = provider.discoveryUrl,
acceptedAudience = listOf(provider.clientId)
)
)
)
)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde
import no.nav.paw.bekreftelse.api.model.InternState
import no.nav.paw.bekreftelse.melding.v1.Bekreftelse
import no.nav.paw.config.env.NaisEnv
import no.nav.paw.config.env.currentNaisEnv
import no.nav.paw.rapportering.melding.v1.Melding
import org.apache.kafka.common.serialization.Deserializer
import org.apache.kafka.common.serialization.Serde
import org.apache.kafka.common.serialization.Serializer
Expand Down Expand Up @@ -52,4 +52,4 @@ inline fun <reified T> buildJsonSerde(): Serde<T> {

fun buildInternStateSerde() = buildJsonSerde<InternState>()

fun buildMeldingSerde() = SpecificAvroSerde<Melding>()
fun buildBekreftelseSerde() = SpecificAvroSerde<Bekreftelse>()
4 changes: 3 additions & 1 deletion apps/bekreftelse-api/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
<logger name="org.apache.kafka.clients.consumer.ConsumerConfig" level="WARN"/>
<logger name="org.apache.kafka.clients.producer.ProducerConfig" level="WARN"/>
<logger name="io.confluent.kafka.serializers.KafkaAvroSerializerConfig" level="WARN"/>
<logger name="no.nav.paw" level="DEBUG"/>
<logger name="no.nav" level="DEBUG"/>
<logger name="io.ktor.auth" level="DEBUG"/>
<logger name="io.ktor.server.auth" level="DEBUG"/>
</then>
<else>
<logger name="tjenestekall" level="DEBUG" additivity="false">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.nav.paw.bekretelsetjeneste

import no.nav.paw.config.kafka.streams.genericProcess
import no.nav.paw.rapportering.ansvar.v1.AnsvarEndret
import no.nav.paw.bekreftelse.ansvar.v1.AnsvarEndret
import no.nav.paw.bekreftelse.internehendelser.BekreftelseHendelse
import org.apache.kafka.streams.StreamsBuilder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import no.nav.paw.bekretelsetjeneste.tilstand.Tilstand
import no.nav.paw.bekretelsetjeneste.tilstand.Tilstand.KlarForUtfylling
import no.nav.paw.bekretelsetjeneste.tilstand.Tilstand.VenterSvar
import no.nav.paw.config.kafka.streams.genericProcess
import no.nav.paw.rapportering.melding.v1.Melding
import org.apache.kafka.streams.StreamsBuilder
import org.apache.kafka.streams.processor.api.Record
import org.slf4j.LoggerFactory
import java.util.*

context(ApplicationConfiguration, ApplicationContext)
fun StreamsBuilder.processBekreftelseMeldingTopic() {
stream<Long, Melding>(bekreftelseTopic)
.genericProcess<Long, Melding, Long, BekreftelseHendelse>(
stream<Long, no.nav.paw.bekreftelse.melding.v1.Bekreftelse>(bekreftelseTopic)
.genericProcess<Long, no.nav.paw.bekreftelse.melding.v1.Bekreftelse, Long, BekreftelseHendelse>(
name = "meldingMottatt",
stateStoreName
) { record ->
Expand Down Expand Up @@ -52,7 +51,7 @@ fun StreamsBuilder.processBekreftelseMeldingTopic() {
}
}

fun behandleGyldigSvar(arbeidssoekerId: Long, record: Record<Long, Melding>, bekreftelse: Bekreftelse): Pair<List<BekreftelseHendelse>, Bekreftelse> {
fun behandleGyldigSvar(arbeidssoekerId: Long, record: Record<Long, no.nav.paw.bekreftelse.melding.v1.Bekreftelse>, bekreftelse: Bekreftelse): Pair<List<BekreftelseHendelse>, Bekreftelse> {
val oppdatertBekreftelse = bekreftelse.copy(tilstand = Tilstand.Levert)
val baOmAaAvslutte = if (!record.value().svar.vilFortsetteSomArbeidssoeker) {
BaOmAaAvsluttePeriode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const val APPLICATION_ID_SUFFIX = "beta"
fun main() {
val applicationConfiguration = ApplicationConfiguration(
periodeTopic = "paw.arbeidssokerperioder-v1",
ansvarsTopic = "paw.bekreftelse-ansvar-v1",
bekreftelseTopic = "paw.bekreftelse-svar-v1",
bekreftelseHendelseloggTopic = "paw.bekreftelse-hendelselogg-v1",
ansvarsTopic = "paw.arbeidssoker-bekreftelse-ansvar-beta-v1",
bekreftelseTopic = "paw.arbeidssoker-bekreftelse-beta-v1",
bekreftelseHendelseloggTopic = "paw.arbeidssoker-bekreftelse-hendelseslogg-beta-v1",
stateStoreName = "bekreftelse",
punctuateInterval = Duration.ofMinutes(5)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import io.confluent.kafka.schemaregistry.testutil.MockSchemaRegistry
import io.confluent.kafka.serializers.KafkaAvroSerializerConfig
import io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde
import no.nav.paw.arbeidssokerregisteret.api.v1.Periode
import no.nav.paw.kafkakeygenerator.client.KafkaKeysResponse
import no.nav.paw.kafkakeygenerator.client.inMemoryKafkaKeysMock
import no.nav.paw.bekretelsetjeneste.tilstand.InternTilstandSerde
import no.nav.paw.rapportering.ansvar.v1.AnsvarEndret
import no.nav.paw.bekreftelse.ansvar.v1.AnsvarEndret
import no.nav.paw.bekreftelse.internehendelser.BekreftelseHendelse
import no.nav.paw.bekreftelse.internehendelser.BekreftelseHendelseSerde
import no.nav.paw.rapportering.melding.v1.Melding
import no.nav.paw.bekreftelse.melding.v1.Bekreftelse
import no.nav.paw.bekretelsetjeneste.tilstand.InternTilstandSerde
import no.nav.paw.kafkakeygenerator.client.KafkaKeysResponse
import no.nav.paw.kafkakeygenerator.client.inMemoryKafkaKeysMock
import org.apache.avro.specific.SpecificRecord
import org.apache.kafka.common.serialization.Serde
import org.apache.kafka.common.serialization.Serdes
Expand All @@ -25,7 +25,7 @@ import java.util.*

class ApplicationTestContext {
val ansvarsTopicSerde: Serde<AnsvarEndret> = opprettSerde()
val rapporteringMeldingSerde: Serde<Melding> = opprettSerde()
val bekreftelseSerde: Serde<Bekreftelse> = opprettSerde()
val periodeTopicSerde: Serde<Periode> = opprettSerde()
val hendelseLoggSerde: Serde<BekreftelseHendelse> = BekreftelseHendelseSerde()
val applicationConfiguration = ApplicationConfiguration(
Expand Down Expand Up @@ -72,7 +72,7 @@ class ApplicationTestContext {
val rapporteringsTopic = testDriver.createInputTopic(
applicationConfiguration.bekreftelseTopic,
Serdes.Long().serializer(),
rapporteringMeldingSerde.serializer()
bekreftelseSerde.serializer()
)

val hendelseLoggTopic = testDriver.createOutputTopic(
Expand Down
4 changes: 2 additions & 2 deletions domain/bekreftelsesansvar-schema/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ val schema by configurations.creating {
}

dependencies {
schema(rapportering.rapporteringsansvarSchema)
implementation(rapportering.rapporteringsansvarSchema)
schema(bekreftelse.bekreftelsesansvarSchema)
implementation(bekreftelse.bekreftelsesansvarSchema)
api(apacheAvro.avro)
}

Expand Down
4 changes: 2 additions & 2 deletions domain/bekreftelsesmelding-schema/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ val schema by configurations.creating {
}

dependencies {
schema(rapportering.rapporteringsmeldingSchema)
implementation(rapportering.rapporteringsmeldingSchema)
schema(bekreftelse.bekreftelsesmeldingSchema)
implementation(bekreftelse.bekreftelsesmeldingSchema)
api(apacheAvro.avro)
}

Expand Down
16 changes: 8 additions & 8 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencyResolutionManagement {
val pawPdlClientVersion = "24.08.08.40-1"
val pawAaregClientVersion = "24.07.04.18-1"
val arbeidssokerregisteretVersion = "1.9348086045.48-1"
val rapporteringsSchemaVersion = "24.09.11.8-1"
val bekreftelseSchemaVersion = "24.09.16.1-1"


//Arrow
Expand Down Expand Up @@ -265,17 +265,17 @@ dependencyResolutionManagement {
create("poao") {
library("tilgangClient", "no.nav.poao-tilgang", "client").version("2024.04.29_13.59-a0ddddd36ac9")
}
create("rapportering") {
create("bekreftelse") {
library(
"rapporteringsansvarSchema",
"bekreftelsesansvarSchema",
"no.nav.paw.arbeidssokerregisteret.api",
"rapporteringsansvar-schema"
).version(rapporteringsSchemaVersion)
"bekreftelsesansvar-schema"
).version(bekreftelseSchemaVersion)
library(
"rapporteringsmeldingSchema",
"bekreftelsesmeldingSchema",
"no.nav.paw.arbeidssokerregisteret.api",
"rapporteringsmelding-schema"
).version(rapporteringsSchemaVersion)
"bekreftelsesmelding-schema"
).version(bekreftelseSchemaVersion)
}
}
}

0 comments on commit 9257f5c

Please sign in to comment.