Skip to content

Commit

Permalink
refactor(retrofit2): remove all retrofit1 references
Browse files Browse the repository at this point in the history
  • Loading branch information
kirangodishala committed Jan 29, 2025
1 parent 51adc6f commit a5ed6b0
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 46 deletions.
3 changes: 0 additions & 3 deletions clouddriver-appengine/clouddriver-appengine.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ dependencies {
implementation "io.spinnaker.kork:kork-moniker"
implementation "io.spinnaker.kork:kork-retrofit"
implementation "io.spinnaker.kork:kork-web"
implementation "com.jakewharton.retrofit:retrofit1-okhttp3-client"
implementation "com.netflix.spectator:spectator-api"
implementation "com.squareup.retrofit:converter-jackson"
implementation "com.squareup.retrofit:retrofit"
implementation "commons-io:commons-io"
implementation "org.apache.commons:commons-compress:1.21"
implementation "org.apache.groovy:groovy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.util.NoSuchElementException;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import retrofit.client.Response;
import retrofit.mime.TypedByteArray;

@Data
@ConfigurationProperties("artifacts.gcs")
Expand All @@ -33,10 +31,6 @@ public class StorageConfigurationProperties {
public static class ManagedAccount {
String name;
String jsonPath;

public static String responseToString(Response response) {
return new String(((TypedByteArray) response.getBody()).getBytes());
}
}

ManagedAccount getAccount(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ActiveProfiles;
import retrofit2.mock.Calls;

/**
* Test class for general test cases related to CreateServerGroup operation. Note: launch template
Expand Down Expand Up @@ -178,7 +179,7 @@ public void setup() {
Map applicationMap = new HashMap();
applicationMap.put("application", "myAwsApp");
applicationMap.put("legacyUdf", null);
when(mockFront50Service.getApplication(ASG_NAME)).thenReturn(applicationMap);
when(mockFront50Service.getApplication(ASG_NAME)).thenReturn(Calls.response(applicationMap));

// mock EC2 responses
when(mockRegionScopedProvider.getAmazonEC2()).thenReturn(mockEc2);
Expand Down
1 change: 0 additions & 1 deletion clouddriver-cloudrun/clouddriver-cloudrun.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ dependencies {
implementation "io.spinnaker.kork:kork-cloud-config-server"
implementation "io.spinnaker.kork:kork-moniker"
implementation "com.netflix.spectator:spectator-api"
implementation "com.squareup.retrofit:retrofit"
implementation "commons-io:commons-io"
implementation "org.apache.commons:commons-compress:1.20"
implementation "org.apache.groovy:groovy"
Expand Down
1 change: 0 additions & 1 deletion clouddriver-consul/clouddriver-consul.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ dependencies {

implementation "com.jakewharton.retrofit:retrofit1-okhttp3-client"
implementation "com.squareup.retrofit:converter-jackson"
implementation "com.squareup.retrofit:retrofit"
implementation "org.apache.groovy:groovy"
implementation "org.apache.groovy:groovy-json"
implementation "org.springframework.boot:spring-boot-starter-web"
Expand Down
4 changes: 1 addition & 3 deletions clouddriver-core/clouddriver-core.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ dependencies {
implementation "io.spinnaker.kork:kork-annotations"
implementation "io.spinnaker.kork:kork-moniker"
implementation "io.spinnaker.kork:kork-secrets"
implementation "com.squareup.retrofit:converter-jackson"
implementation "com.squareup.retrofit:retrofit"
implementation "com.jakewharton.retrofit:retrofit1-okhttp3-client"
implementation "com.squareup.retrofit2:converter-jackson"
implementation "io.reactivex:rxjava"
implementation "net.jodah:failsafe:1.0.4"
implementation "org.apache.groovy:groovy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ import com.netflix.spinnaker.clouddriver.model.SimpleServerGroup
import com.netflix.spinnaker.kork.dynamicconfig.DynamicConfigService
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException
import com.netflix.spinnaker.moniker.Moniker
import retrofit.RetrofitError
import retrofit.client.Response
import okhttp3.MediaType
import okhttp3.ResponseBody
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.jackson.JacksonConverterFactory
import retrofit2.mock.Calls;
import spock.lang.Ignore
import spock.lang.Shared
Expand Down Expand Up @@ -445,7 +448,7 @@ class TrafficGuardSpec extends Specification {
!application.containsKey("trafficGuards")
result == false
1 * front50Service.getApplication("app") >> {
throw new SpinnakerHttpException(new RetrofitError(null, null, new Response("http://stash.com", 404, "test reason", [], null), null, null, null, null))
throw makeSpinnakerHttpException(404)
}
}

Expand Down Expand Up @@ -596,6 +599,23 @@ class TrafficGuardSpec extends Specification {
0 * _
}

static SpinnakerHttpException makeSpinnakerHttpException(int status) {
String url = "https://some-url";
Response retrofit2Response =
Response.error(
status,
ResponseBody.create(
MediaType.parse("application/json"), "{ \"message\": \"arbitrary message\" }"))

Retrofit retrofit =
new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(JacksonConverterFactory.create())
.build()

return new SpinnakerHttpException(retrofit2Response, retrofit)
}

private void addGuard(Map guard) {
if (!guard.containsKey("enabled")) {
guard.enabled = true
Expand Down
2 changes: 0 additions & 2 deletions clouddriver-docker/clouddriver-docker.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ dependencies {
implementation "org.springframework.cloud:spring-cloud-context"
implementation "org.apache.groovy:groovy"
implementation "com.google.guava:guava"
// implementation "com.jakewharton.retrofit:retrofit1-okhttp3-client"
implementation "com.netflix.spectator:spectator-api"
implementation "com.squareup.retrofit2:converter-jackson"
// implementation "com.squareup.retrofit:retrofit"
implementation "org.apache.commons:commons-compress:1.21"
implementation "commons-io:commons-io"
implementation "io.spinnaker.fiat:fiat-api:$fiatVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,20 @@ package com.netflix.spinnaker.clouddriver.docker.registry.api.v2.client

import com.fasterxml.jackson.databind.ObjectMapper
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.netflix.spinnaker.clouddriver.docker.registry.api.v2.DockerUserAgent
import com.netflix.spinnaker.clouddriver.docker.registry.api.v2.auth.DockerBearerToken
import com.netflix.spinnaker.clouddriver.docker.registry.api.v2.auth.DockerBearerTokenService
import com.netflix.spinnaker.clouddriver.docker.registry.api.v2.exception.DockerRegistryAuthenticationException
import com.netflix.spinnaker.clouddriver.docker.registry.api.v2.exception.DockerRegistryOperationException
import com.netflix.spinnaker.config.DefaultServiceEndpoint
import com.netflix.spinnaker.kork.client.ServiceClientProvider
import com.netflix.spinnaker.kork.retrofit.ErrorHandlingExecutorCallAdapterFactory
import com.netflix.spinnaker.kork.retrofit.Retrofit2SyncCall
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerNetworkException
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerRetrofitErrorHandler
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerServerException
import groovy.util.logging.Slf4j
import okhttp3.ResponseBody
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import retrofit.converter.GsonConverter
import retrofit2.Response
import retrofit2.converter.jackson.JacksonConverterFactory;
import retrofit2.Call
Expand Down Expand Up @@ -162,7 +157,6 @@ class DockerRegistryClient {
String address
String email
DockerRegistryService registryService
GsonConverter converter
String catalogFile
String repositoriesRegex

Expand Down Expand Up @@ -191,7 +185,6 @@ class DockerRegistryClient {
.addConverterFactory(JacksonConverterFactory.create())
.build()
.create(DockerRegistryService);
this.converter = new GsonConverter(new GsonBuilder().create())
this.address = address
this.catalogFile = catalogFile
this.repositoriesRegex = repositoriesRegex
Expand Down Expand Up @@ -221,7 +214,6 @@ class DockerRegistryClient {
DockerRegistryService dockerRegistryService,
DockerBearerTokenService dockerBearerTokenService) {
this.paginateSize = paginateSize
this.converter = new GsonConverter(new GsonBuilder().create())
this.address = address
this.catalogFile = catalogFile
this.repositoriesRegex = repositoriesRegex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.netflix.spinnaker.clouddriver.docker.registry.DockerRegistryCloudProv
import com.netflix.spinnaker.clouddriver.docker.registry.api.v2.client.DockerRegistryClient
import com.netflix.spinnaker.clouddriver.docker.registry.api.v2.client.DockerRegistryTags
import com.netflix.spinnaker.clouddriver.docker.registry.security.DockerRegistryCredentials
import retrofit.RetrofitError
import spock.lang.Specification

import java.time.Instant
Expand Down Expand Up @@ -202,7 +201,7 @@ class DockerRegistryImageCachingAgentTest extends Specification {
["repo-1", "tag-2"],
]
client.getCreationDate("repo-1", "tag-1") >> {
throw RetrofitError.httpError("", null, null, null)
throw new IOException()
}
client.getCreationDate("repo-1", "tag-2") >> Instant.EPOCH

Expand Down
2 changes: 0 additions & 2 deletions clouddriver-ecs/clouddriver-ecs.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ dependencies {
implementation "io.spinnaker.kork:kork-credentials-api"
implementation "io.spinnaker.kork:kork-exceptions"
implementation "io.spinnaker.kork:kork-moniker"
implementation "com.squareup.retrofit:converter-jackson"
implementation "com.squareup.retrofit:retrofit"
implementation "commons-io:commons-io"
implementation "org.apache.commons:commons-lang3"
implementation "org.apache.httpcomponents:httpclient"
Expand Down
2 changes: 1 addition & 1 deletion clouddriver-elasticsearch/clouddriver-elasticsearch.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {
implementation "io.spinnaker.kork:kork-moniker"
implementation "io.spinnaker.kork:kork-retrofit"
implementation "io.spinnaker.kork:kork-security"
implementation "com.squareup.retrofit:retrofit"
implementation "com.squareup.retrofit2:converter-jackson"
implementation "org.apache.groovy:groovy"
implementation "org.elasticsearch:elasticsearch"
implementation "org.springframework.boot:spring-boot-starter-web"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import com.netflix.spinnaker.clouddriver.elasticsearch.descriptions.DeleteEntity
import com.netflix.spinnaker.clouddriver.elasticsearch.model.ElasticSearchEntityTagsProvider
import com.netflix.spinnaker.clouddriver.model.EntityTags
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException
import org.springframework.http.HttpStatus
import retrofit.RetrofitError
import retrofit.client.Response
import okhttp3.MediaType
import okhttp3.ResponseBody
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.jackson.JacksonConverterFactory
import retrofit2.mock.Calls
import spock.lang.Specification

Expand All @@ -48,17 +50,12 @@ class DeleteEntityTagsAtomicOperationSpec extends Specification {
}

void 'should remove entityTag from ElasticSearch if not found in Front50'() {
given:
RetrofitError notFoundRetrofitError = RetrofitError.httpError("url",
new Response("url", HttpStatus.NOT_FOUND.value(), "Application Not Found", [], null),
null, null)
SpinnakerHttpException spinnakerHttpException = new SpinnakerHttpException(notFoundRetrofitError)
when:
description.id = 'abc'
operation.operate([])

then:
1 * front50Service.getEntityTags('abc') >> { throw spinnakerHttpException }
1 * front50Service.getEntityTags('abc') >> { throw makeSpinnakerHttpException(404) }
1 * entityTagsProvider.delete('abc')
0 * _
}
Expand Down Expand Up @@ -125,4 +122,22 @@ class DeleteEntityTagsAtomicOperationSpec extends Specification {
Collection<EntityTags.EntityTag> buildTags(Map<String, String> tags) {
return tags.collect { k, v -> new EntityTags.EntityTag(name: k, value: v) }
}

static SpinnakerHttpException makeSpinnakerHttpException(int status) {
String url = "https://some-url";
Response retrofit2Response =
Response.error(
status,
ResponseBody.create(
MediaType.parse("application/json"), "{ \"message\": \"arbitrary message\" }"))

Retrofit retrofit =
new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(JacksonConverterFactory.create())
.build()

return new SpinnakerHttpException(retrofit2Response, retrofit)
}

}
1 change: 0 additions & 1 deletion clouddriver-google/clouddriver-google.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ dependencies {
implementation "io.spinnaker.kork:kork-retrofit2"
implementation "io.spinnaker.kork:kork-exceptions"
implementation "io.spinnaker.kork:kork-web"
implementation "com.squareup.retrofit:retrofit"
implementation "org.springframework.boot:spring-boot-actuator"
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.springframework.cloud:spring-cloud-context"
Expand Down
2 changes: 0 additions & 2 deletions clouddriver-lambda/clouddriver-lambda.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ dependencies {
implementation "org.apache.commons:commons-compress:1.20"
implementation "org.apache.groovy:groovy"
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "com.squareup.retrofit:converter-jackson"
implementation "com.squareup.retrofit:retrofit"
implementation "com.netflix.spectator:spectator-api"
implementation "com.netflix.frigga:frigga"

Expand Down
1 change: 0 additions & 1 deletion clouddriver-yandex/clouddriver-yandex.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ dependencies {
implementation "io.spinnaker.kork:kork-artifacts"
implementation "io.spinnaker.kork:kork-config"
implementation "io.spinnaker.kork:kork-moniker"
implementation "com.squareup.retrofit:retrofit"
implementation "org.springframework.boot:spring-boot-actuator"
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "com.google.protobuf:protobuf-java"
Expand Down

0 comments on commit a5ed6b0

Please sign in to comment.