Search in sources :

Example 1 with EventInformationBuilder

use of com.hortonworks.streamline.streams.common.event.EventInformationBuilder in project streamline by hortonworks.

the class TestRunEventLogger method writeEvent.

// Writing event to file should be mutually exclusive.
// We don't need to worry about performance since it's just for testing topology locally.
public synchronized void writeEvent(long timestamp, String componentName, String streamId, Set<String> targetComponents, StreamlineEvent event) {
    try (FileWriter fw = new FileWriter(eventLogFilePath, true)) {
        LOG.debug("writing event to file " + eventLogFilePath);
        EventInformationBuilder informationBuilder = new EventInformationBuilder();
        EventInformation eventInfo = informationBuilder.build(timestamp, componentName, streamId, targetComponents, event);
        fw.write(objectMapper.writeValueAsString(eventInfo) + "\n");
        fw.flush();
    } catch (FileNotFoundException e) {
        LOG.error("Can't open file for write: " + eventLogFilePath);
        throw new RuntimeException(e);
    } catch (IOException e) {
        LOG.error("Fail to write event to output file " + eventLogFilePath + " : exception occurred.", e);
        throw new RuntimeException(e);
    }
}
Also used : EventInformationBuilder(com.hortonworks.streamline.streams.common.event.EventInformationBuilder) EventInformation(com.hortonworks.streamline.streams.common.event.EventInformation) FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Aggregations

EventInformation (com.hortonworks.streamline.streams.common.event.EventInformation)1 EventInformationBuilder (com.hortonworks.streamline.streams.common.event.EventInformationBuilder)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1