Skip to content

Commit

Permalink
refactor(retrofit2): replace retrofit client with retrofit2 client (#…
Browse files Browse the repository at this point in the history
…1466)

* refactor(retrofit2): upgrade KeelService retrofit API interface to retrofit2

* refactor(retrofit2): upgrade CDEventsSenderClient retrofit API interface to retrofit2

* refactor(retrofit2): upgrade BearychatService retrofit API interface to retrofit2

* refactor(retrofit2): upgrade JiraService retrofit API interface to retrofit2

* refactor(retrofit2): upgrade GoogleChatClient retrofit API interface to retrofit2

* refactor(retrofit2): upgrade GithubService retrofit API interface to retrofit2

* refactor(retrofit2): upgrade SlackClient retrofit API interface to retrofit2

* refactor(retrofit2): upgrade PagerDutyService retrofit API interface to retrofit2

* refactor(retrofit2): upgrade MicrosoftTeamsClient retrofit API interface to retrofit2

* refactor(retrofit2): upgrade TelemetryService retrofit API interface to retrofit2

* refactor(retrofit2): move Retrofit2TestConfig from echo-notification/src/test/.. to echo-test/src/main/.. so that other modules can utilize

* refactor(retrofit2): upgrade RestService retrofit API interface to retrofit2

* refactor(retrofit2): upgrade TwilioService retrofit API interface to retrofit2

* refactor(retrofit2): upgrade OrcaService retrofit API interface to retrofit2

* refactor(retrofit2): upgrade IgorService retrofit API interface to retrofit2

* refactor(retrofit2): upgrade SlackHookService retrofit API interface to retrofit2

* refactor(retrofit2): upgrade SpinnakerService retrofit API interface to retrofit2

* refactor(retrofit2): upgrade Front50Service retrofit API interface to retrofit2

* refactor(retrofit2): Remove RetrofitError from JiraNotificationService

* refactor(retrofit2): remove remaining references to retrofit1

* refactor(retrofit2): Convert Retrofit2TestConfig to java

* refactor(retrofit2): move java classes from main/groovy/.. to main/java/.. in echo-notifications

* refactor(retrofit2): replaced retrofit1's encode=false flag to retrofit2's encoded=true

* refactor(retrofit2): addressed review comments
  • Loading branch information
