org.elasticsearch.common.Strings Java Examples

The following examples show how to use org.elasticsearch.common.Strings. 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: RestIndicesExistsAction.java    From Elasticsearch with Apache License 2.0 13 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest(Strings.splitStringByCommaToArray(request.param("index")));
    indicesExistsRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesExistsRequest.indicesOptions()));
    indicesExistsRequest.local(request.paramAsBoolean("local", indicesExistsRequest.local()));
    client.admin().indices().exists(indicesExistsRequest, new RestResponseListener<IndicesExistsResponse>(channel) {
        @Override
        public RestResponse buildResponse(IndicesExistsResponse response) {
            if (response.isExists()) {
                return new BytesRestResponse(OK);
            } else {
                return new BytesRestResponse(NOT_FOUND);
            }
        }

    });
}
 
Example #2
Source File: RestTermVectorsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
static public void addFieldStringsFromParameter(TermVectorsRequest termVectorsRequest, String fields) {
    Set<String> selectedFields = termVectorsRequest.selectedFields();
    if (fields != null) {
        String[] paramFieldStrings = Strings.commaDelimitedListToStringArray(fields);
        for (String field : paramFieldStrings) {
            if (selectedFields == null) {
                selectedFields = new HashSet<>();
            }
            if (!selectedFields.contains(field)) {
                field = field.replaceAll("\\s", "");
                selectedFields.add(field);
            }
        }
    }
    if (selectedFields != null) {
        termVectorsRequest.selectedFields(selectedFields.toArray(new String[selectedFields.size()]));
    }
}
 
Example #3
Source File: SizeValue.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    long singles = singles();
    double value = singles;
    String suffix = "";
    if (singles >= SizeUnit.C5) {
        value = petaFrac();
        suffix = "p";
    } else if (singles >= SizeUnit.C4) {
        value = teraFrac();
        suffix = "t";
    } else if (singles >= SizeUnit.C3) {
        value = gigaFrac();
        suffix = "g";
    } else if (singles >= SizeUnit.C2) {
        value = megaFrac();
        suffix = "m";
    } else if (singles >= SizeUnit.C1) {
        value = kiloFrac();
        suffix = "k";
    }

    return Strings.format1Decimals(value, suffix);
}
 
Example #4
Source File: Settings.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * The values associated with a setting key as an immutable list.
 * <p>
 * It will also automatically load a comma separated list under the settingPrefix and merge with
 * the numbered format.
 *
 * @param key  The setting key to load the list by
 * @param defaultValue   The default value to use if no value is specified
 * @param commaDelimited Whether to try to parse a string as a comma-delimited value
 * @return The setting list values
 */
public List<String> getAsList(String key, List<String> defaultValue, Boolean commaDelimited) throws SettingsException {
    List<String> result = new ArrayList<>();
    final Object valueFromPrefix = settings.get(key);
    if (valueFromPrefix != null) {
        if (valueFromPrefix instanceof List) {
            return Collections.unmodifiableList((List<String>) valueFromPrefix);
        } else if (commaDelimited) {
            String[] strings = Strings.splitStringByCommaToArray(get(key));
            if (strings.length > 0) {
                for (String string : strings) {
                    result.add(string.trim());
                }
            }
        } else {
            result.add(get(key).trim());
        }
    }

    if (result.isEmpty()) {
        return defaultValue;
    }
    return Collections.unmodifiableList(result);
}
 
Example #5
Source File: MockAmazonS3.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectListing listObjects(final ListObjectsRequest request) throws AmazonClientException {
    assertThat(request.getBucketName(), equalTo(bucket));

    final ObjectListing listing = new ObjectListing();
    listing.setBucketName(request.getBucketName());
    listing.setPrefix(request.getPrefix());

    for (Map.Entry<String, byte[]> blob : blobs.entrySet()) {
        if (Strings.isEmpty(request.getPrefix()) || blob.getKey().startsWith(request.getPrefix())) {
            S3ObjectSummary summary = new S3ObjectSummary();
            summary.setBucketName(request.getBucketName());
            summary.setKey(blob.getKey());
            summary.setSize(blob.getValue().length);
            listing.getObjectSummaries().add(summary);
        }
    }
    return listing;
}
 
