Skip to content
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

fix(web): Implementing missed clouddriver selector callsites #407

Merged
merged 1 commit into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,12 @@ class GateConfig extends RedisHttpSessionConfiguration {
}

@Bean
ClouddriverServiceSelector clouddriverServiceSelector(OkHttpClient okHttpClient) {
ClouddriverService defaultService = createClient "clouddriver", ClouddriverService, okHttpClient
ClouddriverService clouddriverService(OkHttpClient okHttpClient) {
createClient "clouddriver", ClouddriverService, okHttpClient
}

@Bean
ClouddriverServiceSelector clouddriverServiceSelector(ClouddriverService defaultClouddriverService, OkHttpClient okHttpClient) {
// support named clouddriver service clients
Map<String, ClouddriverService> dynamicServices = [:]
if (serviceConfiguration.getService("clouddriver").getConfig().containsKey("dynamicEndpoints")) {
Expand All @@ -163,12 +166,7 @@ class GateConfig extends RedisHttpSessionConfiguration {
}
}

return new ClouddriverServiceSelector(defaultService, dynamicServices)
}

@Bean
ClouddriverService clouddriverService(OkHttpClient okHttpClient) {
createClient "clouddriver", ClouddriverService, okHttpClient
return new ClouddriverServiceSelector(defaultClouddriverService, dynamicServices)
}

//---- semi-optional components:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
Expand Down Expand Up @@ -52,8 +53,9 @@ class ProjectController {
}

@RequestMapping(value = "/{id}/clusters", method = RequestMethod.GET)
List<Map> getClusters(@PathVariable("id") String projectId) {
def result = projectService.getClusters(projectId)
List<Map> getClusters(@PathVariable("id") String projectId,
@RequestHeader(value = "X-RateLimit-App", required = false) String sourceApp) {
def result = projectService.getClusters(projectId, sourceApp)
if (!result) {
log.warn("Project not found (projectId: ${projectId}")
throw new ProjectNotFoundException("Project not found (projectId: ${projectId})")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

package com.netflix.spinnaker.gate.controllers

import com.netflix.spinnaker.gate.services.internal.ClouddriverService
import com.netflix.spinnaker.gate.services.internal.ClouddriverServiceSelector
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RestController
Expand All @@ -29,11 +30,12 @@ import org.springframework.web.bind.annotation.RestController
class SubnetController {

@Autowired
ClouddriverService clouddriverService
ClouddriverServiceSelector clouddriverServiceSelector

@ApiOperation(value = "Retrieve a list of subnets for a given cloud provider")
@RequestMapping(value = "/{cloudProvider}", method = RequestMethod.GET)
List<Map> allByCloudProvider(@PathVariable String cloudProvider) {
clouddriverService.getSubnets(cloudProvider)
List<Map> allByCloudProvider(@PathVariable String cloudProvider,
@RequestHeader(value = "X-RateLimit-App", required = false) String sourceApp) {
clouddriverServiceSelector.select(sourceApp).getSubnets(cloudProvider)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.netflix.spinnaker.gate.services

import com.netflix.hystrix.exception.HystrixBadRequestException
import com.netflix.spinnaker.gate.services.commands.HystrixFactory
import com.netflix.spinnaker.gate.services.internal.ClouddriverService
import com.netflix.spinnaker.gate.services.internal.ClouddriverServiceSelector
import groovy.transform.CompileStatic
import groovy.transform.InheritConstructors
Expand All @@ -33,9 +32,6 @@ import retrofit.RetrofitError
class ClusterService {
private static final String GROUP = "clusters"

@Autowired
ClouddriverService clouddriverService

@Autowired
ClouddriverServiceSelector clouddriverServiceSelector

Expand All @@ -44,20 +40,20 @@ class ClusterService {

Map getClusters(String app, String selectorKey) {
HystrixFactory.newMapCommand(GROUP, "getClustersForApplication") {
clouddriverService.getClusters(app)
clouddriverServiceSelector.select(selectorKey).getClusters(app)
} execute()
}

List<Map> getClustersForAccount(String app, String account, String selectorKey) {
HystrixFactory.newListCommand(GROUP, "getClustersForApplicationInAccount-${providerLookupService.providerForAccount(account)}") {
clouddriverService.getClustersForAccount(app, account)
clouddriverServiceSelector.select(selectorKey).getClustersForAccount(app, account)
} execute()
}

Map getCluster(String app, String account, String clusterName, String selectorKey) {
HystrixFactory.newMapCommand(GROUP, "getCluster-${providerLookupService.providerForAccount(account)}") {
try {
clouddriverService.getCluster(app, account, clusterName)?.getAt(0) as Map
clouddriverServiceSelector.select(selectorKey).getCluster(app, account, clusterName)?.getAt(0) as Map
} catch (RetrofitError e) {
if (e.response?.status == 404) {
return [:]
Expand All @@ -69,19 +65,19 @@ class ClusterService {
}

List<Map> getClusterServerGroups(String app, String account, String clusterName, String selectorKey) {
getCluster(app, account, clusterName, null).serverGroups as List<Map>
getCluster(app, account, clusterName, selectorKey).serverGroups as List<Map>
}

List<Map> getScalingActivities(String app, String account, String clusterName, String serverGroupName, String provider, String region, String selectorKey) {
HystrixFactory.newListCommand(GROUP, "getScalingActivitiesForCluster-${providerLookupService.providerForAccount(account)}") {
clouddriverService.getScalingActivities(app, account, clusterName, provider, serverGroupName, region)
clouddriverServiceSelector.select(selectorKey).getScalingActivities(app, account, clusterName, provider, serverGroupName, region)
} execute()
}

Map getTargetServerGroup(String app, String account, String clusterName, String cloudProviderType, String scope, String target, Boolean onlyEnabled, Boolean validateOldest, String selectorKey) {
HystrixFactory.newMapCommand(GROUP, "getTargetServerGroup-${providerLookupService.providerForAccount(account)}") {
try {
return clouddriverService.getTargetServerGroup(app, account, clusterName, cloudProviderType, scope, target, onlyEnabled, validateOldest)
return clouddriverServiceSelector.select(selectorKey).getTargetServerGroup(app, account, clusterName, cloudProviderType, scope, target, onlyEnabled, validateOldest)
} catch (RetrofitError re) {
if (re.kind == RetrofitError.Kind.HTTP && re.response?.status == 404) {
throw new ServerGroupNotFound("unable to find $target in $cloudProviderType/$account/$scope/$clusterName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package com.netflix.spinnaker.gate.services

import com.netflix.spinnaker.gate.services.commands.HystrixFactory
import com.netflix.spinnaker.gate.services.internal.ClouddriverService
import com.netflix.spinnaker.gate.services.internal.ClouddriverServiceSelector
import groovy.transform.CompileStatic
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
Expand All @@ -29,26 +29,26 @@ class ImageService {
private static final String GROUP = "images"

@Autowired
ClouddriverService clouddriverService
ClouddriverServiceSelector clouddriverServiceSelector

@Autowired
ProviderLookupService providerLookupService

List<Map> getForAccountAndRegion(String provider, String account, String region, String imageId, String selectorKey) {
HystrixFactory.newListCommand(GROUP, "getImagesForAccountAndRegion-${providerLookupService.providerForAccount(account)}") {
clouddriverService.getImageDetails(provider, account, region, imageId)
clouddriverServiceSelector.select(selectorKey).getImageDetails(provider, account, region, imageId)
} execute()
}

List<Map> search(String provider, String query, String region, String account, Integer count, Map<String, Object> additionalFilters, String selectorKey) {
HystrixFactory.newListCommand(GROUP, "searchImages-${providerLookupService.providerForAccount(account)}") {
clouddriverService.findImages(provider, query, region, account, count, additionalFilters)
clouddriverServiceSelector.select(selectorKey).findImages(provider, query, region, account, count, additionalFilters)
} execute()
}

List<String> findTags(String provider, String account, String repository, String selectorKey) {
HystrixFactory.newListCommand(GROUP, "getTags-${providerLookupService.providerForAccount(account)}") {
clouddriverService.findTags(provider, account, repository)
clouddriverServiceSelector.select(selectorKey).findTags(provider, account, repository)
} execute()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.netflix.spinnaker.gate.services

import com.netflix.spinnaker.gate.config.InsightConfiguration
import com.netflix.spinnaker.gate.services.commands.HystrixFactory
import com.netflix.spinnaker.gate.services.internal.ClouddriverService
import com.netflix.spinnaker.gate.services.internal.ClouddriverServiceSelector
import groovy.transform.CompileStatic
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
Expand All @@ -30,7 +30,7 @@ class InstanceService {
private static final String GROUP = "instances"

@Autowired
ClouddriverService clouddriverService
ClouddriverServiceSelector clouddriverServiceSelector

@Autowired
InsightConfiguration insightConfiguration
Expand All @@ -40,8 +40,9 @@ class InstanceService {

Map getForAccountAndRegion(String account, String region, String instanceId, String selectorKey) {
HystrixFactory.newMapCommand(GROUP, "getInstancesForAccountAndRegion-${providerLookupService.providerForAccount(account)}") {
def accountDetails = clouddriverService.getAccount(account)
def instanceDetails = clouddriverService.getInstanceDetails(account, region, instanceId)
def service = clouddriverServiceSelector.select(selectorKey)
def accountDetails = service.getAccount(account)
def instanceDetails = service.getInstanceDetails(account, region, instanceId)
def instanceContext = instanceDetails.collectEntries {
return it.value instanceof String ? [it.key, it.value] : [it.key, ""]
} as Map<String, String>
Expand All @@ -55,7 +56,7 @@ class InstanceService {

Map getConsoleOutput(String account, String region, String instanceId, String provider, String selectorKey) {
HystrixFactory.newMapCommand(GROUP, "getConsoleOutput-${providerLookupService.providerForAccount(account)}") {
return clouddriverService.getConsoleOutput(account, region, instanceId, provider)
return clouddriverServiceSelector.select(selectorKey).getConsoleOutput(account, region, instanceId, provider)
} execute()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.netflix.spinnaker.gate.services

import com.netflix.spinnaker.gate.config.InsightConfiguration
import com.netflix.spinnaker.gate.services.commands.HystrixFactory
import com.netflix.spinnaker.gate.services.internal.ClouddriverService
import com.netflix.spinnaker.gate.services.internal.ClouddriverServiceSelector
import groovy.transform.CompileStatic
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
Expand All @@ -30,7 +30,7 @@ class JobService {
private static final String GROUP = "jobs"

@Autowired
ClouddriverService clouddriverService
ClouddriverServiceSelector clouddriverServiceSelector

@Autowired
InsightConfiguration insightConfiguration
Expand All @@ -41,15 +41,15 @@ class JobService {
List getForApplication(String applicationName, String expand, String selectorKey) {
String commandKey = Boolean.valueOf(expand) ? "getExpandedJobsForApplication" : "getJobsForApplication"
HystrixFactory.newListCommand(GROUP, commandKey) {
clouddriverService.getJobs(applicationName, expand)
clouddriverServiceSelector.select(selectorKey).getJobs(applicationName, expand)
} execute()
}

Map getForApplicationAndAccountAndRegion(String applicationName, String account, String region, String name, String selectorKey) {
HystrixFactory.newMapCommand(GROUP, "getJobsForApplicationAccountAndRegion-${providerLookupService.providerForAccount(account)}", {
try {
def context = getContext(applicationName, account, region, name)
return clouddriverService.getJobDetails(applicationName, account, region, name) + [
return clouddriverServiceSelector.select(selectorKey).getJobDetails(applicationName, account, region, name) + [
"insightActions": insightConfiguration.job.collect { it.applyContext(context) }
]
} catch (RetrofitError e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.netflix.spinnaker.gate.services

import com.netflix.spinnaker.gate.services.commands.HystrixFactory
import com.netflix.spinnaker.gate.services.internal.ClouddriverService
import com.netflix.spinnaker.gate.services.internal.ClouddriverServiceSelector
import groovy.transform.CompileStatic
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
Expand All @@ -28,37 +28,37 @@ class LoadBalancerService {
private static final String GROUP = "loadBalancers"

@Autowired
ClouddriverService clouddriverService
ClouddriverServiceSelector clouddriverServiceSelector

List<Map> getAll(String provider = "aws", String selectorKey) {
HystrixFactory.newListCommand(GROUP, "getAllLoadBalancersForProvider-$provider") {
clouddriverService.getLoadBalancers(provider)
clouddriverServiceSelector.select(selectorKey).getLoadBalancers(provider)
} execute()
}

Map get(String name, String selectorKey, String provider = "aws") {
HystrixFactory.newMapCommand(GROUP, "getLoadBalancer-$provider") {
clouddriverService.getLoadBalancer(provider, name)
clouddriverServiceSelector.select(selectorKey).getLoadBalancer(provider, name)
} execute()
}

List<Map> getDetailsForAccountAndRegion(String account, String region, String name, String selectorKey, String provider = "aws") {
HystrixFactory.newListCommand(GROUP, "getLoadBalancerDetails-$provider") {
clouddriverService.getLoadBalancerDetails(provider, account, region, name)
clouddriverServiceSelector.select(selectorKey).getLoadBalancerDetails(provider, account, region, name)
} execute()
}

List getClusterLoadBalancers(String appName, String account, String provider, String clusterName, String selectorKey) {
HystrixFactory.newListCommand(GROUP,
"getClusterLoadBalancers-$provider") {
clouddriverService.getClusterLoadBalancers(appName, account, clusterName, provider)
clouddriverServiceSelector.select(selectorKey).getClusterLoadBalancers(appName, account, clusterName, provider)
} execute()
}

List getApplicationLoadBalancers(String appName, String selectorKey) {
HystrixFactory.newListCommand(GROUP,
"getApplicationLoadBalancers") {
clouddriverService.getApplicationLoadBalancers(appName)
clouddriverServiceSelector.select(selectorKey).getApplicationLoadBalancers(appName)
} execute()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ package com.netflix.spinnaker.gate.services

import com.netflix.spinnaker.gate.config.InsightConfiguration
import com.netflix.spinnaker.gate.services.internal.ClouddriverService
import com.netflix.spinnaker.gate.services.internal.ClouddriverServiceSelector
import spock.lang.Specification

class InstanceServiceSpec extends Specification {
void "should include relevant insight actions for instance"() {
given:
def service = new InstanceService(
clouddriverService: Mock(ClouddriverService) {
1 * getInstanceDetails(_, _, _) >> { return [privateIpAddress: "10.0.0.1", map: [:]] }
1 * getAccount(_) >> { return [awsAccount: "prod"] }
clouddriverServiceSelector: Mock(ClouddriverServiceSelector) {
1 * select(_) >> {
Mock(ClouddriverService) {
1 * getInstanceDetails(_, _, _) >> { return [privateIpAddress: "10.0.0.1", map: [:]] }
1 * getAccount(_) >> { return [awsAccount: "prod"] }
}
}
},
providerLookupService: Stub(ProviderLookupService) {
providerForAccount(_) >> "test"
Expand Down