Java Code Examples for org.elasticsearch.common.unit.ByteSizeValue#parseBytesSizeValue()

The following examples show how to use org.elasticsearch.common.unit.ByteSizeValue#parseBytesSizeValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpressionToByteSizeValueVisitor.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected ByteSizeValue visitStringLiteral(StringLiteral node, Object[] context) {
    try {
        return ByteSizeValue.parseBytesSizeValue(node.getValue(), DEFAULT_VALUE.toString());
    } catch (ElasticsearchParseException e) {
        throw new IllegalArgumentException(
                String.format(Locale.ENGLISH, "Invalid byte size value '%s'", node.getValue()));
    }
}
 
Example 2
Source File: EngineConfig.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/** 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);
    }
}
 
Example 3
Source File: DiskThresholdDecider.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 4
Source File: DiskThresholdDecider.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
        }
    }
}
 
Example 5
Source File: LangDetectProcessor.java    From elasticsearch-ingest-langdetect with Apache License 2.0 5 votes vote down vote up
@Override
public LangDetectProcessor create(Map<String, Processor.Factory> factories, String tag, Map<String, Object> config)
        throws Exception {
    String field = readStringProperty(TYPE, tag, config, "field");
    String targetField = readStringProperty(TYPE, tag, config, "target_field");
    String maxLengthStr = readOptionalStringProperty(TYPE, tag, config, "max_length");

    ByteSizeValue maxLength = ByteSizeValue.parseBytesSizeValue(maxLengthStr, DEFAULT_MAX_LENGTH, "max_length");

    boolean ignoreMissing = readBooleanProperty(TYPE, tag, config, "ignore_missing", false);

    return new LangDetectProcessor(tag, field, targetField, maxLength, ignoreMissing);
}
 
Example 6
Source File: DiskThresholdSettings.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 7
Source File: DiskThresholdSettings.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 8
Source File: ElasticsearchProvider.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Factory method for creating an Elasticsearch provider within the plugin manager.
 *
 * @param cluster The name of the Elasticsearch cluster to which log event documents will be written.
 * @param host    The host name an Elasticsearch server node of the cluster, defaults to localhost.
 * @param port    The port that Elasticsearch is listening on, defaults to 9300
 * @param index   The index that Elasticsearch shall use for indexing
 * @param type    The type of the index Elasticsearch shall use for indexing
 * @return a new Elasticsearch provider
 */
@PluginFactory
public static ElasticsearchProvider createNoSqlProvider(
        @PluginAttribute("cluster") String cluster,
        @PluginAttribute("host") String host,
        @PluginAttribute("port") Integer port,
        @PluginAttribute("index") String index,
        @PluginAttribute("type") String type,
        @PluginAttribute("timeout") String timeout,
        @PluginAttribute("maxActionsPerBulkRequest") Integer maxActionsPerBulkRequest,
        @PluginAttribute("maxConcurrentBulkRequests") Integer maxConcurrentBulkRequests,
        @PluginAttribute("maxVolumePerBulkRequest") String maxVolumePerBulkRequest,
        @PluginAttribute("flushInterval") String flushInterval) {

    if (cluster == null || cluster.isEmpty()) {
        cluster = "elasticsearch";
    }
    if (host == null || host.isEmpty()) {
        host = "localhost";
    }
    if (port == null || port == 0) {
        port = 9300;
    }
    if (index == null || index.isEmpty()) {
        index = "log4j2";
    }
    if (type == null || type.isEmpty()) {
        type = "log4j2";
    }
    if (timeout == null || timeout.isEmpty()) {
        timeout = "30s";
    }
    if (maxActionsPerBulkRequest == null) {
        maxActionsPerBulkRequest = 1000;
    }
    if (maxConcurrentBulkRequests == null) {
        maxConcurrentBulkRequests = 2 * Runtime.getRuntime().availableProcessors();
    }
    if (maxVolumePerBulkRequest == null || maxVolumePerBulkRequest.isEmpty()) {
        maxVolumePerBulkRequest = "10m";
    }

    Settings settings = settingsBuilder()
            .put("cluster.name", cluster)
            .put("network.server", false)
            .put("node.client", true)
            .put("client.transport.sniff", true)
            .put("client.transport.ping_timeout", timeout)
            .put("client.transport.ignore_cluster_name", false)
            .put("client.transport.nodes_sampler_interval", "30s")
            .build();

    TransportClient client = new TransportClient(settings, false);
    client.addTransportAddress(new InetSocketTransportAddress(host, port));
    if (client.connectedNodes().isEmpty()) {
        logger.error("unable to connect to Elasticsearch cluster");
        return null;
    }
    String description = "cluster=" + cluster + ",host=" + host + ",port=" + port + ",index=" + index + ",type=" + type;
    ElasticsearchTransportClient elasticsearchTransportClient = new ElasticsearchTransportClient(client, index, type,
            maxActionsPerBulkRequest, maxConcurrentBulkRequests,
            ByteSizeValue.parseBytesSizeValue(maxVolumePerBulkRequest),
            TimeValue.parseTimeValue(flushInterval, TimeValue.timeValueSeconds(30)));
    ElasticsearchProvider elasticsearchProvider = new ElasticsearchProvider(elasticsearchTransportClient, description);
    
    return elasticsearchProvider;
}
 
Example 9
Source File: Setting.java    From crate with Apache License 2.0 4 votes vote down vote up
public static Setting<ByteSizeValue> byteSizeSetting(String key, Setting<ByteSizeValue> fallbackSetting,
                                                     Property... properties) {
    return new Setting<>(key, fallbackSetting, (s) -> ByteSizeValue.parseBytesSizeValue(s, key), properties);
}
 
Example 10
Source File: Setting.java    From crate with Apache License 2.0 4 votes vote down vote up
public static Setting<ByteSizeValue> byteSizeSetting(String key, Function<Settings, String> defaultValue,
                                                     Property... properties) {
    return new Setting<>(key, defaultValue, (s) -> ByteSizeValue.parseBytesSizeValue(s, key), properties);
}