-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(front50): use SpinnakerRetrofitErrorHandler with Front50Serv…
…ice (#4623) * refactor(front50): use SpinnakerRetrofitErrorHandler with Front50Service This PR lays the foundational work for upgrading the retrofit version to 2.x, specifically focusing on refactoring the exception handling for Front50Service. There are no behaviour changes detected with these code changes and hence no additional tests added to demonstrate the functionalities. Few existing tests are modified to align it with the new changes. * refactor(applications): Cleanup RetrofitError in DeleteApplicationTask There are 3 APIs invoked inside the try block: 1. Keel Service API - keelService.deleteDeliveryConfig(): With the addition of the commit - c417922, the keelService uses SpinnakerRetrofitErrorHandler. 2. Front50 Service APIs - front50Service.get() and front50Service.delete(): With the addition of the commit - a44b5bb, the front50 service uses SpinnakerRetrofitErrorHandler. and hence with the above mentioned commits, the catch block with RetrofitError becomes irrelevant. * refactor(igor): Cleanup RetrofitError in GetCommitsTask There are total of 5 API calls happening inside the try block: 1. Igor Service API - scmService.compareCommits(): With the addition of the commit - d430b75, the igorService uses SpinnakerRetrofitErrorHandler. 2. Clouddriver APIs (OortService) - cloudDriverService.getByAmiId() - This is invoked twice in the block, and oortService.getServerGroupFromCluster(): With the addition of the commit - 84a7106, the oortService uses SpinnakerRetrofitErrorHandler. 3. Front50 API - front50Service.get(): With the addition of the commit - a44b5bb, the front50Service uses SpinnakerRetrofitErrorHandler. and hence with the above mentioned commits, the catch block with RetrofitError becomes irrelevant. * refactor(test/clouddriver): Cleanup impractical tests in TrafficGuardSpec The API call 'front50Service.get(application)' mocked/stubbed to return null value is not realistic, because if the application is not available , then this API would throw a 404 HTTP error and thats already handled in the same class: https://github.com/spinnaker/orca/blob/7e923cc05af0f66b952245722aa69c667f685c5c/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/utils/TrafficGuardSpec.groovy#L464. and hence this test is cleaned up. * refactor(test/applications): Cleanup impractical tests in UpsertApplicationTaskSpec The API call 'front50Service.get(application)' mocked/stubbed to return null value is not realistic, because if the application is not present, then this API would throw a 404 HTTP error. and hence this test is cleaned up. * refactor(test): adjust UpsertApplicationTaskSpec tests to use realistic behavior of Front50Service.get when an application isn't found. It doesn't return null in this case, it throws an exception. Restore previously removed "should create an application in global registries" test since it was providing useful coverage. --------- Co-authored-by: Pranav-b-7 <[email protected]> Co-authored-by: David Byron <[email protected]>
- Loading branch information
1 parent
fc072b3
commit 38b447f
Showing
23 changed files
with
77 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,12 @@ package com.netflix.spinnaker.orca.applications.tasks | |
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.netflix.spinnaker.kork.dynamicconfig.DynamicConfigService | ||
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException | ||
import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionStatus | ||
import com.netflix.spinnaker.orca.front50.Front50Service | ||
import com.netflix.spinnaker.orca.front50.model.Application | ||
import retrofit.RetrofitError | ||
import retrofit.client.Response | ||
import spock.lang.Specification | ||
import spock.lang.Subject | ||
import spock.lang.Unroll | ||
|
@@ -57,7 +60,7 @@ class UpsertApplicationTaskSpec extends Specification { | |
given: | ||
def app = new Application(config.application + [user: config.user]) | ||
task.front50Service = Mock(Front50Service) { | ||
1 * get(config.application.name) >> null | ||
1 * get(config.application.name) >> { throw notFoundError() } | ||
1 * create(app) | ||
1 * updatePermission(*_) | ||
0 * _._ | ||
|
@@ -99,7 +102,11 @@ class UpsertApplicationTaskSpec extends Specification { | |
application.user = config.user | ||
|
||
task.front50Service = Mock(Front50Service) { | ||
1 * get(config.application.name) >> initialState | ||
if (initialState == null) { | ||
1 * get(config.application.name) >> { throw notFoundError() } | ||
} else { | ||
1 * get(config.application.name) >> initialState | ||
} | ||
1 * "${operation}"(*_) | ||
_ * updatePermission(*_) | ||
0 * _._ | ||
|
@@ -150,4 +157,13 @@ class UpsertApplicationTaskSpec extends Specification { | |
[:] || 1 | ||
[READ: ["[email protected]"], WRITE: ["[email protected]"]] || 1 | ||
} | ||
|
||
private static SpinnakerHttpException notFoundError() { | ||
return new SpinnakerHttpException(RetrofitError.httpError( | ||
"http://front50", | ||
new Response("http://front50", 404, "Not Found", [], null), | ||
null, | ||
null | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.