Search in sources :

Example 11 with SiddhiAppRuntimeException

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

the class SiddhiAppRuntimeImpl method startSources.

public void startSources() {
    if (running) {
        log.warn("Error calling startSources() for Siddhi App '" + siddhiAppContext.getName() + "', " + "SiddhiApp already started with the sources.");
        return;
    }
    if (!runningWithoutSources) {
        throw new SiddhiAppRuntimeException("Cannot call startSources() without calling startWithoutSources() " + "for Siddhi App '" + siddhiAppContext.getName() + "'");
    } else {
        try {
            for (List<Source> sources : sourceMap.values()) {
                for (Source source : sources) {
                    source.connectWithRetry();
                }
            }
            running = true;
            runningWithoutSources = false;
        } catch (Throwable t) {
            log.error("Error starting Siddhi App '" + siddhiAppContext.getName() + "', " + "triggering shutdown process. " + t.getMessage());
            try {
                shutdown();
            } catch (Throwable t1) {
                log.error("Error shutting down partially started Siddhi App '" + siddhiAppContext.getName() + "', " + t1.getMessage());
            }
        }
    }
}
Also used : SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) Source(io.siddhi.core.stream.input.source.Source)

Example 12 with SiddhiAppRuntimeException

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

the class SiddhiAppRuntimeImpl method removeCallback.

public void removeCallback(QueryCallback callback) {
    if (callback.getQueryName() == null) {
        throw new SiddhiAppRuntimeException("Cannot find QueryName in the queryCallback");
    }
    String queryName = callback.getQueryName();
    QueryRuntime queryRuntime = queryProcessorMap.get(queryName);
    if (queryRuntime != null) {
        ((QueryRuntimeImpl) queryRuntime).removeCallback(callback);
    }
}
Also used : QueryRuntimeImpl(io.siddhi.core.query.QueryRuntimeImpl) OnDemandQueryRuntime(io.siddhi.core.query.OnDemandQueryRuntime) QueryRuntime(io.siddhi.core.query.QueryRuntime) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException)

Example 13 with SiddhiAppRuntimeException

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

the class SnapshotService method waitForSystemStabilization.

private void waitForSystemStabilization() {
    int retryCount = 100;
    int activeThreads = siddhiAppContext.getThreadBarrier().getActiveThreads();
    while (activeThreads != 0 && retryCount > 0) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new SiddhiAppRuntimeException("Stabilization of Siddhi App " + siddhiAppContext.getName() + " for snapshot/restore interrupted. " + e.getMessage(), e);
        }
        activeThreads = siddhiAppContext.getThreadBarrier().getActiveThreads();
        retryCount--;
    }
    if (retryCount == 0) {
        throw new SiddhiAppRuntimeException("Siddhi App " + siddhiAppContext.getName() + " not stabilized for snapshot/restore, Active thread count is " + activeThreads);
    }
}
Also used : SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException)

Example 14 with SiddhiAppRuntimeException

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

the class SnapshotService method fullSnapshot.

