Skip to content

Commit

Permalink
Merge pull request #166 from ttomsu/google-bake-options
Browse files Browse the repository at this point in the history
Hooks up and exposes Bakery endpoint for getting bakery options dynam…
  • Loading branch information
cfieber committed Dec 30, 2015
2 parents bea874e + abcd280 commit 7bc1275
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 1 deletion.
24 changes: 23 additions & 1 deletion gate-web/config/gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,29 @@ services:
baseUrl: http://localhost:8080
clouddriver:
baseUrl: http://localhost:7002
#optional services:
# semi-optional services (Everybody except Netflix needs these):
rosco:
enabled: true
baseUrl: http://localhost:8087
# These are here only for Netflix, whose bakery does not support dynamically fetching these properties.
# Modifying the details below when rosco.enabled is true will have no effect (do it in the Rosco config).
defaults:
bakeOptions:
- cloudProvider: aws
baseImages:
- id: ubuntu
shortDescription: v12.04
detailedDescription: Ubuntu Precise Pangolin v12.04
packageType: DEB
- id: trusty
shortDescription: v14.04
detailedDescription: Ubuntu Trusty Tahr v14.04
packageType: DEB
- id: centos
shortDescription: deprecated
detailedDescription: CentOS v5.11
packageType: RPM
# optional services:
echo:
enabled: false
flapjack:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ class GateConfig {
createClient "clouddriver", ClouddriverService, okHttpClient
}

//---- semi-optional components:
@Bean
@ConditionalOnProperty('services.rosco.enabled')
RoscoService roscoService(OkHttpClient okHttpClient) {
createClient "rosco", RoscoService, okHttpClient
}

//---- optional backend components:
@Bean
@ConditionalOnProperty('services.echo.enabled')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2015 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.spinnaker.gate.controllers

import com.netflix.spinnaker.gate.services.BakeService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController

@RequestMapping("/bakery")
@RestController
class BakeController {

@Autowired
BakeService bakeService

@RequestMapping(value = "/options", method = RequestMethod.GET)
def bakeOptions() {
bakeService.bakeOptions()
}

@RequestMapping(value = "/options/{cloudProvider}", method = RequestMethod.GET)
def bakeOptions(@PathVariable("cloudProvider") String cloudProvider) {
bakeService.bakeOptions(cloudProvider)
}

@ExceptionHandler
@ResponseStatus(HttpStatus.NOT_FOUND)
Map handleBakeOptionsException(Exception e) {
[error: "bake.options.not.found", status: HttpStatus.NOT_FOUND, message: e.message]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2015 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.spinnaker.gate.services

import com.netflix.spinnaker.gate.services.internal.RoscoService
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.stereotype.Component

@Slf4j
@Component
@ConfigurationProperties('services.rosco.defaults')
class BakeService {

@Autowired(required = false)
RoscoService roscoService

// Default bake options from configuration.
List<BakeOptions> bakeOptions

def bakeOptions() {
roscoService ? roscoService.bakeOptions() : bakeOptions
}

def bakeOptions(String cloudProvider) {
if (roscoService) {
return roscoService.bakeOptions(cloudProvider)
}
def bakeOpts = bakeOptions.find { it.cloudProvider == cloudProvider }
if (bakeOpts) {
return bakeOpts
}
throw new IllegalArgumentException("Bake options for cloud provider ${cloudProvider} not found")
}

static class BakeOptions {
String cloudProvider
List<BaseImage> baseImages
}

static class BaseImage {
String id
String shortDescription
String detailedDescription
String packageType
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2015 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.spinnaker.gate.services.internal

import retrofit.http.GET
import retrofit.http.Path

interface RoscoService {

@GET("/bakeOptions")
List bakeOptions()

@GET("/bakeOptions/{cloudProvider}")
Map bakeOptions(@Path("cloudProvider") String cloudProvider)

}

0 comments on commit 7bc1275

Please sign in to comment.