Search in sources :

Example 6 with NakadiRuntimeException

use of org.zalando.nakadi.exceptions.NakadiRuntimeException in project nakadi by zalando.

the class AbstractZkSubscriptionClient method listSessions.

@Override
public final Collection<Session> listSessions() throws SubscriptionNotInitializedException, NakadiRuntimeException, ServiceTemporarilyUnavailableException {
    getLog().info("fetching sessions information");
    final List<String> zkSessions;
    try {
        zkSessions = getCurator().getChildren().forPath(getSubscriptionPath("/sessions"));
    } catch (final KeeperException.NoNodeException e) {
        throw new SubscriptionNotInitializedException(getSubscriptionId());
    } catch (Exception ex) {
        throw new NakadiRuntimeException(ex);
    }
    return loadDataAsync(zkSessions, key -> getSubscriptionPath("/sessions/" + key), this::deserializeSession).values();
}
Also used : CreateMode(org.apache.zookeeper.CreateMode) RequestInProgressException(org.zalando.nakadi.exceptions.runtime.RequestInProgressException) Arrays(java.util.Arrays) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Session(org.zalando.nakadi.service.subscription.model.Session) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) InterProcessSemaphoreMutex(org.apache.curator.framework.recipes.locks.InterProcessSemaphoreMutex) Stat(org.apache.zookeeper.data.Stat) MyNakadiRuntimeException1(org.zalando.nakadi.exceptions.runtime.MyNakadiRuntimeException1) UTF_8(com.google.common.base.Charsets.UTF_8) Function(java.util.function.Function) Retryer.executeWithRetry(org.echocat.jomon.runtime.concurrent.Retryer.executeWithRetry) RetryForSpecifiedCountStrategy(org.echocat.jomon.runtime.concurrent.RetryForSpecifiedCountStrategy) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException) Lists(com.google.common.collect.Lists) SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) Map(java.util.Map) OperationInterruptedException(org.zalando.nakadi.exceptions.runtime.OperationInterruptedException) Charsets(com.google.common.base.Charsets) Logger(org.slf4j.Logger) KeeperException(org.apache.zookeeper.KeeperException) Iterator(java.util.Iterator) Collection(java.util.Collection) IOException(java.io.IOException) OperationTimeoutException(org.zalando.nakadi.exceptions.runtime.OperationTimeoutException) ZookeeperException(org.zalando.nakadi.exceptions.runtime.ZookeeperException) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) ServiceTemporarilyUnavailableException(org.zalando.nakadi.exceptions.runtime.ServiceTemporarilyUnavailableException) Closeable(java.io.Closeable) Optional(java.util.Optional) Comparator(java.util.Comparator) Collections(java.util.Collections) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) KeeperException(org.apache.zookeeper.KeeperException) RequestInProgressException(org.zalando.nakadi.exceptions.runtime.RequestInProgressException) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) OperationInterruptedException(org.zalando.nakadi.exceptions.runtime.OperationInterruptedException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) OperationTimeoutException(org.zalando.nakadi.exceptions.runtime.OperationTimeoutException) ZookeeperException(org.zalando.nakadi.exceptions.runtime.ZookeeperException) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) ServiceTemporarilyUnavailableException(org.zalando.nakadi.exceptions.runtime.ServiceTemporarilyUnavailableException)

Example 7 with NakadiRuntimeException

use of org.zalando.nakadi.exceptions.NakadiRuntimeException in project nakadi by zalando.

the class ClosingState method reactOnOffset.

private void reactOnOffset(final EventTypePartition key) {
    if (!listeners.containsKey(key)) {
        return;
    }
    final NakadiCursor newCursor;
    try {
        newCursor = getContext().getCursorConverter().convert(key.getEventType(), listeners.get(key).getData());
    } catch (Exception ex) {
        throw new NakadiRuntimeException(ex);
    }
    if (uncommittedOffsets.containsKey(key) && getComparator().compare(uncommittedOffsets.get(key), newCursor) <= 0) {
        freePartitions(Collections.singletonList(key));
    }
    tryCompleteState();
}
Also used : NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException)

Example 8 with NakadiRuntimeException

use of org.zalando.nakadi.exceptions.NakadiRuntimeException in project nakadi by zalando.

the class MultiTimelineEventConsumer method readEvents.