Example #6
Source File: DiscoveryNode.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    if (nodeName.length() > 0) {
        sb.append('{').append(nodeName).append('}');
    }
    if (nodeId != null) {
        sb.append('{').append(nodeId).append('}');
    }
    if (Strings.hasLength(hostName)) {
        sb.append('{').append(hostName).append('}');
    }
    if (address != null) {
        sb.append('{').append(address).append('}');
    }
    if (!attributes.isEmpty()) {
        sb.append(attributes);
    }
    return sb.toString();
}
 
Example #7
Source File: PropertyPlaceholder.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private int findPlaceholderEndIndex(CharSequence buf, int startIndex) {
    int index = startIndex + this.placeholderPrefix.length();
    int withinNestedPlaceholder = 0;
    while (index < buf.length()) {
        if (Strings.substringMatch(buf, index, this.placeholderSuffix)) {
            if (withinNestedPlaceholder > 0) {
                withinNestedPlaceholder--;
                index = index + this.placeholderSuffix.length();
            } else {
                return index;
            }
        } else if (Strings.substringMatch(buf, index, this.placeholderPrefix)) {
            withinNestedPlaceholder++;
            index = index + this.placeholderPrefix.length();
        } else {
            index++;
        }
    }
    return -1;
}
 
Example #8
Source File: DocumentParser.java    From crate with Apache License 2.0 6 votes vote down vote up
private static String[] splitAndValidatePath(String fullFieldPath) {
    if (fullFieldPath.contains(".")) {
        String[] parts = fullFieldPath.split("\\.");
        for (String part : parts) {
            if (Strings.hasText(part) == false) {
                // check if the field name contains only whitespace
                if (Strings.isEmpty(part) == false) {
                    throw new IllegalArgumentException(
                            "object field cannot contain only whitespace: ['" + fullFieldPath + "']");
                }
                throw new IllegalArgumentException(
                        "object field starting or ending with a [.] makes object resolution ambiguous: [" + fullFieldPath + "]");
            }
        }
        return parts;
    } else {
        if (Strings.isEmpty(fullFieldPath)) {
            throw new IllegalArgumentException("field name cannot be an empty string");
        }
        return new String[] {fullFieldPath};
    }
}
 
Example #9
Source File: RestSegmentsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));

    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    clusterStateRequest.clear().nodes(true).routingTable(true).indices(indices);

    client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            final IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest();
            indicesSegmentsRequest.indices(indices);
            client.admin().indices().segments(indicesSegmentsRequest, new RestResponseListener<IndicesSegmentResponse>(channel) {
                @Override
                public RestResponse buildResponse(final IndicesSegmentResponse indicesSegmentResponse) throws Exception {
                    final Map<String, IndexSegments> indicesSegments = indicesSegmentResponse.getIndices();
                    Table tab = buildTable(request, clusterStateResponse, indicesSegments);
                    return RestTable.buildResponse(tab, channel);
                }
            });
        }
    });
}
 
Example #10
Source File: CorsHandler.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private boolean validateOrigin() {
    if (config.isAnyOriginSupported()) {
        return true;
    }

    final String origin = request.headers().get(ORIGIN);
    if (Strings.isNullOrEmpty(origin)) {
        // Not a CORS request so we cannot validate it. It may be a non CORS request.
        return true;
    }

    if ("null".equals(origin) && config.isNullOriginAllowed()) {
        return true;
    }

    // if the origin is the same as the host of the request, then allow
    if (isSameOrigin(origin, request.headers().get(HOST))) {
        return true;
    }

    return config.isOriginAllowed(origin);
}
 
