Search in sources :

Example 1 with IngestService

use of com.bakdata.quick.ingest.service.IngestService in project quick by bakdata.

the class IngestController method convertIngestData.

/**
 * Processes raw input data for ingesting.
 *
 * <p>
 * Two steps are necessary to ingest the raw payload:
 * <ul>
 *    <li> parse it
 *    <li> check for existing keys if the topic is immutable
 * </ul>
 *
 * <p>
 * This method handles both steps and then forwards all non-existing {@link KeyValuePair} to the
 * {@link IngestService}.
 * Further, it handles merging the error messages. The method returns an error for existing keys as well as possible
 * errors in the ingest service.
 *
 * @param topic   the topic to ingest to
 * @param payload the raw payload
 * @param data    the topic information for the topic
 * @param <K>     the key type of the topic
 * @param <V>     the value type of the topic
 * @return merged completable possibly containing errors from existing keys or the ingest service
 */
private <K, V> Completable convertIngestData(final String topic, final String payload, final QuickTopicData<K, V> data) {
    final Single<List<KeyValuePair<K, V>>> list = Single.fromCallable(() -> this.parser.parseInputData(payload, data));
    return list.flatMap(pairs -> this.filter.prepareIngest(data, pairs)).flatMapCompletable(pairs -> {
        final Completable existingError = createErrorsForExistingKeys(topic, pairs);
        final Completable ingest = this.ingestService.sendData(topic, pairs.getDataToIngest());
        return Completable.mergeArrayDelayError(existingError, ingest);
    });
}
Also used : Controller(io.micronaut.http.annotation.Controller) Secured(io.micronaut.security.annotation.Secured) TopicTypeService(com.bakdata.quick.common.type.TopicTypeService) QuickTopicData(com.bakdata.quick.common.type.QuickTopicData) Completable(io.reactivex.Completable) IngestFilter(com.bakdata.quick.ingest.service.IngestFilter) Delete(io.micronaut.http.annotation.Delete) SecurityRule(io.micronaut.security.rules.SecurityRule) BadArgumentException(com.bakdata.quick.common.exception.BadArgumentException) Single(io.reactivex.Single) Collectors(java.util.stream.Collectors) Post(io.micronaut.http.annotation.Post) Inject(javax.inject.Inject) IngestParser(com.bakdata.quick.ingest.service.IngestParser) IngestService(com.bakdata.quick.ingest.service.IngestService) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Body(io.micronaut.http.annotation.Body) KeyValuePair(com.bakdata.quick.common.api.model.KeyValuePair) IngestLists(com.bakdata.quick.ingest.service.IngestFilter.IngestLists) Completable(io.reactivex.Completable) List(java.util.List)

Aggregations

KeyValuePair (com.bakdata.quick.common.api.model.KeyValuePair)1 BadArgumentException (com.bakdata.quick.common.exception.BadArgumentException)1 QuickTopicData (com.bakdata.quick.common.type.QuickTopicData)1 TopicTypeService (com.bakdata.quick.common.type.TopicTypeService)1 IngestFilter (com.bakdata.quick.ingest.service.IngestFilter)1 IngestLists (com.bakdata.quick.ingest.service.IngestFilter.IngestLists)1 IngestParser (com.bakdata.quick.ingest.service.IngestParser)1 IngestService (com.bakdata.quick.ingest.service.IngestService)1 Body (io.micronaut.http.annotation.Body)1 Controller (io.micronaut.http.annotation.Controller)1 Delete (io.micronaut.http.annotation.Delete)1 Post (io.micronaut.http.annotation.Post)1 Secured (io.micronaut.security.annotation.Secured)1 SecurityRule (io.micronaut.security.rules.SecurityRule)1 Completable (io.reactivex.Completable)1 Single (io.reactivex.Single)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Slf4j (lombok.extern.slf4j.Slf4j)1