From f5b738fedddce00b6151776c6044f97e235af60d Mon Sep 17 00:00:00 2001 From: Sairam Rekapalli Date: Mon, 17 Aug 2020 14:38:46 -0700 Subject: [PATCH] fix(misc): Update jenkins client providers impls to use ok3 (#834) Co-authored-by: Adam Jordens --- .../igor/config/JenkinsConfig.groovy | 27 ++++++++----------- .../DefaultJenkinsOkHttpClientProvider.java | 10 +++++-- .../client/JenkinsOkHttpClientProvider.java | 2 +- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/config/JenkinsConfig.groovy b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/config/JenkinsConfig.groovy index 373e02107..6dffa2784 100644 --- a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/config/JenkinsConfig.groovy +++ b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/config/JenkinsConfig.groovy @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.dataformat.xml.XmlMapper import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule +import com.jakewharton.retrofit.Ok3Client import com.netflix.spectator.api.Registry import com.netflix.spinnaker.fiat.model.resources.Permissions import com.netflix.spinnaker.igor.IgorConfigurationProperties @@ -30,9 +31,8 @@ import com.netflix.spinnaker.igor.config.client.JenkinsRetrofitRequestIntercepto import com.netflix.spinnaker.igor.jenkins.client.JenkinsClient import com.netflix.spinnaker.igor.jenkins.service.JenkinsService import com.netflix.spinnaker.igor.service.BuildServices -import com.netflix.spinnaker.okhttp.OkHttpMetricsInterceptor import com.netflix.spinnaker.retrofit.Slf4jRetrofitLogger -import com.squareup.okhttp.OkHttpClient +import okhttp3.OkHttpClient import groovy.transform.CompileStatic import groovy.util.logging.Slf4j import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry @@ -71,8 +71,8 @@ class JenkinsConfig { @Bean @ConditionalOnMissingBean - JenkinsOkHttpClientProvider jenkinsOkHttpClientProvider() { - return new DefaultJenkinsOkHttpClientProvider() + JenkinsOkHttpClientProvider jenkinsOkHttpClientProvider(OkHttpClient okHttpClient) { + return new DefaultJenkinsOkHttpClientProvider(okHttpClient) } @Bean @@ -132,12 +132,13 @@ class JenkinsConfig { RequestInterceptor requestInterceptor, Registry registry, int timeout = 30000) { - client.setReadTimeout(timeout, TimeUnit.MILLISECONDS) + + OkHttpClient.Builder clientBuilder = client.newBuilder().readTimeout(timeout, TimeUnit.MILLISECONDS) if (host.skipHostnameVerification) { - client.setHostnameVerifier({ hostname, _ -> - true - }) + clientBuilder.hostnameVerifier({ hostname, _ -> + true + }) } TrustManager[] trustManagers = null @@ -175,13 +176,7 @@ class JenkinsConfig { def sslContext = SSLContext.getInstance("TLS") sslContext.init(keyManagers, trustManagers, null) - client.setSslSocketFactory(sslContext.socketFactory) - } - - if (registry == null) { - log.warn("no registry provided, OkHttpMetricsInterceptor will not be created for JenkinsClient") - } else { - client.interceptors().add(new OkHttpMetricsInterceptor({ -> registry }, true)) + clientBuilder.sslSocketFactory(sslContext.socketFactory,(X509TrustManager) trustManagers[0]) } new RestAdapter.Builder() @@ -194,7 +189,7 @@ class JenkinsConfig { } }) .setLogLevel(RestAdapter.LogLevel.BASIC) - .setClient(new OkClient(client)) + .setClient(new Ok3Client(clientBuilder.build())) .setConverter(new JacksonConverter(getObjectMapper())) .setLog(new Slf4jRetrofitLogger(JenkinsClient)) .build() diff --git a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/config/client/DefaultJenkinsOkHttpClientProvider.java b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/config/client/DefaultJenkinsOkHttpClientProvider.java index 0ce31b6d8..740bfd161 100644 --- a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/config/client/DefaultJenkinsOkHttpClientProvider.java +++ b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/config/client/DefaultJenkinsOkHttpClientProvider.java @@ -16,12 +16,18 @@ package com.netflix.spinnaker.igor.config.client; import com.netflix.spinnaker.igor.config.JenkinsProperties; -import com.squareup.okhttp.OkHttpClient; +import okhttp3.OkHttpClient; public class DefaultJenkinsOkHttpClientProvider implements JenkinsOkHttpClientProvider { + private final OkHttpClient okHttpClient; + + public DefaultJenkinsOkHttpClientProvider(OkHttpClient okHttpClient) { + this.okHttpClient = okHttpClient; + } + @Override public OkHttpClient provide(JenkinsProperties.JenkinsHost host) { - return new OkHttpClient(); + return okHttpClient; } } diff --git a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/config/client/JenkinsOkHttpClientProvider.java b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/config/client/JenkinsOkHttpClientProvider.java index f2bbe0a43..475d40dc6 100644 --- a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/config/client/JenkinsOkHttpClientProvider.java +++ b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/config/client/JenkinsOkHttpClientProvider.java @@ -16,7 +16,7 @@ package com.netflix.spinnaker.igor.config.client; import com.netflix.spinnaker.igor.config.JenkinsProperties; -import com.squareup.okhttp.OkHttpClient; +import okhttp3.OkHttpClient; /** Abstracts away the logic for providing an OkHttpClient for Jenkins services. */ public interface JenkinsOkHttpClientProvider {