Search in sources :

Example 1 with SettingsApplier

use of io.crate.metadata.settings.SettingsApplier in project crate by crate.

the class ESClusterUpdateSettingsTask method buildSettingsFrom.

static Settings buildSettingsFrom(Map<String, List<Expression>> settingsMap, Row parameters) {
    Settings.Builder settings = Settings.builder();
    for (Map.Entry<String, List<Expression>> entry : settingsMap.entrySet()) {
        String settingsName = entry.getKey();
        SettingsApplier settingsApplier = CrateSettings.getSettingsApplier(settingsName);
        settingsApplier.apply(settings, parameters, Iterables.getOnlyElement(entry.getValue()));
    }
    return settings.build();
}
Also used : SettingsApplier(io.crate.metadata.settings.SettingsApplier) List(java.util.List) Map(java.util.Map) CrateSettings(io.crate.metadata.settings.CrateSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 2 with SettingsApplier

use of io.crate.metadata.settings.SettingsApplier in project crate by crate.

the class RepositoryParamValidator method convertAndValidate.

public Settings convertAndValidate(String type, Optional<GenericProperties> genericProperties, ParameterContext parameterContext) {
    TypeSettings typeSettings = this.typeSettings.get(type);
    if (typeSettings == null) {
        throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Invalid repository type \"%s\"", type));
    }
    Map<String, SettingsApplier> allSettings = typeSettings.all();
    // create string settings applier for all dynamic settings
    Optional<GenericProperties> dynamicProperties = typeSettings.dynamicProperties(genericProperties);
    if (dynamicProperties.isPresent()) {
        // allSettings are immutable by default, copy map
        allSettings = Maps.newHashMap(allSettings);
        for (String key : dynamicProperties.get().properties().keySet()) {
            allSettings.put(key, new SettingsAppliers.StringSettingsApplier(new StringSetting(key, true)));
        }
    }
    // convert and validate all settings
    Settings settings = GenericPropertiesConverter.settingsFromProperties(genericProperties, parameterContext, allSettings).build();
    Set<String> names = settings.getAsMap().keySet();
    Sets.SetView<String> missingRequiredSettings = Sets.difference(typeSettings.required().keySet(), names);
    if (!missingRequiredSettings.isEmpty()) {
        throw new IllegalArgumentException(String.format(Locale.ENGLISH, "The following required parameters are missing to create a repository of type \"%s\": [%s]", type, Joiner.on(", ").join(missingRequiredSettings)));
    }
    return settings;
}
Also used : SettingsAppliers(io.crate.metadata.settings.SettingsAppliers) SettingsApplier(io.crate.metadata.settings.SettingsApplier) StringSetting(io.crate.metadata.settings.StringSetting) Sets(com.google.common.collect.Sets) GenericProperties(io.crate.sql.tree.GenericProperties) Settings(org.elasticsearch.common.settings.Settings)

Example 3 with SettingsApplier

use of io.crate.metadata.settings.SettingsApplier in project crate by crate.

the class TablePropertiesAnalyzer method analyze.

