Search in sources :

Example 1 with ProfilerConfig

use of org.apache.metron.common.configuration.profiler.ProfilerConfig in project metron by apache.

the class ProfileSplitterBolt method doExecute.

private void doExecute(Tuple input) throws ParseException, UnsupportedEncodingException {
    // retrieve the input message
    byte[] data = input.getBinary(0);
    JSONObject message = (JSONObject) parser.parse(new String(data, "UTF8"));
    // ensure there is a valid profiler configuration
    ProfilerConfig config = getProfilerConfig();
    if (config != null && config.getProfiles().size() > 0) {
        // what time is it?
        Clock clock = clockFactory.createClock(config);
        Optional<Long> timestamp = clock.currentTimeMillis(message);
        // route the message.  if a message does not contain the timestamp field, it cannot be routed.
        timestamp.ifPresent(ts -> routeMessage(input, message, config, ts));
    } else {
        LOG.debug("No Profiler configuration found.  Nothing to do.");
    }
}
Also used : JSONObject(org.json.simple.JSONObject) ProfilerConfig(org.apache.metron.common.configuration.profiler.ProfilerConfig) Clock(org.apache.metron.profiler.clock.Clock)

Example 2 with ProfilerConfig

use of org.apache.metron.common.configuration.profiler.ProfilerConfig in project metron by apache.

the class ProfileSplitterBoltTest method testEmitTupleWithTwoProfiles.

/**
 * If there are two profiles that need the same message, then two tuples should
 * be emitted.  One tuple for each profile.
 */
@Test
public void testEmitTupleWithTwoProfiles() throws Exception {
    // setup the bolt and execute a tuple
    ProfilerConfig config = toProfilerConfig(twoProfilesDefined);
    ProfileSplitterBolt bolt = createBolt(config);
    bolt.execute(tuple);
    // the expected tuple fields
    final String expectedEntity = "global";
    {
        // a tuple should be emitted for the first profile
        ProfileConfig profile1 = config.getProfiles().get(0);
        Values expected = new Values(message, timestamp, expectedEntity, profile1);
        verify(outputCollector, times(1)).emit(eq(tuple), eq(expected));
    }
    {
        // a tuple should be emitted for the second profile
        ProfileConfig profile2 = config.getProfiles().get(1);
        Values expected = new Values(message, timestamp, expectedEntity, profile2);
        verify(outputCollector, times(1)).emit(eq(tuple), eq(expected));
    }
    // the original tuple should be ack'd
    verify(outputCollector, times(1)).ack(eq(tuple));
}
Also used : ProfilerConfig(org.apache.metron.common.configuration.profiler.ProfilerConfig) Values(org.apache.storm.tuple.Values) ProfileConfig(org.apache.metron.common.configuration.profiler.ProfileConfig) Test(org.junit.Test) BaseBoltTest(org.apache.metron.test.bolt.BaseBoltTest)

Example 3 with ProfilerConfig

use of org.apache.metron.common.configuration.profiler.ProfilerConfig in project metron by apache.

the class ProfileSplitterBoltTest method testOnlyIfInvalid.

/**
 * What happens when invalid Stella code is used for 'onlyif'?  The invalid profile should be ignored.
 */
@Test
public void testOnlyIfInvalid() throws Exception {
    ProfilerConfig config = toProfilerConfig(profileWithOnlyIfInvalid);
    ProfileSplitterBolt bolt = createBolt(config);
    bolt.execute(tuple);
    // a tuple should NOT be emitted for the downstream profile builder
    verify(outputCollector, times(0)).emit(any(Values.class));
}
Also used : ProfilerConfig(org.apache.metron.common.configuration.profiler.ProfilerConfig) Values(org.apache.storm.tuple.Values) Test(org.junit.Test) BaseBoltTest(org.apache.metron.test.bolt.BaseBoltTest)

Example 4 with ProfilerConfig

use of org.apache.metron.common.configuration.profiler.ProfilerConfig in project metron by apache.

the class ProfileSplitterBoltTest method testOnlyIfTrue.

/**
 * What happens when a profile's 'onlyif' expression is true?  The message
 * should be applied to the profile.
 */
@Test
public void testOnlyIfTrue() throws Exception {
    ProfilerConfig config = toProfilerConfig(profileWithOnlyIfTrue);
    ProfileSplitterBolt bolt = createBolt(config);
    bolt.execute(tuple);
    // a tuple should be emitted for the downstream profile builder
    verify(outputCollector, times(1)).emit(eq(tuple), any(Values.class));
    // the original tuple should be ack'd
    verify(outputCollector, times(1)).ack(eq(tuple));
}
Also used : ProfilerConfig(org.apache.metron.common.configuration.profiler.ProfilerConfig) Values(org.apache.storm.tuple.Values) Test(org.junit.Test) BaseBoltTest(org.apache.metron.test.bolt.BaseBoltTest)

Example 5 with ProfilerConfig

use of org.apache.metron.common.configuration.profiler.ProfilerConfig in project metron by apache.

the class ProfileSplitterBoltTest method testEmitTupleWithOneProfile.

/**
 * Ensure that a tuple with the correct fields is emitted to downstream bolts
 * when a profile is defined.
 */
@Test
public void testEmitTupleWithOneProfile() throws Exception {
    // setup the bolt and execute a tuple
    ProfilerConfig config = toProfilerConfig(profileWithOnlyIfTrue);
    ProfileSplitterBolt bolt = createBolt(config);
    bolt.execute(tuple);
    // the expected tuple fields
    String expectedEntity = "10.0.0.1";
    ProfileConfig expectedConfig = config.getProfiles().get(0);
    Values expected = new Values(message, timestamp, expectedEntity, expectedConfig);
    // a tuple should be emitted for the downstream profile builder
    verify(outputCollector, times(1)).emit(eq(tuple), eq(expected));
    // the original tuple should be ack'd
    verify(outputCollector, times(1)).ack(eq(tuple));
}
Also used : ProfilerConfig(org.apache.metron.common.configuration.profiler.ProfilerConfig) Values(org.apache.storm.tuple.Values) ProfileConfig(org.apache.metron.common.configuration.profiler.ProfileConfig) Test(org.junit.Test) BaseBoltTest(org.apache.metron.test.bolt.BaseBoltTest)

Aggregations

ProfilerConfig (org.apache.metron.common.configuration.profiler.ProfilerConfig)13 Test (org.junit.Test)10 BaseBoltTest (org.apache.metron.test.bolt.BaseBoltTest)8 Values (org.apache.storm.tuple.Values)6 ProfileConfig (org.apache.metron.common.configuration.profiler.ProfileConfig)3 File (java.io.File)1 Map (java.util.Map)1 SensorEnrichmentConfig (org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig)1 ProfilerConfigurations (org.apache.metron.common.configuration.profiler.ProfilerConfigurations)1 Clock (org.apache.metron.profiler.clock.Clock)1 Tuple (org.apache.storm.tuple.Tuple)1 JSONObject (org.json.simple.JSONObject)1