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

refactor(retrofit2): replace retrofit client with retrofit2 client #1466

Merged
merged 24 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d9bc389
refactor(retrofit2): upgrade KeelService retrofit API interface to re…
kirangodishala Dec 10, 2024
8407943
refactor(retrofit2): upgrade CDEventsSenderClient retrofit API interf…
kirangodishala Dec 10, 2024
e08cc16
refactor(retrofit2): upgrade BearychatService retrofit API interface …
kirangodishala Dec 10, 2024
98bde2b
refactor(retrofit2): upgrade JiraService retrofit API interface to re…
kirangodishala Dec 11, 2024
d35d4d1
refactor(retrofit2): upgrade GoogleChatClient retrofit API interface …
kirangodishala Dec 11, 2024
2bb00e0
refactor(retrofit2): upgrade GithubService retrofit API interface to …
kirangodishala Dec 12, 2024
3473557
refactor(retrofit2): upgrade SlackClient retrofit API interface to re…
kirangodishala Dec 16, 2024
9ea0868
refactor(retrofit2): upgrade PagerDutyService retrofit API interface …
kirangodishala Dec 16, 2024
3428b9b
refactor(retrofit2): upgrade MicrosoftTeamsClient retrofit API interf…
kirangodishala Dec 16, 2024
4659a74
refactor(retrofit2): upgrade TelemetryService retrofit API interface …
kirangodishala Dec 17, 2024
43d1220
refactor(retrofit2): move Retrofit2TestConfig from echo-notification/…
kirangodishala Dec 25, 2024
d163da5
refactor(retrofit2): upgrade RestService retrofit API interface to re…
kirangodishala Dec 25, 2024
2b3ef4f
refactor(retrofit2): upgrade TwilioService retrofit API interface to …
kirangodishala Dec 25, 2024
b3ce19f
refactor(retrofit2): upgrade OrcaService retrofit API interface to re…
kirangodishala Dec 25, 2024
cbc5cbc
refactor(retrofit2): upgrade IgorService retrofit API interface to re…
kirangodishala Dec 27, 2024
4e1b249
refactor(retrofit2): upgrade SlackHookService retrofit API interface …
kirangodishala Dec 27, 2024
1ba8d36
refactor(retrofit2): upgrade SpinnakerService retrofit API interface …
kirangodishala Dec 27, 2024
07c916a
refactor(retrofit2): upgrade Front50Service retrofit API interface to…
kirangodishala Dec 28, 2024
4260887
refactor(retrofit2): Remove RetrofitError from JiraNotificationService
kirangodishala Dec 28, 2024
23d7c20
refactor(retrofit2): remove remaining references to retrofit1
kirangodishala Dec 29, 2024
f6dac52
refactor(retrofit2): Convert Retrofit2TestConfig to java
kirangodishala Dec 31, 2024
f94a6ec
refactor(retrofit2): move java classes from main/groovy/.. to main/ja…
kirangodishala Jan 2, 2025
c63352a
refactor(retrofit2): replaced retrofit1's encode=false flag to retrof…
kirangodishala Jan 3, 2025
ace41e5
refactor(retrofit2): addressed review comments
kirangodishala Jan 3, 2025
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
6 changes: 3 additions & 3 deletions echo-artifacts/echo-artifacts.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
dependencies {
implementation project(':echo-core')
implementation project(':echo-model')
implementation "com.squareup.retrofit:retrofit"
implementation "com.squareup.retrofit:converter-jackson"
implementation "com.jakewharton.retrofit:retrofit1-okhttp3-client:1.1.0"
implementation "com.squareup.retrofit2:retrofit"
implementation "com.squareup.retrofit2:converter-jackson"
implementation "io.spinnaker.kork:kork-web"
implementation "io.spinnaker.kork:kork-artifacts"
implementation "io.spinnaker.kork:kork-retrofit"
implementation "org.springframework.boot:spring-boot-starter-web"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.netflix.spinnaker.echo.config.ArtifactEmitterProperties;
import com.netflix.spinnaker.echo.model.ArtifactEvent;
import com.netflix.spinnaker.echo.services.KeelService;
import com.netflix.spinnaker.kork.retrofit.Retrofit2SyncCall;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
Expand Down Expand Up @@ -64,7 +65,7 @@ public void processEvent(ArtifactEvent event) {
sentEvent.put(
artifactEmitterProperties.getFieldName(), objectMapper.convertValue(event, Map.class));
log.debug("Sending artifacts to Keel: {}", event.getArtifacts());
keelService.sendArtifactEvent(sentEvent);
Retrofit2SyncCall.execute(keelService.sendArtifactEvent(sentEvent));
} catch (Exception e) {
log.error("Could not send event {} to Keel", event, e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,31 @@
package com.netflix.spinnaker.echo.config;

import com.jakewharton.retrofit.Ok3Client;
import com.netflix.spinnaker.config.DefaultServiceEndpoint;
import com.netflix.spinnaker.config.okhttp3.OkHttpClientProvider;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.spinnaker.config.OkHttp3ClientConfiguration;
import com.netflix.spinnaker.echo.services.KeelService;
import com.netflix.spinnaker.retrofit.Slf4jRetrofitLogger;
import com.netflix.spinnaker.kork.retrofit.ErrorHandlingExecutorCallAdapterFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import retrofit.Endpoint;
import retrofit.Endpoints;
import retrofit.RestAdapter;
import retrofit.RestAdapter.LogLevel;
import retrofit.converter.JacksonConverter;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;

@Configuration
@Slf4j
@ConditionalOnExpression("${keel.enabled:false}")
public class KeelConfig {
@Bean
public LogLevel retrofitLogLevel(@Value("${retrofit.log-level:BASIC}") String retrofitLogLevel) {
return LogLevel.valueOf(retrofitLogLevel);
}

@Bean
public Endpoint keelEndpoint(@Value("${keel.base-url}") String keelBaseUrl) {
return Endpoints.newFixedEndpoint(keelBaseUrl);
}

@Bean
public KeelService keelService(
Endpoint keelEndpoint, OkHttpClientProvider clientProvider, LogLevel retrofitLogLevel) {
return new RestAdapter.Builder()
.setEndpoint(keelEndpoint)
.setConverter(new JacksonConverter())
.setClient(
new Ok3Client(
clientProvider.getClient(
new DefaultServiceEndpoint("keel", keelEndpoint.getUrl()))))
.setLogLevel(retrofitLogLevel)
.setLog(new Slf4jRetrofitLogger(KeelService.class))
@Value("${keel.base-url}") String keelBaseUrl,
OkHttp3ClientConfiguration okHttpClientConfig) {
return new Retrofit.Builder()
.baseUrl(keelBaseUrl)
.client(okHttpClientConfig.createForRetrofit2().build())
.addCallAdapterFactory(ErrorHandlingExecutorCallAdapterFactory.getInstance())
.addConverterFactory(JacksonConverterFactory.create(new ObjectMapper()))
.build()
.create(KeelService.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.netflix.spinnaker.echo.services;

import java.util.Map;
import retrofit.http.Body;
import retrofit.http.POST;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST;

public interface KeelService {
@POST("/artifacts/events")
Void sendArtifactEvent(@Body Map event);
Call<Void> sendArtifactEvent(@Body Map event);
}
4 changes: 3 additions & 1 deletion echo-notifications/echo-notifications.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ dependencies {
implementation project(':echo-model')
implementation project(":echo-pipelinetriggers")
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "com.squareup.retrofit:retrofit"
implementation "com.squareup.retrofit2:retrofit"
implementation "com.squareup.retrofit2:converter-jackson"
implementation "com.squareup.retrofit:converter-jackson"
implementation "com.jakewharton.retrofit:retrofit1-okhttp3-client:1.1.0"
implementation "io.spinnaker.kork:kork-core"
implementation "io.spinnaker.kork:kork-artifacts"
implementation "io.spinnaker.kork:kork-retrofit"
implementation "io.spinnaker.kork:kork-web"
implementation "commons-codec:commons-codec"
implementation "org.springframework.boot:spring-boot-starter-mail"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
dbyron-sf marked this conversation as resolved.
Show resolved Hide resolved
* Copyright 2024 OpsMx, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.spinnaker.echo.cdevents;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.netflix.spinnaker.kork.web.exceptions.InvalidRequestException;
import io.cloudevents.CloudEvent;
import io.cloudevents.jackson.JsonFormat;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;

public class CDEventsConverterFactory extends Converter.Factory {
private final ObjectMapper objectMapper;

public CDEventsConverterFactory(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}

public static CDEventsConverterFactory create() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(JsonFormat.getCloudEventJacksonModule());
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
return new CDEventsConverterFactory(objectMapper);
}

@Override
public Converter<ResponseBody, ?> responseBodyConverter(
Type type, Annotation[] annotations, Retrofit retrofit) {
return (Converter<ResponseBody, Object>)
value -> {
try (value) {
JavaType javaType = objectMapper.getTypeFactory().constructType(type);
return objectMapper.readValue(value.charStream(), javaType);
}
};
}

@Override
public Converter<?, RequestBody> requestBodyConverter(
Type type,
Annotation[] parameterAnnotations,
Annotation[] methodAnnotations,
Retrofit retrofit) {
return (Converter<Object, RequestBody>)
value -> {
try {
String json = objectMapper.writeValueAsString(value);
return RequestBody.create(MediaType.parse("application/json"), json);
} catch (JsonProcessingException e) {
throw new IOException("Failed to serialize object to JSON", e);
}
};
}

public String convertCDEventToJson(CloudEvent cdEvent) {
try {
return objectMapper.writeValueAsString(cdEvent);
} catch (JsonProcessingException e) {
throw new InvalidRequestException("Unable to convert CDEvent to Json format.", e);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

package com.netflix.spinnaker.echo.cdevents;

import retrofit.client.Response;
import retrofit.http.Body;
import retrofit.http.POST;
import retrofit.http.Path;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.http.Body;
import retrofit2.http.POST;
import retrofit2.http.Path;

public interface CDEventsSenderClient {
@POST("/{brokerUrl}")
Response sendCDEvent(
@Body String cdEvent, @Path(value = "brokerUrl", encode = false) String brokerUrl);
Call<Response<ResponseBody>> sendCDEvent(
@Body String cdEvent, @Path(value = "brokerUrl") String brokerUrl);
}
Loading