Skip to content

Commit

Permalink
Merge pull request #163 from cfieber/master
Browse files Browse the repository at this point in the history
exposes TargetServerGroup lookup endpoint from clouddriver
  • Loading branch information
cfieber committed Dec 7, 2015
2 parents d069547 + 8679d81 commit 45fd7aa
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {}
}

0 comments on commit 45fd7aa

Please sign in to comment.