Search in sources :

Example 1 with PollingServiceManager

use of co.cask.cdap.file.dropzone.polling.PollingServiceManager in project cdap-ingest by caskdata.

the class FileDropZoneMain method main.

public static void main(String[] args) throws Exception {
    File configurationFile;
    if (args.length == 0) {
        LOG.info("Application started using default file: \"file-drop-zone.properties\"");
        configurationFile = new File(FileDropZoneMain.class.getClassLoader().getResource("file-drop-zone.properties").getPath());
    } else {
        LOG.info("Application started using file: {}", args[0]);
        configurationFile = new File(args[0]);
    }
    PollingServiceManager pollingServiceManager = new PollingServiceManager(configurationFile);
    try {
        pollingServiceManager.initManager();
        pollingServiceManager.initObservers();
    } catch (IOException e) {
        LOG.error("Error during manager setup: {}", e);
        return;
    }
    LOG.info("Starting monitor");
    pollingServiceManager.startMonitor();
    Runtime.getRuntime().addShutdownHook(new Thread(new FileDropZoneShutdownTask(pollingServiceManager)));
}
Also used : IOException(java.io.IOException) File(java.io.File) PollingServiceManager(co.cask.cdap.file.dropzone.polling.PollingServiceManager)

Example 2 with PollingServiceManager

use of co.cask.cdap.file.dropzone.polling.PollingServiceManager 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

PollingServiceManager (co.cask.cdap.file.dropzone.polling.PollingServiceManager)2 File (java.io.File)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 FileTailerMetricsProcessor (co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Test (org.junit.Test)1