@Override
public List<ConsumedEvent> readEvents() {
    if (timelinesChanged.compareAndSet(true, false)) {
        try {
            onTimelinesChanged();
        } catch (final NakadiException | InvalidCursorException ex) {
            throw new NakadiRuntimeException(ex);
        }
    }
    final List<ConsumedEvent> result = poll();
    for (final ConsumedEvent event : result) {
        final EventTypePartition etp = event.getPosition().getEventTypePartition();
        latestOffsets.put(etp, event.getPosition());
        final String border = borderOffsets.get(etp);
        final boolean timelineBorderReached = null != border && border.compareTo(event.getPosition().getOffset()) <= 0;
        if (timelineBorderReached) {
            timelinesChanged.set(true);
        }
    }
    return result;
}
Also used : NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) ConsumedEvent(org.zalando.nakadi.domain.ConsumedEvent) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) NakadiException(org.zalando.nakadi.exceptions.NakadiException)

Example 9 with NakadiRuntimeException

use of org.zalando.nakadi.exceptions.NakadiRuntimeException in project nakadi by zalando.

the class TopicRepositoryHolder method createStoragePosition.

public Timeline.StoragePosition createStoragePosition(final Timeline timeline) {
    try {
        final Storage storage = timeline.getStorage();
        final List<NakadiCursor> offsets = getTopicRepository(storage).loadTopicStatistics(Collections.singleton(timeline)).stream().map(PartitionStatistics::getLast).collect(Collectors.toList());
        return getTopicRepositoryCreator(storage.getType()).createStoragePosition(offsets);
    } catch (final ServiceUnavailableException e) {
        throw new NakadiRuntimeException(e);
    }
}
Also used : NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) Storage(org.zalando.nakadi.domain.Storage) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException)

Example 10 with NakadiRuntimeException

use of org.zalando.nakadi.exceptions.NakadiRuntimeException in project nakadi by zalando.

the class ConsumerLimitingService method acquireConnectionSlot.

private ConnectionSlot acquireConnectionSlot(final String client, final String eventType, final String partition) {
    final String parent = zkPathForConsumer(client, eventType, partition);
    final String slotId = UUID.randomUUID().toString();
    final String zkPath = ZKPaths.makePath(parent, slotId);
    try {
        zkHolder.get().create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(zkPath);
    } catch (Exception e) {
        LOG.error("Zookeeper error when creating consumer node", e);
        throw new NakadiRuntimeException(e);
    }
    final ConnectionSlot acquiredSlot = new ConnectionSlot(client, eventType, partition, slotId);
    ACQUIRED_SLOTS.add(acquiredSlot);
    return acquiredSlot;
}
Also used : NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) NoConnectionSlotsException(org.zalando.nakadi.exceptions.NoConnectionSlotsException)

Aggregations

NakadiRuntimeException (org.zalando.nakadi.exceptions.NakadiRuntimeException)18 IOException (java.io.IOException)13 ServiceUnavailableException (org.zalando.nakadi.exceptions.ServiceUnavailableException)11 KeeperException (org.apache.zookeeper.KeeperException)10 ServiceTemporarilyUnavailableException (org.zalando.nakadi.exceptions.runtime.ServiceTemporarilyUnavailableException)10 UnableProcessException (org.zalando.nakadi.exceptions.UnableProcessException)8 OperationInterruptedException (org.zalando.nakadi.exceptions.runtime.OperationInterruptedException)8 OperationTimeoutException (org.zalando.nakadi.exceptions.runtime.OperationTimeoutException)8 RequestInProgressException (org.zalando.nakadi.exceptions.runtime.RequestInProgressException)8 ZookeeperException (org.zalando.nakadi.exceptions.runtime.ZookeeperException)8 EventTypePartition (org.zalando.nakadi.domain.EventTypePartition)6 Closeable (java.io.Closeable)5 Collections (java.util.Collections)5 HashMap (java.util.HashMap)5 List (java.util.List)5 Map (java.util.Map)5 TimeUnit (java.util.concurrent.TimeUnit)5 Collectors (java.util.stream.Collectors)5 MyNakadiRuntimeException1 (org.zalando.nakadi.exceptions.runtime.MyNakadiRuntimeException1)5 Arrays (java.util.Arrays)4