public static void analyze(TableParameter tableParameter, TableParameterInfo tableParameterInfo, Optional<GenericProperties> properties, Row parameters, boolean withDefaults) {
    if (withDefaults) {
        SettingsApplier settingsApplier = SETTINGS_APPLIER.get(TableParameterInfo.NUMBER_OF_REPLICAS);
        tableParameter.settingsBuilder().put(settingsApplier.getDefault());
        for (String mappingEntry : tableParameterInfo.supportedMappings()) {
            MappingsApplier mappingsApplier = MAPPINGS_APPLIER.get(mappingEntry);
            tableParameter.mappings().put(mappingsApplier.name, mappingsApplier.getDefault());
        }
    }
    if (properties.isPresent()) {
        Map<String, Expression> tableProperties = properties.get().properties();
        validateTableProperties(tableParameterInfo, tableProperties.keySet());
        for (String setting : tableParameterInfo.supportedSettings()) {
            String settingName = ES_TO_CRATE_SETTINGS_MAP.get(setting);
            if (tableProperties.containsKey(settingName)) {
                SettingsApplier settingsApplier = SETTINGS_APPLIER.get(setting);
                settingsApplier.apply(tableParameter.settingsBuilder(), parameters, tableProperties.get(settingName));
            }
        }
        for (String mappingEntry : tableParameterInfo.supportedMappings()) {
            String mappingName = ES_TO_CRATE_MAPPINGS_MAP.get(mappingEntry);
            if (tableProperties.containsKey(mappingName)) {
                MappingsApplier mappingsApplier = MAPPINGS_APPLIER.get(mappingEntry);
                mappingsApplier.apply(tableParameter.mappings(), parameters, tableProperties.get(mappingName));
            }
        }
    }
}
Also used : Expression(io.crate.sql.tree.Expression) SettingsApplier(io.crate.metadata.settings.SettingsApplier)

Example 4 with SettingsApplier

use of io.crate.metadata.settings.SettingsApplier in project crate by crate.

the class GenericPropertiesConverter method settingsFromProperties.

public static Settings.Builder settingsFromProperties(Optional<GenericProperties> properties, ParameterContext parameterContext, Map<String, ? extends SettingsApplier> settingAppliers) {
    Settings.Builder builder = Settings.builder();
    setDefaults(settingAppliers, builder);
    if (properties.isPresent()) {
        for (Map.Entry<String, Expression> entry : properties.get().properties().entrySet()) {
            SettingsApplier settingsApplier = settingAppliers.get(entry.getKey());
            if (settingsApplier == null) {
                throw new IllegalArgumentException(String.format(Locale.ENGLISH, "setting '%s' not supported", entry.getKey()));
            }
            settingsApplier.apply(builder, parameterContext.parameters(), entry.getValue());
        }
    }
    return builder;
}
Also used : Expression(io.crate.sql.tree.Expression) SettingsApplier(io.crate.metadata.settings.SettingsApplier) Settings(org.elasticsearch.common.settings.Settings)

Example 5 with SettingsApplier

use of io.crate.metadata.settings.SettingsApplier in project crate by crate.

the class TablePropertiesAnalyzer method analyze.

public static void analyze(TableParameter tableParameter, TableParameterInfo tableParameterInfo, List<String> properties) {
    validateTableProperties(tableParameterInfo, properties);
    for (String setting : tableParameterInfo.supportedSettings()) {
        String settingName = ES_TO_CRATE_SETTINGS_MAP.get(setting);
        if (properties.contains(settingName)) {
            SettingsApplier settingsApplier = SETTINGS_APPLIER.get(setting);
            tableParameter.settingsBuilder().put(settingsApplier.getDefault());
        }
    }
    for (String mappingEntry : tableParameterInfo.supportedMappings()) {
        String mappingName = ES_TO_CRATE_MAPPINGS_MAP.get(mappingEntry);
        if (properties.contains(mappingName)) {
            MappingsApplier mappingsApplier = MAPPINGS_APPLIER.get(mappingEntry);
            tableParameter.mappings().put(mappingsApplier.name, mappingsApplier.getDefault());
        }
    }
}
Also used : SettingsApplier(io.crate.metadata.settings.SettingsApplier)

Aggregations

SettingsApplier (io.crate.metadata.settings.SettingsApplier)5 Settings (org.elasticsearch.common.settings.Settings)3 Expression (io.crate.sql.tree.Expression)2 Sets (com.google.common.collect.Sets)1 CrateSettings (io.crate.metadata.settings.CrateSettings)1 SettingsAppliers (io.crate.metadata.settings.SettingsAppliers)1 StringSetting (io.crate.metadata.settings.StringSetting)1 GenericProperties (io.crate.sql.tree.GenericProperties)1 List (java.util.List)1 Map (java.util.Map)1