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 #1174

Merged
merged 2 commits 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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 @@ -31,6 +32,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 @@ -43,9 +45,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 @@ -55,6 +60,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))
.setErrorHandler(SpinnakerRetrofitErrorHandler.getInstance())
.build()
Expand Down
Original file line number Diff line number Diff line change
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 @@ -28,6 +29,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 @@ -36,9 +38,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 @@ -48,6 +53,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))
.setErrorHandler(SpinnakerRetrofitErrorHandler.getInstance())
Expand Down
Original file line number Diff line number Diff line change
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 @@ -40,6 +41,7 @@
import org.springframework.scheduling.TaskScheduler;
import retrofit.Endpoints;
import retrofit.RestAdapter;
import retrofit.converter.JacksonConverter;

@Configuration
@ConditionalOnProperty("services.front50.base-url")
Expand All @@ -55,7 +57,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 @@ -66,6 +69,7 @@ public PluginReleaseService pluginReleaseService(
clientProvider.getClient(new DefaultServiceEndpoint("front50", address))))
.setLogLevel(retrofitLogLevel)
.setLog(new Slf4jRetrofitLogger(Front50Service.class))
.setConverter(new JacksonConverter(objectMapper))
.setErrorHandler(SpinnakerRetrofitErrorHandler.getInstance())
.build()
.create(Front50Service.class);
Expand Down
Original file line number Diff line number Diff line change
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 @@ -27,6 +28,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 @@ -43,28 +45,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))
.setErrorHandler(SpinnakerRetrofitErrorHandler.getInstance())
.setClient(new Ok3Client(client))
Expand Down
Original file line number Diff line number Diff line change
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