/** * Sets the setting group. */ public Builder put(String settingPrefix, String groupName, String[] settings, String[] values) throws SettingsException { if (settings.length != values.length) { throw new SettingsException("The settings length must match the value length"); } for (int i = 0; i < settings.length; i++) { if (values[i] == null) { continue; } put(settingPrefix + "." + groupName + "." + settings[i], values[i]); } return this; }
/** * Returns the setting value (as float) associated with the setting key. If it does not exists, * returns the default value provided. */ public Float getAsFloat(String setting, Float defaultValue) { String sValue = get(setting); if (sValue == null) { return defaultValue; } try { return Float.parseFloat(sValue); } catch (NumberFormatException e) { throw new SettingsException("Failed to parse float setting [" + setting + "] with value [" + sValue + "]", e); } }
/** * Returns the setting value (as double) associated with the setting key. If it does not exists, * returns the default value provided. */ public Double getAsDouble(String setting, Double defaultValue) { String sValue = get(setting); if (sValue == null) { return defaultValue; } try { return Double.parseDouble(sValue); } catch (NumberFormatException e) { throw new SettingsException("Failed to parse double setting [" + setting + "] with value [" + sValue + "]", e); } }
/** * Returns the setting value (as int) associated with the setting key. If it does not exists, * returns the default value provided. */ public Integer getAsInt(String setting, Integer defaultValue) { String sValue = get(setting); if (sValue == null) { return defaultValue; } try { return Integer.parseInt(sValue); } catch (NumberFormatException e) { throw new SettingsException("Failed to parse int setting [" + setting + "] with value [" + sValue + "]", e); } }
/** * Returns the setting value (as long) associated with the setting key. If it does not exists, * returns the default value provided. */ public Long getAsLong(String setting, Long defaultValue) { String sValue = get(setting); if (sValue == null) { return defaultValue; } try { return Long.parseLong(sValue); } catch (NumberFormatException e) { throw new SettingsException("Failed to parse long setting [" + setting + "] with value [" + sValue + "]", e); } }
/** * Loads settings from the actual string content that represents them using {@link #fromXContent(XContentParser)} */ public Builder loadFromSource(String source, XContentType xContentType) { try (XContentParser parser = XContentFactory.xContent(xContentType) .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) { this.put(fromXContent(parser, true, true)); } catch (Exception e) { throw new SettingsException("Failed to load settings from [" + source + "]", e); } return this; }
/** * Returns a parsed version. */ public Version getAsVersion(String setting, Version defaultVersion) throws SettingsException { String sValue = get(setting); if (sValue == null) { return defaultVersion; } try { return Version.fromId(Integer.parseInt(sValue)); } catch (Exception e) { throw new SettingsException("Failed to parse version setting [" + setting + "] with value [" + sValue + "]", e); } }
private Map<String, Settings> getGroupsInternal(String settingPrefix, boolean ignoreNonGrouped) throws SettingsException { Settings prefixSettings = getByPrefix(settingPrefix); Map<String, Settings> groups = new HashMap<>(); for (String groupName : prefixSettings.names()) { Settings groupSettings = prefixSettings.getByPrefix(groupName + "."); if (groupSettings.isEmpty()) { if (ignoreNonGrouped) { continue; } throw new SettingsException("Failed to get setting group for [" + settingPrefix + "] setting prefix and setting [" + settingPrefix + groupName + "] because of a missing '.'"); } groups.put(groupName, groupSettings); } return Collections.unmodifiableMap(groups); } /**
/** * Loads settings from a stream that represents them using {@link #fromXContent(XContentParser)} */ public Builder loadFromStream(String resourceName, InputStream is, boolean acceptNullValues) throws IOException { final XContentType xContentType; if (resourceName.endsWith(".json")) { xContentType = XContentType.JSON; } else if (resourceName.endsWith(".yml") || resourceName.endsWith(".yaml")) { xContentType = XContentType.YAML; } else { throw new IllegalArgumentException("unable to detect content type from resource name [" + resourceName + "]"); } // fromXContent doesn't use named xcontent or deprecation. try (XContentParser parser = XContentFactory.xContent(xContentType) .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, is)) { if (parser.currentToken() == null) { if (parser.nextToken() == null) { return this; // empty file } } put(fromXContent(parser, acceptNullValues, true)); } catch (ElasticsearchParseException e) { throw e; } catch (Exception e) { throw new SettingsException("Failed to load settings from [" + resourceName + "]", e); } finally { IOUtils.close(is); } return this; }
throw new SettingsException("elasticsearch.yaml was deprecated in 5.5.0 and must be renamed to elasticsearch.yml"); throw new SettingsException("elasticsearch.json was deprecated in 5.5.0 and must be converted to elasticsearch.yml"); output.loadFromPath(path); } catch (IOException e) { throw new SettingsException("Failed to load settings from " + path.toString(), e);
private void validateConfigurationObject(Object value, String configFieldName) throws SettingsException { if (value == null) { throw new SettingsException("No default '" + configFieldName + "' configuration found!"); } }
/** * Sets the setting group. */ public Builder put(String settingPrefix, String groupName, String[] settings, String[] values) throws SettingsException { if (settings.length != values.length) { throw new SettingsException("The settings length must match the value length"); } for (int i = 0; i < settings.length; i++) { if (values[i] == null) { continue; } put(settingPrefix + "." + groupName + "." + settings[i], values[i]); } return this; }
/** * Sets the setting group. */ public Builder put(String settingPrefix, String groupName, String[] settings, String[] values) throws SettingsException { if (settings.length != values.length) { throw new SettingsException("The settings length must match the value length"); } for (int i = 0; i < settings.length; i++) { if (values[i] == null) { continue; } put(settingPrefix + "." + groupName + "." + settings[i], values[i]); } return this; }
/** * Sets the setting group. */ public Builder put(String settingPrefix, String groupName, String[] settings, String[] values) throws SettingsException { if (settings.length != values.length) { throw new SettingsException("The settings length must match the value length"); } for (int i = 0; i < settings.length; i++) { if (values[i] == null) { continue; } put(settingPrefix + "." + groupName + "." + settings[i], values[i]); } return this; }
/** * Loads settings from a url that represents them using the * {@link SettingsLoaderFactory#loaderFromSource(String)}. */ public Builder loadFromPath(Path path) throws SettingsException { try { return loadFromStream(path.getFileName().toString(), Files.newInputStream(path)); } catch (IOException e) { throw new SettingsException("Failed to open stream for url [" + path + "]", e); } }
private void validateConfigurationString(String value, String configFieldName) throws SettingsException { if (Utils.isEmpty(value)) { throw new SettingsException("No default '" + configFieldName + "' configuration found!"); } }
/** * Returns a parsed version. */ public Version getAsVersion(String setting, Version defaultVersion) throws SettingsException { String sValue = get(setting); if (sValue == null) { return defaultVersion; } try { return Version.fromId(Integer.parseInt(sValue)); } catch (Exception e) { throw new SettingsException("Failed to parse version setting [" + setting + "] with value [" + sValue + "]", e); } }
/** * Returns the setting value (as int) associated with the setting key. If it does not exists, * returns the default value provided. */ public Integer getAsInt(String setting, Integer defaultValue) { String sValue = get(setting); if (sValue == null) { return defaultValue; } try { return Integer.parseInt(sValue); } catch (NumberFormatException e) { throw new SettingsException("Failed to parse int setting [" + setting + "] with value [" + sValue + "]", e); } }
/** * Returns the setting value (as double) associated with the setting key. If it does not exists, * returns the default value provided. */ public Double getAsDouble(String setting, Double defaultValue) { String sValue = get(setting); if (sValue == null) { return defaultValue; } try { return Double.parseDouble(sValue); } catch (NumberFormatException e) { throw new SettingsException("Failed to parse double setting [" + setting + "] with value [" + sValue + "]", e); } }
/** * Returns the setting value (as long) associated with the setting key. If it does not exists, * returns the default value provided. */ public Long getAsLong(String setting, Long defaultValue) { String sValue = get(setting); if (sValue == null) { return defaultValue; } try { return Long.parseLong(sValue); } catch (NumberFormatException e) { throw new SettingsException("Failed to parse long setting [" + setting + "] with value [" + sValue + "]", e); } }