use of io.siddhi.core.exception.ConnectionUnavailableException in project siddhi by wso2.
the class AbstractRecordTable method updateOrAdd.
@Override
public void updateOrAdd(ComplexEventChunk<StateEvent> updateOrAddingEventChunk, CompiledCondition compiledCondition, CompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
RecordTableCompiledUpdateSet recordTableCompiledUpdateSet = (RecordTableCompiledUpdateSet) compiledUpdateSet;
List<Map<String, Object>> updateConditionParameterMaps = new ArrayList<>();
List<Map<String, Object>> updateSetParameterMaps = new ArrayList<>();
List<Object[]> addingRecords = new ArrayList<>();
updateOrAddingEventChunk.reset();
long timestamp = 0L;
while (updateOrAddingEventChunk.hasNext()) {
StateEvent stateEvent = updateOrAddingEventChunk.next();
Map<String, Object> variableMap = new HashMap<>();
for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
variableMap.put(entry.getKey(), entry.getValue().execute(stateEvent));
}
updateConditionParameterMaps.add(variableMap);
Map<String, Object> variableMapForUpdateSet = new HashMap<>();
for (Map.Entry<String, ExpressionExecutor> entry : recordTableCompiledUpdateSet.getExpressionExecutorMap().entrySet()) {
variableMapForUpdateSet.put(entry.getKey(), entry.getValue().execute(stateEvent));
}
updateSetParameterMaps.add(variableMapForUpdateSet);
addingRecords.add(stateEvent.getStreamEvent(0).getOutputData());
timestamp = stateEvent.getTimestamp();
}
try {
if (recordTableHandler != null) {
recordTableHandler.updateOrAdd(timestamp, recordStoreCompiledCondition.getCompiledCondition(), updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps, addingRecords);
} else {
updateOrAdd(recordStoreCompiledCondition.getCompiledCondition(), updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps, addingRecords);
}
} catch (ConnectionUnavailableException | DatabaseRuntimeException e) {
onUpdateOrAddError(updateOrAddingEventChunk, compiledCondition, compiledUpdateSet, addingStreamEventExtractor, e);
}
}
use of io.siddhi.core.exception.ConnectionUnavailableException in project siddhi by wso2.
the class ErrorHandlerUtils method constructErrorRecordString.
public static String constructErrorRecordString(ComplexEventChunk<StateEvent> eventChunk, boolean isObjectColumnPresent, TableDefinition tableDefinition, Exception e) {
JsonObject payloadJson = new JsonObject();
if (isObjectColumnPresent || e instanceof ConnectionUnavailableException) {
payloadJson.addProperty("isEditable", false);
} else {
payloadJson.addProperty("isEditable", true);
}
JsonArray attributes = new JsonArray();
JsonArray records = new JsonArray();
for (Attribute attribute : tableDefinition.getAttributeList()) {
JsonObject attributeJson = new JsonObject();
attributeJson.add("name", new JsonPrimitive(attribute.getName()));
attributeJson.add("type", new JsonPrimitive(String.valueOf(attribute.getType())));
attributes.add(attributeJson);
}
payloadJson.add("attributes", attributes);
while (eventChunk.hasNext()) {
StateEvent stateEvent = eventChunk.next();
for (StreamEvent streamEvent : stateEvent.getStreamEvents()) {
if (streamEvent != null) {
JsonArray record = new JsonArray();
for (Object item : streamEvent.getOutputData()) {
if (item == null) {
record.add(JsonNull.INSTANCE);
} else {
record.add(String.valueOf(item));
}
}
records.add(record);
}
}
}
payloadJson.add("records", records);
return payloadJson.toString();
}
use of io.siddhi.core.exception.ConnectionUnavailableException 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.exception.ConnectionUnavailableException 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