blob: 43ef5602d8a5587d873bd530a1d9f6b14d990ca6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.provision;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* All the available node flavors.
*
* @author freva
*/
public interface NodeFlavors {
/** Returns list of all available flavors in the system */
List<Flavor> getFlavors();
/** Returns a flavor by name, or empty if there is no flavor with this name. */
Optional<Flavor> getFlavor(String name);
/** Returns the flavor with the given name or throws an IllegalArgumentException if it does not exist */
default Flavor getFlavorOrThrow(String flavorName) {
return getFlavor(flavorName).orElseThrow(() -> new IllegalArgumentException("Unknown flavor '" + flavorName +
"'. Flavors are " + canonicalFlavorNames()));
}
private List<String> canonicalFlavorNames() {
return getFlavors().stream().map(Flavor::canonicalName).distinct().sorted().collect(Collectors.toList());
}
}
|