Search in sources :

Example 1 with MappingFailedException

use of io.siddhi.core.exception.MappingFailedException in project siddhi by wso2.

the class SourceMapper method onEvent.

public final void onEvent(Object eventObject, Object[] transportProperties, String[] transportSyncProperties) {
    try {
        if (eventObject != null) {
            if (!allowNullInTransportProperties() && transportProperties != null) {
                for (Object property : transportProperties) {
                    if (property == null) {
                        log.error("Dropping event " + eventObject.toString() + " belonging to stream " + streamDefinition.getId() + " as it contains null transport properties and system " + "is configured to not allow null transport properties. You can " + "configure it via source mapper if the respective " + "mapper type allows it. Refer mapper documentation to verify " + "supportability");
                        return;
                    }
                }
            }
            trpProperties.set(transportProperties);
            if (transportSyncProperties != null) {
                trpSyncProperties.set(transportSyncProperties);
            }
            try {
                if (throughputTracker != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
                    throughputTracker.eventIn();
                }
                if (throughputTracker != null && Level.DETAIL.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
                    mapperLatencyTracker.markIn();
                }
                mapAndProcess(eventObject, inputEventHandler);
                if (logEventCount) {
                    if (firstRun) {
                        receivedEventCounter.scheduleEventCounterLogger();
                        firstRun = false;
                    }
                    receivedEventCounter.countEvents(eventObject);
                }
            } finally {
                if (throughputTracker != null && Level.DETAIL.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
                    mapperLatencyTracker.markOut();
                }
            }
        }
    } catch (MappingFailedException e) {
        ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.BEFORE_SOURCE_MAPPING, siddhiAppContext.getName(), e.getFailures(), streamDefinition.getId());
        log.error("Error while processing '" + eventObject + "', for the input Mapping '" + mapType + "' for the stream '" + streamDefinition.getId() + "'.", e);
    } catch (InterruptedException | RuntimeException e) {
        ErroneousEvent erroneousEvent = new ErroneousEvent(eventObject, e, "Error while processing '" + eventObject + "', for the input Mapping '" + mapType + "' for the stream '" + streamDefinition.getId() + "'.");
        ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.BEFORE_SOURCE_MAPPING, siddhiAppContext.getName(), Collections.singletonList(erroneousEvent), streamDefinition.getId());
        log.error("Error while processing '" + eventObject + "', for the input Mapping '" + mapType + "' for the stream '" + streamDefinition.getId() + "'.", e);
    } finally {
        trpProperties.remove();
        if (transportSyncProperties != null) {
            trpSyncProperties.remove();
        }
    }
}
Also used : MappingFailedException(io.siddhi.core.exception.MappingFailedException) ErroneousEvent(io.siddhi.core.util.error.handler.model.ErroneousEvent)

Example 2 with MappingFailedException

use of io.siddhi.core.exception.MappingFailedException in project siddhi by wso2.

the class TestTrpSourceMapper method mapAndProcess.

@Override
protected void mapAndProcess(Object eventObject, InputEventHandler inputEventHandler) throws MappingFailedException, InterruptedException {
    if (eventObject != null) {
        if (eventObject instanceof Event) {
            Event output = new Event(streamDefinition.getAttributeList().size());
            for (AttributeMapping attributeMapping : attributeMappingList) {
                output.getData()[attributeMapping.getPosition()] = ((Event) eventObject).getData(Integer.parseInt(attributeMapping.getMapping()));
            }
            inputEventHandler.sendEvent(output);
        } else {
            throw new MappingFailedException(Collections.singletonList(new ErroneousEvent(eventObject, "Event object must be either Event[], Event or Object[] " + "but found " + eventObject.getClass().getCanonicalName())));
        }
    }
}
Also used : AttributeMapping(io.siddhi.core.stream.input.source.AttributeMapping) ErroneousEvent(io.siddhi.core.util.error.handler.model.ErroneousEvent) Event(io.siddhi.core.event.Event) MappingFailedException(io.siddhi.core.exception.MappingFailedException) ErroneousEvent(io.siddhi.core.util.error.handler.model.ErroneousEvent)

Example 3 with MappingFailedException

use of io.siddhi.core.exception.MappingFailedException in project siddhi by wso2.

the class TestSourceOptionSourceMapper method mapAndProcess.

@Override
protected void mapAndProcess(Object eventObject, InputEventHandler inputEventHandler) throws MappingFailedException, InterruptedException {
    if (eventObject != null) {
        if (eventObject instanceof Event) {
            Event event = ((Event) eventObject);
            event.getData()[0] = sourceOptionHolder.validateAndGetOption("topic").getValue(event);
            event.getData()[1] = sourceType;
            inputEventHandler.sendEvent((Event) eventObject);
        } else {
            throw new MappingFailedException(Collections.singletonList(new ErroneousEvent(eventObject, "Event object must be Event " + "but found " + eventObject.getClass().getCanonicalName())));
        }
    }
}
Also used : ErroneousEvent(io.siddhi.core.util.error.handler.model.ErroneousEvent) Event(io.siddhi.core.event.Event) MappingFailedException(io.siddhi.core.exception.MappingFailedException) ErroneousEvent(io.siddhi.core.util.error.handler.model.ErroneousEvent)

Example 4 with MappingFailedException

use of io.siddhi.core.exception.MappingFailedException in project siddhi by wso2.

the class PassThroughSourceMapper method mapAndProcess.

@Override
protected void mapAndProcess(Object eventObject, InputEventHandler inputEventHandler) throws MappingFailedException, InterruptedException {
    if (eventObject != null) {
        if (eventObject instanceof Event[]) {
            inputEventHandler.sendEvents((Event[]) eventObject);
        } else if (eventObject instanceof Event) {
            inputEventHandler.sendEvent((Event) eventObject);
        } else if (eventObject instanceof Object[]) {
            Event event = new Event(-1, (Object[]) eventObject);
            inputEventHandler.sendEvent(event);
        } else {
            throw new MappingFailedException(Collections.singletonList(new ErroneousEvent(eventObject, "Event object must be either Event[], Event or Object[] " + "but found " + eventObject.getClass().getCanonicalName())));
        }
    }
}
Also used : ErroneousEvent(io.siddhi.core.util.error.handler.model.ErroneousEvent) Event(io.siddhi.core.event.Event) MappingFailedException(io.siddhi.core.exception.MappingFailedException) ErroneousEvent(io.siddhi.core.util.error.handler.model.ErroneousEvent)

Aggregations

MappingFailedException (io.siddhi.core.exception.MappingFailedException)4 ErroneousEvent (io.siddhi.core.util.error.handler.model.ErroneousEvent)4 Event (io.siddhi.core.event.Event)3 AttributeMapping (io.siddhi.core.stream.input.source.AttributeMapping)1