public static ByteSizeValue parseBytesSizeValue(String sValue, String settingName) throws ElasticsearchParseException { return parseBytesSizeValue(sValue, null, settingName); }
bulkBuilder.bulkActions(bulkActions); String size = XContentMapValues.nodeStringValue(bulkSettings.get(SIZE_FIELD), DEFAULT_BULK_SIZE.toString()); bulkBuilder.bulkSize(ByteSizeValue.parseBytesSizeValue(size)); bulkBuilder.concurrentRequests(XContentMapValues.nodeIntegerValue(bulkSettings.get(CONCURRENT_REQUESTS_FIELD), EsExecutors.boundedNumberOfProcessors(ImmutableSettings.EMPTY)));
/** * Attempts to parse the watermark into a {@link ByteSizeValue}, returning zero bytes 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 byte size * @param settingName the name of the setting * @param lenient true if lenient parsing should be applied * @return the parsed byte size value */ private static ByteSizeValue thresholdBytesFromWatermark(String watermark, String settingName, boolean lenient) { try { return ByteSizeValue.parseBytesSizeValue(watermark, settingName); } 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 ByteSizeValue.parseBytesSizeValue("0b", settingName); } throw ex; } }
/** * Returns the setting value (as size) associated with the setting key. If it does not exists, * returns the default value provided. */ public ByteSizeValue getAsBytesSize(String setting, ByteSizeValue defaultValue) throws SettingsException { return parseBytesSizeValue(get(setting), defaultValue, setting); }
public static Setting<ByteSizeValue> byteSizeSetting(String key, Setting<ByteSizeValue> fallbackSetting, Property... properties) { return new Setting<>(key, fallbackSetting, (s) -> ByteSizeValue.parseBytesSizeValue(s, key), properties); }
public static Setting<ByteSizeValue> byteSizeSetting(String key, Function<Settings, String> defaultValue, Property... properties) { return new Setting<>(key, defaultValue, (s) -> ByteSizeValue.parseBytesSizeValue(s, key), properties); }
public ByteSizeValue paramAsSize(String key, ByteSizeValue defaultValue) { return parseBytesSizeValue(param(key), defaultValue, key); }
/** * 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; } }
public static MaxSizeCondition fromXContent(XContentParser parser) throws IOException { if (parser.nextToken() == XContentParser.Token.VALUE_STRING) { return new MaxSizeCondition(ByteSizeValue.parseBytesSizeValue(parser.text(), NAME)); } else { throw new IllegalArgumentException("invalid token: " + parser.currentToken()); } } }
/** Parse the provided string as a memory size. This method either accepts absolute values such as * {@code 42} (default assumed unit is byte) or {@code 2mb}, or percentages of the heap size: if * the heap is 1G, {@code 10%} will be parsed as {@code 100mb}. */ public static ByteSizeValue parseBytesSizeValueOrHeapRatio(String sValue, String settingName) { settingName = Objects.requireNonNull(settingName); if (sValue != null && sValue.endsWith("%")) { final String percentAsString = sValue.substring(0, sValue.length() - 1); try { final double percent = Double.parseDouble(percentAsString); if (percent < 0 || percent > 100) { throw new ElasticsearchParseException("percentage should be in [0-100], got [{}]", percentAsString); } return new ByteSizeValue((long) ((percent / 100) * JvmInfo.jvmInfo().getMem().getHeapMax().getBytes()), ByteSizeUnit.BYTES); } catch (NumberFormatException e) { throw new ElasticsearchParseException("failed to parse [{}] as a double", e, percentAsString); } } else { return parseBytesSizeValue(sValue, settingName); } } }
public static ByteSizeValue parseByteSize(String s, ByteSizeValue minValue, ByteSizeValue maxValue, String key) { ByteSizeValue value = ByteSizeValue.parseBytesSizeValue(s, key); if (value.getBytes() < minValue.getBytes()) { final String message = String.format( Locale.ROOT, "failed to parse value [%s] for setting [%s], must be >= [%s]", s, key, minValue.getStringRep()); throw new IllegalArgumentException(message); } if (value.getBytes() > maxValue.getBytes()) { final String message = String.format( Locale.ROOT, "failed to parse value [%s] for setting [%s], must be <= [%s]", s, key, maxValue.getStringRep()); throw new IllegalArgumentException(message); } return value; }
/** * Attempts to parse the watermark into a {@link ByteSizeValue}, returning * a ByteSizeValue of 0 bytes if the value cannot be parsed. */ public ByteSizeValue thresholdBytesFromWatermark(String watermark, String settingName) { try { return ByteSizeValue.parseBytesSizeValue(watermark, settingName); } 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 ByteSizeValue.parseBytesSizeValue("0b", settingName); } }
/** * Returns the setting value (as size) associated with the setting key. If it does not exists, * returns the default value provided. */ public ByteSizeValue getAsBytesSize(String setting, ByteSizeValue defaultValue) throws SettingsException { return parseBytesSizeValue(get(setting), defaultValue, setting); }
/** * Returns the setting value (as size) associated with the setting key. If it does not exists, * returns the default value provided. */ public ByteSizeValue getAsBytesSize(String setting, ByteSizeValue defaultValue) throws SettingsException { return parseBytesSizeValue(get(setting), defaultValue, setting); }
/** * Returns the setting value (as size) associated with the setting key. If it does not exists, * returns the default value provided. */ public ByteSizeValue getAsBytesSize(String setting, ByteSizeValue defaultValue) throws SettingsException { return parseBytesSizeValue(get(setting), defaultValue, setting); }
/** updates {@link #versionMapSize} based on current setting and {@link #indexingBufferSize} */ private void updateVersionMapSize() { if (versionMapSizeSetting.endsWith("%")) { double percent = Double.parseDouble(versionMapSizeSetting.substring(0, versionMapSizeSetting.length() - 1)); versionMapSize = new ByteSizeValue((long) ((double) indexingBufferSize.bytes() * (percent / 100))); } else { versionMapSize = ByteSizeValue.parseBytesSizeValue(versionMapSizeSetting, INDEX_VERSION_MAP_SIZE); } }
public static Optional<ByteSizeValue> getSize(TomlTable toml, String dottedKey) { return Optional.ofNullable( ByteSizeValue.parseBytesSizeValue( toml.getString(dottedKey), "'" + dottedKey + "' at " + toml.inputPositionOf(dottedKey))); }
public static ByteSizeValue parseByteSize(String s, ByteSizeValue minValue, ByteSizeValue maxValue, String key) { ByteSizeValue value = ByteSizeValue.parseBytesSizeValue(s, key); if (value.getBytes() < minValue.getBytes()) { throw new IllegalArgumentException("Failed to parse value [" + s + "] for setting [" + key + "] must be >= " + minValue); } if (value.getBytes() > maxValue.getBytes()) { throw new IllegalArgumentException("Failed to parse value [" + s + "] for setting [" + key + "] must be <= " + maxValue); } return value; }
public static MaxSizeCondition fromXContent(XContentParser parser) throws IOException { if (parser.nextToken() == XContentParser.Token.VALUE_STRING) { return new MaxSizeCondition(ByteSizeValue.parseBytesSizeValue(parser.text(), NAME)); } else { throw new IllegalArgumentException("invalid token: " + parser.currentToken()); } } }
public static MaxSizeCondition fromXContent(XContentParser parser) throws IOException { if (parser.nextToken() == XContentParser.Token.VALUE_STRING) { return new MaxSizeCondition(ByteSizeValue.parseBytesSizeValue(parser.text(), NAME)); } else { throw new IllegalArgumentException("invalid token: " + parser.currentToken()); } } }