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);
}
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);
}
}
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);
}
}
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);
}
}
Aggregations