You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metron.apache.org by ot...@apache.org on 2018/04/18 14:59:39 UTC
[09/52] [abbrv] metron git commit: METRON-1490: Better error message
when user specifies an enrichment type that doesn't exist closes
apache/metron#963
METRON-1490: Better error message when user specifies an enrichment type that doesn't exist closes apache/metron#963
Project: http://git-wip-us.apache.org/repos/asf/metron/repo
Commit: http://git-wip-us.apache.org/repos/asf/metron/commit/37662d3b
Tree: http://git-wip-us.apache.org/repos/asf/metron/tree/37662d3b
Diff: http://git-wip-us.apache.org/repos/asf/metron/diff/37662d3b
Branch: refs/heads/feature/METRON-1211-extensions-parsers-gradual
Commit: 37662d3bd8a4162bef4474be7ab60a2fabbe3e2f
Parents: 03a4aa3
Author: cstella <ce...@gmail.com>
Authored: Thu Mar 15 12:05:39 2018 -0400
Committer: cstella <ce...@gmail.com>
Committed: Thu Mar 15 12:05:39 2018 -0400
----------------------------------------------------------------------
.../enrichment/parallel/ParallelEnricher.java | 5 +++
.../parallel/ParallelEnricherTest.java | 39 +++++++++++++++++++-
2 files changed, 43 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/metron/blob/37662d3b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/parallel/ParallelEnricher.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/parallel/ParallelEnricher.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/parallel/ParallelEnricher.java
index 2238c92..6ddb892 100644
--- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/parallel/ParallelEnricher.java
+++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/parallel/ParallelEnricher.java
@@ -18,6 +18,7 @@
package org.apache.metron.enrichment.parallel;
import com.github.benmanes.caffeine.cache.stats.CacheStats;
+import com.google.common.base.Joiner;
import org.apache.metron.common.Constants;
import org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig;
import org.apache.metron.common.configuration.enrichment.handler.ConfigHandler;
@@ -152,6 +153,10 @@ public class ParallelEnricher {
for(Map.Entry<String, List<JSONObject>> task : tasks.entrySet()) {
//task is the list of enrichment tasks for the task.getKey() adapter
EnrichmentAdapter<CacheKey> adapter = enrichmentsByType.get(task.getKey());
+ if(adapter == null) {
+ throw new IllegalStateException("Unable to find an adapter for " + task.getKey()
+ + ", possible adapters are: " + Joiner.on(",").join(enrichmentsByType.keySet()));
+ }
for(JSONObject m : task.getValue()) {
/* now for each unit of work (each of these only has one element in them)
* the key is the field name and the value is value associated with that field.
http://git-wip-us.apache.org/repos/asf/metron/blob/37662d3b/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/parallel/ParallelEnricherTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/parallel/ParallelEnricherTest.java b/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/parallel/ParallelEnricherTest.java
index c3a3109..4a4573b 100644
--- a/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/parallel/ParallelEnricherTest.java
+++ b/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/parallel/ParallelEnricherTest.java
@@ -17,6 +17,7 @@
*/
package org.apache.metron.enrichment.parallel;
+import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import org.adrianwalker.multilinestring.Multiline;
import org.apache.metron.common.Constants;
@@ -24,6 +25,7 @@ import org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig;
import org.apache.metron.common.utils.JSONUtils;
import org.apache.metron.enrichment.adapters.stellar.StellarAdapter;
import org.apache.metron.enrichment.bolt.CacheKey;
+import org.apache.metron.enrichment.interfaces.EnrichmentAdapter;
import org.apache.metron.stellar.dsl.Context;
import org.apache.metron.stellar.dsl.StellarFunctions;
import org.json.simple.JSONObject;
@@ -32,6 +34,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import java.util.HashMap;
+import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
public class ParallelEnricherTest {
@@ -61,6 +64,7 @@ public class ParallelEnricherTest {
private static ParallelEnricher enricher;
private static Context stellarContext;
private static AtomicInteger numAccesses = new AtomicInteger(0);
+ private static Map<String, EnrichmentAdapter<CacheKey>> enrichmentsByType;
@BeforeClass
public static void setup() {
ConcurrencyContext infrastructure = new ConcurrencyContext();
@@ -75,7 +79,8 @@ public class ParallelEnricherTest {
}
}.ofType("ENRICHMENT");
adapter.initializeAdapter(new HashMap<>());
- enricher = new ParallelEnricher(ImmutableMap.of("stellar", adapter), infrastructure, false);
+ enrichmentsByType = ImmutableMap.of("stellar", adapter);
+ enricher = new ParallelEnricher(enrichmentsByType, infrastructure, false);
}
@Test
@@ -154,4 +159,36 @@ public class ParallelEnricherTest {
Assert.assertEquals("TEST", ret.get("ALL_CAPS"));
Assert.assertEquals(1, result.getEnrichmentErrors().size());
}
+
+ /**
+ * {
+ "enrichment": {
+ "fieldMap": {
+ "hbaseThreatIntel" : [ "ip_src_addr"]
+ }
+ ,"fieldToTypeMap": { }
+ },
+ "threatIntel": { }
+}
+ */
+ @Multiline
+ public static String badConfigWrongEnrichmentType;
+
+ @Test
+ public void testBadConfigWrongEnrichmentType() throws Exception {
+ SensorEnrichmentConfig config = JSONUtils.INSTANCE.load(badConfigWrongEnrichmentType, SensorEnrichmentConfig.class);
+ config.getConfiguration().putIfAbsent("stellarContext", stellarContext);
+ JSONObject message = new JSONObject() {{
+ put(Constants.SENSOR_TYPE, "test");
+ }};
+ try {
+ enricher.apply(message, EnrichmentStrategies.ENRICHMENT, config, null);
+ Assert.fail("This is an invalid config, we should have failed.");
+ }
+ catch(IllegalStateException ise) {
+ Assert.assertEquals(ise.getMessage()
+ , "Unable to find an adapter for hbaseThreatIntel, possible adapters are: " + Joiner.on(",").join(enrichmentsByType.keySet())
+ );
+ }
+ }
}