Skip to content

Commit

Permalink
Merge pull request #371 from tomaslin/prevent-clusters
Browse files Browse the repository at this point in the history
feat(applications): allow clusters to be skipped when application details
  • Loading branch information
tomaslin committed Apr 5, 2017
2 parents f4f058e + ff4d606 commit 78b1dab
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
Expand Up @@ -57,8 +57,8 @@ class ApplicationController {
}

@RequestMapping(value = "/{application:.+}", method = RequestMethod.GET)
Map getApplication(@PathVariable("application") String application) {
def result = applicationService.getApplication(application)
Map getApplication(@PathVariable("application") String application, @RequestParam(value = "expand", defaultValue = "true") boolean expand) {
def result = applicationService.getApplication(application, expand)
if (!result) {
log.warn("Application ${application} not found")
throw new ApplicationNotFoundException("Application ${application} not found")
Expand Down
Expand Up @@ -122,8 +122,8 @@ class ApplicationService {
return allApplicationsCache.get()
}

Map getApplication(String name) {
def applicationRetrievers = buildApplicationRetrievers(name)
Map getApplication(String name, boolean expand) {
def applicationRetrievers = buildApplicationRetrievers(name, expand)
def futures = executorService.invokeAll(applicationRetrievers)
List<Map> applications
try {
Expand Down Expand Up @@ -167,11 +167,14 @@ class ApplicationService {
)] as Collection<Callable<List<Map>>>
}

private Collection<Callable<Map>> buildApplicationRetrievers(String applicationName) {
return [
new Front50ApplicationRetriever(applicationName, front50Service, allApplicationsCache),
new ClouddriverApplicationRetriever(applicationName, clouddriverService)
] as Collection<Callable<Map>>
private Collection<Callable<Map>> buildApplicationRetrievers(String applicationName, boolean expand) {
def retrievers = [
new Front50ApplicationRetriever(applicationName, front50Service, allApplicationsCache) as Callable<Map>
]
if (expand) {
retrievers.add(new ClouddriverApplicationRetriever(applicationName, clouddriverService) as Callable<Map>)
}
return retrievers
}

@CompileDynamic
Expand Down
Expand Up @@ -48,7 +48,7 @@ class ApplicationServiceSpec extends Specification {
def front50App = [name: name, email: email, owner: owner, accounts: account]

when:
def app = service.getApplication(name)
def app = service.getApplication(name, true)

then:
1 * clouddriver.getApplication(name) >> clouddriverApp
Expand Down Expand Up @@ -84,7 +84,7 @@ class ApplicationServiceSpec extends Specification {
def front50App = [name: name, email: email, owner: owner, accounts: front50Account]

when:
def app = service.getApplication(name)
def app = service.getApplication(name, true)

then:
1 * clouddriver.getApplication(name) >> clouddriverApp
Expand Down Expand Up @@ -119,7 +119,7 @@ class ApplicationServiceSpec extends Specification {
service.executorService = Executors.newFixedThreadPool(1)

when:
def app = service.getApplication(name)
def app = service.getApplication(name, true)

then:
1 * clouddriver.getApplication(name) >> null
Expand Down Expand Up @@ -157,7 +157,7 @@ class ApplicationServiceSpec extends Specification {
service.executorService = Executors.newFixedThreadPool(1)

when:
def app = service.getApplication(name)
def app = service.getApplication(name, true)

then:
1 * clouddriver.getApplication(name) >> null
Expand Down Expand Up @@ -203,7 +203,7 @@ class ApplicationServiceSpec extends Specification {

when: "should return last known good values if an exception is thrown"
def allApps = service.getAllApplications()
def singleApp = service.getApplication(name)
def singleApp = service.getApplication(name, true)

then:
1 * front50.getApplication(name) >> { throw new SocketTimeoutException() }
Expand Down Expand Up @@ -260,4 +260,27 @@ class ApplicationServiceSpec extends Specification {
"by-name" || true
"not-id" || false
}

void "should skip clouddriver call if expand set to false"() {
setup:
HystrixRequestContext.initializeContext()

def service = new ApplicationService()
def front50 = Mock(Front50Service)
def clouddriver = Mock(ClouddriverService)
def config = new ServiceConfiguration(services: [front50: new Service()])
def name = 'myApp'

service.serviceConfiguration = config
service.front50Service = front50
service.clouddriverService = clouddriver
service.executorService = Executors.newFixedThreadPool(1)

when:
def app = service.getApplication(name, false)

then:
0 * clouddriver.getApplication(name)
1 * front50.getApplication(name) >> null
}
}
Expand Up @@ -112,7 +112,7 @@ class FunctionalSpec extends Specification {
api.getApplication(name)

then:
1 * applicationService.getApplication(name) >> [name: name]
1 * applicationService.getApplication(name, true) >> [name: name]

where:
name = "foo"
Expand All @@ -123,7 +123,7 @@ class FunctionalSpec extends Specification {
api.getApplication(name)

then:
1 * applicationService.getApplication(name) >> null
1 * applicationService.getApplication(name, true) >> null

RetrofitError exception = thrown()
exception.response.status == 404
Expand Down

0 comments on commit 78b1dab

Please sign in to comment.