Example #11
Source File: ReplaceFunction.java    From crate with Apache License 2.0 6 votes vote down vote up
public static void register(ScalarFunctionModule module) {
    module.register(
        Signature.scalar(
            NAME,
            DataTypes.STRING.getTypeSignature(),
            DataTypes.STRING.getTypeSignature(),
            DataTypes.STRING.getTypeSignature(),
            DataTypes.STRING.getTypeSignature()
        ),
        (signature, boundSignature) ->
            new TripleScalar<>(
                signature,
                boundSignature,
                DataTypes.STRING,
                Strings::replace
            )
    );
}
 
Example #12
Source File: RestShardsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    clusterStateRequest.clear().nodes(true).metaData(true).routingTable(true).indices(indices);
    client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest(indices);
            indicesStatsRequest.all();
            client.admin().indices().stats(indicesStatsRequest, new RestResponseListener<IndicesStatsResponse>(channel) {
                @Override
                public RestResponse buildResponse(IndicesStatsResponse indicesStatsResponse) throws Exception {
                    return RestTable.buildResponse(buildTable(request, clusterStateResponse, indicesStatsResponse), channel);
                }
            });
        }
    });
}
 
Example #13
Source File: ArrayType.java    From crate with Apache License 2.0 6 votes vote down vote up
private String anyValueToString(Object value) {
    if (value == null) {
        return null;
    }
    try {
        if (value instanceof Map) {
            //noinspection unchecked
            return
                Strings.toString(
                    XContentFactory.jsonBuilder().map((Map<String, ?>) value));
        } else if (value instanceof Collection) {
            var array = XContentFactory.jsonBuilder().startArray();
            for (var element : (Collection<?>) value) {
                array.value(element);
            }
            array.endArray();
            return Strings.toString(array);
        } else {
            return value.toString();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #14
Source File: Settings.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
Settings(Map<String, String> settings) {
    // we use a sorted map for consistent serialization when using getAsMap()
    // TODO: use Collections.unmodifiableMap with a TreeMap
    this.settings = ImmutableSortedMap.copyOf(settings);
    Map<String, String> forcedUnderscoreSettings = null;
    for (Map.Entry<String, String> entry : settings.entrySet()) {
        String toUnderscoreCase = Strings.toUnderscoreCase(entry.getKey());
        if (!toUnderscoreCase.equals(entry.getKey())) {
            if (forcedUnderscoreSettings == null) {
                forcedUnderscoreSettings = new HashMap<>();
            }
            forcedUnderscoreSettings.put(toUnderscoreCase, entry.getValue());
        }
    }
    this.forcedUnderscoreSettings = forcedUnderscoreSettings == null ? ImmutableMap.<String, String>of() : ImmutableMap.copyOf(forcedUnderscoreSettings);
}
 
Example #15
Source File: TransportClusterHealthAction.java    From crate with Apache License 2.0 6 votes vote down vote up
private ClusterHealthResponse clusterHealth(ClusterHealthRequest request, ClusterState clusterState, int numberOfPendingTasks, int numberOfInFlightFetch,
                                            TimeValue pendingTaskTimeInQueue) {
    if (logger.isTraceEnabled()) {
        logger.trace("Calculating health based on state version [{}]", clusterState.version());
    }

    String[] concreteIndices;
    try {
        concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request);
    } catch (IndexNotFoundException e) {
        // one of the specified indices is not there - treat it as RED.
        ClusterHealthResponse response = new ClusterHealthResponse(clusterState.getClusterName().value(), Strings.EMPTY_ARRAY, clusterState,
                numberOfPendingTasks, numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(clusterState),
                pendingTaskTimeInQueue);
        response.setStatus(ClusterHealthStatus.RED);
        return response;
    }

    return new ClusterHealthResponse(clusterState.getClusterName().value(), concreteIndices, clusterState, numberOfPendingTasks,
            numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), pendingTaskTimeInQueue);
}
 
Example #16
Source File: TypeParsers.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public static void parseTermVector(String fieldName, String termVector, FieldMapper.Builder builder) throws MapperParsingException {
    termVector = Strings.toUnderscoreCase(termVector);
    if ("no".equals(termVector)) {
        builder.storeTermVectors(false);
    } else if ("yes".equals(termVector)) {
        builder.storeTermVectors(true);
    } else if ("with_offsets".equals(termVector)) {
        builder.storeTermVectorOffsets(true);
    } else if ("with_positions".equals(termVector)) {
        builder.storeTermVectorPositions(true);
    } else if ("with_positions_offsets".equals(termVector)) {
        builder.storeTermVectorPositions(true);
        builder.storeTermVectorOffsets(true);
    } else if ("with_positions_payloads".equals(termVector)) {
        builder.storeTermVectorPositions(true);
        builder.storeTermVectorPayloads(true);
    } else if ("with_positions_offsets_payloads".equals(termVector)) {
        builder.storeTermVectorPositions(true);
        builder.storeTermVectorOffsets(true);
        builder.storeTermVectorPayloads(true);
    } else {
        throw new MapperParsingException("wrong value for termVector [" + termVector + "] for field [" + fieldName + "]");
    }
}
 
Example #17
Source File: PrometheusFetcherProvider.java    From skywalking with Apache License 2.0 6 votes vote down vote up
private void generateTraffic(MeterEntity entity) {
        ServiceTraffic s = new ServiceTraffic();
        s.setName(requireNonNull(entity.getServiceName()));
        s.setNodeType(NodeType.Normal);
        s.setTimeBucket(TimeBucket.getMinuteTimeBucket(System.currentTimeMillis()));
        MetricsStreamProcessor.getInstance().in(s);
        if (!Strings.isNullOrEmpty(entity.getInstanceName())) {
            InstanceTraffic instanceTraffic = new InstanceTraffic();
            instanceTraffic.setName(entity.getInstanceName());
            instanceTraffic.setServiceId(entity.serviceId());
            instanceTraffic.setTimeBucket(TimeBucket.getMinuteTimeBucket(System.currentTimeMillis()));
            instanceTraffic.setLastPingTimestamp(System.currentTimeMillis());
            MetricsStreamProcessor.getInstance().in(instanceTraffic);
        }
        if (!Strings.isNullOrEmpty(entity.getEndpointName())) {
            EndpointTraffic endpointTraffic = new EndpointTraffic();
            endpointTraffic.setName(entity.getEndpointName());
            endpointTraffic.setServiceId(entity.serviceId());
            endpointTraffic.setTimeBucket(TimeBucket.getMinuteTimeBucket(System.currentTimeMillis()));
            MetricsStreamProcessor.getInstance().in(endpointTraffic);
        }
}
 
Example #18
Source File: LangDetectProcessor.java    From elasticsearch-ingest-langdetect with Apache License 2.0 6 votes vote down vote up
@Override
public IngestDocument execute(IngestDocument ingestDocument) throws Exception {
    Detector detector = DetectorFactory.create();
    detector.setMaxTextLength(maxLength.bytesAsInt());

    String content;
    try {
        content = ingestDocument.getFieldValue(field, String.class);
    } catch (IllegalArgumentException e) {
        if (ignoreMissing) {
            return ingestDocument;
        }
        throw e;
    }
    if (Strings.isEmpty(content)) {
        return ingestDocument;
    }

    detector.append(content);
    String language = detector.detect();

    ingestDocument.setFieldValue(targetField, language);

    return ingestDocument;
}
 
Example #19
Source File: ADStatsTests.java    From anomaly-detection with Apache License 2.0 6 votes vote down vote up
@Test
public void testADStatsNodeResponse() throws IOException, JsonPathNotFoundException {
    Map<String, Object> stats = new HashMap<String, Object>() {
        {
            put("testKey", "testValue");
        }
    };

    // Test serialization
    ADStatsNodeResponse adStatsNodeResponse = new ADStatsNodeResponse(discoveryNode1, stats);
    BytesStreamOutput output = new BytesStreamOutput();
    adStatsNodeResponse.writeTo(output);
    StreamInput streamInput = output.bytes().streamInput();
    ADStatsNodeResponse readResponse = ADStatsNodeResponse.readStats(streamInput);
    assertEquals("readStats failed", readResponse.getStatsMap(), adStatsNodeResponse.getStatsMap());

    // Test toXContent
    XContentBuilder builder = jsonBuilder();
    adStatsNodeResponse.toXContent(builder.startObject(), ToXContent.EMPTY_PARAMS).endObject();
    String json = Strings.toString(builder);

    for (Map.Entry<String, Object> stat : stats.entrySet()) {
        assertEquals("toXContent does not work", JsonDeserializer.getTextValue(json, stat.getKey()), stat.getValue());
    }
}
 
Example #20
Source File: Elasticsearch5Sink.java    From sylph with Apache License 2.0 6 votes vote down vote up
@Autowired
public Elasticsearch5Sink(SinkContext context, ClientFactory clientFactory)
{
    this.config = clientFactory.getConfig();
    this.schema = context.getSchema();
    this.clientFactory = clientFactory;

    if (!Strings.isNullOrEmpty(config.getIdField())) {
        int fieldIndex = schema.getFieldIndex(config.getIdField());
        checkState(fieldIndex != -1, config.getIdField() + " does not exist, only " + schema.getFields());
        this.idIndex = fieldIndex;
    }
    if (config.isUpdate()) {
        checkState(idIndex != -1, "This is Update mode, `id_field` must be set");
    }
}
 
Example #21
Source File: AliasOrIndex.java    From crate with Apache License 2.0 6 votes vote down vote up
public void computeAndValidateWriteIndex() {
    List<IndexMetaData> writeIndices = referenceIndexMetaDatas.stream()
        .filter(idxMeta -> Boolean.TRUE.equals(idxMeta.getAliases().get(aliasName).writeIndex()))
        .collect(Collectors.toList());

    if (writeIndices.isEmpty() && referenceIndexMetaDatas.size() == 1
            && referenceIndexMetaDatas.get(0).getAliases().get(aliasName).writeIndex() == null) {
        writeIndices.add(referenceIndexMetaDatas.get(0));
    }

    if (writeIndices.size() == 1) {
        writeIndex.set(writeIndices.get(0));
    } else if (writeIndices.size() > 1) {
        List<String> writeIndicesStrings = writeIndices.stream()
            .map(i -> i.getIndex().getName()).collect(Collectors.toList());
        throw new IllegalStateException("alias [" + aliasName + "] has more than one write index [" +
            Strings.collectionToCommaDelimitedString(writeIndicesStrings) + "]");
    }
}
 
Example #22
Source File: IpFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    IpFieldMapper.Builder builder = ipField(name);
    parseNumberField(builder, name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = Strings.toUnderscoreCase(entry.getKey());
        Object propNode = entry.getValue();
        if (propName.equals("null_value")) {
            if (propNode == null) {
                throw new MapperParsingException("Property [null_value] cannot be null.");
            }
            builder.nullValue(propNode.toString());
            iterator.remove();
        }
    }
    return builder;
}
 
