Search in sources :

Example 11 with PipeConfiguration

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

the class TailerLogUtils method loadConfig.

public static PipeConfiguration loadConfig() throws ConfigurationLoadingException {
    ConfigurationLoader loader = new ConfigurationLoaderImpl();
    Class<? extends Class> path1 = TailerLogUtils.class.getClass();
    String path = TailerLogUtils.class.getClassLoader().getResource("test4.properties").getFile();
    Configuration configuration = loader.load(new File(path));
    List<PipeConfiguration> flowConfig = configuration.getPipeConfigurations();
    return flowConfig.get(0);
}
Also used : PipeConfiguration(co.cask.cdap.filetailer.config.PipeConfiguration) Configuration(co.cask.cdap.filetailer.config.Configuration) PipeConfiguration(co.cask.cdap.filetailer.config.PipeConfiguration) ConfigurationLoaderImpl(co.cask.cdap.filetailer.config.ConfigurationLoaderImpl) File(java.io.File) ConfigurationLoader(co.cask.cdap.filetailer.config.ConfigurationLoader)

Example 12 with PipeConfiguration

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

the class BaseTailerTest method fileTimeRotationTest.

@Test
public void fileTimeRotationTest() throws ConfigurationLoadingException, InterruptedException {
    FileTailerQueue queue = new FileTailerQueue(QUEUE_SIZE);
    PipeConfiguration flowConfig = TailerLogUtils.loadConfig();
    LogTailer tailer = TailerLogUtils.createTailer(queue, flowConfig);
    String filePath = flowConfig.getSourceConfiguration().getWorkDir().getAbsolutePath() + "/" + flowConfig.getSourceConfiguration().getFileName();
    Logger logger = TailerLogUtils.getTimeLogger(filePath);
    RandomStringUtils randomUtils = new RandomStringUtils();
    List<String> logList = new ArrayList<String>(ENTRY_NUMBER);
    tailer.startAsync();
    for (int i = 0; i < ENTRY_NUMBER; i++) {
        String currLine = randomUtils.randomAlphanumeric(LINE_SIZE);
        logger.debug(currLine);
        logList.add(currLine);
        Thread.currentThread().sleep(WRITING_INTERVAL);
    }
    Thread.currentThread().sleep(SLEEP_TIME);
    tailer.stopAsync();
    for (String str : logList) {
        Assert.assertEquals(true, queue.take().getEventData().contains(str));
    }
}
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 13 with PipeConfiguration

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

the class FileTailerIT method deleteTestDir.

private void deleteTestDir() throws Exception {
    File configFile = getConfigFile();
    PipeConfiguration pipeConfig = loadConfig(configFile);
    File workDir = pipeConfig.getSourceConfiguration().getWorkDir();
    FileUtils.deleteDirectory(workDir);
    File daemonDir = pipeConfig.getDaemonDir();
    FileUtils.deleteDirectory(daemonDir);
}
Also used : PipeConfiguration(co.cask.cdap.filetailer.config.PipeConfiguration) File(java.io.File)

Example 14 with PipeConfiguration

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

the class FileTailerIT method fileTailerNoLogsBeforeStartIT.

@Test
public void fileTailerNoLogsBeforeStartIT() throws Exception {
    File configFile = getConfigFile();
    PipeConfiguration pipeConfig = loadConfig(configFile);
    String logFilePath = pipeConfig.getSourceConfiguration().getWorkDir().getAbsolutePath() + "/" + pipeConfig.getSourceConfiguration().getFileName();
    Logger logger = getTimeLogger(logFilePath);
    PipeManager manager = new PipeManager(configFile);
    mockMetricsProcessor(manager);
    long startTime = System.currentTimeMillis();
    manager.startAsync();
    Thread.sleep(SLEEP_TIME);
    writeLogs(logger, ENTRY_NUMBER);
    Thread.sleep(SLEEP_TIME);
    logger.getAppender("File Tailer IT").stop();
    manager.stopAsync();
    Thread.sleep(SLEEP_TIME);
    Assert.assertEquals(read.get(), ingest.get());
    checkDeliveredEvents(ENTRY_NUMBER, startTime);
}
Also used : PipeConfiguration(co.cask.cdap.filetailer.config.PipeConfiguration) Logger(ch.qos.logback.classic.Logger) File(java.io.File) Test(org.junit.Test)

Example 15 with PipeConfiguration

use of co.cask.cdap.filetailer.config.PipeConfiguration 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)

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