throw new ElasticsearchParseException("Percentage should be in [0-100], got [{}]", percentAsString); return new RatioValue(Math.abs(percent)); } catch (NumberFormatException e) { throw new ElasticsearchParseException("Failed to parse [{}] as a double", e, percentAsString); throw new ElasticsearchParseException("Ratio should be in [0-1.0], got [{}]", ratio); return new RatioValue(100.0 * Math.abs(ratio)); } catch (NumberFormatException e) { throw new ElasticsearchParseException("Invalid ratio or percentage [{}]", sValue);
/** * Attempts to parse the watermark into a percentage, returning 100.0% if it can not be parsed and the specified lenient parameter is * true, otherwise throwing an {@link ElasticsearchParseException}. * * @param watermark the watermark to parse as a percentage * @param lenient true if lenient parsing should be applied * @return the parsed percentage */ private static double thresholdPercentageFromWatermark(String watermark, boolean lenient) { try { return RatioValue.parseRatioValue(watermark).getAsPercent(); } catch (ElasticsearchParseException ex) { // NOTE: this is not end-user leniency, since up above we check that it's a valid byte or percentage, and then store the two // cases separately if (lenient) { return 100.0; } throw ex; } }
/** * Returns the setting value (as a RatioValue) associated with the setting key. Provided values can * either be a percentage value (eg. 23%), or expressed as a floating point number (eg. 0.23). If * it does not exist, parses the default value provided. */ public RatioValue getAsRatio(String setting, String defaultValue) throws SettingsException { return RatioValue.parseRatioValue(get(setting, defaultValue)); }
/** * Checks if a watermark string is a valid percentage or byte size value, * @return the watermark value given */ private static String validWatermarkSetting(String watermark, String settingName) { try { RatioValue.parseRatioValue(watermark); } catch (ElasticsearchParseException e) { try { ByteSizeValue.parseBytesSizeValue(watermark, settingName); } catch (ElasticsearchParseException ex) { ex.addSuppressed(e); throw ex; } } return watermark; } }
/** * Attempts to parse the watermark into a percentage, returning 100.0% if * it cannot be parsed. */ private double thresholdPercentageFromWatermark(String watermark) { try { return RatioValue.parseRatioValue(watermark).getAsPercent(); } catch (ElasticsearchParseException ex) { // NOTE: this is not end-user leniency, since up above we check that it's a valid byte or percentage, and then store the two // cases separately return 100.0; } }
/** * Returns the setting value (as a RatioValue) associated with the setting key. Provided values can * either be a percentage value (eg. 23%), or expressed as a floating point number (eg. 0.23). If * it does not exist, parses the default value provided. */ public RatioValue getAsRatio(String setting, String defaultValue) throws SettingsException { return RatioValue.parseRatioValue(get(setting, defaultValue)); }
throw new ElasticsearchParseException("Percentage should be in [0-100], got [{}]", percentAsString); return new RatioValue(Math.abs(percent)); } catch (NumberFormatException e) { throw new ElasticsearchParseException("Failed to parse [{}] as a double", e, percentAsString); throw new ElasticsearchParseException("Ratio should be in [0-1.0], got [{}]", ratio); return new RatioValue(100.0 * Math.abs(ratio)); } catch (NumberFormatException e) { throw new ElasticsearchParseException("Invalid ratio or percentage [{}]", sValue);
/** * Attempts to parse the watermark into a percentage, returning 100.0% if * it cannot be parsed. */ public double thresholdPercentageFromWatermark(String watermark) { try { return RatioValue.parseRatioValue(watermark).getAsPercent(); } catch (ElasticsearchParseException ex) { // NOTE: this is not end-user leniency, since up above we check that it's a valid byte or percentage, and then store the two cases separately return 100.0; } }
/** * Returns the setting value (as a RatioValue) associated with the setting key. Provided values can * either be a percentage value (eg. 23%), or expressed as a floating point number (eg. 0.23). If * it does not exist, parses the default value provided. */ public RatioValue getAsRatio(String setting, String defaultValue) throws SettingsException { return RatioValue.parseRatioValue(get(setting, defaultValue)); }
throw new ElasticsearchParseException("Percentage should be in [0-100], got [{}]", percentAsString); return new RatioValue(Math.abs(percent)); } catch (NumberFormatException e) { throw new ElasticsearchParseException("Failed to parse [{}] as a double", e, percentAsString); throw new ElasticsearchParseException("Ratio should be in [0-1.0], got [{}]", ratio); return new RatioValue(100.0 * Math.abs(ratio)); } catch (NumberFormatException e) { throw new ElasticsearchParseException("Invalid ratio or percentage [{}]", sValue);
/** * Attempts to parse the watermark into a percentage, returning 100.0% if it can not be parsed and the specified lenient parameter is * true, otherwise throwing an {@link ElasticsearchParseException}. * * @param watermark the watermark to parse as a percentage * @param lenient true if lenient parsing should be applied * @return the parsed percentage */ private static double thresholdPercentageFromWatermark(String watermark, boolean lenient) { try { return RatioValue.parseRatioValue(watermark).getAsPercent(); } catch (ElasticsearchParseException ex) { // NOTE: this is not end-user leniency, since up above we check that it's a valid byte or percentage, and then store the two // cases separately if (lenient) { return 100.0; } throw ex; } }
/** * Returns the setting value (as a RatioValue) associated with the setting key. Provided values can * either be a percentage value (eg. 23%), or expressed as a floating point number (eg. 0.23). If * it does not exist, parses the default value provided. */ public RatioValue getAsRatio(String setting, String defaultValue) throws SettingsException { return RatioValue.parseRatioValue(get(setting, defaultValue)); }
throw new ElasticsearchParseException("Percentage should be in [0-100], got [{}]", percentAsString); return new RatioValue(Math.abs(percent)); } catch (NumberFormatException e) { throw new ElasticsearchParseException("Failed to parse [{}] as a double", e, percentAsString); throw new ElasticsearchParseException("Ratio should be in [0-1.0], got [{}]", ratio); return new RatioValue(100.0 * Math.abs(ratio)); } catch (NumberFormatException e) { throw new ElasticsearchParseException("Invalid ratio or percentage [{}]", sValue);
/** * Attempts to parse the watermark into a percentage, returning 100.0% if it can not be parsed and the specified lenient parameter is * true, otherwise throwing an {@link ElasticsearchParseException}. * * @param watermark the watermark to parse as a percentage * @param lenient true if lenient parsing should be applied * @return the parsed percentage */ private static double thresholdPercentageFromWatermark(String watermark, boolean lenient) { try { return RatioValue.parseRatioValue(watermark).getAsPercent(); } catch (ElasticsearchParseException ex) { // NOTE: this is not end-user leniency, since up above we check that it's a valid byte or percentage, and then store the two // cases separately if (lenient) { return 100.0; } throw ex; } }
/** * Returns the setting value (as a RatioValue) associated with the setting key. Provided values can * either be a percentage value (eg. 23%), or expressed as a floating point number (eg. 0.23). If * it does not exist, parses the default value provided. */ public RatioValue getAsRatio(String setting, String defaultValue) throws SettingsException { return RatioValue.parseRatioValue(get(setting, defaultValue)); }
throw new ElasticsearchParseException("Percentage should be in [0-100], got [{}]", percentAsString); return new RatioValue(Math.abs(percent)); } catch (NumberFormatException e) { throw new ElasticsearchParseException("Failed to parse [{}] as a double", e, percentAsString); throw new ElasticsearchParseException("Ratio should be in [0-1.0], got [{}]", ratio); return new RatioValue(100.0 * Math.abs(ratio)); } catch (NumberFormatException e) { throw new ElasticsearchParseException("Invalid ratio or percentage [{}]", sValue);
/** * Returns the setting value (as a RatioValue) associated with the setting key. Provided values can * either be a percentage value (eg. 23%), or expressed as a floating point number (eg. 0.23). If * it does not exist, parses the default value provided. */ public RatioValue getAsRatio(String[] settings, String defaultValue) throws SettingsException { return RatioValue.parseRatioValue(get(settings, defaultValue)); }
/** * Checks if a watermark string is a valid percentage or byte size value, * returning true if valid, false if invalid. */ public boolean validWatermarkSetting(String watermark, String settingName) { try { RatioValue.parseRatioValue(watermark); return true; } catch (ElasticsearchParseException e) { try { ByteSizeValue.parseBytesSizeValue(watermark, settingName); return true; } catch (ElasticsearchParseException ex) { return false; } } }
/** * Checks if a watermark string is a valid percentage or byte size value, * @return the watermark value given */ private static String validWatermarkSetting(String watermark, String settingName) { try { RatioValue.parseRatioValue(watermark); } catch (ElasticsearchParseException e) { try { ByteSizeValue.parseBytesSizeValue(watermark, settingName); } catch (ElasticsearchParseException ex) { ex.addSuppressed(e); throw ex; } } return watermark; } }
/** * Checks if a watermark string is a valid percentage or byte size value, * @return the watermark value given */ private static String validWatermarkSetting(String watermark, String settingName) { try { RatioValue.parseRatioValue(watermark); } catch (ElasticsearchParseException e) { try { ByteSizeValue.parseBytesSizeValue(watermark, settingName); } catch (ElasticsearchParseException ex) { ex.addSuppressed(e); throw ex; } } return watermark; } }