Example #23
Source File: ClusterHealthRequest.java    From crate with Apache License 2.0 6 votes vote down vote up
public ClusterHealthRequest(StreamInput in) throws IOException {
    super(in);
    int size = in.readVInt();
    if (size == 0) {
        indices = Strings.EMPTY_ARRAY;
    } else {
        indices = new String[size];
        for (int i = 0; i < indices.length; i++) {
            indices[i] = in.readString();
        }
    }
    timeout = in.readTimeValue();
    if (in.readBoolean()) {
        waitForStatus = ClusterHealthStatus.fromValue(in.readByte());
    }
    waitForNoRelocatingShards = in.readBoolean();
    waitForActiveShards = ActiveShardCount.readFrom(in);
    waitForNodes = in.readString();
    if (in.readBoolean()) {
        waitForEvents = Priority.readFrom(in);
    }
    waitForNoInitializingShards = in.readBoolean();
}
 
Example #24
Source File: Netty4CorsHandler.java    From crate with Apache License 2.0 5 votes vote down vote up
private static boolean isSameOrigin(final String origin, final String host) {
    if (Strings.isNullOrEmpty(host) == false) {
        // strip protocol from origin
        final String originDomain = SCHEME_PATTERN.matcher(origin).replaceFirst("");
        if (host.equals(originDomain)) {
            return true;
        }
    }
    return false;
}
 
