Search in sources :

Example 1 with ProvenanceException

use of com.thinkbiganalytics.provenance.api.ProvenanceException in project kylo by Teradata.

the class KyloKafkaProvenanceEventService method sendEvents.

@Override
public void sendEvents(List<ProvenanceEventRecordDTO> events) throws ProvenanceException {
    try {
        List<Future<RecordMetadata>> resultFutures = new ArrayList<>();
        ProvenanceEventRecordDTOHolder eventRecordDTOHolder = new ProvenanceEventRecordDTOHolder();
        List<ProvenanceEventRecordDTO> batchEvents = new ArrayList<>();
        for (ProvenanceEventRecordDTO event : events) {
            if (!event.isStream()) {
                batchEvents.add(event);
            }
        }
        eventRecordDTOHolder.setEvents(batchEvents);
        byte[] data = SerializationUtils.serialize(eventRecordDTOHolder);
        ProducerRecord<byte[], byte[]> eventsMessage = new ProducerRecord<>(KYLO_BATCH_EVENT_TOPIC, data);
        log.info("Sending {} events to Kafka ", eventRecordDTOHolder);
        resultFutures.add(kafkaProducer.send(eventsMessage));
        AggregatedFeedProcessorStatisticsHolder stats = GroupedStatsUtil.gatherStats(events);
        data = SerializationUtils.serialize(stats);
        ProducerRecord<byte[], byte[]> statsMessage = new ProducerRecord<>(KYLO_EVENT_STATS_TOPIC, data);
        resultFutures.add(kafkaProducer.send(statsMessage));
        processAcks(resultFutures);
    } catch (Exception e) {
        throw new ProvenanceException(e);
    }
}
Also used : ProvenanceEventRecordDTO(com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTO) ProvenanceException(com.thinkbiganalytics.provenance.api.ProvenanceException) ProvenanceEventRecordDTOHolder(com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTOHolder) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) ArrayList(java.util.ArrayList) AggregatedFeedProcessorStatisticsHolder(com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatisticsHolder) Future(java.util.concurrent.Future) TimeoutException(java.util.concurrent.TimeoutException) ProvenanceException(com.thinkbiganalytics.provenance.api.ProvenanceException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with ProvenanceException

use of com.thinkbiganalytics.provenance.api.ProvenanceException in project kylo by Teradata.

the class TestProvenanceRest method testProvenanceRest.

// @Test
public void testProvenanceRest() {
    ProvenanceEventService restProvenanceEventService = new KyloRestProvenanceEventService();
    Map<String, String> params = new HashMap<>();
    params.put(KyloRestProvenanceEventService.USERNAME_CONFIG, "dladmin");
    params.put(KyloRestProvenanceEventService.PASSWORD_CONFIG, "thinkbig");
    params.put(KyloRestProvenanceEventService.HOST_CONFIG, "localhost");
    params.put(KyloRestProvenanceEventService.PORT_CONFIG, "8400");
    restProvenanceEventService.configure(params);
    String feedName = "provenance.provenance_test";
    String flowfileId = UUID.randomUUID().toString();
    DateTime startTime = DateTime.now().minusMinutes(1);
    Long start = startTime.getMillis();
    ProvenanceEventRecordDTO event1 = new ProvenanceEventDtoBuilder(feedName, flowfileId, "First Step").startingEvent(true).startTime(start).build();
    ProvenanceEventRecordDTO event2 = new ProvenanceEventDtoBuilder(feedName, flowfileId, "Second Step").startTime(startTime.plusSeconds(30).getMillis()).build();
    ProvenanceEventRecordDTO event3 = new ProvenanceEventDtoBuilder(feedName, flowfileId, "Final Step").endingEvent(true).build();
    List<ProvenanceEventRecordDTO> events = new ArrayList<>();
    events.add(event1);
    events.add(event2);
    events.add(event3);
    try {
        restProvenanceEventService.sendEvents(events);
    } catch (ProvenanceException e) {
        e.printStackTrace();
    }
}
Also used : ProvenanceEventService(com.thinkbiganalytics.provenance.api.ProvenanceEventService) ProvenanceEventDtoBuilder(com.thinkbiganalytics.nifi.provenance.model.util.ProvenanceEventDtoBuilder) ProvenanceEventRecordDTO(com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTO) ProvenanceException(com.thinkbiganalytics.provenance.api.ProvenanceException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime)

Aggregations

ProvenanceEventRecordDTO (com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTO)2 ProvenanceException (com.thinkbiganalytics.provenance.api.ProvenanceException)2 ArrayList (java.util.ArrayList)2 ProvenanceEventRecordDTOHolder (com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTOHolder)1 AggregatedFeedProcessorStatisticsHolder (com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatisticsHolder)1 ProvenanceEventDtoBuilder (com.thinkbiganalytics.nifi.provenance.model.util.ProvenanceEventDtoBuilder)1 ProvenanceEventService (com.thinkbiganalytics.provenance.api.ProvenanceEventService)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 TimeoutException (java.util.concurrent.TimeoutException)1 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)1 DateTime (org.joda.time.DateTime)1