Search in sources :

Example 1 with EnrichmentException

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

the class MetadataEnrichmentStrategy method enrich.

@Override
public void enrich(final BatchItem batchItem, final EventType eventType) throws EnrichmentException {
    try {
        final JSONObject metadata = batchItem.getEvent().getJSONObject(BatchItem.Injection.METADATA.name);
        setReceivedAt(metadata);
        setEventTypeName(metadata, eventType);
        setFlowId(metadata);
        setPartition(metadata, batchItem);
        setVersion(metadata, eventType);
        batchItem.inject(BatchItem.Injection.METADATA, metadata.toString());
    } catch (final JSONException e) {
        throw new EnrichmentException("enrichment error", e);
    }
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) EnrichmentException(org.zalando.nakadi.exceptions.EnrichmentException)

Example 2 with EnrichmentException

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

the class EventPublisher method enrich.

private void enrich(final List<BatchItem> batch, final EventType eventType) throws EnrichmentException {
    for (final BatchItem batchItem : batch) {
        try {
            batchItem.setStep(EventPublishingStep.ENRICHING);
            enrichment.enrich(batchItem, eventType);
        } catch (EnrichmentException e) {
            batchItem.updateStatusAndDetail(EventPublishingStatus.FAILED, e.getMessage());
            throw e;
        }
    }
}
Also used : BatchItem(org.zalando.nakadi.domain.BatchItem) EnrichmentException(org.zalando.nakadi.exceptions.EnrichmentException)

Example 3 with EnrichmentException

use of org.zalando.nakadi.exceptions.EnrichmentException 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);
        }
    }
}
Also used : EventValidationException(org.zalando.nakadi.exceptions.EventValidationException) PartitioningException(org.zalando.nakadi.exceptions.PartitioningException) EventType(org.zalando.nakadi.domain.EventType) Closeable(java.io.Closeable) BatchItem(org.zalando.nakadi.domain.BatchItem) EnrichmentException(org.zalando.nakadi.exceptions.EnrichmentException) IOException(java.io.IOException) EventTypeTimeoutException(org.zalando.nakadi.exceptions.EventTypeTimeoutException) EventPublishingException(org.zalando.nakadi.exceptions.EventPublishingException) TimeoutException(java.util.concurrent.TimeoutException) EventTypeTimeoutException(org.zalando.nakadi.exceptions.EventTypeTimeoutException)

Aggregations

EnrichmentException (org.zalando.nakadi.exceptions.EnrichmentException)3 BatchItem (org.zalando.nakadi.domain.BatchItem)2 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 EventType (org.zalando.nakadi.domain.EventType)1 EventPublishingException (org.zalando.nakadi.exceptions.EventPublishingException)1 EventTypeTimeoutException (org.zalando.nakadi.exceptions.EventTypeTimeoutException)1 EventValidationException (org.zalando.nakadi.exceptions.EventValidationException)1 PartitioningException (org.zalando.nakadi.exceptions.PartitioningException)1