Search in sources :

Example 1 with ApiVersionValidator$

use of kafka.api.ApiVersionValidator$ in project strimzi-kafka-operator by strimzi.

the class KafkaConfigModelGenerator method configs.

private static Map<String, ConfigModel> configs() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    ConfigDef def = brokerConfigs();
    Map<String, String> dynamicUpdates = brokerDynamicUpdates();
    Method getConfigValueMethod = def.getClass().getDeclaredMethod("getConfigValue", ConfigDef.ConfigKey.class, String.class);
    getConfigValueMethod.setAccessible(true);
    Method sortedConfigs = ConfigDef.class.getDeclaredMethod("sortedConfigs");
    sortedConfigs.setAccessible(true);
    List<ConfigDef.ConfigKey> keys = (List) sortedConfigs.invoke(def);
    Map<String, ConfigModel> result = new TreeMap<>();
    for (ConfigDef.ConfigKey key : keys) {
        String configName = String.valueOf(getConfigValueMethod.invoke(def, key, "Name"));
        Type type = parseType(String.valueOf(getConfigValueMethod.invoke(def, key, "Type")));
        Scope scope = parseScope(dynamicUpdates.getOrDefault(key.name, "read-only"));
        ConfigModel descriptor = new ConfigModel();
        descriptor.setType(type);
        descriptor.setScope(scope);
        if (key.validator instanceof ConfigDef.Range) {
            descriptor = range(key, descriptor);
        } else if (key.validator instanceof ConfigDef.ValidString) {
            descriptor.setValues(enumer(key.validator));
        } else if (key.validator instanceof ConfigDef.ValidList) {
            descriptor.setItems(validList(key));
        } else if (key.validator instanceof ApiVersionValidator$) {
            Iterator<ApiVersion> iterator = ApiVersion$.MODULE$.allVersions().iterator();
            LinkedHashSet<String> versions = new LinkedHashSet<>();
            while (iterator.hasNext()) {
                ApiVersion next = iterator.next();
                ApiVersion$.MODULE$.apply(next.shortVersion());
                versions.add(Pattern.quote(next.shortVersion()) + "(\\.[0-9]+)*");
                ApiVersion$.MODULE$.apply(next.version());
                versions.add(Pattern.quote(next.version()));
            }
            descriptor.setPattern(String.join("|", versions));
        } else if (key.validator instanceof ConfigDef.NonEmptyString) {
            descriptor.setPattern(".+");
        } else if (key.validator instanceof RaftConfig.ControllerQuorumVotersValidator) {
            continue;
        } else if (key.validator != null) {
            throw new IllegalStateException("Invalid validator class " + key.validator.getClass() + " for option " + configName);
        }
        result.put(configName, descriptor);
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConfigModel(io.strimzi.kafka.config.model.ConfigModel) Iterator(scala.collection.Iterator) List(java.util.List) RaftConfig(org.apache.kafka.raft.RaftConfig) ApiVersionValidator$(kafka.api.ApiVersionValidator$) ApiVersion(kafka.api.ApiVersion) Method(java.lang.reflect.Method) TreeMap(java.util.TreeMap) Type(io.strimzi.kafka.config.model.Type) Scope(io.strimzi.kafka.config.model.Scope) ConfigDef(org.apache.kafka.common.config.ConfigDef)

Example 2 with ApiVersionValidator$

use of kafka.api.ApiVersionValidator$ in project strimzi by strimzi.

the class KafkaConfigModelGenerator method configs.

private static Map<String, ConfigModel> configs() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    ConfigDef def = brokerConfigs();
    Map<String, String> dynamicUpdates = brokerDynamicUpdates();
    Method getConfigValueMethod = def.getClass().getDeclaredMethod("getConfigValue", ConfigDef.ConfigKey.class, String.class);
    getConfigValueMethod.setAccessible(true);
    Method sortedConfigs = ConfigDef.class.getDeclaredMethod("sortedConfigs");
    sortedConfigs.setAccessible(true);
    List<ConfigDef.ConfigKey> keys = (List) sortedConfigs.invoke(def);
    Map<String, ConfigModel> result = new TreeMap<>();
    for (ConfigDef.ConfigKey key : keys) {
        String configName = String.valueOf(getConfigValueMethod.invoke(def, key, "Name"));
        Type type = parseType(String.valueOf(getConfigValueMethod.invoke(def, key, "Type")));
        Scope scope = parseScope(dynamicUpdates.getOrDefault(key.name, "read-only"));
        ConfigModel descriptor = new ConfigModel();
        descriptor.setType(type);
        descriptor.setScope(scope);
        if (key.validator instanceof ConfigDef.Range) {
            descriptor = range(key, descriptor);
        } else if (key.validator instanceof ConfigDef.ValidString) {
            descriptor.setValues(enumer(key.validator));
        } else if (key.validator instanceof ConfigDef.ValidList) {
            descriptor.setItems(validList(key));
        } else if (key.validator instanceof ApiVersionValidator$) {
            Iterator<ApiVersion> iterator = ApiVersion$.MODULE$.allVersions().iterator();
            LinkedHashSet<String> versions = new LinkedHashSet<>();
            while (iterator.hasNext()) {
                ApiVersion next = iterator.next();
                ApiVersion$.MODULE$.apply(next.shortVersion());
                versions.add(Pattern.quote(next.shortVersion()) + "(\\.[0-9]+)*");
                ApiVersion$.MODULE$.apply(next.version());
                versions.add(Pattern.quote(next.version()));
            }
            descriptor.setPattern(String.join("|", versions));
        } else if (key.validator instanceof ConfigDef.NonEmptyString) {
            descriptor.setPattern(".+");
        } else if (key.validator instanceof RaftConfig.ControllerQuorumVotersValidator) {
            continue;
        } else if (key.validator != null) {
            throw new IllegalStateException("Invalid validator class " + key.validator.getClass() + " for option " + configName);
        }
        result.put(configName, descriptor);
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConfigModel(io.strimzi.kafka.config.model.ConfigModel) Iterator(scala.collection.Iterator) List(java.util.List) RaftConfig(org.apache.kafka.raft.RaftConfig) ApiVersionValidator$(kafka.api.ApiVersionValidator$) ApiVersion(kafka.api.ApiVersion) Method(java.lang.reflect.Method) TreeMap(java.util.TreeMap) Type(io.strimzi.kafka.config.model.Type) Scope(io.strimzi.kafka.config.model.Scope) ConfigDef(org.apache.kafka.common.config.ConfigDef)

Aggregations

ConfigModel (io.strimzi.kafka.config.model.ConfigModel)2 Scope (io.strimzi.kafka.config.model.Scope)2 Type (io.strimzi.kafka.config.model.Type)2 Method (java.lang.reflect.Method)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 ApiVersion (kafka.api.ApiVersion)2 ApiVersionValidator$ (kafka.api.ApiVersionValidator$)2 ConfigDef (org.apache.kafka.common.config.ConfigDef)2 RaftConfig (org.apache.kafka.raft.RaftConfig)2 Iterator (scala.collection.Iterator)2