Example #25
Source File: RestClusterSearchShardsAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final ClusterSearchShardsRequest clusterSearchShardsRequest = Requests.clusterSearchShardsRequest(indices);
    clusterSearchShardsRequest.local(request.paramAsBoolean("local", clusterSearchShardsRequest.local()));

    clusterSearchShardsRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
    clusterSearchShardsRequest.routing(request.param("routing"));
    clusterSearchShardsRequest.preference(request.param("preference"));
    clusterSearchShardsRequest.indicesOptions(IndicesOptions.fromRequest(request, clusterSearchShardsRequest.indicesOptions()));

    client.admin().cluster().searchShards(clusterSearchShardsRequest, new RestToXContentListener<ClusterSearchShardsResponse>(channel));
}
 
Example #26
Source File: RestCloseIndexAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    CloseIndexRequest closeIndexRequest = new CloseIndexRequest(Strings.splitStringByCommaToArray(request.param("index")));
    closeIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", closeIndexRequest.masterNodeTimeout()));
    closeIndexRequest.timeout(request.paramAsTime("timeout", closeIndexRequest.timeout()));
    closeIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, closeIndexRequest.indicesOptions()));
    client.admin().indices().close(closeIndexRequest, new AcknowledgedRestListener<CloseIndexResponse>(channel));
}
 
