Search in sources :

Example 36 with IndexingConfigurations

use of org.apache.metron.common.configuration.IndexingConfigurations in project metron by apache.

the class SensorIndexingConfigServiceImplTest method getAllIndicesWithOnlyIndexing.

@Test
public void getAllIndicesWithOnlyIndexing() throws RestException {
    ParserConfigurations parserConfiguration = mock(ParserConfigurations.class);
    when(parserConfiguration.getTypes()).thenReturn(Collections.emptyList());
    IndexingConfigurations indexingConfiguration = mock(IndexingConfigurations.class);
    // rename bro, include snort by default configs, and disable yaf
    when(indexingConfiguration.getTypes()).thenReturn(ImmutableList.of("bro", "snort", "yaf"));
    when(indexingConfiguration.getIndex(eq("bro"), eq("elasticsearch"))).thenReturn("renamed_bro");
    when(indexingConfiguration.getIndex(eq("snort"), eq("elasticsearch"))).thenReturn(null);
    when(indexingConfiguration.isEnabled(eq("snort"), eq("elasticsearch"))).thenReturn(true);
    when(indexingConfiguration.isEnabled(eq("bro"), eq("elasticsearch"))).thenReturn(true);
    when(indexingConfiguration.isEnabled(eq("yaf"), eq("elasticsearch"))).thenReturn(false);
    when(cache.get(eq(ParserConfigurations.class))).thenReturn(parserConfiguration);
    when(cache.get(eq(IndexingConfigurations.class))).thenReturn(indexingConfiguration);
    List<String> indices = new ArrayList<String>();
    Iterables.addAll(indices, sensorIndexingConfigService.getAllIndices("elasticsearch"));
    assertEquals(2, indices.size());
    assertTrue(indices.contains("renamed_bro"));
    assertTrue(indices.contains("snort"));
}
Also used : ParserConfigurations(org.apache.metron.common.configuration.ParserConfigurations) IndexingConfigurations(org.apache.metron.common.configuration.IndexingConfigurations) Test(org.junit.jupiter.api.Test)

Example 37 with IndexingConfigurations

use of org.apache.metron.common.configuration.IndexingConfigurations in project metron by apache.

the class SensorIndexingConfigServiceImplTest method getAllTypesShouldProperlyReturnTypes.

@Test
public void getAllTypesShouldProperlyReturnTypes() throws Exception {
    IndexingConfigurations configs = new IndexingConfigurations() {

        @Override
        public Map<String, Object> getConfigurations() {
            return ImmutableMap.of(IndexingConfigurations.getKey("bro"), new HashMap<>(), IndexingConfigurations.getKey("squid"), new HashMap<>());
        }
    };
    when(cache.get(eq(IndexingConfigurations.class))).thenReturn(configs);
    assertEquals(new ArrayList() {

        {
            add("bro");
            add("squid");
        }
    }, sensorIndexingConfigService.getAllTypes());
}
Also used : IndexingConfigurations(org.apache.metron.common.configuration.IndexingConfigurations) Test(org.junit.jupiter.api.Test)

Example 38 with IndexingConfigurations

use of org.apache.metron.common.configuration.IndexingConfigurations in project metron by apache.

the class SolrWriterTest method testWriter.

@Test
public void testWriter() throws Exception {
    IndexingConfigurations configurations = SampleUtil.getSampleIndexingConfigs();
    JSONObject message1 = new JSONObject();
    message1.put(Constants.GUID, "guid-1");
    message1.put(Constants.SENSOR_TYPE, "test");
    message1.put("intField", 100);
    message1.put("doubleField", 100.0);
    JSONObject message2 = new JSONObject();
    message2.put(Constants.GUID, "guid-2");
    message2.put(Constants.SENSOR_TYPE, "test");
    message2.put("intField", 200);
    message2.put("doubleField", 200.0);
    List<BulkMessage<JSONObject>> messages = new ArrayList<>();
    messages.add(new BulkMessage<>("message1", message1));
    messages.add(new BulkMessage<>("message2", message2));
    String collection = "metron";
    MetronSolrClient solr = Mockito.mock(MetronSolrClient.class);
    SolrWriter writer = new SolrWriter().withMetronSolrClient(solr);
    writer.init(null, new IndexingWriterConfiguration("solr", configurations));
    verify(solr, times(1)).setDefaultCollection(collection);
    collection = "metron2";
    Map<String, Object> globalConfig = configurations.getGlobalConfig();
    globalConfig.put("solr.collection", collection);
    configurations.updateGlobalConfig(globalConfig);
    writer = new SolrWriter().withMetronSolrClient(solr);
    writer.init(null, new IndexingWriterConfiguration("solr", configurations));
    verify(solr, times(1)).setDefaultCollection(collection);
    writer.write("test", new IndexingWriterConfiguration("solr", configurations), messages);
    verify(solr, times(1)).add(eq("yaf"), argThat(new SolrInputDocumentMatcher(ImmutableList.of(message1, message2))));
    verify(solr, times(1)).commit("yaf", (boolean) SolrWriter.SolrProperties.COMMIT_WAIT_FLUSH.defaultValue.get(), (boolean) SolrWriter.SolrProperties.COMMIT_WAIT_SEARCHER.defaultValue.get(), (boolean) SolrWriter.SolrProperties.COMMIT_SOFT.defaultValue.get());
}
Also used : IndexingWriterConfiguration(org.apache.metron.common.configuration.writer.IndexingWriterConfiguration) ArrayList(java.util.ArrayList) BulkMessage(org.apache.metron.common.writer.BulkMessage) JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) IndexingConfigurations(org.apache.metron.common.configuration.IndexingConfigurations) Test(org.junit.jupiter.api.Test)

Aggregations

IndexingConfigurations (org.apache.metron.common.configuration.IndexingConfigurations)38 Test (org.junit.jupiter.api.Test)29 IndexingWriterConfiguration (org.apache.metron.common.configuration.writer.IndexingWriterConfiguration)20 JSONObject (org.json.simple.JSONObject)14 WriterConfiguration (org.apache.metron.common.configuration.writer.WriterConfiguration)13 ParserConfigurations (org.apache.metron.common.configuration.ParserConfigurations)5 FileInputStream (java.io.FileInputStream)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 ConfigurationsCache (org.apache.metron.common.zookeeper.ConfigurationsCache)3 Map (java.util.Map)2 BulkMessage (org.apache.metron.common.writer.BulkMessage)2 BaseEnrichmentBoltTest (org.apache.metron.test.bolt.BaseEnrichmentBoltTest)2 JSONParser (org.json.simple.parser.JSONParser)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 FakeClock (org.apache.metron.common.system.FakeClock)1 MessageId (org.apache.metron.common.writer.MessageId)1 DefaultFileNameFormat (org.apache.storm.hdfs.bolt.format.DefaultFileNameFormat)1