From ddfae6e03d8974d0976551e5438eebce968d0bcf Mon Sep 17 00:00:00 2001 From: Adam Jordens Date: Fri, 28 Jun 2019 10:40:57 -0700 Subject: [PATCH] fix(web): Better merging of `/applications/{app}?expand=false` responses (#839) Addresses an issue where the attributes of `cachedApplication` were overriding the most recent values from `front50`. --- .../gate/services/ApplicationService.groovy | 5 +++-- .../spinnaker/gate/ApplicationServiceSpec.groovy | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ApplicationService.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ApplicationService.groovy index 509dd28b4e..2434b92f94 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ApplicationService.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ApplicationService.groovy @@ -107,10 +107,11 @@ class ApplicationService { } catch (ExecutionException ee) { throw ee.cause } - if (expand == false) { + if (!expand) { def cachedApplication = allApplicationsCache.get().find { name.equalsIgnoreCase(it.name as String) } if (cachedApplication) { - applications.add(cachedApplication) + // ensure that `cachedApplication` attributes are overridden by any previously fetched metadata from front50 + applications.add(0, cachedApplication) } } List mergedApps = mergeApps(applications, serviceConfiguration.getService('front50')) diff --git a/gate-web/src/test/groovy/com/netflix/spinnaker/gate/ApplicationServiceSpec.groovy b/gate-web/src/test/groovy/com/netflix/spinnaker/gate/ApplicationServiceSpec.groovy index 86bb3b172f..80e4d67189 100644 --- a/gate-web/src/test/groovy/com/netflix/spinnaker/gate/ApplicationServiceSpec.groovy +++ b/gate-web/src/test/groovy/com/netflix/spinnaker/gate/ApplicationServiceSpec.groovy @@ -265,12 +265,23 @@ class ApplicationServiceSpec extends Specification { service.front50Service = front50 service.clouddriverService = clouddriver service.executorService = Executors.newFixedThreadPool(1) + service.allApplicationsCache.set([ + [name: name, email: "cached@email.com"] + ]) when: def app = service.getApplication(name, false) + then: 0 * clouddriver.getApplication(name) - 1 * front50.getApplication(name) >> null + 1 * front50.getApplication(name) >> { + return [ + name: name, + email: "updated@email.com" + ] + } + + app.attributes.email == "updated@email.com" } }