Search in sources :

Example 16 with NakadiRuntimeException

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

the class EventTypeService method update.

public void update(final String eventTypeName, final EventTypeBase eventTypeBase) throws TopicConfigException, InconsistentStateException, NakadiRuntimeException, ServiceTemporarilyUnavailableException, UnableProcessException, DbWriteOperationsBlockedException {
    if (featureToggleService.isFeatureEnabled(FeatureToggleService.Feature.DISABLE_DB_WRITE_OPERATIONS)) {
        throw new DbWriteOperationsBlockedException("Cannot update event type: write operations on DB " + "are blocked by feature flag.");
    }
    Closeable updatingCloser = null;
    try {
        updatingCloser = timelineSync.workWithEventType(eventTypeName, nakadiSettings.getTimelineWaitTimeoutMs());
        final EventType original = eventTypeRepository.findByName(eventTypeName);
        authorizationValidator.authorizeEventTypeAdmin(original);
        authorizationValidator.validateAuthorization(original, eventTypeBase);
        validateName(eventTypeName, eventTypeBase);
        validateSchema(eventTypeBase);
        partitionResolver.validate(eventTypeBase);
        final EventType eventType = schemaEvolutionService.evolve(original, eventTypeBase);
        eventType.setDefaultStatistic(validateStatisticsUpdate(original.getDefaultStatistic(), eventType.getDefaultStatistic()));
        updateRetentionTime(original, eventType);
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new ServiceTemporarilyUnavailableException("Event type is currently in maintenance, please repeat request", e);
    } catch (final TimeoutException e) {
        LOG.error("Failed to wait for timeline switch", e);
        throw new ServiceTemporarilyUnavailableException("Event type is currently in maintenance, please repeat request", e);
    } catch (final NakadiException e) {
        LOG.error("Unable to update event type", e);
        throw new NakadiRuntimeException(e);
    } finally {
        try {
            if (updatingCloser != null) {
                updatingCloser.close();
            }
        } catch (final IOException e) {
            LOG.error("Exception occurred when releasing usage of event-type", e);
        }
    }
    nakadiKpiPublisher.publish(etLogEventType, () -> new JSONObject().put("event_type", eventTypeName).put("status", "updated").put("category", eventTypeBase.getCategory()).put("authz", identifyAuthzState(eventTypeBase)).put("compatibility_mode", eventTypeBase.getCompatibilityMode()));
}
Also used : ServiceTemporarilyUnavailableException(org.zalando.nakadi.exceptions.runtime.ServiceTemporarilyUnavailableException) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) Closeable(java.io.Closeable) IOException(java.io.IOException) DbWriteOperationsBlockedException(org.zalando.nakadi.exceptions.runtime.DbWriteOperationsBlockedException) TimeoutException(java.util.concurrent.TimeoutException) NakadiException(org.zalando.nakadi.exceptions.NakadiException) InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException)

Example 17 with NakadiRuntimeException

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

the class ClosingState method reactOnTopologyChange.

private void reactOnTopologyChange() throws NakadiRuntimeException {
    final ZkSubscriptionClient.Topology topology = topologyListener.getData();
    // Collect current partitions state from Zk
    final Map<EventTypePartition, Partition> partitions = new HashMap<>();
    Stream.of(topology.getPartitions()).filter(p -> getSessionId().equals(p.getSession())).forEach(p -> partitions.put(p.getKey(), p));
    // Select which partitions need to be freed from this session
    final Set<EventTypePartition> freeRightNow = new HashSet<>();
    final Set<EventTypePartition> addListeners = new HashSet<>();
    for (final Partition p : partitions.values()) {
        if (Partition.State.REASSIGNING.equals(p.getState())) {
            if (!uncommittedOffsets.containsKey(p.getKey())) {
                freeRightNow.add(p.getKey());
            } else {
                if (!listeners.containsKey(p.getKey())) {
                    addListeners.add(p.getKey());
                }
            }
        } else {
            // ASSIGNED
            if (uncommittedOffsets.containsKey(p.getKey()) && !listeners.containsKey(p.getKey())) {
                addListeners.add(p.getKey());
            }
        }
    }
    uncommittedOffsets.keySet().stream().filter(p -> !partitions.containsKey(p)).forEach(freeRightNow::add);
    freePartitions(freeRightNow);
    addListeners.forEach(this::registerListener);
    tryCompleteState();
}
Also used : EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) LongSupplier(java.util.function.LongSupplier) ZkSubscription(org.zalando.nakadi.service.subscription.zk.ZkSubscription) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) Collection(java.util.Collection) Set(java.util.Set) HashMap(java.util.HashMap) MyNakadiRuntimeException1(org.zalando.nakadi.exceptions.runtime.MyNakadiRuntimeException1) ZkSubscriptionClient(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient) Supplier(java.util.function.Supplier) Partition(org.zalando.nakadi.service.subscription.model.Partition) HashSet(java.util.HashSet) TimeUnit(java.util.concurrent.TimeUnit) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) Stream(java.util.stream.Stream) SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) Map(java.util.Map) Collections(java.util.Collections) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Partition(org.zalando.nakadi.service.subscription.model.Partition) ZkSubscriptionClient(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient) HashMap(java.util.HashMap) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) HashSet(java.util.HashSet)

Example 18 with NakadiRuntimeException

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

the class StreamingState method onExit.

@Override
public void onExit() {
    uncommittedOffsets = offsets.entrySet().stream().filter(e -> !e.getValue().isCommitted()).collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getSentOffset()));
    getContext().getSubscription().getEventTypes().stream().forEach(et -> publishKpi(et));
    if (null != topologyChangeSubscription) {
        try {
            topologyChangeSubscription.close();
        } catch (final RuntimeException ex) {
            getLog().warn("Failed to cancel topology subscription", ex);
        } finally {
            topologyChangeSubscription = null;
            new HashSet<>(offsets.keySet()).forEach(this::removeFromStreaming);
        }
    }
    if (null != eventConsumer) {
        try {
            eventConsumer.close();
        } catch (final IOException e) {
            throw new NakadiRuntimeException(e);
        } finally {
            eventConsumer = null;
        }
    }
    if (cursorResetSubscription != null) {
        try {
            cursorResetSubscription.close();
        } catch (IOException ignore) {
        }
        cursorResetSubscription = null;
    }
}
Also used : NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) IOException(java.io.IOException)

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