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