Skip to content

Commit

Permalink
Merge branch 'fix/jre17' of github.com:spinnaker/igor into fix/jre17
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgogerly committed Sep 20, 2023
2 parents 258e2df + 70e2cd9 commit 629ca17
Show file tree
Hide file tree
Showing 21 changed files with 126 additions and 111 deletions.
1 change: 1 addition & 0 deletions igor-web/igor-web.gradle
Expand Up @@ -12,6 +12,7 @@ dependencies {
implementation project(":igor-monitor-artifactory")
implementation project(":igor-monitor-plugins")
implementation project(":igor-monitor-travis")
implementation "io.spinnaker.kork:kork-retrofit"

implementation platform("io.spinnaker.kork:kork-bom:$korkVersion")
compileOnly "org.projectlombok:lombok"
Expand Down
Expand Up @@ -18,6 +18,7 @@ package com.netflix.spinnaker.igor.config

import com.netflix.spinnaker.igor.scm.bitbucket.client.BitBucketClient
import com.netflix.spinnaker.igor.scm.bitbucket.client.BitBucketMaster
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerRetrofitErrorHandler
import com.netflix.spinnaker.retrofit.Slf4jRetrofitLogger
import com.squareup.okhttp.Credentials
import groovy.transform.CompileStatic
Expand Down Expand Up @@ -58,6 +59,7 @@ class BitBucketConfig {
.setClient(new OkClient())
.setConverter(new JacksonConverter())
.setLog(new Slf4jRetrofitLogger(BitBucketClient))
.setErrorHandler(SpinnakerRetrofitErrorHandler.getInstance())
.build()
.create(BitBucketClient)
}
Expand Down
Expand Up @@ -19,6 +19,7 @@ package com.netflix.spinnaker.igor.config
import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spinnaker.igor.scm.github.client.GitHubClient
import com.netflix.spinnaker.igor.scm.github.client.GitHubMaster
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerRetrofitErrorHandler
import com.netflix.spinnaker.retrofit.Slf4jRetrofitLogger
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
Expand Down Expand Up @@ -57,6 +58,7 @@ class GitHubConfig {
.setClient(new OkClient())
.setConverter(new JacksonConverter(mapper))
.setLog(new Slf4jRetrofitLogger(GitHubClient))
.setErrorHandler(SpinnakerRetrofitErrorHandler.getInstance())
.build()
.create(GitHubClient)

Expand Down
Expand Up @@ -21,6 +21,7 @@
import com.netflix.spinnaker.igor.gitlabci.client.GitlabCiClient;
import com.netflix.spinnaker.igor.gitlabci.service.GitlabCiService;
import com.netflix.spinnaker.igor.service.BuildServices;
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerRetrofitErrorHandler;
import com.netflix.spinnaker.retrofit.Slf4jRetrofitLogger;
import com.squareup.okhttp.OkHttpClient;
import java.util.Map;
Expand Down Expand Up @@ -95,6 +96,7 @@ public static GitlabCiClient gitlabCiClient(
.setLog(new Slf4jRetrofitLogger(GitlabCiClient.class))
.setLogLevel(RestAdapter.LogLevel.FULL)
.setConverter(new JacksonConverter(objectMapper))
.setErrorHandler(SpinnakerRetrofitErrorHandler.getInstance())
.build()
.create(GitlabCiClient.class);
}
Expand Down
Expand Up @@ -31,6 +31,7 @@ import retrofit.RequestInterceptor
import retrofit.RestAdapter
import retrofit.client.OkClient
import retrofit.converter.JacksonConverter
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerRetrofitErrorHandler;

import javax.validation.Valid

Expand Down Expand Up @@ -61,7 +62,8 @@ class StashConfig {
.setConverter(new JacksonConverter())
.setLogLevel(retrofitLogLevel)
.setLog(new Slf4jRetrofitLogger(StashClient))
.build()
.setErrorHandler(SpinnakerRetrofitErrorHandler.getInstance())
.build()
.create(StashClient)
}

Expand Down
Expand Up @@ -17,6 +17,7 @@ import com.netflix.spinnaker.igor.service.BuildServices
import com.netflix.spinnaker.igor.wercker.WerckerCache
import com.netflix.spinnaker.igor.wercker.WerckerClient
import com.netflix.spinnaker.igor.wercker.WerckerService
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerRetrofitErrorHandler
import com.netflix.spinnaker.retrofit.Slf4jRetrofitLogger

import groovy.transform.CompileStatic
Expand Down Expand Up @@ -65,6 +66,7 @@ class WerckerConfig {
.setLog(new Slf4jRetrofitLogger(WerckerService))
.setLogLevel(retrofitLogLevel)
.setEndpoint(Endpoints.newFixedEndpoint(host.address))
.setErrorHandler(SpinnakerRetrofitErrorHandler.getInstance())
.setClient(new Ok3Client(client))
.build()
.create(WerckerClient)
Expand Down
Expand Up @@ -31,7 +31,9 @@
import com.netflix.spinnaker.igor.service.BuildProperties;
import com.netflix.spinnaker.igor.travis.client.logparser.PropertyParser;
import com.netflix.spinnaker.kork.core.RetrySupport;
import com.netflix.spinnaker.kork.exceptions.SpinnakerException;
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException;
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerNetworkException;
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerServerException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
Expand All @@ -40,7 +42,6 @@
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import retrofit.RetrofitError;

@Slf4j
public class GitlabCiService implements BuildOperations, BuildProperties {
Expand Down Expand Up @@ -175,17 +176,20 @@ private Map<String, Object> getPropertyFileFromLog(String projectId, Integer pip

return properties;

} catch (RetrofitError e) {
// retry on network issue, 404 and 5XX
if (e.getKind() == RetrofitError.Kind.NETWORK
|| (e.getKind() == RetrofitError.Kind.HTTP
&& (e.getResponse().getStatus() == 404
|| e.getResponse().getStatus() >= 500))) {
} catch (SpinnakerNetworkException e) {
// retry on network issue
throw e;
} catch (SpinnakerHttpException e) {
// retry on 404 and 5XX
if (e.getResponseCode() == 404 || e.getResponseCode() >= 500) {
throw e;
}
SpinnakerException ex = new SpinnakerException(e);
ex.setRetryable(false);
throw ex;
e.setRetryable(false);
throw e;
} catch (SpinnakerServerException e) {
// do not retry
e.setRetryable(false);
throw e;
} catch (IOException e) {
log.error("Error while parsing GitLab CI log to build properties", e);
return properties;
Expand Down
Expand Up @@ -21,6 +21,8 @@ import com.netflix.spinnaker.igor.exceptions.UnhandledDownstreamServiceErrorExce
import com.netflix.spinnaker.igor.scm.AbstractCommitController
import com.netflix.spinnaker.igor.scm.bitbucket.client.BitBucketMaster
import com.netflix.spinnaker.igor.scm.bitbucket.client.model.CompareCommitsResponse
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerServerException
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
Expand All @@ -29,7 +31,6 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import retrofit.RetrofitError

@Slf4j
@RestController(value = "BitBucketCommitController")
Expand Down Expand Up @@ -68,8 +69,8 @@ class CommitController extends AbstractCommitController {
if (fromIndex > -1) {
commitsResponse.values = commitsResponse.values.subList(0, fromIndex + 1)
}
} catch (RetrofitError e) {
if (e.response.status == 404) {
} catch (SpinnakerServerException e) {
if (e instanceof SpinnakerHttpException && ((SpinnakerHttpException) e).getResponseCode() == 404) {
return getNotFoundCommitsResponse(projectKey, repositorySlug, requestParams.to, requestParams.from, bitBucketMaster.baseUrl)
}
throw new UnhandledDownstreamServiceErrorException("Unhandled bitbucket error for ${bitBucketMaster.baseUrl}", e)
Expand Down
Expand Up @@ -20,6 +20,9 @@ import com.netflix.spinnaker.igor.config.GitHubProperties
import com.netflix.spinnaker.igor.scm.AbstractCommitController
import com.netflix.spinnaker.igor.scm.github.client.GitHubMaster
import com.netflix.spinnaker.igor.scm.github.client.model.CompareCommitsResponse
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerNetworkException
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerServerException
import com.netflix.spinnaker.kork.web.exceptions.NotFoundException
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -29,7 +32,6 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import retrofit.RetrofitError

@Slf4j
@RestController(value = "GitHubCommitController")
Expand All @@ -50,14 +52,14 @@ class CommitController extends AbstractCommitController {

try {
commitsResponse = master.gitHubClient.getCompareCommits(projectKey, repositorySlug, requestParams.to, requestParams.from)
} catch (RetrofitError e) {
if(e.getKind() == RetrofitError.Kind.NETWORK) {
throw new NotFoundException("Could not find the server ${master.baseUrl}")
} else if(e.response.status == 404) {
return getNotFoundCommitsResponse(projectKey, repositorySlug, requestParams.to, requestParams.from, master.baseUrl)
}
log.error("Unhandled error response, acting like commit response was not found", e)
} catch (SpinnakerNetworkException e) {
throw new NotFoundException("Could not find the server ${master.baseUrl}")
} catch (SpinnakerServerException e) {
if (e instanceof SpinnakerHttpException && ((SpinnakerHttpException)e).getResponseCode() == 404) {
return getNotFoundCommitsResponse(projectKey, repositorySlug, requestParams.to, requestParams.from, master.baseUrl)
}
log.error("Unhandled error response, acting like commit response was not found", e)
return getNotFoundCommitsResponse(projectKey, repositorySlug, requestParams.to, requestParams.from, master.baseUrl)
}

commitsResponse.commits.each {
Expand Down
Expand Up @@ -20,9 +20,10 @@ package com.netflix.spinnaker.igor.scm.github.client
import com.netflix.spinnaker.igor.scm.AbstractScmMaster
import com.netflix.spinnaker.igor.scm.github.client.model.Commit
import com.netflix.spinnaker.igor.scm.github.client.model.GetRepositoryContentResponse
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerNetworkException
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerServerException
import com.netflix.spinnaker.kork.web.exceptions.NotFoundException
import groovy.util.logging.Slf4j
import retrofit.RetrofitError

import java.util.stream.Collectors

Expand All @@ -44,10 +45,10 @@ class GitHubMaster extends AbstractScmMaster {
return response.stream()
.map({ r -> r.path })
.collect(Collectors.toList())
} catch (RetrofitError e) {
if (e.getKind() == RetrofitError.Kind.NETWORK) {
throw new NotFoundException("Could not find the server ${baseUrl}")
}
} catch (SpinnakerNetworkException e) {
throw new NotFoundException("Could not find the server ${baseUrl}")
}
catch (SpinnakerServerException e) {
log.error(
"Failed to fetch file from {}/{}/{}, reason: {}",
projectKey, repositorySlug, path, e.message
Expand All @@ -64,10 +65,9 @@ class GitHubMaster extends AbstractScmMaster {
throw new NotFoundException("Unexpected content type: ${response.type}");
}
return new String(Base64.mimeDecoder.decode(response.content));
} catch (RetrofitError e) {
if (e.getKind() == RetrofitError.Kind.NETWORK) {
throw new NotFoundException("Could not find the server ${baseUrl}")
}
} catch (SpinnakerNetworkException e) {
throw new NotFoundException("Could not find the server ${baseUrl}")
}catch (SpinnakerServerException e) {
log.error(
"Failed to fetch file from {}/{}/{}, reason: {}",
projectKey, repositorySlug, path, e.message
Expand Down
Expand Up @@ -20,6 +20,9 @@
import com.netflix.spinnaker.igor.scm.AbstractCommitController;
import com.netflix.spinnaker.igor.scm.gitlab.client.GitLabMaster;
import com.netflix.spinnaker.igor.scm.gitlab.client.model.CompareCommitsResponse;
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException;
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerNetworkException;
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerServerException;
import com.netflix.spinnaker.kork.web.exceptions.NotFoundException;
import java.util.HashMap;
import java.util.List;
Expand All @@ -30,7 +33,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.*;
import retrofit.RetrofitError;

@RestController(value = "GitLabCommitController")
@ConditionalOnProperty("gitlab.base-url")
Expand Down Expand Up @@ -66,13 +68,15 @@ public List<Map<String, Object>> compareCommits(
queryMap.put("from", fromParam);
commitsResponse =
gitLabMaster.getGitLabClient().getCompareCommits(projectKey, repositorySlug, queryMap);
} catch (RetrofitError e) {
if (e.getKind() == RetrofitError.Kind.NETWORK) {
throw new NotFoundException("Could not find the server " + gitLabMaster.getBaseUrl());
} else if (e.getResponse().getStatus() == 404) {
return getNotFoundCommitsResponse(
projectKey, repositorySlug, toParam, fromParam, gitLabMaster.getBaseUrl());
} catch (SpinnakerNetworkException e) {
throw new NotFoundException("Could not find the server " + gitLabMaster.getBaseUrl());
} catch (SpinnakerHttpException e) {
if (e.getResponseCode() != 404) {
log.error("Unhandled error response, acting like commit response was not found", e);
}
return getNotFoundCommitsResponse(
projectKey, repositorySlug, toParam, fromParam, gitLabMaster.getBaseUrl());
} catch (SpinnakerServerException e) {
log.error("Unhandled error response, acting like commit response was not found", e);
return getNotFoundCommitsResponse(
projectKey, repositorySlug, toParam, fromParam, gitLabMaster.getBaseUrl());
Expand Down
Expand Up @@ -19,6 +19,9 @@ package com.netflix.spinnaker.igor.scm.stash
import com.netflix.spinnaker.igor.scm.AbstractCommitController
import com.netflix.spinnaker.igor.scm.stash.client.StashMaster
import com.netflix.spinnaker.igor.scm.stash.client.model.CompareCommitsResponse
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerNetworkException
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerServerException
import com.netflix.spinnaker.kork.web.exceptions.NotFoundException
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -28,7 +31,6 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import retrofit.RetrofitError

@Slf4j
@RestController(value = "StashCommitController")
Expand All @@ -44,16 +46,21 @@ class CommitController extends AbstractCommitController {
CompareCommitsResponse commitsResponse
try {
commitsResponse = stashMaster.stashClient.getCompareCommits(projectKey, repositorySlug, requestParams)
} catch (RetrofitError e) {
if (e.getKind() == RetrofitError.Kind.NETWORK) {
throw new NotFoundException("Could not find the server ${stashMaster.baseUrl}")
} else if (e.response.status == 404) {
} catch (SpinnakerNetworkException e) {
throw new NotFoundException("Could not find the server ${stashMaster.baseUrl}")
} catch (SpinnakerHttpException e) {
if(e.getResponseCode() == 404) {
return getNotFoundCommitsResponse(projectKey, repositorySlug, requestParams.to, requestParams.from, stashMaster.baseUrl)
}
log.error(
}
log.error(
"Failed to fetch commits for {}/{}, reason: {}",
projectKey, repositorySlug, e.message
)
}catch (SpinnakerServerException e) {
log.error(
"Failed to fetch commits for {}/{}, reason: {}",
projectKey, repositorySlug, e.message
)
}

List result = []
Expand Down
Expand Up @@ -18,10 +18,10 @@ package com.netflix.spinnaker.igor.scm.stash.client

import com.netflix.spinnaker.igor.scm.AbstractScmMaster
import com.netflix.spinnaker.igor.scm.stash.client.model.TextLinesResponse
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerNetworkException
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerServerException
import com.netflix.spinnaker.kork.web.exceptions.NotFoundException
import groovy.util.logging.Slf4j
import retrofit.RetrofitError

/**
* Wrapper class for a collection of Stash clients
*/
Expand All @@ -35,10 +35,10 @@ class StashMaster extends AbstractScmMaster {
List<String> listDirectory(String projectKey, String repositorySlug, String path, String ref) {
try {
return stashClient.listDirectory(projectKey, repositorySlug, path, ref).toChildFilenames()
} catch (RetrofitError e) {
if (e.getKind() == RetrofitError.Kind.NETWORK) {
throw new NotFoundException("Could not find the server ${baseUrl}")
}
}catch (SpinnakerNetworkException e) {
throw new NotFoundException("Could not find the server ${baseUrl}")
}
catch (SpinnakerServerException e) {
log.error(
"Failed to fetch file from {}/{}/{}, reason: {}",
projectKey, repositorySlug, path, e.message
Expand All @@ -61,10 +61,9 @@ class StashMaster extends AbstractScmMaster {
contents += response.toTextContents() + "\n"
}
return contents
} catch (RetrofitError e) {
if (e.getKind() == RetrofitError.Kind.NETWORK) {
throw new NotFoundException("Could not find the server ${baseUrl}")
}
} catch (SpinnakerNetworkException e) {
throw new NotFoundException("Could not find the server ${baseUrl}")
} catch(SpinnakerServerException e) {
log.error(
"Failed to fetch file from {}/{}/{}, reason: {}",
projectKey, repositorySlug, path, e.message
Expand Down

0 comments on commit 629ca17

Please sign in to comment.