Search in sources :

Example 16 with InternalNakadiException

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

the class SubscriptionService method createSubscriptionStat.

private List<SubscriptionEventTypeStats> createSubscriptionStat(final Subscription subscription) throws InconsistentStateException, ServiceTemporarilyUnavailableException {
    final List<EventType> eventTypes = subscription.getEventTypes().stream().map(Try.wrap(eventTypeRepository::findByName)).map(Try::getOrThrow).sorted(Comparator.comparing(EventType::getName)).collect(Collectors.toList());
    final List<PartitionEndStatistics> topicPartitions;
    try {
        topicPartitions = loadPartitionEndStatistics(eventTypes);
    } catch (final ServiceUnavailableException ex) {
        throw new ServiceTemporarilyUnavailableException(ex);
    }
    final ZkSubscriptionClient subscriptionClient;
    try {
        subscriptionClient = subscriptionClientFactory.createClient(subscription, "subscription." + subscription.getId() + ".stats");
    } catch (final InternalNakadiException | NoSuchEventTypeException e) {
        throw new ServiceTemporarilyUnavailableException(e);
    }
    final Optional<ZkSubscriptionNode> zkSubscriptionNode = subscriptionClient.getZkSubscriptionNodeLocked();
    return loadStats(eventTypes, zkSubscriptionNode, subscriptionClient, topicPartitions);
}
Also used : ServiceTemporarilyUnavailableException(org.zalando.nakadi.exceptions.runtime.ServiceTemporarilyUnavailableException) InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) EventType(org.zalando.nakadi.domain.EventType) ZkSubscriptionClient(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) PartitionEndStatistics(org.zalando.nakadi.domain.PartitionEndStatistics) Try(org.zalando.nakadi.exceptions.Try) ZkSubscriptionNode(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionNode) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException)

Example 17 with InternalNakadiException

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

the class CachingEventTypeRepository method update.

@Override
public void update(final EventType eventType) throws InternalNakadiException, NoSuchEventTypeException {
    final EventType original = this.repository.findByName(eventType.getName());
    this.repository.update(eventType);
    try {
        this.cache.updated(eventType.getName());
    } catch (Exception e) {
        LOG.error("Failed to update cache for event type '" + eventType.getName() + "'", e);
        this.repository.update(original);
        throw new InternalNakadiException("Failed to update event type", e);
    }
}
Also used : InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) EventType(org.zalando.nakadi.domain.EventType) DuplicatedEventTypeNameException(org.zalando.nakadi.exceptions.DuplicatedEventTypeNameException) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException)

Example 18 with InternalNakadiException

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

the class EventTypeDbRepository method update.

@Override
@Transactional
public void update(final EventType eventType) throws InternalNakadiException {
    try {
        final String sql = "SELECT et_event_type_object -> 'schema' ->> 'version' " + "FROM zn_data.event_type WHERE et_name = ?";
        final String currentVersion = jdbcTemplate.queryForObject(sql, String.class, eventType.getName());
        if (!currentVersion.equals(eventType.getSchema().getVersion().toString())) {
            insertEventTypeSchema(eventType);
        }
        jdbcTemplate.update("UPDATE zn_data.event_type SET et_event_type_object = ?::jsonb WHERE et_name = ?", jsonMapper.writer().writeValueAsString(eventType), eventType.getName());
    } catch (JsonProcessingException e) {
        throw new InternalNakadiException("Serialization problem during persistence of event type \"" + eventType.getName() + "\"", e);
    }
}
Also used : InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with InternalNakadiException

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

the class EventTypeDbRepository method removeEventType.

@Override
@Transactional
public void removeEventType(final String name) throws NoSuchEventTypeException, InternalNakadiException {
    try {
        jdbcTemplate.update("DELETE FROM zn_data.event_type_schema WHERE ets_event_type_name = ?", name);
        final int deletedRows = jdbcTemplate.update("DELETE FROM zn_data.event_type WHERE et_name = ?", name);
        if (deletedRows == 0) {
            throw new NoSuchEventTypeException("EventType " + name + " doesn't exist");
        }
    } catch (DataAccessException e) {
        throw new InternalNakadiException("Error occurred when deleting EventType " + name, e);
    }
}
Also used : InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) DataAccessException(org.springframework.dao.DataAccessException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)19 EventType (org.zalando.nakadi.domain.EventType)11 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)11 ServiceUnavailableException (org.zalando.nakadi.exceptions.ServiceUnavailableException)7 Test (org.junit.Test)6 TopicRepository (org.zalando.nakadi.repository.TopicRepository)5 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)4 InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)4 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 CursorError (org.zalando.nakadi.domain.CursorError)3 PartitionStatistics (org.zalando.nakadi.domain.PartitionStatistics)3 Subscription (org.zalando.nakadi.domain.Subscription)3 Timeline (org.zalando.nakadi.domain.Timeline)3 DuplicatedEventTypeNameException (org.zalando.nakadi.exceptions.DuplicatedEventTypeNameException)3 ServiceTemporarilyUnavailableException (org.zalando.nakadi.exceptions.runtime.ServiceTemporarilyUnavailableException)3 TimelineService (org.zalando.nakadi.service.timeline.TimelineService)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ImmutableList (com.google.common.collect.ImmutableList)2