kirangodishala authored Jan 9, 2025
1 parent 469d50f commit 6a0e784
Show file tree
Hide file tree
Showing 120 changed files with 1,635 additions and 1,346 deletions.
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);
}
7 changes: 4 additions & 3 deletions echo-core/echo-core.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ dependencies {

api "io.spinnaker.kork:kork-plugins"

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-core"
implementation "io.spinnaker.kork:kork-exceptions"
implementation "io.spinnaker.kork:kork-security"
implementation "io.spinnaker.kork:kork-retrofit"

implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.apache.commons:commons-lang3"
Expand All @@ -42,4 +42,5 @@ dependencies {
testImplementation "org.spockframework:spock-spring"
testImplementation "org.springframework:spring-test"
testImplementation "org.apache.groovy:groovy-json"
testImplementation "com.github.tomakehurst:wiremock-jre8"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.netflix.spinnaker.echo.services.IgorService;
import com.netflix.spinnaker.kork.artifacts.model.Artifact;
import com.netflix.spinnaker.kork.retrofit.Retrofit2SyncCall;
import java.util.List;

/** Given an artifact, fetch the details from an artifact provider */
Expand All @@ -31,10 +32,11 @@ public ArtifactInfoService(IgorService igorService) {
}

public List<String> getVersions(String provider, String packageName) {
return igorService.getVersions(provider, packageName);
return Retrofit2SyncCall.execute(igorService.getVersions(provider, packageName));
}

public Artifact getArtifactByVersion(String provider, String packageName, String version) {
return igorService.getArtifactByVersion(provider, packageName, version);
return Retrofit2SyncCall.execute(
igorService.getArtifactByVersion(provider, packageName, version));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.netflix.spinnaker.echo.services.IgorService;
import com.netflix.spinnaker.kork.artifacts.model.Artifact;
import com.netflix.spinnaker.kork.core.RetrySupport;
import com.netflix.spinnaker.kork.retrofit.Retrofit2SyncCall;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -58,8 +59,10 @@ public BuildEvent getBuildEvent(String master, String job, int buildNumber) {
Map<String, Object> rawBuild =
retry(
igorConfigurationProperties.isJobNameAsQueryParameter()
? () -> igorService.getBuildStatusWithJobQueryParameter(buildNumber, master, job)
: () -> igorService.getBuild(buildNumber, master, job));
? () ->
Retrofit2SyncCall.execute(
igorService.getBuildStatusWithJobQueryParameter(buildNumber, master, job))
: () -> Retrofit2SyncCall.execute(igorService.getBuild(buildNumber, master, job)));
BuildEvent.Build build = objectMapper.convertValue(rawBuild, BuildEvent.Build.class);
BuildEvent.Project project = new BuildEvent.Project(job, build);
BuildEvent.Content content = new BuildEvent.Content(project, master);
Expand All @@ -77,8 +80,9 @@ public Map<String, Object> getBuildInfo(BuildEvent event) {
return retry(
() ->
igorConfigurationProperties.isJobNameAsQueryParameter()
? igorService.getBuildStatusWithJobQueryParameter(buildNumber, master, job)
: igorService.getBuild(buildNumber, master, job));
? Retrofit2SyncCall.execute(
igorService.getBuildStatusWithJobQueryParameter(buildNumber, master, job))
: Retrofit2SyncCall.execute(igorService.getBuild(buildNumber, master, job)));
}
return Collections.emptyMap();
}
Expand All @@ -96,9 +100,11 @@ public Map<String, Object> getProperties(BuildEvent event, String propertyFile)
return retry(
() ->
igorConfigurationProperties.isJobNameAsQueryParameter()
? igorService.getPropertyFileWithJobQueryParameter(
buildNumber, propertyFileFinal, master, job)
: igorService.getPropertyFile(buildNumber, propertyFileFinal, master, job));
? Retrofit2SyncCall.execute(
igorService.getPropertyFileWithJobQueryParameter(
buildNumber, propertyFileFinal, master, job))
: Retrofit2SyncCall.execute(
igorService.getPropertyFile(buildNumber, propertyFileFinal, master, job)));
}
return Collections.emptyMap();
}
Expand All @@ -111,9 +117,11 @@ private List<Artifact> getArtifactsFromPropertyFile(BuildEvent event, String pro
return retry(
() ->
igorConfigurationProperties.isJobNameAsQueryParameter()
? igorService.getArtifactsWithJobQueryParameter(
buildNumber, propertyFile, master, job)
: igorService.getArtifacts(buildNumber, propertyFile, master, job));
? Retrofit2SyncCall.execute(
igorService.getArtifactsWithJobQueryParameter(
buildNumber, propertyFile, master, job))
: Retrofit2SyncCall.execute(
igorService.getArtifacts(buildNumber, propertyFile, master, job)));
}
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,40 @@
import com.netflix.spinnaker.echo.model.Pipeline;
import java.util.List;
import java.util.Map;
import retrofit.http.*;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;

