From 8f58a3fef173a2e860953cefeb2e9be664b2d344 Mon Sep 17 00:00:00 2001 From: David An Date: Tue, 25 Mar 2025 16:52:20 -0400 Subject: [PATCH] reuse okhttp client for Leo DAO --- .../rawls/dataaccess/HttpLeonardoDAO.scala | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/core/src/main/scala/org/broadinstitute/dsde/rawls/dataaccess/HttpLeonardoDAO.scala b/core/src/main/scala/org/broadinstitute/dsde/rawls/dataaccess/HttpLeonardoDAO.scala index e552da96b6..06e8f31236 100644 --- a/core/src/main/scala/org/broadinstitute/dsde/rawls/dataaccess/HttpLeonardoDAO.scala +++ b/core/src/main/scala/org/broadinstitute/dsde/rawls/dataaccess/HttpLeonardoDAO.scala @@ -1,5 +1,6 @@ package org.broadinstitute.dsde.rawls.dataaccess +import okhttp3.{Dispatcher, Protocol} import org.broadinstitute.dsde.rawls.config.LeonardoConfig import org.broadinstitute.dsde.rawls.model.GoogleProjectId import org.broadinstitute.dsde.workbench.client.leonardo.ApiClient @@ -11,24 +12,34 @@ import scala.jdk.CollectionConverters._ class HttpLeonardoDAO(leonardoConfig: LeonardoConfig) extends LeonardoDAO { + private val okHttpClient = { + val dispatcher = new Dispatcher() + new ApiClient().getHttpClient.newBuilder + .protocols(Seq(Protocol.HTTP_1_1).asJava) + .dispatcher(dispatcher) + .build() + } + + protected def getApiClient(accessToken: String): ApiClient = { + val leoApiClient = new ApiClient(okHttpClient) + leoApiClient.setBasePath(leonardoConfig.baseUrl) + leoApiClient.setAccessToken(accessToken) + + leoApiClient + } + private def getAppsV2LeonardoApi(accessToken: String): AppsApi = { - val apiClient = new ApiClient() - apiClient.setAccessToken(accessToken) - apiClient.setBasePath(leonardoConfig.baseUrl) + val apiClient = getApiClient(accessToken) new AppsApi(apiClient) } private def getResourcesLeonardoApi(accessToken: String) = { - val apiClient = new ApiClient() - apiClient.setAccessToken(accessToken) - apiClient.setBasePath(leonardoConfig.baseUrl) + val apiClient = getApiClient(accessToken) new ResourcesApi(apiClient) } private def getRuntimesV2LeonardoApi(accessToken: String): RuntimesApi = { - val apiClient = new ApiClient() - apiClient.setAccessToken(accessToken) - apiClient.setBasePath(leonardoConfig.baseUrl) + val apiClient = getApiClient(accessToken) new RuntimesApi(apiClient) } override def deleteApps(token: String, workspaceId: UUID, deleteDisk: Boolean) =