use of io.siddhi.core.util.error.handler.model.ErroneousEvent in project siddhi by wso2.
the class Sink method onError.
public void onError(Object payload, DynamicOptions dynamicOptions, Exception e) {
OnErrorAction errorAction = onErrorAction;
if (e instanceof ConnectionUnavailableException) {
setConnected(false);
if (connectionCallback != null) {
connectionCallback.connectionFailed();
}
} else if (errorAction == OnErrorAction.WAIT) {
LOG.error("Error on '" + siddhiAppContext.getName() + "'. Dropping event at Sink '" + type + "' at '" + streamDefinition.getId() + "' as on.error='wait' does not handle " + "'" + e.getClass().getName() + "' error: '" + e.getMessage() + "', events dropped '" + payload + "'", e);
return;
}
try {
switch(errorAction) {
case STREAM:
connectWithRetry();
streamJunction.handleError(dynamicOptions.getEvent(), e);
break;
case WAIT:
LOG.error(StringUtil.removeCRLFCharacters(ExceptionUtil.getMessageWithContext(e, siddhiAppContext) + ", error while connecting Sink '" + type + "' at '" + streamDefinition.getId() + "', will retry every '5 sec'."), e);
int count = 0;
while (!isConnected.get()) {
if (isShutdown.get()) {
isTryingToConnect.set(false);
return;
}
retryWait(5000);
count++;
if (!isConnected.get() && !isTryingToConnect.getAndSet(true)) {
while (!isConnected.get()) {
if (isShutdown.get()) {
isTryingToConnect.set(false);
return;
}
S state = stateHolder.getState();
try {
connectAndPublish(payload, dynamicOptions, state);
isTryingToConnect.set(false);
return;
} catch (ConnectionUnavailableException ignore) {
} finally {
stateHolder.returnState(state);
}
if (count % 12 == 0) {
LOG.warn(StringUtil.removeCRLFCharacters(ExceptionUtil.getMessageWithContext(e, siddhiAppContext) + ", still waiting to connect Sink '" + type + "' at '" + streamDefinition.getId() + "' retrying every '5 sec'."), e);
}
retryWait(5000);
count++;
}
}
if (count % 12 == 0) {
LOG.warn(StringUtil.removeCRLFCharacters(ExceptionUtil.getMessageWithContext(e, siddhiAppContext) + ", still waiting to connect Sink '" + type + "' at '" + streamDefinition.getId() + "."), e);
}
}
S state = stateHolder.getState();
try {
publish(payload, dynamicOptions, state);
} catch (ConnectionUnavailableException ignore) {
onError(payload, dynamicOptions, e);
} finally {
stateHolder.returnState(state);
}
break;
case STORE:
connectWithRetry();
ErroneousEvent erroneousEvent = new ErroneousEvent(dynamicOptions.getEvent(), e, e.getMessage());
erroneousEvent.setOriginalPayload(payload);
ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.STORE_ON_SINK_ERROR, siddhiAppContext.getName(), erroneousEvent, streamDefinition.getId());
break;
case LOG:
default:
connectWithRetry();
LOG.error("Error on '" + siddhiAppContext.getName() + "'. Dropping event at Sink '" + type + "' at '" + streamDefinition.getId() + "' as its still trying to reconnect!, " + "events dropped '" + payload + "'");
if (LOG.isDebugEnabled()) {
LOG.debug(e);
}
break;
}
} catch (Throwable t) {
LOG.error("Error on '" + siddhiAppContext.getName() + "'. Dropping event at Sink '" + type + "' at '" + streamDefinition.getId() + "' as there is an issue when " + "handling the error: '" + t.getMessage() + "', events dropped '" + payload + "'", e);
}
}
use of io.siddhi.core.util.error.handler.model.ErroneousEvent in project siddhi by wso2.
the class StreamJunction method handleError.
public void handleError(long timeStamp, Object[] data, Exception e) {
if (exceptionListener != null) {
exceptionListener.exceptionThrown(e);
}
switch(onErrorAction) {
case LOG:
log.error("Error in '" + siddhiAppContext.getName() + "' after consuming events " + "from Stream '" + streamDefinition.getId() + "', " + e.getMessage() + ". Hence, dropping event '" + Arrays.toString(data) + "'", e);
break;
case STREAM:
if (faultStreamJunction != null) {
StreamEvent streamEvent = faultStreamEventConverter.convert(timeStamp, data, e);
faultStreamJunction.sendEvent(streamEvent);
} else {
log.error("Error in SiddhiApp '" + siddhiAppContext.getName() + "' after consuming events from Stream '" + streamDefinition.getId() + "', " + e.getMessage() + ". Siddhi Fault Stream for '" + streamDefinition.getId() + "' is not defined. " + "Hence, dropping data '" + Arrays.toString(data) + "'", e);
}
break;
case STORE:
StreamEvent streamEvent = faultStreamEventConverter.convert(timeStamp, data, e);
ErroneousEvent erroneousEvent = new ErroneousEvent(streamEvent, e, "Error in SiddhiApp '" + siddhiAppContext.getName() + "' after consuming events from Stream '" + streamDefinition.getId() + "', " + e.getMessage() + ". Siddhi Fault Stream for '" + streamDefinition.getId() + "' is not defined. " + "Hence, dropping data '" + Arrays.toString(data) + "'");
ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.STORE_ON_STREAM_ERROR, siddhiAppContext.getName(), erroneousEvent, streamDefinition.getId());
break;
default:
break;
}
}
use of io.siddhi.core.util.error.handler.model.ErroneousEvent 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())));
}
}
}
use of io.siddhi.core.util.error.handler.model.ErroneousEvent in project siddhi by wso2.
the class Table method handleStoreAddError.
private void handleStoreAddError(ComplexEventChunk addingEventChunk, boolean isFromConnectionUnavailableException, Exception e) {
addingEventChunk.reset();
ReplayableTableRecord record = new ReplayableTableRecord(addingEventChunk);
record.setFromConnectionUnavailableException(isFromConnectionUnavailableException);
record.setEditable(!isObjectColumnPresent);
ErroneousEvent erroneousEvent = new ErroneousEvent(record, e, e.getMessage());
erroneousEvent.setOriginalPayload(ErrorHandlerUtils.constructAddErrorRecordString(addingEventChunk, isFromConnectionUnavailableException, tableDefinition, e));
ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.STORE_ON_TABLE_ADD, siddhiAppContext.getName(), erroneousEvent, tableDefinition.getId());
}
use of io.siddhi.core.util.error.handler.model.ErroneousEvent in project siddhi by wso2.
the class Table method onDeleteError.
protected void onDeleteError(ComplexEventChunk<StateEvent> deletingEventChunk, CompiledCondition compiledCondition, Exception e) {
OnErrorAction errorAction = onErrorAction;
if (e instanceof ConnectionUnavailableException) {
isConnected.set(false);
if (errorAction == OnErrorAction.STORE) {
deletingEventChunk.reset();
ErroneousEvent erroneousEvent = new ErroneousEvent(new ReplayableTableRecord(deletingEventChunk, compiledCondition), e, e.getMessage());
erroneousEvent.setOriginalPayload(ErrorHandlerUtils.constructErrorRecordString(deletingEventChunk, isObjectColumnPresent, tableDefinition, e));
ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.STORE_ON_TABLE_DELETE, siddhiAppContext.getName(), erroneousEvent, tableDefinition.getId());
LOG.error("Error on '" + siddhiAppContext.getName() + "' while performing delete for events at '" + tableDefinition.getId() + "'. Events saved '" + deletingEventChunk.toString() + "'");
if (LOG.isDebugEnabled()) {
LOG.debug(e);
}
if (!isTryingToConnect.get()) {
connectWithRetry();
}
} else {
if (isTryingToConnect.get()) {
LOG.warn("Error on '" + siddhiAppContext.getName() + "' while performing delete for events '" + deletingEventChunk + "', operation busy waiting at Table '" + tableDefinition.getId() + "' as its trying to reconnect!");
waitWhileConnect();
LOG.info("SiddhiApp '" + siddhiAppContext.getName() + "' table '" + tableDefinition.getId() + "' has become available for delete operation for events '" + deletingEventChunk + "'");
delete(deletingEventChunk, compiledCondition);
} else {
connectWithRetry();
delete(deletingEventChunk, compiledCondition);
}
}
} else if (e instanceof DatabaseRuntimeException) {
if (errorAction == OnErrorAction.STORE) {
deletingEventChunk.reset();
ReplayableTableRecord record = new ReplayableTableRecord(deletingEventChunk, compiledCondition);
record.setFromConnectionUnavailableException(false);
ErroneousEvent erroneousEvent = new ErroneousEvent(record, e, e.getMessage());
erroneousEvent.setOriginalPayload(ErrorHandlerUtils.constructErrorRecordString(deletingEventChunk, isObjectColumnPresent, tableDefinition, e));
ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.STORE_ON_TABLE_DELETE, siddhiAppContext.getName(), erroneousEvent, tableDefinition.getId());
LOG.error("Error on '" + siddhiAppContext.getName() + "' while performing delete for events at '" + tableDefinition.getId() + "'. Events saved '" + deletingEventChunk.toString() + "'");
if (LOG.isDebugEnabled()) {
LOG.debug(e);
}
}
}
}
Aggregations