|
@@ -237,23 +237,12 @@ public class ClusterUtil {
|
|
|
|
|
|
public static Mono<Set<ExtendedAdminClient.SupportedFeature>> getSupportedFeatures(
|
|
|
AdminClient adminClient) {
|
|
|
- return ClusterUtil.toMono(adminClient.describeCluster().controller())
|
|
|
- .map(Node::id)
|
|
|
- .map(id -> Collections
|
|
|
- .singletonList(new ConfigResource(ConfigResource.Type.BROKER, id.toString())))
|
|
|
- .map(brokerCR -> adminClient.describeConfigs(brokerCR).all())
|
|
|
- .flatMap(ClusterUtil::toMono)
|
|
|
+ return getClusterVersion(adminClient)
|
|
|
.map(ClusterUtil::getSupportedUpdateFeature)
|
|
|
.map(Collections::singleton);
|
|
|
}
|
|
|
|
|
|
- private static ExtendedAdminClient.SupportedFeature getSupportedUpdateFeature(
|
|
|
- Map<ConfigResource, Config> configs) {
|
|
|
- String version = configs.values().stream()
|
|
|
- .map(Config::entries)
|
|
|
- .flatMap(Collection::stream)
|
|
|
- .filter(entry -> entry.name().contains(CLUSTER_VERSION_PARAM_KEY))
|
|
|
- .findFirst().orElseThrow().value();
|
|
|
+ private static ExtendedAdminClient.SupportedFeature getSupportedUpdateFeature(String version) {
|
|
|
try {
|
|
|
final String[] parts = version.split("\\.");
|
|
|
if (parts.length > 2) {
|
|
@@ -268,6 +257,25 @@ public class ClusterUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static Mono<String> getClusterVersion(AdminClient adminClient) {
|
|
|
+ return ClusterUtil.toMono(adminClient.describeCluster().controller())
|
|
|
+ .map(Node::id)
|
|
|
+ .map(id -> Collections
|
|
|
+ .singletonList(new ConfigResource(ConfigResource.Type.BROKER, id.toString())))
|
|
|
+ .map(brokerCR -> adminClient.describeConfigs(brokerCR).all())
|
|
|
+ .flatMap(ClusterUtil::toMono)
|
|
|
+ .map(ClusterUtil::getClusterVersion);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getClusterVersion(Map<ConfigResource, Config> configs) {
|
|
|
+ return configs.values().stream()
|
|
|
+ .map(Config::entries)
|
|
|
+ .flatMap(Collection::stream)
|
|
|
+ .filter(entry -> entry.name().contains(CLUSTER_VERSION_PARAM_KEY))
|
|
|
+ .findFirst().orElseThrow().value();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public static <T, R> Map<T, R> toSingleMap(Stream<Map<T, R>> streamOfMaps) {
|
|
|
return streamOfMaps
|
|
|
.reduce((map1, map2) -> Stream.concat(map1.entrySet().stream(), map2.entrySet().stream())
|