From a7730b05b20d83f14ce9bcd53450f15baa272073 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 13 Jan 2016 23:35:41 +0100 Subject: [PATCH] Fix some todos --- .../elasticsearch/ingest/core/Pipeline.java | 12 ++++++---- .../ingest/core/ValueSource.java | 4 +--- .../{ => core}/PipelineFactoryTests.java | 23 ++++++++++--------- 3 files changed, 21 insertions(+), 18 deletions(-) rename core/src/test/java/org/elasticsearch/ingest/{ => core}/PipelineFactoryTests.java (78%) diff --git a/core/src/main/java/org/elasticsearch/ingest/core/Pipeline.java b/core/src/main/java/org/elasticsearch/ingest/core/Pipeline.java index 84ddb6aa9e7..ebf570710e5 100644 --- a/core/src/main/java/org/elasticsearch/ingest/core/Pipeline.java +++ b/core/src/main/java/org/elasticsearch/ingest/core/Pipeline.java @@ -30,6 +30,10 @@ import java.util.Map; */ public final class Pipeline { + final static String DESCRIPTION_KEY = "description"; + final static String PROCESSORS_KEY = "processors"; + final static String ON_FAILURE_KEY = "on_failure"; + private final String id; private final String description; private final CompoundProcessor compoundProcessor; @@ -79,9 +83,9 @@ public final class Pipeline { public final static class Factory { public Pipeline create(String id, Map config, Map processorRegistry) throws Exception { - String description = ConfigurationUtils.readOptionalStringProperty(config, "description"); // TODO(simonw): can we make these strings constants? - List processors = readProcessors("processors", processorRegistry, config); - List onFailureProcessors = readProcessors("on_failure", processorRegistry, config); + String description = ConfigurationUtils.readOptionalStringProperty(config, DESCRIPTION_KEY); + List processors = readProcessors(PROCESSORS_KEY, processorRegistry, config); + List onFailureProcessors = readProcessors(ON_FAILURE_KEY, processorRegistry, config); if (config.isEmpty() == false) { throw new IllegalArgumentException("pipeline [" + id + "] doesn't support one or more provided configuration parameters " + Arrays.toString(config.keySet().toArray())); } @@ -106,7 +110,7 @@ public final class Pipeline { private Processor readProcessor(Map processorRegistry, String type, Map config) throws Exception { Processor.Factory factory = processorRegistry.get(type); if (factory != null) { - List onFailureProcessors = readProcessors("on_failure", processorRegistry, config); + List onFailureProcessors = readProcessors(ON_FAILURE_KEY, processorRegistry, config); Processor processor = factory.create(config); if (config.isEmpty() == false) { throw new IllegalArgumentException("processor [" + type + "] doesn't support one or more provided configuration parameters " + Arrays.toString(config.keySet().toArray())); diff --git a/core/src/main/java/org/elasticsearch/ingest/core/ValueSource.java b/core/src/main/java/org/elasticsearch/ingest/core/ValueSource.java index 5280b3e6702..e9f09a1a9f8 100644 --- a/core/src/main/java/org/elasticsearch/ingest/core/ValueSource.java +++ b/core/src/main/java/org/elasticsearch/ingest/core/ValueSource.java @@ -57,9 +57,7 @@ public interface ValueSource { valueSourceList.add(wrap(item, templateService)); } return new ListValue(valueSourceList); - } else if (value == null || value instanceof Integer || // TODO(simonw): maybe we just check for Number? - value instanceof Long || value instanceof Float || - value instanceof Double || value instanceof Boolean) { + } else if (value == null || value instanceof Number || value instanceof Boolean) { return new ObjectValue(value); } else if (value instanceof String) { return new TemplatedValue(templateService.compile((String) value)); diff --git a/core/src/test/java/org/elasticsearch/ingest/PipelineFactoryTests.java b/core/src/test/java/org/elasticsearch/ingest/core/PipelineFactoryTests.java similarity index 78% rename from core/src/test/java/org/elasticsearch/ingest/PipelineFactoryTests.java rename to core/src/test/java/org/elasticsearch/ingest/core/PipelineFactoryTests.java index e1a46e7f0d6..153dc30019e 100644 --- a/core/src/test/java/org/elasticsearch/ingest/PipelineFactoryTests.java +++ b/core/src/test/java/org/elasticsearch/ingest/core/PipelineFactoryTests.java @@ -17,8 +17,9 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.core; +import org.elasticsearch.ingest.TestProcessor; import org.elasticsearch.ingest.core.Pipeline; import org.elasticsearch.ingest.core.Processor; import org.elasticsearch.test.ESTestCase; @@ -34,8 +35,8 @@ public class PipelineFactoryTests extends ESTestCase { public void testCreate() throws Exception { Map processorConfig = new HashMap<>(); Map pipelineConfig = new HashMap<>(); - pipelineConfig.put("description", "_description"); - pipelineConfig.put("processors", Collections.singletonList(Collections.singletonMap("test", processorConfig))); + pipelineConfig.put(Pipeline.DESCRIPTION_KEY, "_description"); + pipelineConfig.put(Pipeline.PROCESSORS_KEY, Collections.singletonList(Collections.singletonMap("test", processorConfig))); Pipeline.Factory factory = new Pipeline.Factory(); Map processorRegistry = Collections.singletonMap("test", new TestProcessor.Factory()); Pipeline pipeline = factory.create("_id", pipelineConfig, processorRegistry); @@ -48,9 +49,9 @@ public class PipelineFactoryTests extends ESTestCase { public void testCreateWithPipelineOnFailure() throws Exception { Map processorConfig = new HashMap<>(); Map pipelineConfig = new HashMap<>(); - pipelineConfig.put("description", "_description"); - pipelineConfig.put("processors", Collections.singletonList(Collections.singletonMap("test", processorConfig))); - pipelineConfig.put("on_failure", Collections.singletonList(Collections.singletonMap("test", processorConfig))); + pipelineConfig.put(Pipeline.DESCRIPTION_KEY, "_description"); + pipelineConfig.put(Pipeline.PROCESSORS_KEY, Collections.singletonList(Collections.singletonMap("test", processorConfig))); + pipelineConfig.put(Pipeline.ON_FAILURE_KEY, Collections.singletonList(Collections.singletonMap("test", processorConfig))); Pipeline.Factory factory = new Pipeline.Factory(); Map processorRegistry = Collections.singletonMap("test", new TestProcessor.Factory()); Pipeline pipeline = factory.create("_id", pipelineConfig, processorRegistry); @@ -66,8 +67,8 @@ public class PipelineFactoryTests extends ESTestCase { Map processorConfig = new HashMap<>(); processorConfig.put("unused", "value"); Map pipelineConfig = new HashMap<>(); - pipelineConfig.put("description", "_description"); - pipelineConfig.put("processors", Collections.singletonList(Collections.singletonMap("test", processorConfig))); + pipelineConfig.put(Pipeline.DESCRIPTION_KEY, "_description"); + pipelineConfig.put(Pipeline.PROCESSORS_KEY, Collections.singletonList(Collections.singletonMap("test", processorConfig))); Pipeline.Factory factory = new Pipeline.Factory(); Map processorRegistry = Collections.singletonMap("test", new TestProcessor.Factory()); try { @@ -79,11 +80,11 @@ public class PipelineFactoryTests extends ESTestCase { public void testCreateProcessorsWithOnFailureProperties() throws Exception { Map processorConfig = new HashMap<>(); - processorConfig.put("on_failure", Collections.singletonList(Collections.singletonMap("test", new HashMap<>()))); + processorConfig.put(Pipeline.ON_FAILURE_KEY, Collections.singletonList(Collections.singletonMap("test", new HashMap<>()))); Map pipelineConfig = new HashMap<>(); - pipelineConfig.put("description", "_description"); - pipelineConfig.put("processors", Collections.singletonList(Collections.singletonMap("test", processorConfig))); + pipelineConfig.put(Pipeline.DESCRIPTION_KEY, "_description"); + pipelineConfig.put(Pipeline.PROCESSORS_KEY, Collections.singletonList(Collections.singletonMap("test", processorConfig))); Pipeline.Factory factory = new Pipeline.Factory(); Map processorRegistry = Collections.singletonMap("test", new TestProcessor.Factory()); Pipeline pipeline = factory.create("_id", pipelineConfig, processorRegistry);