Example #27
Source File: RestGetSnapshotsAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    String repository = request.param("repository");
    String[] snapshots = request.paramAsStringArray("snapshot", Strings.EMPTY_ARRAY);

    GetSnapshotsRequest getSnapshotsRequest = getSnapshotsRequest(repository).snapshots(snapshots);
    getSnapshotsRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", getSnapshotsRequest.ignoreUnavailable()));

    getSnapshotsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getSnapshotsRequest.masterNodeTimeout()));
    client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestToXContentListener<GetSnapshotsResponse>(channel));
}
 
Example #28
Source File: DiscoveryNodeFilters.java    From crate with Apache License 2.0 5 votes vote down vote up
public static DiscoveryNodeFilters buildFromKeyValue(OpType opType, Map<String, String> filters) {
    Map<String, String[]> bFilters = new HashMap<>();
    for (Map.Entry<String, String> entry : filters.entrySet()) {
        String[] values = Strings.tokenizeToStringArray(entry.getValue(), ",");
        if (values.length > 0) {
            bFilters.put(entry.getKey(), values);
        }
    }
    if (bFilters.isEmpty()) {
        return null;
    }
    return new DiscoveryNodeFilters(opType, bFilters);
}
 
Example #29
Source File: DiscoveryService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public static String generateNodeId(Settings settings) {
    String seed = settings.get(DiscoveryService.SETTING_DISCOVERY_SEED);
    if (seed != null) {
        return Strings.randomBase64UUID(new Random(Long.parseLong(seed)));
    }
    return Strings.randomBase64UUID();
}
 
Example #30
Source File: StreamInput.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public String[] readStringArray() throws IOException {
    int size = readVInt();
    if (size == 0) {
        return Strings.EMPTY_ARRAY;
    }
    String[] ret = new String[size];
    for (int i = 0; i < size; i++) {
        ret[i] = readString();
    }
    return ret;
}