Search in sources :

Example 1 with PipeConfiguration

use of co.cask.cdap.filetailer.config.PipeConfiguration in project cdap-ingest by caskdata.

the class ObserverConfigurationImplTest method getDaemonDirTest.

@Test
public void getDaemonDirTest() throws NoSuchFieldException, IllegalAccessException {
    Properties properties = Mockito.mock(Properties.class);
    PipeConfiguration pipeConfiguration = Mockito.mock(PipeConfiguration.class);
    Mockito.when(pipeConfiguration.getDaemonDir()).thenReturn(new File(OLD_DAEMON_DIR));
    ObserverConfiguration observerConfiguration = new ObserverConfigurationImpl("obs2", properties, "key");
    Field field = observerConfiguration.getClass().getDeclaredField("pipeConfiguration");
    field.setAccessible(true);
    Field modifiersField = Field.class.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
    field.set(observerConfiguration, pipeConfiguration);
    Assert.assertEquals(new File(NEW_DAEMON_DIR), observerConfiguration.getDaemonDir());
}
Also used : Field(java.lang.reflect.Field) PipeConfiguration(co.cask.cdap.filetailer.config.PipeConfiguration) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 2 with PipeConfiguration

use of co.cask.cdap.filetailer.config.PipeConfiguration in project cdap-ingest by caskdata.

the class SizeBasedRotationTest method fileRotationTest.

@Test
public void fileRotationTest() throws ConfigurationLoadingException, InterruptedException {
    FileTailerQueue queue = new FileTailerQueue(QUEUE_SIZE);
    PipeConfiguration flowConfig = TailerLogUtils.loadConfig();
    FileTailerStateProcessor stateProcessor = new FileTailerStateProcessorImpl(flowConfig.getDaemonDir(), flowConfig.getStateFile());
    FileTailerMetricsProcessor metricsProcessor = new FileTailerMetricsProcessor(flowConfig.getDaemonDir(), flowConfig.getStatisticsFile(), flowConfig.getStatisticsSleepInterval(), flowConfig.getPipeName(), flowConfig.getSourceConfiguration().getFileName());
    LogTailer tailer = new LogTailer(TailerLogUtils.loadConfig(), queue, stateProcessor, metricsProcessor, null);
    String filePath = flowConfig.getSourceConfiguration().getWorkDir().getAbsolutePath() + "/" + flowConfig.getSourceConfiguration().getFileName();
    List<String> logList = new ArrayList<String>(ENTRY_WRITE_NUMBER);
    RandomStringUtils randomUtils = new RandomStringUtils();
    Logger logger = TailerLogUtils.getSizeLogger(filePath, LOG_FILE_SIZE);
    tailer.startAsync();
    for (int i = 0; i < ENTRY_WRITE_NUMBER; i++) {
        String currLine = randomUtils.randomAlphanumeric(LINE_SIZE);
        logger.debug(currLine);
        logList.add(currLine);
        if (i % 50 == 0) {
            Thread.currentThread().sleep(300);
        }
    }
    Thread.currentThread().sleep(SLEEP_TIME);
    for (int i = 0; i < logList.size(); i++) {
        Assert.assertEquals(true, queue.take().getEventData().contains(logList.get(i)));
    }
    tailer.stopAsync();
}
Also used : FileTailerStateProcessorImpl(co.cask.cdap.filetailer.state.FileTailerStateProcessorImpl) PipeConfiguration(co.cask.cdap.filetailer.config.PipeConfiguration) FileTailerQueue(co.cask.cdap.filetailer.queue.FileTailerQueue) ArrayList(java.util.ArrayList) FileTailerStateProcessor(co.cask.cdap.filetailer.state.FileTailerStateProcessor) Logger(ch.qos.logback.classic.Logger) FileTailerMetricsProcessor(co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) Test(org.junit.Test)

Example 3 with PipeConfiguration

use of co.cask.cdap.filetailer.config.PipeConfiguration in project cdap-ingest by caskdata.

the class BaseTailerTest method baseReadingLogDirTest.

@Test
public void baseReadingLogDirTest() throws ConfigurationLoadingException, InterruptedException {
    FileTailerQueue queue = new FileTailerQueue(1);
    PipeConfiguration flowConfig = TailerLogUtils.loadConfig();
    LogTailer tailer = TailerLogUtils.createTailer(queue, flowConfig);
    String filePath = flowConfig.getSourceConfiguration().getWorkDir().getAbsolutePath() + "/" + flowConfig.getSourceConfiguration().getFileName();
    Logger logger = TailerLogUtils.getSizeLogger(filePath, LOG_FILE_SIZE);
    RandomStringUtils randomUtils = new RandomStringUtils();
    List<String> logList = new ArrayList<String>(ENTRY_NUMBER);
    for (int i = 0; i < ENTRY_NUMBER; i++) {
        String currLine = randomUtils.randomAlphanumeric(LINE_SIZE);
        logger.debug(currLine);
        logList.add(currLine);
    }
    tailer.startAsync();
    Thread.currentThread().sleep(SLEEP_TIME);
    for (String str : logList) {
        Assert.assertEquals(true, queue.take().getEventData().contains(str));
    }
    tailer.stopAsync();
    Thread.currentThread().sleep(1000);
}
Also used : PipeConfiguration(co.cask.cdap.filetailer.config.PipeConfiguration) FileTailerQueue(co.cask.cdap.filetailer.queue.FileTailerQueue) ArrayList(java.util.ArrayList) Logger(ch.qos.logback.classic.Logger) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) Test(org.junit.Test)

Example 4 with PipeConfiguration

