use of org.zalando.nakadi.exceptions.EventValidationException in project nakadi by zalando.
the class EventPublisher method validateSchema.
private void validateSchema(final JSONObject event, final EventType eventType) throws EventValidationException, InternalNakadiException, NoSuchEventTypeException {
final EventTypeValidator validator = eventTypeCache.getValidator(eventType.getName());
final Optional<ValidationError> validationError = validator.validate(event);
if (validationError.isPresent()) {
throw new EventValidationException(validationError.get());
}
}
use of org.zalando.nakadi.exceptions.EventValidationException in project nakadi by zalando.
the class EventPublisher method validate.
private void validate(final List<BatchItem> batch, final EventType eventType) throws EventValidationException, InternalNakadiException, NoSuchEventTypeException {
for (final BatchItem item : batch) {
item.setStep(EventPublishingStep.VALIDATING);
try {
validateSchema(item.getEvent(), eventType);
validateEventSize(item);
} catch (final EventValidationException e) {
item.updateStatusAndDetail(EventPublishingStatus.FAILED, e.getMessage());
throw e;
}
}
}
use of org.zalando.nakadi.exceptions.EventValidationException in project nakadi by zalando.
the class EventPublisher method publishInternal.
EventPublishResult publishInternal(final String events, final String eventTypeName, final boolean useAuthz) throws NoSuchEventTypeException, InternalNakadiException, EventTypeTimeoutException, AccessDeniedException, ServiceTemporarilyUnavailableException {
Closeable publishingCloser = null;
final List<BatchItem> batch = BatchFactory.from(events);
try {
publishingCloser = timelineSync.workWithEventType(eventTypeName, nakadiSettings.getTimelineWaitTimeoutMs());
final EventType eventType = eventTypeCache.getEventType(eventTypeName);
if (useAuthz) {
authValidator.authorizeEventTypeWrite(eventType);
}
validate(batch, eventType);
partition(batch, eventType);
enrich(batch, eventType);
submit(batch, eventType);
return ok(batch);
} catch (final EventValidationException e) {
LOG.debug("Event validation error: {}", e.getMessage());
return aborted(EventPublishingStep.VALIDATING, batch);
} catch (final PartitioningException e) {
LOG.debug("Event partition error: {}", e.getMessage());
return aborted(EventPublishingStep.PARTITIONING, batch);
} catch (final EnrichmentException e) {
LOG.debug("Event enrichment error: {}", e.getMessage());
return aborted(EventPublishingStep.ENRICHING, batch);
} catch (final EventPublishingException e) {
LOG.error("error publishing event", e);
return failed(batch);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
LOG.error("Failed to wait for timeline switch", e);
throw new EventTypeTimeoutException("Event type is currently in maintenance, please repeat request");
} catch (final TimeoutException e) {
LOG.error("Failed to wait for timeline switch", e);
throw new EventTypeTimeoutException("Event type is currently in maintenance, please repeat request");
} finally {
try {
if (publishingCloser != null) {
publishingCloser.close();
}
} catch (final IOException e) {
LOG.error("Exception occurred when releasing usage of event-type", e);
}
}
}
Aggregations