public interface Front50Service {
@GET("/pipelines?restricted=false")
@Headers("Accept: application/json")
List<Map<String, Object>>
Call<List<Map<String, Object>>>
getPipelines(); // Return Map here so we don't throw away MPT attributes.

@GET("/pipelines?restricted=false")
@Headers("Accept: application/json")
List<Map<String, Object>> getPipelines(
Call<List<Map<String, Object>>> getPipelines(
@Query("enabledPipelines") Boolean enabledPipelines,
@Query("enabledTriggers") Boolean enabledTriggers,
@Query("triggerTypes")
String triggerTypes); // Return Map here so we don't throw away MPT attributes.

@GET("/pipelines/{application}?refresh=false")
@Headers("Accept: application/json")
List<Pipeline> getPipelines(@Path("application") String application);
Call<List<Pipeline>> getPipelines(@Path("application") String application);

@GET("/pipelines/{pipelineId}/get")
Map<String, Object> getPipeline(@Path("pipelineId") String pipelineId);
Call<Map<String, Object>> getPipeline(@Path("pipelineId") String pipelineId);

@GET("/pipelines/{application}/name/{name}?refresh=true")
Map<String, Object> getPipelineByName(
Call<Map<String, Object>> getPipelineByName(
@Path("application") String application, @Path("name") String name);

@POST("/graphql")
@Headers("Accept: application/json")
GraphQLQueryResponse query(@Body GraphQLQuery body);
Call<GraphQLQueryResponse> query(@Body GraphQLQuery body);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,70 +19,75 @@
import com.netflix.spinnaker.kork.artifacts.model.Artifact;
import java.util.List;
import java.util.Map;
import okhttp3.ResponseBody;
import org.jetbrains.annotations.NotNull;
import retrofit.client.Response;
import retrofit.http.*;
import retrofit.mime.TypedInput;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import retrofit2.http.Query;

public interface IgorService {
@GET("/builds/status/{buildNumber}/{master}/{job}")
Map<String, Object> getBuild(
Call<Map<String, Object>> getBuild(
@Path("buildNumber") Integer buildNumber,
@Path("master") String master,
@Path(value = "job", encode = false) String job);
@Path(value = "job", encoded = true) String job);

@GET("/builds/status/{buildNumber}/{master}")
Map<String, Object> getBuildStatusWithJobQueryParameter(
Call<Map<String, Object>> getBuildStatusWithJobQueryParameter(
@NotNull @Path("buildNumber") Integer buildNumber,
@NotNull @Path("master") String master,
@NotNull @Query(value = "job") String job);

@GET("/builds/properties/{buildNumber}/{fileName}/{master}/{job}")
Map<String, Object> getPropertyFile(
Call<Map<String, Object>> getPropertyFile(
@Path("buildNumber") Integer buildNumber,
@Path("fileName") String fileName,
@Path("master") String master,
@Path(value = "job", encode = false) String job);
@Path(value = "job", encoded = true) String job);

@GET("/builds/properties/{buildNumber}/{fileName}/{master}")
Map<String, Object> getPropertyFileWithJobQueryParameter(
Call<Map<String, Object>> getPropertyFileWithJobQueryParameter(
@Path("buildNumber") Integer buildNumber,
@Path("fileName") String fileName,
@Path("master") String master,
@Query(value = "job") String job);

@GET("/builds/artifacts/{buildNumber}/{master}/{job}")
List<Artifact> getArtifacts(
Call<List<Artifact>> getArtifacts(
@Path("buildNumber") Integer buildNumber,
@Query("propertyFile") String propertyFile,
@Path("master") String master,
@Path(value = "job", encode = false) String job);
@Path(value = "job", encoded = true) String job);

@GET("/builds/artifacts/{buildNumber}/{master}")
List<Artifact> getArtifactsWithJobQueryParameter(
Call<List<Artifact>> getArtifactsWithJobQueryParameter(
@Path("buildNumber") Integer buildNumber,
@Query("propertyFile") String propertyFile,
@Path("master") String master,
@Query(value = "job") String job);

@GET("/artifacts/{provider}/{packageName}")
List<String> getVersions(
Call<List<String>> getVersions(
@Path("provider") String provider, @Path("packageName") String packageName);

@GET("/artifacts/{provider}/{packageName}/{version}")
Artifact getArtifactByVersion(
Call<Artifact> getArtifactByVersion(
@Path("provider") String provider,
@Path("packageName") String packageName,
@Path("version") String version);

@PUT("/gcb/builds/{account}/{buildId}")
Response updateBuildStatus(
Call<ResponseBody> updateBuildStatus(
@Path("account") String account,
@Path("buildId") String buildId,
@Query("status") String status,
@Body TypedInput build);

@PUT("/gcb/artifacts/extract/{account}")
List<Artifact> extractGoogleCloudBuildArtifacts(
Call<List<Artifact>> extractGoogleCloudBuildArtifacts(
@Path("account") String account, @Body TypedInput build);
}
Loading

0 comments on commit 6a0e784

Please sign in to comment.