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

fix(java17): add Jackson converter to RestAdapters to avoid Gson (backport #1174) #1176

Merged
merged 1 commit into from Sep 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -16,6 +16,7 @@

package com.netflix.spinnaker.igor.config

import com.fasterxml.jackson.databind.ObjectMapper
import com.jakewharton.retrofit.Ok3Client
import com.netflix.spinnaker.config.DefaultServiceEndpoint
import com.netflix.spinnaker.config.okhttp3.OkHttpClientProvider
Expand All @@ -30,6 +31,7 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import retrofit.Endpoints
import retrofit.RestAdapter
import retrofit.converter.JacksonConverter

@Configuration
@ConditionalOnProperty(['services.clouddriver.base-url', 'docker-registry.enabled'])
Expand All @@ -42,9 +44,12 @@ class DockerRegistryConfig {
}

@Bean
ClouddriverService dockerRegistryProxyService(OkHttpClientProvider clientProvider,
IgorConfigurationProperties igorConfigurationProperties,
RestAdapter.LogLevel retrofitLogLevel) {
ClouddriverService dockerRegistryProxyService(
OkHttpClientProvider clientProvider,
IgorConfigurationProperties igorConfigurationProperties,
RestAdapter.LogLevel retrofitLogLevel,
ObjectMapper objectMapper
) {
def address = igorConfigurationProperties.services.clouddriver.baseUrl ?: 'none'
if (address == 'none') {
null
Expand All @@ -54,6 +59,7 @@ class DockerRegistryConfig {
.setEndpoint(Endpoints.newFixedEndpoint(address))
.setClient(new Ok3Client(clientProvider.getClient(new DefaultServiceEndpoint("clouddriver", address))))
.setLogLevel(retrofitLogLevel)
.setConverter(new JacksonConverter(objectMapper))
.setLog(new Slf4jRetrofitLogger(ClouddriverService))
.build()
.create(ClouddriverService)
Expand Down
Expand Up @@ -16,6 +16,7 @@

package com.netflix.spinnaker.igor.config

import com.fasterxml.jackson.databind.ObjectMapper
import com.jakewharton.retrofit.Ok3Client
import com.netflix.spinnaker.config.DefaultServiceEndpoint
import com.netflix.spinnaker.config.okhttp3.OkHttpClientProvider
Expand All @@ -27,6 +28,7 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import retrofit.Endpoints
import retrofit.RestAdapter
import retrofit.converter.JacksonConverter

/**
* history service configuration
Expand All @@ -35,9 +37,12 @@ import retrofit.RestAdapter
@Configuration
class EchoConfig {
@Bean
EchoService echoService(OkHttpClientProvider okHttpClientProvider,
IgorConfigurationProperties igorConfigurationProperties,
RestAdapter.LogLevel retrofitLogLevel) {
EchoService echoService(
OkHttpClientProvider okHttpClientProvider,
IgorConfigurationProperties igorConfigurationProperties,
RestAdapter.LogLevel retrofitLogLevel,
ObjectMapper objectMapper
) {
String address = igorConfigurationProperties.services.echo.baseUrl ?: 'none'

if (address == 'none') {
Expand All @@ -47,6 +52,7 @@ class EchoConfig {
new RestAdapter.Builder()
.setEndpoint(Endpoints.newFixedEndpoint(address))
.setClient(new Ok3Client(okHttpClientProvider.getClient(new DefaultServiceEndpoint("echo", address))))
.setConverter(new JacksonConverter(objectMapper))
.setLogLevel(retrofitLogLevel)
.setLog(new Slf4jRetrofitLogger(EchoService))
.build()
Expand Down
Expand Up @@ -16,6 +16,7 @@
*/
package com.netflix.spinnaker.igor.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.jakewharton.retrofit.Ok3Client;
import com.netflix.spectator.api.Registry;
import com.netflix.spinnaker.config.DefaultServiceEndpoint;
Expand All @@ -39,6 +40,7 @@
import org.springframework.scheduling.TaskScheduler;
import retrofit.Endpoints;
import retrofit.RestAdapter;
import retrofit.converter.JacksonConverter;

@Configuration
@ConditionalOnProperty("services.front50.base-url")
Expand All @@ -54,7 +56,8 @@ public PluginCache pluginCache(
public PluginReleaseService pluginReleaseService(
OkHttpClientProvider clientProvider,
IgorConfigurationProperties properties,
RestAdapter.LogLevel retrofitLogLevel) {
RestAdapter.LogLevel retrofitLogLevel,
ObjectMapper objectMapper) {
String address = properties.getServices().getFront50().getBaseUrl();

Front50Service front50Service =
Expand All @@ -65,6 +68,7 @@ public PluginReleaseService pluginReleaseService(
clientProvider.getClient(new DefaultServiceEndpoint("front50", address))))
.setLogLevel(retrofitLogLevel)
.setLog(new Slf4jRetrofitLogger(Front50Service.class))
.setConverter(new JacksonConverter(objectMapper))
.build()
.create(Front50Service.class);

Expand Down
Expand Up @@ -8,6 +8,7 @@
*/
package com.netflix.spinnaker.igor.config

import com.fasterxml.jackson.databind.ObjectMapper
import com.jakewharton.retrofit.Ok3Client
import com.netflix.spinnaker.config.DefaultServiceEndpoint
import com.netflix.spinnaker.config.okhttp3.OkHttpClientProvider
Expand All @@ -26,6 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import retrofit.converter.JacksonConverter

import java.util.concurrent.TimeUnit

Expand All @@ -42,28 +44,37 @@ import retrofit.RestAdapter
class WerckerConfig {
@Bean
Map<String, WerckerService> werckerMasters(
BuildServices buildServices,
WerckerCache cache,
IgorConfigurationProperties igorConfigurationProperties,
OkHttpClientProvider clientProvider,
@Valid WerckerProperties werckerProperties,
RestAdapter.LogLevel retrofitLogLevel) {
BuildServices buildServices,
WerckerCache cache,
IgorConfigurationProperties igorConfigurationProperties,
OkHttpClientProvider clientProvider,
@Valid WerckerProperties werckerProperties,
RestAdapter.LogLevel retrofitLogLevel,
ObjectMapper objectMapper
) {
log.debug "creating werckerMasters"
Map<String, WerckerService> werckerMasters = werckerProperties?.masters?.collectEntries { WerckerHost host ->
log.debug "bootstrapping Wercker ${host.address} as ${host.name}"
[(host.name): new WerckerService(host, cache, werckerClient(host, igorConfigurationProperties.getClient().timeout, clientProvider, retrofitLogLevel), host.permissions.build())]
[(host.name): new WerckerService(host, cache, werckerClient(host, igorConfigurationProperties.getClient().timeout, clientProvider, retrofitLogLevel, objectMapper), host.permissions.build())]
}

buildServices.addServices(werckerMasters)
werckerMasters
}

static WerckerClient werckerClient(WerckerHost host, int timeout = 30000, OkHttpClientProvider clientProvider, RestAdapter.LogLevel retrofitLogLevel) {
static WerckerClient werckerClient(
WerckerHost host,
int timeout = 30000,
OkHttpClientProvider clientProvider,
RestAdapter.LogLevel retrofitLogLevel,
ObjectMapper objectMapper
) {
OkHttpClient client = clientProvider.getClient(new DefaultServiceEndpoint(host.name, host.address, false))
client = client.newBuilder().readTimeout(timeout, TimeUnit.MILLISECONDS).build()
return new RestAdapter.Builder()
.setLog(new Slf4jRetrofitLogger(WerckerService))
.setLogLevel(retrofitLogLevel)
.setConverter(new JacksonConverter(objectMapper))
.setEndpoint(Endpoints.newFixedEndpoint(host.address))
.setClient(new Ok3Client(client))
.build()
Expand Down
Expand Up @@ -9,6 +9,8 @@
*/
package com.netflix.spinnaker.igor.wercker

import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spinnaker.config.okhttp3.InsecureOkHttpClientBuilderProvider
import com.netflix.spinnaker.config.okhttp3.OkHttpClientProvider
import com.netflix.spinnaker.igor.config.*
Expand All @@ -29,8 +31,13 @@ class WerckerClientSpec extends Specification {
@Shared
MockWebServer server

@Shared
ObjectMapper objectMapper

void setup() {
server = new MockWebServer()
objectMapper = new ObjectMapper()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
}

void cleanup() {
Expand Down Expand Up @@ -101,7 +108,7 @@ class WerckerClientSpec extends Specification {
)
server.start()
def host = new WerckerHost(name: 'werckerMaster', address: server.url('/').toString())
client = new WerckerConfig().werckerClient(host, 30000, new OkHttpClientProvider([new InsecureOkHttpClientBuilderProvider(new OkHttpClient())]), RestAdapter.LogLevel.BASIC)
client = new WerckerConfig().werckerClient(host, 30000, new OkHttpClientProvider([new InsecureOkHttpClientBuilderProvider(new OkHttpClient())]), RestAdapter.LogLevel.BASIC, objectMapper)
}

String read(String fileName) {
Expand Down