Search in sources :

Example 36 with ElasticSearchException

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

the class TruncateTranslogCommand method warnAboutDeletingFiles.

/** Show a warning about deleting files, asking for a confirmation if {@code batchMode} is false */
public static void warnAboutDeletingFiles(Terminal terminal, Set<Path> files, boolean batchMode) {
    terminal.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    terminal.println("!   WARNING: Elasticsearch MUST be stopped before running this tool   !");
    terminal.println("!                                                                     !");
    terminal.println("!   WARNING:    Documents inside of translog files will be lost       !");
    terminal.println("!                                                                     !");
    terminal.println("!   WARNING:          The following files will be DELETED!            !");
    terminal.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    for (Path file : files) {
        terminal.println("--> " + file);
    }
    terminal.println("");
    if (batchMode == false) {
        String text = terminal.readText("Continue and DELETE files? [y/N] ");
        if (!text.equalsIgnoreCase("y")) {
            throw new ElasticsearchException("aborted by user");
        }
    }
}
Also used : Path(java.nio.file.Path) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Example 37 with ElasticSearchException

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

the class GeoGridAggregationBuilder method innerBuild.

@Override
protected ValuesSourceAggregatorFactory<ValuesSource.GeoPoint, ?> innerBuild(SearchContext context, ValuesSourceConfig<ValuesSource.GeoPoint> config, AggregatorFactory<?> parent, Builder subFactoriesBuilder) throws IOException {
    int shardSize = this.shardSize;
    int requiredSize = this.requiredSize;
    if (shardSize < 0) {
        // Use default heuristic to avoid any wrong-ranking caused by
        // distributed counting
        shardSize = BucketUtils.suggestShardSideQueueSize(requiredSize, context.numberOfShards());
    }
    if (requiredSize <= 0 || shardSize <= 0) {
        throw new ElasticsearchException("parameters [required_size] and [shard_size] must be >0 in geohash_grid aggregation [" + name + "].");
    }
    if (shardSize < requiredSize) {
        shardSize = requiredSize;
    }
    return new GeoHashGridAggregatorFactory(name, config, precision, requiredSize, shardSize, context, parent, subFactoriesBuilder, metaData);
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Example 38 with ElasticSearchException

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

the class FailProcessorFactoryTests method testInvalidMustacheTemplate.

public void testInvalidMustacheTemplate() throws Exception {
    FailProcessor.Factory factory = new FailProcessor.Factory(TestTemplateService.instance(true));
    Map<String, Object> config = new HashMap<>();
    config.put("message", "error");
    String processorTag = randomAsciiOfLength(10);
    ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> factory.create(null, processorTag, config));
    assertThat(exception.getMessage(), equalTo("java.lang.RuntimeException: could not compile script"));
    assertThat(exception.getHeader("processor_tag").get(0), equalTo(processorTag));
}
Also used : HashMap(java.util.HashMap) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Example 39 with ElasticSearchException

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

the class ScriptProcessorFactoryTests method testFactoryInvalidateWithInvalidCompiledScript.

public void testFactoryInvalidateWithInvalidCompiledScript() throws Exception {
    String randomType = randomFrom("inline", "file", "id");
    ScriptService mockedScriptService = mock(ScriptService.class);
    ScriptException thrownException = new ScriptException("compile-time exception", new RuntimeException(), Collections.emptyList(), "script", "mockscript");
    when(mockedScriptService.compile(any(), any())).thenThrow(thrownException);
    factory = new ScriptProcessor.Factory(mockedScriptService);
    Map<String, Object> configMap = new HashMap<>();
    configMap.put("lang", "mockscript");
    configMap.put(randomType, "my_script");
    ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> factory.create(null, randomAsciiOfLength(10), configMap));
    assertThat(exception.getMessage(), is("compile-time exception"));
}
Also used : ScriptService(org.elasticsearch.script.ScriptService) ScriptException(org.elasticsearch.script.ScriptException) HashMap(java.util.HashMap) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Example 40 with ElasticSearchException

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

the class SetProcessorFactoryTests method testInvalidMustacheTemplate.

public void testInvalidMustacheTemplate() throws Exception {
    SetProcessor.Factory factory = new SetProcessor.Factory(TestTemplateService.instance(true));
    Map<String, Object> config = new HashMap<>();
    config.put("field", "field1");
    config.put("value", "value1");
    String processorTag = randomAsciiOfLength(10);
    ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> factory.create(null, processorTag, config));
    assertThat(exception.getMessage(), equalTo("java.lang.RuntimeException: could not compile script"));
    assertThat(exception.getHeader("processor_tag").get(0), equalTo(processorTag));
}
Also used : HashMap(java.util.HashMap) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Aggregations

ElasticsearchException (org.elasticsearch.ElasticsearchException)309 IOException (java.io.IOException)127 Settings (org.elasticsearch.common.settings.Settings)32 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)30 HashMap (java.util.HashMap)29 ClusterState (org.elasticsearch.cluster.ClusterState)29 ArrayList (java.util.ArrayList)28 Matchers.containsString (org.hamcrest.Matchers.containsString)25 List (java.util.List)20 Map (java.util.Map)20 AtomicReference (java.util.concurrent.atomic.AtomicReference)20 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)18 XContentParser (org.elasticsearch.common.xcontent.XContentParser)17 Path (java.nio.file.Path)16 Test (org.junit.Test)16 ActionListener (org.elasticsearch.action.ActionListener)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 Version (org.elasticsearch.Version)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 ResourceNotFoundException (org.elasticsearch.ResourceNotFoundException)13