use of co.cask.cdap.filetailer.config.PipeConfiguration in project cdap-ingest by caskdata.

the class RunFromSaveStateTest method runFromSaveStateTest.

@Test
public void runFromSaveStateTest() throws Exception {
    FileTailerQueue queue = new FileTailerQueue(QUEUE_SIZE);
    PipeConfiguration flowConfig = TailerLogUtils.loadConfig();
    FileTailerStateProcessor stateProcessor = new FileTailerStateProcessorImpl(flowConfig.getDaemonDir(), flowConfig.getStateFile());
    FileTailerMetricsProcessor metricsProcessor = new FileTailerMetricsProcessor(flowConfig.getDaemonDir(), flowConfig.getStatisticsFile(), flowConfig.getStatisticsSleepInterval(), flowConfig.getPipeName(), flowConfig.getSourceConfiguration().getFileName());
    String filePath = flowConfig.getSourceConfiguration().getWorkDir().getAbsolutePath() + "/" + flowConfig.getSourceConfiguration().getFileName();
    List<String> logList = new ArrayList<String>(ENTRY_WRITE_NUMBER);
    List<String> readLogList = new ArrayList<String>(ENTRY_WRITE_NUMBER);
    Logger logger = TailerLogUtils.getSizeLogger(filePath, LOG_FILE_SIZE);
    Field queueField = queue.getClass().getDeclaredField("queue");
    queueField.setAccessible(true);
    LinkedBlockingQueue<FileTailerEvent> intQueue = (LinkedBlockingQueue<FileTailerEvent>) queueField.get(queue);
    write_log(ENTRY_WRITE_NUMBER, logger, logList);
    LogTailer tailer = new LogTailer(TailerLogUtils.loadConfig(), queue, stateProcessor, metricsProcessor, null);
    tailer.startAsync();
    Thread.sleep(SLEEP_TIME);
    tailer.stopAsync();
    saveState(intQueue, queue, readLogList, stateProcessor);
    write_log(ENTRY_WRITE_NUMBER, logger, logList);
    tailer = new LogTailer(TailerLogUtils.loadConfig(), queue, stateProcessor, metricsProcessor, null);
    tailer.startAsync();
    Thread.sleep(SLEEP_TIME);
    tailer.stopAsync();
    saveState(intQueue, queue, readLogList, stateProcessor);
    write_log(ENTRY_WRITE_NUMBER, logger, logList);
    tailer = new LogTailer(TailerLogUtils.loadConfig(), queue, stateProcessor, metricsProcessor, null);
    tailer.startAsync();
    Thread.sleep(SLEEP_TIME);
    tailer.stopAsync();
    saveState(intQueue, queue, readLogList, stateProcessor);
    for (int i = 0; i < logList.size(); i++) {
        Assert.assertEquals(true, readLogList.get(i).contains(logList.get(i)));
    }
}
Also used : FileTailerEvent(co.cask.cdap.filetailer.event.FileTailerEvent) ArrayList(java.util.ArrayList) FileTailerStateProcessor(co.cask.cdap.filetailer.state.FileTailerStateProcessor) Logger(ch.qos.logback.classic.Logger) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) 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) Test(org.junit.Test)

Example 5 with PipeConfiguration

use of co.cask.cdap.filetailer.config.PipeConfiguration in project cdap-ingest by caskdata.

the class PipeManager method getPipeConfigs.

/**
   * Get pipes configuration
   *
   * @return the pipes configuration read from the configuration file
   * @throws ConfigurationLoadingException in case can not load configuration
   */
private List<PipeConfiguration> getPipeConfigs() throws ConfigurationLoadingException {
    ConfigurationLoader loader = new ConfigurationLoaderImpl();
    Configuration configuration = loader.load(confFile);
    return configuration.getPipeConfigurations();
}
Also used : Configuration(co.cask.cdap.filetailer.config.Configuration) PipeConfiguration(co.cask.cdap.filetailer.config.PipeConfiguration) ConfigurationLoaderImpl(co.cask.cdap.filetailer.config.ConfigurationLoaderImpl) ConfigurationLoader(co.cask.cdap.filetailer.config.ConfigurationLoader)

Aggregations

PipeConfiguration (co.cask.cdap.filetailer.config.PipeConfiguration)17 File (java.io.File)8 FileTailerQueue (co.cask.cdap.filetailer.queue.FileTailerQueue)7 Test (org.junit.Test)7 Logger (ch.qos.logback.classic.Logger)6 FileTailerStateProcessor (co.cask.cdap.filetailer.state.FileTailerStateProcessor)5 FileTailerStateProcessorImpl (co.cask.cdap.filetailer.state.FileTailerStateProcessorImpl)5 ArrayList (java.util.ArrayList)5 FileTailerMetricsProcessor (co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor)4 StreamWriter (co.cask.cdap.client.StreamWriter)3 Configuration (co.cask.cdap.filetailer.config.Configuration)3 ConfigurationLoader (co.cask.cdap.filetailer.config.ConfigurationLoader)3 ConfigurationLoaderImpl (co.cask.cdap.filetailer.config.ConfigurationLoaderImpl)3 FileTailerSink (co.cask.cdap.filetailer.sink.FileTailerSink)3 LogTailer (co.cask.cdap.filetailer.tailer.LogTailer)3 Field (java.lang.reflect.Field)3 RandomStringUtils (org.apache.commons.lang.RandomStringUtils)3 StreamClient (co.cask.cdap.client.StreamClient)2 ServiceManager (com.google.common.util.concurrent.ServiceManager)2 Pipe (co.cask.cdap.filetailer.Pipe)1