/** 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; } }
/** * 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; } } }