Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IS-2720: Upgrade to Ktor3 and some other deps #386

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ val dialogmeldingVersion = "1.5d21db9"
val fellesformat2Version = "1.0329dd1"
val flywayVersion = "10.17.3"
val hikariVersion = "5.1.0"
val jacksonVersion = "2.17.2"
val jacksonVersion = "2.18.2"
val jaxbVersion = "2.3.1"
val jsonVersion = "20240303"
val kafkaVersion = "3.7.0"
val kithApprecVersion = "2019.07.30-04-23-2a0d1388209441ec05d2e92a821eed4f796a3ae2"
val kithHodemeldingVersion = "2019.07.30-12-26-5c924ef4f04022bbb850aaf299eb8e4464c1ca6a"
val kluentVersion = "1.73"
val ktorVersion = "2.3.12"
val logbackVersion = "1.5.6"
val ktorVersion = "3.0.2"
val logbackVersion = "1.5.12"
val logstashEncoderVersion = "7.4"
val micrometerRegistryVersion = "1.12.7"
val mockkVersion = "1.13.9"
val mockkVersion = "1.13.13"
val mqVersion = "9.3.4.1"
val nimbusjosejwtVersion = "9.40"
val nimbusjosejwtVersion = "9.47"
val postgresVersion = "42.7.4"
val postgresEmbeddedVersion = "2.0.7"
val postgresEmbeddedVersion = "2.1.0"
val spekVersion = "2.0.19"
val syfotjenesterVersion = "1.2021.06.09-13.09-b3d30de9996e"

plugins {
kotlin("jvm") version "2.0.20"
id("com.gradleup.shadow") version "8.3.2"
kotlin("jvm") version "2.1.0"
id("com.gradleup.shadow") version "8.3.5"
id("org.jlleitschuh.gradle.ktlint") version "11.4.2"
}

