use of org.apache.metron.common.error.MetronError in project metron by apache.
the class ParserBolt method handleError.
protected void handleError(String sensorType, byte[] originalMessage, Tuple tuple, Throwable ex, OutputCollector collector) {
MetronError error = new MetronError().withErrorType(Constants.ErrorType.PARSER_ERROR).withThrowable(ex).withSensorType(Collections.singleton(sensorType)).addRawMessage(originalMessage);
handleError(collector, error);
}
use of org.apache.metron.common.error.MetronError in project metron by apache.
the class AckTuplesPolicyTest method shouldProperlyHandleSuccessAndErrors.
@Test
public void shouldProperlyHandleSuccessAndErrors() throws Exception {
String messageId1 = "messageId1";
String messageId2 = "messageId2";
String messageId3 = "messageId3";
JSONObject message1 = new JSONObject();
JSONObject message2 = new JSONObject();
JSONObject message3 = new JSONObject();
message1.put("value", "message1");
message2.put("value", "message2");
message3.put("value", "message3");
Tuple tuple3 = mock(Tuple.class);
Throwable e = new Exception("test exception");
MetronError expectedError1 = new MetronError().withSensorType(Collections.singleton(sensorType)).withErrorType(Constants.ErrorType.INDEXING_ERROR).withThrowable(e).withRawMessages(Collections.singletonList(message1));
MetronError expectedError2 = new MetronError().withSensorType(Collections.singleton(sensorType)).withErrorType(Constants.ErrorType.INDEXING_ERROR).withThrowable(e).withRawMessages(Collections.singletonList(message2));
BulkWriterResponse response = new BulkWriterResponse();
response.addAllErrors(e, Arrays.asList(new MessageId(messageId1), new MessageId(messageId2)));
response.addSuccess(new MessageId(messageId3));
when(messageGetStrategy.get(tuple1)).thenReturn(message1);
when(messageGetStrategy.get(tuple2)).thenReturn(message2);
ackTuplesPolicy.addTupleMessageIds(tuple1, Collections.singleton(messageId1));
ackTuplesPolicy.addTupleMessageIds(tuple2, Collections.singleton(messageId2));
ackTuplesPolicy.addTupleMessageIds(tuple3, Collections.singleton(messageId3));
ackTuplesPolicy.onFlush(sensorType, response);
assertEquals(0, ackTuplesPolicy.getTupleMessageMap().size());
assertEquals(0, ackTuplesPolicy.getTupleErrorMap().size());
verify(collector, times(1)).emit(eq(Constants.ERROR_STREAM), new Values(argThat(new MetronErrorJSONMatcher(expectedError1.getJSONObject()))));
verify(collector, times(1)).emit(eq(Constants.ERROR_STREAM), new Values(argThat(new MetronErrorJSONMatcher(expectedError2.getJSONObject()))));
verify(collector, times(1)).ack(tuple1);
verify(collector, times(1)).ack(tuple2);
verify(collector, times(1)).ack(tuple3);
verify(collector, times(1)).reportError(e);
verifyNoMoreInteractions(collector);
}
use of org.apache.metron.common.error.MetronError in project metron by apache.
the class ErrorUtilsTest method handleErrorShouldEmitAndReportError.
@Test
public void handleErrorShouldEmitAndReportError() {
Throwable e = new Exception("error");
MetronError error = new MetronError().withMessage("error message").withThrowable(e);
OutputCollector collector = mock(OutputCollector.class);
StormErrorUtils.handleError(collector, error);
verify(collector, times(1)).emit(eq(Constants.ERROR_STREAM), argThat(new MetronErrorJSONMatcher(error.getJSONObject())));
verify(collector, times(1)).reportError(any());
}
use of org.apache.metron.common.error.MetronError in project metron by apache.
the class UnifiedEnrichmentBolt method execute.
/**
* Fully enrich a message based on the strategy which was used to configure the bolt.
* Each enrichment is done in parallel and the results are joined together. Each enrichment
* will use a cache so computation is avoided if the result has been computed before.
*
* Errors in the enrichment result in an error message being sent on the "error" stream.
* The successful enrichments will be joined with the original message and the message will
* be sent along the "message" stream.
*
* @param input The input tuple to be processed.
*/
@Override
public void execute(Tuple input) {
JSONObject message = generateMessage(input);
try {
String sourceType = MessageUtils.getSensorType(message);
SensorEnrichmentConfig config = getConfigurations().getSensorEnrichmentConfig(sourceType);
if (config == null) {
LOG.debug("Unable to find SensorEnrichmentConfig for sourceType: {}", sourceType);
config = new SensorEnrichmentConfig();
}
// This is an existing kludge for the stellar adapter to pass information along.
// We should figure out if this can be rearchitected a bit. This smells.
config.getConfiguration().putIfAbsent(STELLAR_CONTEXT_CONF, stellarContext);
String guid = getGUID(input, message);
// enrich the message
ParallelEnricher.EnrichmentResult result = enricher.apply(message, strategy, config, perfLog);
JSONObject enriched = result.getResult();
enriched = strategy.postProcess(enriched, config, enrichmentContext);
// we can emit the message now
collector.emit("message", input, new Values(guid, enriched));
// and handle each of the errors in turn. If any adapter errored out, we will have one message per.
for (Map.Entry<Object, Throwable> t : result.getEnrichmentErrors()) {
LOG.error("[Metron] Unable to enrich message: {}", message, t);
MetronError error = new MetronError().withErrorType(strategy.getErrorType()).withMessage(t.getValue().getMessage()).withThrowable(t.getValue()).addRawMessage(t.getKey());
StormErrorUtils.handleError(collector, error);
}
} catch (Exception e) {
// If something terrible and unexpected happens then we want to send an error along, but this
// really shouldn't be happening.
LOG.error("[Metron] Unable to enrich message: {}", message, e);
MetronError error = new MetronError().withErrorType(strategy.getErrorType()).withMessage(e.getMessage()).withThrowable(e).addRawMessage(message);
StormErrorUtils.handleError(collector, error);
} finally {
collector.ack(input);
}
}
use of org.apache.metron.common.error.MetronError in project metron by apache.
the class AckTuplesPolicy method handleError.
private void handleError(String sensorType, Throwable e, Tuple tuple) {
MetronError error = new MetronError().withSensorType(Collections.singleton(sensorType)).withErrorType(Constants.ErrorType.INDEXING_ERROR).withThrowable(e).addRawMessage(messageGetStrategy.get(tuple));
collector.emit(Constants.ERROR_STREAM, new Values(error.getJSONObject()));
}
Aggregations