From cd39e856bf8740eb168c73d725f4724cb8729443 Mon Sep 17 00:00:00 2001 From: chrisb Date: Wed, 16 Dec 2015 12:14:06 -0800 Subject: [PATCH] add project clusters endpoint --- .../gate/services/internal/ClouddriverService.groovy | 4 ++++ .../gate/controllers/ProjectController.groovy | 10 ++++++++++ .../spinnaker/gate/services/ProjectService.groovy | 10 ++++++++++ 3 files changed, 24 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 03a4701912..6104d910b8 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 @@ -157,6 +157,10 @@ interface ClouddriverService { @Path("region") String region, @Path("imageId") String imageId) + @Headers("Accept: application/json") + @GET("/projects/{project}/clusters") + List getProjectClusters(@Path("project") String project) + @Headers("Accept: application/json") @GET("/reports/reservation") List getReservationReports() diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/ProjectController.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/ProjectController.groovy index fdb8ec1b04..f175e1385b 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/ProjectController.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/ProjectController.groovy @@ -51,6 +51,16 @@ class ProjectController { result } + @RequestMapping(value = "/{id}/clusters", method = RequestMethod.GET) + List getClusters(@PathVariable("id") String projectId) { + def result = projectService.getClusters(projectId) + if (!result) { + log.warn("Project not found (projectId: ${projectId}") + throw new ProjectNotFoundException("Project not found (projectId: ${projectId})") + } + result + } + @RequestMapping(value = "/{id:.+}/pipelines", method = RequestMethod.GET) List allPipelinesForProject(@PathVariable("id") String projectId, @RequestParam(value = "limit", defaultValue = "5") int limit, diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ProjectService.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ProjectService.groovy index 1a2f2f81f0..856806b790 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ProjectService.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ProjectService.groovy @@ -18,6 +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.Front50Service import com.netflix.spinnaker.gate.services.internal.OrcaService import groovy.transform.CompileStatic @@ -37,6 +38,9 @@ class ProjectService { @Autowired OrcaService orcaService + @Autowired + ClouddriverService clouddriverService + List getAll() { HystrixFactory.newListCommand(GROUP, "getAll") { return front50Service.getAllProjects().embedded.projects ?: [] @@ -54,4 +58,10 @@ class ProjectService { return orcaService.getPipelinesForProject(projectId, limit, statuses) } execute() } + + List getClusters(String projectId) { + HystrixFactory.newListCommand(GROUP, "getClusters") { + return clouddriverService.getProjectClusters(projectId) + } execute() + } }