Search in sources :

Example 1 with EnrichmentConfigurations

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

the class GlobalConfigServiceImpl method get.

@Override
public Map<String, Object> get() throws RestException {
    Map<String, Object> globalConfig;
    try {
        EnrichmentConfigurations configs = cache.get(EnrichmentConfigurations.class);
        globalConfig = configs.getGlobalConfig(false);
    } catch (Exception e) {
        throw new RestException(e.getMessage(), e);
    }
    return globalConfig;
}
Also used : EnrichmentConfigurations(org.apache.metron.common.configuration.EnrichmentConfigurations) RestException(org.apache.metron.rest.RestException) KeeperException(org.apache.zookeeper.KeeperException) RestException(org.apache.metron.rest.RestException)

Example 2 with EnrichmentConfigurations

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

the class SensorEnrichmentConfigServiceImplTest method getAllShouldProperlyReturnSensorEnrichmentConfigs.

@Test
public void getAllShouldProperlyReturnSensorEnrichmentConfigs() throws Exception {
    final SensorEnrichmentConfig sensorEnrichmentConfig = getTestSensorEnrichmentConfig();
    EnrichmentConfigurations configs = new EnrichmentConfigurations() {

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

        {
            put("bro", sensorEnrichmentConfig);
        }
    }, sensorEnrichmentConfigService.getAll());
}
Also used : EnrichmentConfigurations(org.apache.metron.common.configuration.EnrichmentConfigurations) HashMap(java.util.HashMap) SensorEnrichmentConfig(org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig) Test(org.junit.Test)

Example 3 with EnrichmentConfigurations

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

the class GlobalConfigServiceImplTest method getShouldProperlyReturnGlobalConfig.

@Test
public void getShouldProperlyReturnGlobalConfig() throws Exception {
    final String config = "{\"k\":\"v\"}";
    final Map<String, Object> configMap = new HashMap<String, Object>() {

        {
            put("k", "v");
        }
    };
    EnrichmentConfigurations configs = new EnrichmentConfigurations() {

        @Override
        public Map<String, Object> getConfigurations() {
            return ImmutableMap.of(ConfigurationType.GLOBAL.getTypeName(), configMap);
        }
    };
    when(cache.get(eq(EnrichmentConfigurations.class))).thenReturn(configs);
    assertEquals(configMap, globalConfigService.get());
}
Also used : EnrichmentConfigurations(org.apache.metron.common.configuration.EnrichmentConfigurations) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with EnrichmentConfigurations

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

the class SensorEnrichmentConfigServiceImplTest method findOneShouldProperlyReturnSensorEnrichmentConfig.

@Test
public void findOneShouldProperlyReturnSensorEnrichmentConfig() throws Exception {
    final SensorEnrichmentConfig sensorEnrichmentConfig = getTestSensorEnrichmentConfig();
    EnrichmentConfigurations configs = new EnrichmentConfigurations() {

        @Override
        public Map<String, Object> getConfigurations() {
            return ImmutableMap.of(EnrichmentConfigurations.getKey("bro"), sensorEnrichmentConfig);
        }
    };
    when(cache.get(eq(EnrichmentConfigurations.class))).thenReturn(configs);
    // We only have bro, so we should expect it to be returned
    assertEquals(getTestSensorEnrichmentConfig(), sensorEnrichmentConfigService.findOne("bro"));
    // and blah should be a miss.
    assertNull(sensorEnrichmentConfigService.findOne("blah"));
}
Also used : EnrichmentConfigurations(org.apache.metron.common.configuration.EnrichmentConfigurations) SensorEnrichmentConfig(org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig) Test(org.junit.Test)

Example 5 with EnrichmentConfigurations

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

the class SensorEnrichmentConfigServiceImplTest method getAllTypesShouldProperlyReturnTypes.

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

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

        {
            add("bro");
            add("squid");
        }
    }, sensorEnrichmentConfigService.getAllTypes());
}
Also used : EnrichmentConfigurations(org.apache.metron.common.configuration.EnrichmentConfigurations) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

EnrichmentConfigurations (org.apache.metron.common.configuration.EnrichmentConfigurations)5 Test (org.junit.Test)4 HashMap (java.util.HashMap)2 SensorEnrichmentConfig (org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig)2 ArrayList (java.util.ArrayList)1 RestException (org.apache.metron.rest.RestException)1 KeeperException (org.apache.zookeeper.KeeperException)1