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.");
}
}
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));
}
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));
}
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));
}
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));
}
Aggregations