Expand Down
167 changes: 82 additions & 85 deletions src/main/kotlin/no/nav/syfo/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,22 @@ fun main() {
lateinit var dialogmeldingToBehandlerService: DialogmeldingToBehandlerService
lateinit var dialogmeldingStatusService: DialogmeldingStatusService

val applicationEngineEnvironment = applicationEngineEnvironment {
val applicationEngineEnvironment = applicationEnvironment {
log = logger
config = HoconApplicationConfig(ConfigFactory.load())

connector {
port = applicationPort
}

module {
}
val server = embeddedServer(
factory = Netty,
environment = applicationEngineEnvironment,
configure = {
connector {
port = applicationPort
}
connectionGroupSize = 8
workerGroupSize = 8
callGroupSize = 16
},
module = {
databaseModule(environment = environment)

behandlerService = BehandlerService(
Expand Down Expand Up @@ -130,91 +137,81 @@ fun main() {
dialogmeldingToBehandlerService = dialogmeldingToBehandlerService,
veilederTilgangskontrollClient = veilederTilgangskontrollClient,
)
}
}

applicationEngineEnvironment.monitor.subscribe(ApplicationStarted) {
applicationState.ready = true
logger.info("Application is ready, running Java VM ${Runtime.version()}")
launchKafkaTaskDialogmeldingBestilling(
applicationState = applicationState,
applicationEnvironmentKafka = environment.kafka,
dialogmeldingToBehandlerService = dialogmeldingToBehandlerService,
)
val dialogmeldingService = DialogmeldingService(
pdlClient = pdlClient,
mqSender = mqSender,
)
cronjobModule(
applicationState = applicationState,
environment = environment,
dialogmeldingToBehandlerService = dialogmeldingToBehandlerService,
dialogmeldingService = dialogmeldingService,
dialogmeldingStatusService = dialogmeldingStatusService,
behandlerService = behandlerService,
partnerinfoClient = partnerinfoClient,
legeSuspensjonClient = legeSuspensjonClient,
fastlegeClient = fastlegeClient,
syfohelsenettproxyClient = syfohelsenettproxyClient,
)
launchKafkaTaskSykmelding(
applicationState = applicationState,
applicationEnvironmentKafka = environment.kafka,
behandlerService = behandlerService,
)
launchKafkaTaskDialogmeldingFromBehandler(
applicationState = applicationState,
applicationEnvironmentKafka = environment.kafka,
database = applicationDatabase,
)
launchBackgroundTask(
applicationState = applicationState,
) {
val factory = connectionFactory(environment)

factory.createConnection(
environment.serviceuserUsername,
environment.serviceuserPassword,
).use { connection ->
connection.start()
val session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE)
val inputconsumer = session.consumerForQueue(environment.apprecQueueName)
val apprecService = ApprecService(
monitor.subscribe(ApplicationStarted) {
applicationState.ready = true
logger.info("Application is ready, running Java VM ${Runtime.version()}")
launchKafkaTaskDialogmeldingBestilling(
applicationState = applicationState,
applicationEnvironmentKafka = environment.kafka,
dialogmeldingToBehandlerService = dialogmeldingToBehandlerService,
)
val dialogmeldingService = DialogmeldingService(
pdlClient = pdlClient,
mqSender = mqSender,
)
cronjobModule(
applicationState = applicationState,
environment = environment,
dialogmeldingToBehandlerService = dialogmeldingToBehandlerService,
dialogmeldingService = dialogmeldingService,
dialogmeldingStatusService = dialogmeldingStatusService,
behandlerService = behandlerService,
partnerinfoClient = partnerinfoClient,
legeSuspensjonClient = legeSuspensjonClient,
fastlegeClient = fastlegeClient,
syfohelsenettproxyClient = syfohelsenettproxyClient,
)
launchKafkaTaskSykmelding(
applicationState = applicationState,
applicationEnvironmentKafka = environment.kafka,
behandlerService = behandlerService,
)
launchKafkaTaskDialogmeldingFromBehandler(
applicationState = applicationState,
applicationEnvironmentKafka = environment.kafka,
database = applicationDatabase,
)
val blockingApplicationRunner = ApprecConsumer(
launchBackgroundTask(
applicationState = applicationState,
) {
val factory = connectionFactory(environment)

factory.createConnection(
environment.serviceuserUsername,
environment.serviceuserPassword,
).use { connection ->
connection.start()
val session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE)
val inputconsumer = session.consumerForQueue(environment.apprecQueueName)
val apprecService = ApprecService(
database = applicationDatabase,
)
val blockingApplicationRunner = ApprecConsumer(
applicationState = applicationState,
database = applicationDatabase,
inputconsumer = inputconsumer,
apprecService = apprecService,
dialogmeldingToBehandlerService = dialogmeldingToBehandlerService,
)
blockingApplicationRunner.run()
}
}
val identhendelseService = IdenthendelseService(
database = applicationDatabase,
inputconsumer = inputconsumer,
apprecService = apprecService,
dialogmeldingToBehandlerService = dialogmeldingToBehandlerService,
pdlClient = pdlClient,
)
val identhendelseConsumerService = IdenthendelseConsumerService(
identhendelseService = identhendelseService,
)

launchKafkaTaskIdenthendelse(
applicationState = applicationState,
applicationEnvironmentKafka = environment.kafka,
kafkaIdenthendelseConsumerService = identhendelseConsumerService,
)
blockingApplicationRunner.run()
}
}
val identhendelseService = IdenthendelseService(
database = applicationDatabase,
pdlClient = pdlClient,
)
val identhendelseConsumerService = IdenthendelseConsumerService(
identhendelseService = identhendelseService,
)

launchKafkaTaskIdenthendelse(
applicationState = applicationState,
applicationEnvironmentKafka = environment.kafka,
kafkaIdenthendelseConsumerService = identhendelseConsumerService,
)
}

val server = embeddedServer(
factory = Netty,
environment = applicationEngineEnvironment,
) {
connectionGroupSize = 8
workerGroupSize = 8
callGroupSize = 16
}
)

Runtime.getRuntime().addShutdownHook(
Thread {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package no.nav.syfo.behandler.api.access

import io.ktor.server.application.*
import io.ktor.util.pipeline.*
import io.ktor.server.routing.*
import no.nav.syfo.client.veiledertilgang.VeilederTilgangskontrollClient
import no.nav.syfo.domain.Personident
import no.nav.syfo.util.getBearerHeader
import no.nav.syfo.util.getCallId

suspend fun PipelineContext<out Unit, ApplicationCall>.validateVeilederAccess(
suspend fun RoutingContext.validateVeilederAccess(
action: String,
personidentToAccess: Personident,
veilederTilgangskontrollClient: VeilederTilgangskontrollClient,
Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/no/nav/syfo/util/RequestUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package no.nav.syfo.util

import io.ktor.server.application.*
import io.ktor.http.*
import io.ktor.server.routing.*
import io.ktor.util.pipeline.*
import net.logstash.logback.argument.StructuredArguments

const val NAV_CALL_ID_HEADER = "Nav-Call-Id"
const val NAV_PERSONIDENT_HEADER = "nav-personident"

fun PipelineContext<out Unit, ApplicationCall>.getCallId(): String {
fun RoutingContext.getCallId(): String {
return this.call.getCallId()
}
fun ApplicationCall.getCallId(): String {
Expand All @@ -17,16 +18,16 @@ fun ApplicationCall.getCallId(): String {

fun callIdArgument(callId: String) = StructuredArguments.keyValue("callId", callId)!!

fun PipelineContext<out Unit, ApplicationCall>.getBearerHeader(): String? {
fun RoutingContext.getBearerHeader(): String? {
return this.call.request.headers[HttpHeaders.Authorization]?.removePrefix("Bearer ")
}

fun PipelineContext<out Unit, ApplicationCall>.getPersonidentHeader(): String? {
fun RoutingContext.getPersonidentHeader(): String? {
return this.call.request.headers[NAV_PERSONIDENT_HEADER]
}

suspend fun PipelineContext<out Unit, ApplicationCall>.withValidToken(
block: suspend PipelineContext<out Unit, ApplicationCall>.() -> Unit
suspend fun RoutingContext.withValidToken(
block: suspend RoutingContext.() -> Unit
) {
if (getBearerHeader() != null) {
block()
Expand Down
Loading
Loading