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();
}
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;
}
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));
}
}
}
}
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;
}
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());
}
}
}
Aggregations