use of com.hortonworks.streamline.streams.exception.ProcessingException in project streamline by hortonworks.
the class CustomProcessorBolt method process.
@Override
protected void process(Tuple input, StreamlineEvent event) {
try {
StreamlineEvent toProcess = null;
if (inputSchemaMap == null || inputSchemaMap.isEmpty() || !inputSchemaMap.containsKey(input.getSourceStreamId())) {
toProcess = event;
} else {
// Create a new mapped event based on mapping to pass it to CP implementation
Map<String, Object> mappedEventMap = new HashMap<>();
for (Map.Entry<String, String> entry : inputSchemaMap.get(input.getSourceStreamId()).entrySet()) {
if (event.get(entry.getValue()) != null) {
mappedEventMap.put(entry.getKey(), event.get(entry.getValue()));
}
}
toProcess = StreamlineEventImpl.builder().from(event).sourceStream(input.getSourceStreamId()).fieldsAndValues(mappedEventMap).build();
}
List<StreamlineEvent> results = customProcessorRuntime.process(toProcess);
if (results != null) {
Schema schema = outputSchema.values().iterator().next();
String outputStream = outputSchema.keySet().iterator().next();
for (StreamlineEvent e : results) {
Map<String, Object> newFieldsAndValues = new HashMap<>();
// event and CP defined output schema. UI will make sure that the fields are from one of the two sets.
for (Schema.Field field : schema.getFields()) {
// value has to be present either in the input event
newFieldsAndValues.put(field.getName(), e.containsKey(field.getName()) ? e.get(field.getName()) : event.get(field.getName()));
}
StreamlineEvent toEmit = StreamlineEventImpl.builder().from(e).sourceStream(outputStream).fieldsAndValues(newFieldsAndValues).build();
collector.emit(outputStream, input, new Values(toEmit));
}
}
} catch (ProcessingException e) {
LOG.error("Custom Processor threw a ProcessingException. ", e);
throw new RuntimeException(e);
}
}
use of com.hortonworks.streamline.streams.exception.ProcessingException in project streamline by hortonworks.
the class WindowRulesBolt method processAndEmit.
private void processAndEmit(StreamlineEvent event, Map<String, Tuple> curGroup) throws ProcessingException {
List<Result> results = ruleProcessorRuntime.process(eventWithWindowId(event));
for (Result result : results) {
for (StreamlineEvent e : result.events) {
// anchor parent events if such information is available
if (EventCorrelationInjector.containsParentIds(e)) {
Set<String> parentIds = EventCorrelationInjector.getParentIds(e);
List<Tuple> parents = parentIds.stream().map(pid -> {
if (!curGroup.containsKey(pid)) {
throw new IllegalStateException("parents should be in grouped tuples");
}
return curGroup.get(pid);
}).collect(Collectors.toList());
collector.emit(result.stream, parents, new Values(updateHeaders(e, parents)));
} else {
// put all events in current group if there's no information
collector.emit(result.stream, curGroup.values(), new Values(updateHeaders(e, curGroup.values())));
}
}
}
}
use of com.hortonworks.streamline.streams.exception.ProcessingException in project streamline by hortonworks.
the class RuleRuntime method process.
/**
* Executes a {@link Rule}'s Action
*
* @param event runtime input to this rule
*/
@Override
public List<Result> process(StreamlineEvent event) throws ProcessingException {
LOG.debug("process invoked with StreamlineEvent {}", event);
List<Result> allResults = new ArrayList<>();
try {
for (ActionRuntime action : actions) {
List<Result> actionResults = action.execute(event);
LOG.debug("Applied action {}, Result {}", action, actionResults);
if (actionResults != null) {
allResults.addAll(actionResults);
}
}
} catch (Exception e) {
String message = "Error evaluating rule with id:" + rule.getId();
LOG.error(message);
throw new ProcessingException(message, e);
}
LOG.debug("Returning allResults {}", allResults);
return allResults;
}
use of com.hortonworks.streamline.streams.exception.ProcessingException in project streamline by hortonworks.
the class CustomProcessorBoltTest method testExecute.
private void testExecute(boolean isSuccess) throws ProcessingException, ClassNotFoundException, MalformedURLException, InstantiationException, IllegalAccessException {
customProcessorBolt.customProcessorImpl(ConsoleCustomProcessor.class.getCanonicalName());
customProcessorBolt.outputSchema(outputStreamToSchema);
Map<String, Object> data = new HashMap<>();
data.put("key", "value");
final StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(data).dataSourceId("dsrcid").build();
final List<StreamlineEvent> result = Arrays.asList(event);
final ProcessingException pe = new ProcessingException("Test");
new Expectations() {
{
tuple.getSourceComponent();
returns("datasource");
tuple.getSourceStreamId();
returns(stream);
tuple.getValueByField(StreamlineEvent.STREAMLINE_EVENT);
returns(event);
}
};
if (!isSuccess) {
new Expectations() {
{
customProcessorRuntime.process(event);
result = pe;
}
};
} else {
new Expectations() {
{
customProcessorRuntime.process(event);
returns(result);
}
};
}
Map<Object, Object> conf = new HashMap<>();
customProcessorBolt.prepare(conf, null, mockOutputCollector);
customProcessorBolt.execute(tuple);
if (!isSuccess) {
new VerificationsInOrder() {
{
RuntimeException e;
customProcessorRuntime.process(event);
times = 1;
mockOutputCollector.fail(tuple);
times = 1;
mockOutputCollector.reportError(e = withCapture());
assertTrue(e.getCause() == pe);
}
};
} else {
new VerificationsInOrder() {
{
tuple.getSourceComponent();
times = 1;
tuple.getSourceStreamId();
times = 1;
StreamlineEvent actual;
customProcessorRuntime.process(actual = withCapture());
times = 1;
Assert.assertEquals(actual.getSourceStream(), stream);
Assert.assertEquals(actual, event);
Values actualValues;
mockOutputCollector.emit(outputStream, tuple, actualValues = withCapture());
times = 1;
mockOutputCollector.ack(tuple);
times = 1;
}
};
}
}
use of com.hortonworks.streamline.streams.exception.ProcessingException in project streamline by hortonworks.
the class RuleProcessorRuntime method process.
@Override
public List<Result> process(StreamlineEvent event) throws ProcessingException {
List<Result> results = new ArrayList<>();
try {
List<RuleRuntime> ruleRuntimes = getRulesRuntime(event);
LOG.debug("Process event {}, rule runtimes {}", event, ruleRuntimes);
for (RuleRuntime rr : ruleRuntimes) {
boolean succeeded = false;
for (StreamlineEvent result : rr.evaluate(event)) {
if (result != null) {
results.addAll(rr.process(result));
succeeded = true;
}
}
if (!processAll && succeeded)
break;
}
} catch (Exception e) {
String message = String.format("Error evaluating rule processor with id: %s, error: %s", rulesProcessor.getId(), e.getMessage());
LOG.error(message, e);
throw new ProcessingException(message, e);
}
return results;
}
Aggregations