public byte[] fullSnapshot() {
    try {
        SnapshotRequest.requestForFullSnapshot(true);
        Map<String, Map<String, Map<String, Map<String, Map<String, Object>>>>> fullSnapshot = new HashMap<>();
        byte[] serializedFullState = null;
        if (log.isDebugEnabled()) {
            log.debug("Taking snapshot ...");
        }
        try {
            threadBarrier.lock();
            waitForSystemStabilization();
            for (Map.Entry<String, PartitionIdStateHolder> partitionIdState : partitionIdStates.entrySet()) {
                for (Map.Entry<String, ElementStateHolder> queryState : partitionIdState.getValue().queryStateHolderMap.entrySet()) {
                    for (Map.Entry<String, StateHolder> elementState : queryState.getValue().elementHolderMap.entrySet()) {
                        Map<String, Map<String, State>> partitionKeyStates = elementState.getValue().getAllStates();
                        try {
                            for (Map.Entry<String, Map<String, State>> partitionKeyState : partitionKeyStates.entrySet()) {
                                for (Map.Entry<String, State> groupByKeyState : partitionKeyState.getValue().entrySet()) {
                                    String partitionAndGroupByKey = partitionKeyState.getKey() + "--" + groupByKeyState.getKey();
                                    State state = groupByKeyState.getValue();
                                    Map<String, Object> itemStates = state.snapshot();
                                    if (itemStates != null) {
                                        Map<String, Object> itemSnapshots = new HashMap<>();
                                        for (Map.Entry<String, Object> itemState : itemStates.entrySet()) {
                                            if (itemState.getValue() instanceof Snapshot) {
                                                if (((Snapshot) itemState.getValue()).isIncrementalSnapshot()) {
                                                    throw new NoPersistenceStoreException("No incremental " + "persistence store exist to store incremental " + "snapshot of siddhiApp:'" + siddhiAppContext.getName() + "' subElement:'" + queryState.getKey() + "' elementId:'" + elementState.getKey() + "' partitionKey:'" + partitionKeyState.getKey() + "' groupByKey:'" + groupByKeyState.getKey() + "' and itemKey:'" + itemState.getKey() + "'");
                                                } else {
                                                    itemSnapshots.put(itemState.getKey(), itemState.getValue());
                                                }
                                            } else {
                                                itemSnapshots.put(itemState.getKey(), itemState.getValue());
                                            }
                                        }
                                        Map<String, Map<String, Map<String, Map<String, Object>>>> partitionIdSnapshot = fullSnapshot.computeIfAbsent(partitionIdState.getKey(), k -> new HashMap<>());
                                        Map<String, Map<String, Map<String, Object>>> partitionGroupByKeySnapshot = partitionIdSnapshot.computeIfAbsent(partitionAndGroupByKey, k -> new HashMap<>());
                                        Map<String, Map<String, Object>> querySnapshot = partitionGroupByKeySnapshot.computeIfAbsent(queryState.getKey(), k -> new HashMap<>());
                                        Map<String, Object> elementSnapshot = querySnapshot.get(elementState.getKey());
                                        if (elementSnapshot == null) {
                                            querySnapshot.put(elementState.getKey(), itemSnapshots);
                                        } else {
                                            throw new SiddhiAppRuntimeException("Duplicate state exist for " + "siddhiApp:'" + siddhiAppContext.getName() + "' partitionKey:'" + partitionKeyState.getKey() + "' groupByKey:'" + groupByKeyState.getKey() + "' subElement:'" + queryState.getKey() + "' elementId:'" + elementState.getKey() + "'");
                                        }
                                    }
                                }
                            }
                        } finally {
                            elementState.getValue().returnAllStates(partitionKeyStates);
                        }
                    }
                }
            }
            if (log.isDebugEnabled()) {
                log.debug("Snapshot serialization started ...");
            }
            serializedFullState = ByteSerializer.objectToByte(fullSnapshot, siddhiAppContext);
            if (log.isDebugEnabled()) {
                log.debug("Snapshot serialization finished.");
            }
        } finally {
            threadBarrier.unlock();
        }
        if (log.isDebugEnabled()) {
            log.debug("Snapshot taken for Siddhi app '" + siddhiAppContext.getName() + "'");
        }
        return serializedFullState;
    } finally {
        SnapshotRequest.requestForFullSnapshot(false);
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) StateHolder(io.siddhi.core.util.snapshot.state.StateHolder) NoPersistenceStoreException(io.siddhi.core.exception.NoPersistenceStoreException) Snapshot(io.siddhi.core.util.snapshot.state.Snapshot) State(io.siddhi.core.util.snapshot.state.State) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(java.util.TreeMap)

Example 15 with SiddhiAppRuntimeException

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

the class PartitionStateHolder method returnState.

@Override
public void returnState(State state) {
    String partitionFlowId = SiddhiAppContext.getPartitionFlowId();
    String groupByFlowId = SiddhiAppContext.getGroupByFlowId();
    if (state.activeUseCount == 0) {
        try {
            if (state.canDestroy()) {
                removeState(partitionFlowId, groupByFlowId);
            }
        } catch (Throwable t) {
            log.error("Dropping partition state for partition key '" + partitionFlowId + "' and the group by key '" + groupByFlowId + "', due to error! " + t.getMessage(), t);
            removeState(partitionFlowId, groupByFlowId);
        }
    } else if (state.activeUseCount < 0) {
        throw new SiddhiAppRuntimeException("State active count has reached less then zero for partition key '" + partitionFlowId + "' and the group by key '" + groupByFlowId + "', current value is " + state.activeUseCount);
    }
}
Also used : SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException)

Aggregations

SiddhiAppRuntimeException (io.siddhi.core.exception.SiddhiAppRuntimeException)19 HashMap (java.util.HashMap)7 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)5 StreamEvent (io.siddhi.core.event.stream.StreamEvent)5 Attribute (io.siddhi.query.api.definition.Attribute)5 ReturnAttribute (io.siddhi.annotation.ReturnAttribute)4 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)4 Expression (io.siddhi.query.api.expression.Expression)4 Map (java.util.Map)4 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)3 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)3 Set (java.util.Set)3 SiddhiOnDemandQueryContext (io.siddhi.core.config.SiddhiOnDemandQueryContext)2 SiddhiQueryContext (io.siddhi.core.config.SiddhiQueryContext)2 ComplexEvent (io.siddhi.core.event.ComplexEvent)2 StateEvent (io.siddhi.core.event.state.StateEvent)2 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)2 TreeMap (java.util.TreeMap)2 IncrementalDataAggregator (io.siddhi.core.aggregation.IncrementalDataAggregator)1 OutOfOrderEventsDataAggregator (io.siddhi.core.aggregation.OutOfOrderEventsDataAggregator)1