Search in sources :

Example 6 with FileTailerMetricsProcessor

use of co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor in project cdap-ingest by caskdata.

the class PipeManager method setupPipes.

/**
   * Pipes setup
   *
   * @throws IOException in case a client stream cannot be created
   */
private ServiceManager setupPipes() throws IOException {
    StreamClient client = null;
    StreamWriter writer = null;
    try {
        List<PipeConfiguration> pipeConfList = getPipeConfigs();
        for (PipeConfiguration pipeConf : pipeConfList) {
            FileTailerQueue queue = new FileTailerQueue(pipeConf.getQueueSize());
            client = pipeConf.getSinkConfiguration().getStreamClient();
            String streamName = pipeConf.getSinkConfiguration().getStreamName();
            writer = getStreamWriterForPipe(client, streamName);
            FileTailerStateProcessor stateProcessor = new FileTailerStateProcessorImpl(pipeConf.getDaemonDir(), pipeConf.getStateFile());
            FileTailerMetricsProcessor metricsProcessor = new FileTailerMetricsProcessor(pipeConf.getDaemonDir(), pipeConf.getStatisticsFile(), pipeConf.getStatisticsSleepInterval(), pipeConf.getPipeName(), pipeConf.getSourceConfiguration().getFileName());
            pipeList.add(new Pipe(new LogTailer(pipeConf, queue, stateProcessor, metricsProcessor, null), new FileTailerSink(queue, writer, SinkStrategy.LOADBALANCE, stateProcessor, metricsProcessor, null, pipeConf.getSinkConfiguration().getPackSize()), metricsProcessor));
            client = null;
            writer = null;
        }
        return new ServiceManager(pipeList);
    } catch (ConfigurationLoadingException e) {
        throw new ConfigurationLoadingException("Error during loading configuration from file: " + confFile.getAbsolutePath() + e.getMessage());
    } finally {
        if (client != null) {
            client.close();
        }
        if (writer != null) {
            writer.close();
        }
    }
}
Also used : StreamWriter(co.cask.cdap.client.StreamWriter) ConfigurationLoadingException(co.cask.cdap.filetailer.config.exception.ConfigurationLoadingException) FileTailerStateProcessor(co.cask.cdap.filetailer.state.FileTailerStateProcessor) FileTailerMetricsProcessor(co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor) FileTailerStateProcessorImpl(co.cask.cdap.filetailer.state.FileTailerStateProcessorImpl) PipeConfiguration(co.cask.cdap.filetailer.config.PipeConfiguration) FileTailerQueue(co.cask.cdap.filetailer.queue.FileTailerQueue) StreamClient(co.cask.cdap.client.StreamClient) LogTailer(co.cask.cdap.filetailer.tailer.LogTailer) FileTailerSink(co.cask.cdap.filetailer.sink.FileTailerSink) ServiceManager(com.google.common.util.concurrent.ServiceManager)

Example 7 with FileTailerMetricsProcessor

use of co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor in project cdap-ingest by caskdata.

the class FileTailerSinkTest method basicTestWithCustomPackSize.

@Test
public void basicTestWithCustomPackSize() throws Exception {
    FileTailerStateProcessor stateProcessor = Mockito.mock(FileTailerStateProcessor.class);
    FileTailerMetricsProcessor metricsProcessor = Mockito.mock(FileTailerMetricsProcessor.class);
    FileTailerQueue queue = new FileTailerQueue(DEFAULT_QUEUE_SIZE);
    StreamWriter writerMock = getDummyStreamWriter();
    FileTailerSink sink = new FileTailerSink(queue, writerMock, SinkStrategy.LOADBALANCE, stateProcessor, metricsProcessor, null, CUSTOM_PACK_SIZE);
    try {
        sink.startAsync();
        for (int i = 0; i < TEST_EVENTS_SIZE; i++) {
            queue.put(new FileTailerEvent(new FileTailerState("file", 0L, 42, 0L), "test", Charset.defaultCharset()));
        }
        Mockito.verify(writerMock, Mockito.timeout(10000).times(TEST_EVENTS_SIZE)).write("test", Charset.defaultCharset());
    } finally {
        sink.stopAsync();
    }
}
Also used : FileTailerState(co.cask.cdap.filetailer.state.FileTailerState) FileTailerQueue(co.cask.cdap.filetailer.queue.FileTailerQueue) FileTailerEvent(co.cask.cdap.filetailer.event.FileTailerEvent) StreamWriter(co.cask.cdap.client.StreamWriter) FileTailerStateProcessor(co.cask.cdap.filetailer.state.FileTailerStateProcessor) FileTailerMetricsProcessor(co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor) Test(org.junit.Test)

