Search in sources :

Example 71 with ElasticsearchParseException

use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.

the class PipelineStoreTests method testValidate.

public void testValidate() throws Exception {
    PutPipelineRequest putRequest = new PutPipelineRequest("_id", new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\", \"tag\": \"tag1\"}}," + "{\"remove\" : {\"field\": \"_field\", \"tag\": \"tag2\"}}]}"), XContentType.JSON);
    DiscoveryNode node1 = new DiscoveryNode("_node_id1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    DiscoveryNode node2 = new DiscoveryNode("_node_id2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    Map<DiscoveryNode, IngestInfo> ingestInfos = new HashMap<>();
    ingestInfos.put(node1, new IngestInfo(Arrays.asList(new ProcessorInfo("set"), new ProcessorInfo("remove"))));
    ingestInfos.put(node2, new IngestInfo(Arrays.asList(new ProcessorInfo("set"))));
    ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> store.validatePipeline(ingestInfos, putRequest));
    assertEquals("Processor type [remove] is not installed on node [" + node2 + "]", e.getMessage());
    assertEquals("remove", e.getHeader("processor_type").get(0));
    assertEquals("tag2", e.getHeader("processor_tag").get(0));
    ingestInfos.put(node2, new IngestInfo(Arrays.asList(new ProcessorInfo("set"), new ProcessorInfo("remove"))));
    store.validatePipeline(ingestInfos, putRequest);
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) HashMap(java.util.HashMap) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) PutPipelineRequest(org.elasticsearch.action.ingest.PutPipelineRequest)

Example 72 with ElasticsearchParseException

use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.

the class PipelineStoreTests method testPutWithErrorResponse.

public void testPutWithErrorResponse() {
    String id = "_id";
    Pipeline pipeline = store.get(id);
    assertThat(pipeline, nullValue());
    ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
    PutPipelineRequest putRequest = new PutPipelineRequest(id, new BytesArray("{\"description\": \"empty processors\"}"), XContentType.JSON);
    ClusterState previousClusterState = clusterState;
    clusterState = store.innerPut(putRequest, clusterState);
    try {
        store.innerUpdatePipelines(previousClusterState, clusterState);
        fail("should fail");
    } catch (ElasticsearchParseException e) {
        assertThat(e.getMessage(), equalTo("[processors] required property is missing"));
    }
    pipeline = store.get(id);
    assertThat(pipeline, nullValue());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) BytesArray(org.elasticsearch.common.bytes.BytesArray) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) ClusterName(org.elasticsearch.cluster.ClusterName) PutPipelineRequest(org.elasticsearch.action.ingest.PutPipelineRequest)

Example 73 with ElasticsearchParseException

use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.

the class GrokProcessorFactoryTests method testBuildMissingPatterns.

public void testBuildMissingPatterns() throws Exception {
    GrokProcessor.Factory factory = new GrokProcessor.Factory(Collections.emptyMap());
    Map<String, Object> config = new HashMap<>();
    config.put("field", "foo");
    ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> factory.create(null, null, config));
    assertThat(e.getMessage(), equalTo("[patterns] required property is missing"));
}
Also used : HashMap(java.util.HashMap) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException)

Example 74 with ElasticsearchParseException

use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.

the class GrokProcessorFactoryTests method testCreateWithInvalidPatternDefinition.

public void testCreateWithInvalidPatternDefinition() throws Exception {
    GrokProcessor.Factory factory = new GrokProcessor.Factory(Collections.emptyMap());
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    config.put("patterns", Collections.singletonList("%{MY_PATTERN:name}!"));
    config.put("pattern_definitions", Collections.singletonMap("MY_PATTERN", "["));
    ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> factory.create(null, null, config));
    assertThat(e.getMessage(), equalTo("[patterns] Invalid regex pattern found in: [%{MY_PATTERN:name}!]. premature end of char-class"));
}
Also used : HashMap(java.util.HashMap) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException)

Example 75 with ElasticsearchParseException

use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.

the class RestUpdateByQueryAction method parseScript.

@SuppressWarnings("unchecked")
private static Script parseScript(Map<String, Object> config) {
    String script = null;
    ScriptType type = null;
    String lang = DEFAULT_SCRIPT_LANG;
    Map<String, Object> params = Collections.emptyMap();
    for (Iterator<Map.Entry<String, Object>> itr = config.entrySet().iterator(); itr.hasNext(); ) {
        Map.Entry<String, Object> entry = itr.next();
        String parameterName = entry.getKey();
        Object parameterValue = entry.getValue();
        if (Script.LANG_PARSE_FIELD.match(parameterName)) {
            if (parameterValue instanceof String || parameterValue == null) {
                lang = (String) parameterValue;
            } else {
                throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]");
            }
        } else if (Script.PARAMS_PARSE_FIELD.match(parameterName)) {
            if (parameterValue instanceof Map || parameterValue == null) {
                params = (Map<String, Object>) parameterValue;
            } else {
                throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]");
            }
        } else if (ScriptType.INLINE.getParseField().match(parameterName)) {
            if (parameterValue instanceof String || parameterValue == null) {
                script = (String) parameterValue;
                type = ScriptType.INLINE;
            } else {
                throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]");
            }
        } else if (ScriptType.FILE.getParseField().match(parameterName)) {
            if (parameterValue instanceof String || parameterValue == null) {
                script = (String) parameterValue;
                type = ScriptType.FILE;
            } else {
                throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]");
            }
        } else if (ScriptType.STORED.getParseField().match(parameterName)) {
            if (parameterValue instanceof String || parameterValue == null) {
                script = (String) parameterValue;
                type = ScriptType.STORED;
            } else {
                throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]");
            }
        }
    }
    if (script == null) {
        throw new ElasticsearchParseException("expected one of [{}], [{}] or [{}] fields, but found none", ScriptType.INLINE.getParseField().getPreferredName(), ScriptType.FILE.getParseField().getPreferredName(), ScriptType.STORED.getParseField().getPreferredName());
    }
    assert type != null : "if script is not null, type should definitely not be null";
    return new Script(type, lang, script, params);
}
Also used : ScriptType(org.elasticsearch.script.ScriptType) Script(org.elasticsearch.script.Script) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)106 XContentParser (org.elasticsearch.common.xcontent.XContentParser)44 HashMap (java.util.HashMap)28 ArrayList (java.util.ArrayList)18 IOException (java.io.IOException)13 Map (java.util.Map)11 List (java.util.List)7 GeoPoint (org.elasticsearch.common.geo.GeoPoint)7 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 ParsingException (org.elasticsearch.common.ParsingException)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)4 Version (org.elasticsearch.Version)4 NoNodeAvailableException (org.elasticsearch.client.transport.NoNodeAvailableException)4 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)4 UncheckedIOException (java.io.UncheckedIOException)3 LinkedHashSet (java.util.LinkedHashSet)3 PutPipelineRequest (org.elasticsearch.action.ingest.PutPipelineRequest)3