From 8679d818cd116f1a2bbf9c46fa86bf3b6eaacf56 Mon Sep 17 00:00:00 2001 From: Cameron Fieber Date: Thu, 3 Dec 2015 23:10:14 -0800 Subject: [PATCH] exposes TargetServerGroup lookup endpoint from clouddriver --- .../internal/ClouddriverService.groovy | 11 ++++++++++ .../gate/controllers/ClusterController.groovy | 12 ++++++++++ .../gate/services/ClusterService.groovy | 22 +++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/gate-core/src/main/groovy/com/netflix/spinnaker/gate/services/internal/ClouddriverService.groovy b/gate-core/src/main/groovy/com/netflix/spinnaker/gate/services/internal/ClouddriverService.groovy index 3c96d449ad..03a4701912 100644 --- a/gate-core/src/main/groovy/com/netflix/spinnaker/gate/services/internal/ClouddriverService.groovy +++ b/gate-core/src/main/groovy/com/netflix/spinnaker/gate/services/internal/ClouddriverService.groovy @@ -88,6 +88,17 @@ interface ClouddriverService { @Path("type") String type, @Path("serverGroupName") String serverGroupName) + @Headers("Accept: application/json") + @GET("/applications/{name}/clusters/{account}/{cluster}/{type}/{scope}/serverGroups/target/{target}") + Map getTargetServerGroup(@Path("name") String application, + @Path("account") String account, + @Path("cluster") String cluster, + @Path("type") String type, + @Path("scope") String scope, + @Path("target") String target, + @Query("onlyEnabled") Boolean onlyEnabled, + @Query("validateOldest") Boolean validateOldest) + @Headers("Accept: application/json") @GET("/applications/{name}/serverGroups") List getServerGroups(@Path("name") String name, @Query("expand") String expand) diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/ClusterController.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/ClusterController.groovy index aeed4693e1..b67d7bca32 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/ClusterController.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/ClusterController.groovy @@ -86,4 +86,16 @@ class ClusterController { it.name == serverGroupName } } + + @RequestMapping(value = "/{account:.+}/{clusterName:.+}/{cloudProvider}/{scope}/serverGroups/target/{target:.+}", method = RequestMethod.GET) + Map getTargetServerGroup(@PathVariable("application") String app, + @PathVariable("account") String account, + @PathVariable("clusterName") String clusterName, + @PathVariable("cloudProvider") String cloudProvider, + @PathVariable("scope") String scope, + @PathVariable("target") String target, + @RequestParam(value = "onlyEnabled", required = false) Boolean onlyEnabled, + @RequestParam(value = "validateOldest", required = false) Boolean validateOldest) { + clusterService.getTargetServerGroup(app, account, clusterName, cloudProvider, scope, target, onlyEnabled, validateOldest) + } } diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ClusterService.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ClusterService.groovy index cfe4a7c782..f19c2d2141 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ClusterService.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ClusterService.groovy @@ -15,11 +15,16 @@ */ 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 groovy.transform.CompileStatic +import groovy.transform.InheritConstructors import org.springframework.beans.factory.annotation.Autowired +import org.springframework.http.HttpStatus import org.springframework.stereotype.Component +import org.springframework.web.bind.annotation.ResponseStatus import retrofit.RetrofitError @CompileStatic @@ -65,4 +70,21 @@ class ClusterService { clouddriverService.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) { + HystrixFactory.newMapCommand(GROUP, "getTargetServerGroup") { + try { + return clouddriverService.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") + } + throw re + } + } execute() + } + + @ResponseStatus(HttpStatus.NOT_FOUND) + @InheritConstructors + static class ServerGroupNotFound extends HystrixBadRequestException {} }