Example 8 with FileTailerMetricsProcessor

use of co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor in project cdap-ingest by caskdata.

the class FileTailerIT method mockMetricsProcessor.

private void mockMetricsProcessor(PipeManager manager) throws IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
    List<Pipe> pipeList = new ArrayList<Pipe>();
    StreamClient client = null;
    StreamWriter writer = null;
    try {
        Method method1 = manager.getClass().getDeclaredMethod("getPipeConfigs");
        method1.setAccessible(true);
        List<PipeConfiguration> pipeConfList = (List<PipeConfiguration>) method1.invoke(manager);
        for (PipeConfiguration pipeConf : pipeConfList) {
            FileTailerQueue queue = new FileTailerQueue(pipeConf.getQueueSize());
            client = pipeConf.getSinkConfiguration().getStreamClient();
            String streamName = pipeConf.getSinkConfiguration().getStreamName();
            Method method2 = manager.getClass().getDeclaredMethod("getStreamWriterForPipe", StreamClient.class, String.class);
            method2.setAccessible(true);
            writer = (StreamWriter) method2.invoke(manager, client, streamName);
            FileTailerStateProcessor stateProcessor = new FileTailerStateProcessorImpl(pipeConf.getDaemonDir(), pipeConf.getStateFile());
            FileTailerMetricsProcessor metricsProcessor = new FileTailerMetricsProcessor(pipeConf.getDaemonDir(), pipeConf.getStatisticsFile(), pipeConf.getStatisticsSleepInterval(), pipeConf.getPipeName(), pipeConf.getSourceConfiguration().getFileName()) {

                @Override
                public void onReadEventMetric(int eventSize) {
                    super.onReadEventMetric(eventSize);
                    read.incrementAndGet();
                }

                @Override
                public void onIngestEventMetric(int latency) {
                    super.onIngestEventMetric(latency);
                    ingest.incrementAndGet();
                }
            };
            pipeList.add(new Pipe(new LogTailer(pipeConf, queue, stateProcessor, metricsProcessor, null), new FileTailerSink(queue, writer, SinkStrategy.LOADBALANCE, stateProcessor, metricsProcessor, null, pipeConf.getSinkConfiguration().getPackSize()), metricsProcessor));
            client = null;
            writer = null;
        }
        Field field = manager.getClass().getDeclaredField("serviceManager");
        field.setAccessible(true);
        Field modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(manager, new ServiceManager(pipeList));
    } finally {
        if (client != null) {
            client.close();
        }
        if (writer != null) {
            writer.close();
        }
    }
}
Also used : StreamWriter(co.cask.cdap.client.StreamWriter) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) FileTailerStateProcessor(co.cask.cdap.filetailer.state.FileTailerStateProcessor) FileTailerMetricsProcessor(co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor) Field(java.lang.reflect.Field) FileTailerStateProcessorImpl(co.cask.cdap.filetailer.state.FileTailerStateProcessorImpl) PipeConfiguration(co.cask.cdap.filetailer.config.PipeConfiguration) FileTailerQueue(co.cask.cdap.filetailer.queue.FileTailerQueue) StreamClient(co.cask.cdap.client.StreamClient) LogTailer(co.cask.cdap.filetailer.tailer.LogTailer) FileTailerSink(co.cask.cdap.filetailer.sink.FileTailerSink) ServiceManager(com.google.common.util.concurrent.ServiceManager) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with FileTailerMetricsProcessor

