Class SelectableService<T>
java.lang.Object
com.netflix.spinnaker.kork.web.selector.v2.SelectableService<T>
- Type Parameters:
T- the type of service to be selected
Provides support for sharding a service based on
SelectableService.Parameter. Example of a service
definition:
bakery:
baseUrl: http://bakery.com
altBakeryApiEnabled: false
timeoutMs: 3000
baseUrls:
- baseUrl: http://alt-bakery.us-west-x.com
priority: 1
config:
altBakeryApiEnabled: true
maxItemsCached: 10
parameters:
- name: region
values:
- us-west-1
- us-west-2
- baseUrl: http://alt-bakery.other.com
priority: 2
config:
altBakeryApiEnabled: true
parameters:
- name: artifactType
values:
- RPM
- name: baseOS
values:
- centOS
- name: user
values:
- regx:^[a-f].+@netflix.com
Usage:
val config = mapOf("timeoutMs", 3000)
val selectableBakery: SelectableService<BakeryService> = SelectableService(
baseUrls: properties.baseUrls,
defaultService: bakery,
defaultConfig: config,
getServiceByUrlFx: { url -> getService(url)}
)
// select by artifact type
val authenticatedUser = "alice@netflix.com"
val params = listOf(Parameter("artifactType", listOf("RPM")), Parameter("user", listOf(authenticatedUser)))
val bakery = selectableBakery.byParameters(params)
val result = bakery.getService().createBake(request)
// configuration {@link BaseUrl#config} attributes for each service definition are accessible like this
if (bakery.config["altBakeryApiEnabled"]) {
// Do interesting things
}
assert bakery.baseUrl == "http://alt-bakery.other.com"
assert bakery.config == mapOf("timeoutMs" to 3000, "altBakeryApiEnabled" to true)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classRepresents a selected service -
Constructor Summary
ConstructorsConstructorDescriptionSelectableService(List<SelectableService.BaseUrl> baseUrls, T defaultService, Map<String, Object> defaultConfig, Function<String, T> getServiceByUrlFx) -
Method Summary
Modifier and TypeMethodDescriptionbyParameters(List<SelectableService.Parameter> inputParameters) Selects a service based on inputSelectableService.Parameteras criteria
-
Constructor Details
-
SelectableService
-
-
Method Details
-
byParameters
public SelectableService.SelectedService<T> byParameters(List<SelectableService.Parameter> inputParameters) Selects a service based on inputSelectableService.Parameteras criteria- Parameters:
inputParameters- parameters to use to select a service- Returns:
- new
SelectableService.SelectedServicecontaining the selecting parameter.
-
getDefaultService
-
getServices
-