-
Notifications
You must be signed in to change notification settings - Fork 662
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): upgrade code to use retrofit2 #1313
base: master
Are you sure you want to change the base?
Conversation
@Mergifyio update |
✅ Branch has been successfully updated |
igor-web/src/main/java/com/netflix/spinnaker/igor/config/HelmConverterFactory.java
Show resolved
Hide resolved
igor-monitor-travis/src/main/java/com/netflix/spinnaker/igor/travis/config/TravisConfig.java
Outdated
Show resolved
Hide resolved
igor-web/src/main/groovy/com/netflix/spinnaker/igor/build/BuildController.groovy
Show resolved
Hide resolved
OkHttpClient.Builder clientBuilder = client.newBuilder().readTimeout(timeout, TimeUnit.MILLISECONDS) | ||
Interceptor requestInterceptor = (jenkinsRetrofitRequestInterceptorProvider != null) ? jenkinsRetrofitRequestInterceptorProvider.provide(host): null | ||
OkHttpClient.Builder clientBuilder = okHttpClientConfig.createForRetrofit2().readTimeout(timeout, TimeUnit.MILLISECONDS) | ||
if(requestInterceptor != null){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(requestInterceptor != null){ | |
if (requestInterceptor != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
} catch (SpinnakerHttpException e) { | ||
if (e.getResponseCode() == 404 || e.getResponseCode() >= 500) { | ||
e.setRetryable(true); // 404 not retryable by default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this. Is there a test for this code path?
@@ -182,6 +190,7 @@ private Map<String, Object> getPropertyFileFromLog(String projectId, Long pipeli | |||
} catch (SpinnakerHttpException e) { | |||
// retry on 404 and 5XX | |||
if (e.getResponseCode() == 404 || e.getResponseCode() >= 500) { | |||
e.setRetryable(true); // 404 not retryable by default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a test for this?
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please avoid star imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
.values() | ||
.stream() | ||
.collect(Collectors.toList()); | ||
return new ArrayList<>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not keep the .collect(Collectors.toList());
?
@@ -54,8 +57,6 @@ class ConcourseClientSpec extends Specification { | |||
|
|||
req3.path == '/sky/userinfo' | |||
req3.getHeader('Authorization') == "bearer my_token" | |||
|
|||
resp.status == 200 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What can we do to keep this assertion? Is it a change to use Retrofit2SyncCall.executeCall instead of execute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I was able to put the assertion back after changing the method call to Retrofit2syncCall.executeCall
Type type, Annotation[] annotations, Retrofit retrofit) { | ||
// If the return type is a String, provide it as such | ||
if (type.getTypeName().equals("java.lang.String")) { | ||
return (Converter<ResponseBody, String>) value -> IOUtils.toString(value.byteStream()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old code catches IOException and turns it into ConversionException. Is it more correct to throw SpinnakerConversion in that case here?
@@ -1,4 +1,4 @@ | |||
fiatVersion=1.53.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked mergify to update, but it'd be cleaner for you to rebase and make this commit disappear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github is still saying that this branch is out of date. Can you try rebasing again please?
.setLog(new Slf4jRetrofitLogger(TravisClient.class)) | ||
.setErrorHandler(SpinnakerRetrofitErrorHandler.getInstance()) | ||
return new Retrofit.Builder() | ||
.baseUrl(address) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you refer this and make sure the address doesn't end up in baseUrl must end in /
error. And this is applicable to all such retrofit2 client definitions.
@@ -264,7 +271,8 @@ public void updateBuild(String jobName, Long buildNumber, UpdatedBuild updatedBu | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retrofit2SyncCall.execute() is missing for jenkinsClient.submitDescription() at line 267
.setErrorHandler(SpinnakerRetrofitErrorHandler.getInstance()) | ||
BitBucketClient bitBucketClient(String address, String username, String password, OkHttp3ClientConfiguration okHttpClientConfig) { | ||
new Retrofit.Builder() | ||
.baseUrl(address) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure the baseUrl doesn't cause baseUrl must end in /
. Refer this for more details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used the PR you linked as a reference to fix this and added some tests. Added all the missing Retrofit2SyncCall.execute() calls also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alice485 - there are several places where Retrofit2SynCall.execute() is missing. Here are what I found so far:
…y class to prevent 'baseUrl must end in /' error
6d69e8a
to
0c4d482
Compare
public Response userInfo() { | ||
return skyServiceV1 != null ? skyServiceV1.userInfo() : skyServiceV2.userInfo(); | ||
public Response<ResponseBody> userInfo() { | ||
return skyServiceV1 != null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a nit, but
return skyServiceV1 != null | |
return Retrofit2SyncCall.executeCall(skyServiceV1 != null ? skyServiceV1.userInfo() : skyServiceV2.userInfo()); |
RetrofitError