Skip to content

Commit

Permalink
Task/update dependencies second try (#111)
Browse files Browse the repository at this point in the history
* Oppdatere 3.parts biblioteker

* BUG: Using blocking primitives on this dispatcher is not allowed. Consider using async channel instead or use blocking primitives in withContext(Dispatchers.IO) instead.
Ser ut til at vi treffer samme bug som i https://youtrack.jetbrains.com/issue/KTOR-1286
Workaround: Pakke call.receive inn i coroutine IO kontekst
  • Loading branch information
geiralund authored Feb 19, 2021
1 parent 6898362 commit d66ffbc
Show file tree
Hide file tree
Showing 18 changed files with 214 additions and 183 deletions.
37 changes: 19 additions & 18 deletions buildSrc/src/main/kotlin/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object Cucumber {
object Dagpenger {

object Biblioteker {
const val version = "2020.07.30-12.21.8857eb1469bf"
const val version = "2020.11.24-08.15.86482b2eead8"
const val stsKlient = "com.github.navikt.dp-biblioteker:sts-klient:$version"
const val grunnbeløp = "com.github.navikt.dp-biblioteker:grunnbelop:$version"
const val ktorUtils = "com.github.navikt.dp-biblioteker:ktor-utils:$version"
Expand All @@ -45,8 +45,8 @@ object Dagpenger {
}
}

const val Streams = "com.github.navikt:dagpenger-streams:2020.05.15-23.03.e0ab571caee4"
const val Events = "com.github.navikt:dagpenger-events:2020.05.15-21.57.e4685fc2a371"
const val Streams = "com.github.navikt:dagpenger-streams:2020.08.19-13.32.0fd360f3ef11"
const val Events = "com.github.navikt:dagpenger-events:2020.08.19-10.57.d2fe892352eb"
}

object Database {
Expand All @@ -69,18 +69,19 @@ object GradleWrapper {
}

object Jackson {
const val version = "2.10.3"
const val version = "2.12.1"
const val core = "com.fasterxml.jackson.core:jackson-core:$version"
const val kotlin = "com.fasterxml.jackson.module:jackson-module-kotlin:$version"
const val jsr310 = "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$version"
}

object Junit5 {
const val version = "5.6.1"
const val version = "5.7.1"
const val api = "org.junit.jupiter:junit-jupiter-api:$version"
const val params = "org.junit.jupiter:junit-jupiter-params:$version"
const val engine = "org.junit.jupiter:junit-jupiter-engine:$version"
const val vintageEngine = "org.junit.vintage:junit-vintage-engine:$version"
const val kotlinRunner = "io.kotlintest:kotlintest-runner-junit5:3.4.2"
fun library(name: String) = "org.junit.jupiter:junit-jupiter-$name:$version"
}

Expand Down Expand Up @@ -121,22 +122,22 @@ object Konfig {
}

object Kotlin {
const val version = "1.3.72"
const val version = "1.4.30"
const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib:$version"

object Coroutines {
const val version = "1.3.7"
const val version = "1.4.2"
fun module(name: String) = "org.jetbrains.kotlinx:kotlinx-coroutines-$name:$version"
}

object Logging {
const val version = "1.7.9"
const val version = "2.0.4"
const val kotlinLogging = "io.github.microutils:kotlin-logging:$version"
}
}

object KoTest {
const val version = "4.0.3"
const val version = "4.4.1"

// for kotest framework
const val runner = "io.kotest:kotest-runner-junit5-jvm:$version"
Expand All @@ -156,7 +157,7 @@ object Kotlinx {
}

object Ktor {
const val version = "1.3.2"
const val version = "1.5.1"
const val server = "io.ktor:ktor-server:$version"
const val serverNetty = "io.ktor:ktor-server-netty:$version"
const val auth = "io.ktor:ktor-auth:$version"
Expand All @@ -168,15 +169,15 @@ object Ktor {
}

object Log4j2 {
const val version = "2.13.1"
const val version = "2.14.0"
const val api = "org.apache.logging.log4j:log4j-api:$version"
const val core = "org.apache.logging.log4j:log4j-core:$version"
const val slf4j = "org.apache.logging.log4j:log4j-slf4j-impl:$version"

fun library(name: String) = "org.apache.logging.log4j:log4j-$name:$version"

object Logstash {
private const val version = "1.0.2"
private const val version = "1.0.5"
const val logstashLayout = "com.vlkan.log4j2:log4j2-logstash-layout:$version"
}
}
Expand All @@ -198,7 +199,7 @@ object Moshi {
}

object Mockk {
const val version = "1.10.0"
const val version = "1.10.6"
const val mockk = "io.mockk:mockk:$version"
}

Expand All @@ -220,19 +221,19 @@ object Prometheus {
}
}

const val RapidAndRivers = "com.github.navikt:rapids-and-rivers:1.74ae9cb"
const val RapidAndRivers = "com.github.navikt:rapids-and-rivers:1.6d6256d"

object Slf4j {
const val version = "1.7.25"
const val api = "org.slf4j:slf4j-api:$version"
}

object Ktlint {
const val version = "0.37.2"
const val version = "0.38.1"
}

object Spotless {
const val version = "5.1.0"
const val version = "5.10.1"
const val spotless = "com.diffplug.spotless"
}

Expand All @@ -257,12 +258,12 @@ object Vault {
}

object Wiremock {
const val version = "2.21.0"
const val version = "2.27.2"
const val standalone = "com.github.tomakehurst:wiremock-standalone:$version"
}

object Graphql {
const val version = "3.1.1"
const val version = "4.0.0-alpha.12"
const val graphql = "com.expediagroup.graphql"
val client = library("client")
fun library(name: String) = "com.expediagroup:graphql-kotlin-$name:$version"
Expand Down
6 changes: 4 additions & 2 deletions dp-inntekt-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ buildscript {
}

repositories {
mavenCentral()
maven("https://packages.confluent.io/maven/")
}

Expand All @@ -20,7 +21,7 @@ application {
mainClassName = "no.nav.dagpenger.inntekt.ApplicationKt"
}

val grpcVersion = "1.29.0"
val grpcVersion = "1.35.0"

dependencies {
implementation(project(":dp-inntekt-grpc"))
Expand All @@ -36,6 +37,7 @@ dependencies {
implementation(Micrometer.prometheusRegistry)

implementation(Graphql.client)
implementation(Graphql.library("ktor-client"))
implementation(Ktor.library("client-logging-jvm"))
implementation(Ktor.library("client-apache"))

Expand Down Expand Up @@ -90,10 +92,10 @@ dependencies {

testImplementation(kotlin("test"))
testImplementation(Ktor.ktorTest)
testImplementation(Ktor.library("client-mock"))
testImplementation(Junit5.api)
testImplementation(Junit5.params)
testRuntimeOnly(Junit5.engine)
testRuntimeOnly(Junit5.vintageEngine)
testImplementation(Wiremock.standalone)
testImplementation(KoTest.assertions)
testImplementation(KoTest.runner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun main() {
val pdlPersonOppslag = PdlGraphQLRepository(
client = PdlGraphQLClientFactory(
url = config.pdl.url,
oidcProvider = { stsOidcClient.oidcToken().access_token }
oidcProvider = { runBlocking { stsOidcClient.oidcToken().access_token } }
)
)
val enhetsregisterClient = EnhetsregisterClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ internal class PostgresInntektStore(private val dataSource: DataSource) : Inntek
return using(sessionOf(dataSource)) { session ->
session.run(
queryOf(
statement, mapOf("inntektId" to inntektId.id)
statement,
mapOf("inntektId" to inntektId.id)
).map { row ->
row.localDateOrNull("beregningsdato")
}.asSingle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EnhetsregisterClient(
suspend fun hentEnhet(orgnummer: String): String {
return withContext(Dispatchers.IO) {
try {
httpClient.get<String>("$baseUrl/api/enheter/$orgnummer")
httpClient.get("$baseUrl/api/enheter/$orgnummer")
} catch (e: ClientRequestException) {
when (e.response.status.value) {
404 -> httpClient.get<String>("$baseUrl/api/underenheter/$orgnummer")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nav.dagpenger.inntekt.oppslag.pdl

import com.expediagroup.graphql.client.GraphQLClient
import com.expediagroup.graphql.client.ktor.GraphQLKtorClient
import com.expediagroup.graphql.types.GraphQLResponse
import io.ktor.client.features.defaultRequest
import io.ktor.client.features.logging.LogLevel
Expand All @@ -21,7 +22,7 @@ private val sikkerlogg = KotlinLogging.logger("tjenestekall")

@KtorExperimentalAPI
class PdlGraphQLRepository constructor(
client: GraphQLClient<*>
client: GraphQLClient
) : PersonOppslag {

private val query = HentPerson(client)
Expand Down Expand Up @@ -56,7 +57,7 @@ class PdlGraphQLRepository constructor(
fun PdlGraphQLClientFactory(
url: String,
oidcProvider: () -> String
) = GraphQLClient(url = URL(url)) {
) = GraphQLKtorClient(url = URL(url)) {
install(Logging) {
logger = object : Logger {
override fun log(message: String) = sikkerlogg.info { message }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,28 @@ import io.ktor.response.respondText
import io.ktor.routing.Route
import io.ktor.routing.get
import io.ktor.routing.route
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import no.nav.dagpenger.inntekt.oppslag.enhetsregister.EnhetsregisterClient

private const val CACHE_SECONDS = 86400

fun Route.enhetsregisteret(client: EnhetsregisterClient) {
route("enhetsregisteret") {
get("enhet/{orgnummer}") {
val orgnummer = call.parameters["orgnummer"] ?: throw BadRequestException("Orgnummer ikke spesifisert")
try {
val result = client.hentEnhet(orgnummer)
call.response.cacheControl(CacheControl.MaxAge(CACHE_SECONDS))
call.respondText(result, ContentType.Application.Json)
} catch (e: Exception) {
when (e) {
is ClientRequestException -> when (e.response.status.value) {
in 400..499 -> call.response.status(e.response.status)
} else -> call.response.status(HttpStatusCode.BadGateway)
withContext(Dispatchers.IO) {
val orgnummer = call.parameters["orgnummer"] ?: throw BadRequestException("Orgnummer ikke spesifisert")
try {
val result = client.hentEnhet(orgnummer)
call.response.cacheControl(CacheControl.MaxAge(CACHE_SECONDS))
call.respondText(result, ContentType.Application.Json)
} catch (e: Exception) {
when (e) {
is ClientRequestException -> when (e.response?.status?.value) {
in 400..499 -> call.response.status(e.response!!.status)
}
else -> call.response.status(HttpStatusCode.BadGateway)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,48 @@ import io.ktor.response.respond
import io.ktor.routing.Route
import io.ktor.routing.post
import io.ktor.routing.route
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.withContext
import no.nav.dagpenger.inntekt.BehandlingsInntektsGetter
import no.nav.dagpenger.inntekt.db.Inntektparametre
import java.time.LocalDate
import java.util.concurrent.Executors

val api = Executors.newFixedThreadPool(4).asCoroutineDispatcher()

fun Route.inntekt(behandlingsInntektsGetter: BehandlingsInntektsGetter) {
authenticate {
route("spesifisert") {
post {
val request = call.receive<InntektRequestMedFnr>()

val spesifisertInntekt = withContext(api) {
behandlingsInntektsGetter.getSpesifisertInntekt(
Inntektparametre(
aktørId = request.aktørId,
vedtakId = request.vedtakId,
beregningsdato = request.beregningsDato,
fødselnummer = request.fødselsnummer
withContext(IO) {
val request = call.receive<InntektRequestMedFnr>()

val spesifisertInntekt =
behandlingsInntektsGetter.getSpesifisertInntekt(
Inntektparametre(
aktørId = request.aktørId,
vedtakId = request.vedtakId,
beregningsdato = request.beregningsDato,
fødselnummer = request.fødselsnummer
)
)
)
}

call.respond(HttpStatusCode.OK, spesifisertInntekt)
call.respond(HttpStatusCode.OK, spesifisertInntekt)
}
}
}
route("klassifisert") {
post {
val request = call.receive<InntektRequestMedFnr>()

val klassifisertInntekt = withContext(api) {
behandlingsInntektsGetter.getKlassifisertInntekt(
Inntektparametre(
aktørId = request.aktørId,
vedtakId = request.vedtakId,
beregningsdato = request.beregningsDato,
fødselnummer = request.fødselsnummer
withContext(IO) {
val request = call.receive<InntektRequestMedFnr>()
val klassifisertInntekt =
behandlingsInntektsGetter.getKlassifisertInntekt(
Inntektparametre(
aktørId = request.aktørId,
vedtakId = request.vedtakId,
beregningsdato = request.beregningsDato,
fødselnummer = request.fødselsnummer
)
)
)
call.respond(HttpStatusCode.OK, klassifisertInntekt)
}

call.respond(HttpStatusCode.OK, klassifisertInntekt)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import io.ktor.response.respond
import io.ktor.routing.Route
import io.ktor.routing.post
import io.ktor.routing.route
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import no.nav.dagpenger.inntekt.db.InntektId
import no.nav.dagpenger.inntekt.db.InntektStore
import no.nav.dagpenger.inntekt.opptjeningsperiode.Opptjeningsperiode
Expand All @@ -18,19 +20,21 @@ fun Route.opptjeningsperiodeApi(inntektStore: InntektStore) {

route("is-samme-inntjeningsperiode") {
post {
val parametere = call.receive<InntjeningsperiodeParametre>()
withContext(Dispatchers.IO) {
val parametere = call.receive<InntjeningsperiodeParametre>()

val gammelBeregningsdato = inntektStore.getBeregningsdato(InntektId(parametere.inntektsId))
val gammelBeregningsdato = inntektStore.getBeregningsdato(InntektId(parametere.inntektsId))

val resultat = Opptjeningsperiode(gammelBeregningsdato).sammeOpptjeningsPeriode(
Opptjeningsperiode(
LocalDate.parse(parametere.beregningsdato)
val resultat = Opptjeningsperiode(gammelBeregningsdato).sammeOpptjeningsPeriode(
Opptjeningsperiode(
LocalDate.parse(parametere.beregningsdato)
)
)
)

val response = InntjeningsperiodeResultat(resultat, parametere)
val response = InntjeningsperiodeResultat(resultat, parametere)

call.respond(HttpStatusCode.OK, response)
call.respond(HttpStatusCode.OK, response)
}
}
}
}
Loading

0 comments on commit d66ffbc

Please sign in to comment.