Skip to content

Commit

Permalink
feat(bakery): Add rosco service selector (#800)
Browse files Browse the repository at this point in the history
- Added RoscoServiceSelector to find services by location/region
- Make bakeService use the roscoServiceSelector
- Refactor OrcaServiceSelector criteria instantiation
  • Loading branch information
jeyrschabu authored and cfieber committed May 17, 2019
1 parent cfeaf8a commit e1cafc7
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
kotlinVersion = "1.3.21"
korkVersion = "5.3.1"
korkVersion = "5.3.2"
fiatVersion = "1.0.4"
}
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import com.netflix.spinnaker.gate.services.internal.MineService
import com.netflix.spinnaker.gate.services.internal.OrcaService
import com.netflix.spinnaker.gate.services.internal.OrcaServiceSelector
import com.netflix.spinnaker.gate.services.internal.RoscoService
import com.netflix.spinnaker.gate.services.internal.RoscoServiceSelector
import com.netflix.spinnaker.gate.services.internal.SwabbieService
import com.netflix.spinnaker.kork.dynamicconfig.DynamicConfigService
import com.netflix.spinnaker.kork.web.selector.DefaultServiceSelector
Expand Down Expand Up @@ -194,6 +195,15 @@ class GateConfig extends RedisHttpSessionConfiguration {
createClient "rosco", RoscoService, okHttpClient
}

@Bean
@ConditionalOnProperty('services.rosco.enabled')
RoscoServiceSelector roscoServiceSelector(OkHttpClient okHttpClient, RoscoService defaultService) {
return new RoscoServiceSelector(
createClientSelector("rosco", RoscoService, okHttpClient),
defaultService
)
}

//---- optional backend components:
@Bean
@ConditionalOnProperty('services.echo.enabled')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.netflix.spinnaker.gate.services

import com.netflix.spinnaker.gate.services.internal.RoscoService
import com.netflix.spinnaker.gate.services.internal.RoscoServiceSelector
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.context.properties.ConfigurationProperties
Expand All @@ -26,20 +26,19 @@ import org.springframework.stereotype.Component
@Component
@ConfigurationProperties('services.rosco.defaults')
class BakeService {

@Autowired(required = false)
RoscoService roscoService
RoscoServiceSelector roscoServiceSelector

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

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

def bakeOptions(String cloudProvider) {
if (roscoService) {
return roscoService.bakeOptions(cloudProvider)
if (roscoServiceSelector) {
return roscoServiceSelector.withLocation().bakeOptions(cloudProvider)
}
def bakeOpts = bakeOptions.find { it.cloudProvider == cloudProvider }
if (bakeOpts) {
Expand All @@ -49,8 +48,8 @@ class BakeService {
}

String lookupLogs(String region, String statusId) {
if (roscoService) {
def logsMap = roscoService.lookupLogs(region, statusId)
if (roscoServiceSelector) {
def logsMap = roscoServiceSelector.withLocation(region).lookupLogs(region, statusId)

if (logsMap?.logsContent) {
return "<pre>$logsMap.logsContent</pre>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ public OrcaServiceSelector(SelectableService selectableService) {
}

public OrcaService withContext(RequestContext context) {
SelectableService.Criteria criteria =
new SelectableService.Criteria(null, null, null, null, null);

SelectableService.Criteria criteria = new SelectableService.Criteria();
if (context != null) {
criteria =
new SelectableService.Criteria(
context.getApplication(),
context.getAuthenticatedUser(),
context.getExecutionType(),
context.getExecutionId(),
context.getOrigin());
criteria
.withApplication(context.getApplication())
.withAuthenticatedUser(context.getAuthenticatedUser())
.withExecutionId(context.getExecutionId())
.withOrigin(context.getOrigin())
.withExecutionType(context.getExecutionType());
}

return (OrcaService) selectableService.getService(criteria);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2019 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 com.netflix.spinnaker.kork.web.selector.SelectableService;

public class RoscoServiceSelector {
private final SelectableService selectableService;
private final RoscoService defaultService;

public RoscoServiceSelector(SelectableService selectableService, RoscoService roscoService) {
this.selectableService = selectableService;
this.defaultService = roscoService;
}

public RoscoService withLocation(String location) {
if (location == null) {
return defaultService;
}

return (RoscoService)
selectableService.getService(new SelectableService.Criteria().withLocation(location));
}
}

0 comments on commit e1cafc7

Please sign in to comment.