use of co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor in project cdap-ingest by caskdata.

the class FileDropZoneIT method fileDropZoneBasicIT.

@Test
public void fileDropZoneBasicIT() throws Exception {
    final File configurationFile = getConfigFile();
    PollingServiceManager pollingServiceManager = new PollingServiceManager(configurationFile);
    pollingServiceManager.initManager();
    Field monitor = pollingServiceManager.getClass().getDeclaredField("monitor");
    monitor.setAccessible(true);
    PollingService myMonitor = (PollingService) monitor.get(pollingServiceManager);
    ObserverConfiguration observerConf = loadConfig(configurationFile);
    PollingListener myPollingListener = new PollingListenerImpl(myMonitor, observerConf);
    FileTailerMetricsProcessor metricsProcessor = getMetricsProcessor(observerConf);
    Field metricsProcessorField = myPollingListener.getClass().getDeclaredField("metricsProcessor");
    metricsProcessorField.setAccessible(true);
    metricsProcessorField.set(myPollingListener, metricsProcessor);
    myMonitor.registerDirMonitor(observerConf.getPipeConf().getSourceConfiguration().getWorkDir(), myPollingListener);
    createFile(observerConf.getPipeConf().getSourceConfiguration().getWorkDir().getAbsolutePath());
    long start = System.currentTimeMillis();
    pollingServiceManager.startMonitor();
    Thread.sleep(SLEEP_TIME);
    pollingServiceManager.stopMonitor();
    checkDeliveredEvents(start, System.currentTimeMillis());
    Assert.assertEquals(read.get(), ingest.get());
}
Also used : PollingListenerImpl(co.cask.cdap.file.dropzone.polling.PollingListenerImpl) Field(java.lang.reflect.Field) ObserverConfiguration(co.cask.cdap.file.dropzone.config.ObserverConfiguration) PollingListener(co.cask.cdap.file.dropzone.polling.PollingListener) PollingService(co.cask.cdap.file.dropzone.polling.PollingService) File(java.io.File) PollingServiceManager(co.cask.cdap.file.dropzone.polling.PollingServiceManager) FileTailerMetricsProcessor(co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor) Test(org.junit.Test)

Aggregations

FileTailerMetricsProcessor (co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor)9 FileTailerStateProcessor (co.cask.cdap.filetailer.state.FileTailerStateProcessor)8 FileTailerQueue (co.cask.cdap.filetailer.queue.FileTailerQueue)7 Test (org.junit.Test)6 StreamWriter (co.cask.cdap.client.StreamWriter)5 FileTailerStateProcessorImpl (co.cask.cdap.filetailer.state.FileTailerStateProcessorImpl)5 PipeConfiguration (co.cask.cdap.filetailer.config.PipeConfiguration)4 FileTailerEvent (co.cask.cdap.filetailer.event.FileTailerEvent)4 FileTailerState (co.cask.cdap.filetailer.state.FileTailerState)3 Field (java.lang.reflect.Field)3 ArrayList (java.util.ArrayList)3 Logger (ch.qos.logback.classic.Logger)2 StreamClient (co.cask.cdap.client.StreamClient)2 FileTailerSink (co.cask.cdap.filetailer.sink.FileTailerSink)2 LogTailer (co.cask.cdap.filetailer.tailer.LogTailer)2 ServiceManager (com.google.common.util.concurrent.ServiceManager)2 ObserverConfiguration (co.cask.cdap.file.dropzone.config.ObserverConfiguration)1 PollingListener (co.cask.cdap.file.dropzone.polling.PollingListener)1 PollingListenerImpl (co.cask.cdap.file.dropzone.polling.PollingListenerImpl)1 PollingService (co.cask.cdap.file.dropzone.polling.PollingService)1