org.apache.flume.ChannelSelector Java Examples
The following examples show how to use
org.apache.flume.ChannelSelector.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestSyslogUdpSource.java From mt-flume with Apache License 2.0 | 6 votes |
@Before public void setUp() { source = new SyslogUDPSource(); //SyslogTcpSource(); channel = new MemoryChannel(); Configurables.configure(channel, new Context()); List<Channel> channels = new ArrayList<Channel>(); channels.add(channel); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); Context context = new Context(); context.put("port", String.valueOf(TEST_SYSLOG_PORT)); source.configure(context); }
Example #2
Source File: TestLog4jAppenderWithAvro.java From kite with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { URL schemaUrl = getClass().getClassLoader().getResource("myrecord.avsc"); Files.copy(Resources.newInputStreamSupplier(schemaUrl), new File("/tmp/myrecord.avsc")); int port = 25430; source = new AvroSource(); ch = new MemoryChannel(); Configurables.configure(ch, new Context()); Context context = new Context(); context.put("port", String.valueOf(port)); context.put("bind", "localhost"); Configurables.configure(source, context); List<Channel> channels = new ArrayList<Channel>(); channels.add(ch); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); source.start(); }
Example #3
Source File: TestLog4jAppenderWithAvro.java From mt-flume with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { URL schemaUrl = getClass().getClassLoader().getResource("myrecord.avsc"); Files.copy(Resources.newInputStreamSupplier(schemaUrl), new File("/tmp/myrecord.avsc")); int port = 25430; source = new AvroSource(); ch = new MemoryChannel(); Configurables.configure(ch, new Context()); Context context = new Context(); context.put("port", String.valueOf(port)); context.put("bind", "localhost"); Configurables.configure(source, context); List<Channel> channels = new ArrayList<Channel>(); channels.add(ch); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); source.start(); }
Example #4
Source File: TestNetcatSource.java From mt-flume with Apache License 2.0 | 6 votes |
@Before public void setUp() { logger.info("Running setup"); channel = new MemoryChannel(); source = new NetcatSource(); Context context = new Context(); Configurables.configure(channel, context); List<Channel> channels = Lists.newArrayList(channel); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); }
Example #5
Source File: TestSpoolDirectorySource.java From mt-flume with Apache License 2.0 | 6 votes |
@Before public void setUp() { source = new SpoolDirectorySource(); channel = new MemoryChannel(); Configurables.configure(channel, new Context()); List<Channel> channels = new ArrayList<Channel>(); channels.add(channel); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); tmpDir = Files.createTempDir(); }
Example #6
Source File: TestChannelProcessor.java From mt-flume with Apache License 2.0 | 6 votes |
/** * Ensure that we see the original NPE from the PreConditions check instead * of an auto-generated NPE, which could be masking something else. */ @Test public void testNullFromGetTransaction() { // channel which returns null from getTransaction() Channel ch = mock(Channel.class); when(ch.getTransaction()).thenReturn(null); ChannelSelector sel = new ReplicatingChannelSelector(); sel.setChannels(Lists.newArrayList(ch)); ChannelProcessor proc = new ChannelProcessor(sel); List<Event> events = Lists.newArrayList(); events.add(EventBuilder.withBody("event 1", Charsets.UTF_8)); boolean threw = false; try { proc.processEventBatch(events); } catch (NullPointerException ex) { threw = true; Assert.assertNotNull("NPE must be manually thrown", ex.getMessage()); } Assert.assertTrue("Must throw NPE", threw); }
Example #7
Source File: TestChannelProcessor.java From mt-flume with Apache License 2.0 | 6 votes |
/** * Ensure that we bubble up any specific exception thrown from getTransaction * instead of another exception masking it such as an NPE */ @Test(expected = ChannelException.class) public void testExceptionFromGetTransaction() { // create a channel which unexpectedly throws a ChEx on getTransaction() Channel ch = mock(Channel.class); when(ch.getTransaction()).thenThrow(new ChannelException("doh!")); ChannelSelector sel = new ReplicatingChannelSelector(); sel.setChannels(Lists.newArrayList(ch)); ChannelProcessor proc = new ChannelProcessor(sel); List<Event> events = Lists.newArrayList(); events.add(EventBuilder.withBody("event 1", Charsets.UTF_8)); proc.processEventBatch(events); }
Example #8
Source File: TestFlumeThriftTarget.java From datacollector with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { port = NetworkUtils.getRandomPort(); source = new ThriftSource(); ch = new MemoryChannel(); Configurables.configure(ch, new Context()); Context context = new Context(); context.put("port", String.valueOf(port)); context.put("bind", "localhost"); Configurables.configure(source, context); List<Channel> channels = new ArrayList<>(); channels.add(ch); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); source.start(); }
Example #9
Source File: TestFlumeFailoverTarget.java From datacollector with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { port = NetworkUtils.getRandomPort(); source = new AvroSource(); ch = new MemoryChannel(); Configurables.configure(ch, new Context()); Context context = new Context(); context.put("port", String.valueOf(port)); context.put("bind", "localhost"); Configurables.configure(source, context); List<Channel> channels = new ArrayList<>(); channels.add(ch); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); source.start(); }
Example #10
Source File: TestSequenceGeneratorSource.java From mt-flume with Apache License 2.0 | 5 votes |
@Test public void testBatchProcessWithLifeCycle() throws InterruptedException, LifecycleException, EventDeliveryException { int batchSize = 10; Channel channel = new PseudoTxnMemoryChannel(); Context context = new Context(); context.put("logicalNode.name", "test"); context.put("batchSize", Integer.toString(batchSize)); Configurables.configure(source, context); Configurables.configure(channel, context); List<Channel> channels = new ArrayList<Channel>(); channels.add(channel); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); source.start(); for (long i = 0; i < 100; i++) { source.process(); for (long j = batchSize; j > 0; j--) { Event event = channel.take(); String expectedVal = String.valueOf(((i+1)*batchSize)-j); String resultedVal = new String(event.getBody()); Assert.assertTrue("Expected " + expectedVal + " is not equals to " + resultedVal, expectedVal.equals(resultedVal)); } } source.stop(); }
Example #11
Source File: TestLog4jAppender.java From kite with Apache License 2.0 | 5 votes |
@Before public void initiate() throws Exception{ int port = 25430; source = new AvroSource(); ch = new MemoryChannel(); Configurables.configure(ch, new Context()); Context context = new Context(); context.put("port", String.valueOf(port)); context.put("bind", "localhost"); Configurables.configure(source, context); List<Channel> channels = new ArrayList<Channel>(); channels.add(ch); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); source.start(); File TESTFILE = new File( TestLog4jAppender.class.getClassLoader() .getResource("flume-log4jtest.properties").getFile()); FileReader reader = new FileReader(TESTFILE); props = new Properties(); props.load(reader); reader.close(); }
Example #12
Source File: FlumeAppenderTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { eventSource = new AvroSource(); channel = new MemoryChannel(); Configurables.configure(channel, new Context()); avroLogger = (Logger) LogManager.getLogger("avrologger"); /* * Clear out all other appenders associated with this logger to ensure * we're only hitting the Avro appender. */ removeAppenders(avroLogger); final Context context = new Context(); testPort = String.valueOf(AvailablePortFinder.getNextAvailable()); context.put("port", testPort); context.put("bind", "0.0.0.0"); Configurables.configure(eventSource, context); final List<Channel> channels = new ArrayList<>(); channels.add(channel); final ChannelSelector cs = new ReplicatingChannelSelector(); cs.setChannels(channels); eventSource.setChannelProcessor(new ChannelProcessor(cs)); eventSource.start(); Assert.assertTrue("Reached start or error", LifecycleController .waitForOneOf(eventSource, LifecycleState.START_OR_ERROR)); Assert.assertEquals("Server is started", LifecycleState.START, eventSource.getLifecycleState()); }
Example #13
Source File: RedisSourceTest.java From ingestion with Apache License 2.0 | 5 votes |
@Before public void setUp() { source = new RedisSource(); channel = new MemoryChannel(); Configurables.configure(channel, new Context()); List<Channel> channels = new ArrayList<Channel>(); channels.add(channel); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); }
Example #14
Source File: SNMPSourceTestIT.java From ingestion with Apache License 2.0 | 5 votes |
@Before public void setUp() { source = new SNMPSource(); channel = new MemoryChannel(); Configurables.configure(channel, new Context()); List<Channel> channels = new ArrayList<Channel>(); channels.add(channel); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); }
Example #15
Source File: TestLegacyAvroSource.java From mt-flume with Apache License 2.0 | 5 votes |
@Before public void setUp() { source = new AvroLegacySource(); channel = new MemoryChannel(); Configurables.configure(channel, new Context()); List<Channel> channels = new ArrayList<Channel>(); channels.add(channel); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); }
Example #16
Source File: TestThriftLegacySource.java From mt-flume with Apache License 2.0 | 5 votes |
@Before public void setUp() { source = new ThriftLegacySource(); channel = new MemoryChannel(); Configurables.configure(channel, new Context()); List<Channel> channels = new ArrayList<Channel>(); channels.add(channel); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); }
Example #17
Source File: TestFlumeLoadBalancingTarget.java From datacollector with Apache License 2.0 | 5 votes |
@Before public void setUp() { sources = new ArrayList<>(NUM_HOSTS); chs = new ArrayList<>(NUM_HOSTS); for(int i = 0; i < NUM_HOSTS; i++) { AvroSource source = new AvroSource(); Channel channel = new MemoryChannel(); Configurables.configure(channel, new Context()); Context context = new Context(); context.put("port", String.valueOf(ports.get(i))); context.put("bind", "localhost"); Configurables.configure(source, context); List<Channel> channels = new ArrayList<>(); channels.add(channel); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); sources.add(source); chs.add(channel); source.start(); } }
Example #18
Source File: TestLog4jAppender.java From mt-flume with Apache License 2.0 | 5 votes |
private void configureSource() { List<Channel> channels = new ArrayList<Channel>(); channels.add(ch); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); source.start(); }
Example #19
Source File: TestSequenceGeneratorSource.java From mt-flume with Apache License 2.0 | 5 votes |
@Test public void testLifecycle() throws InterruptedException, EventDeliveryException { Channel channel = new PseudoTxnMemoryChannel(); Context context = new Context(); context.put("logicalNode.name", "test"); Configurables.configure(source, context); Configurables.configure(channel, context); List<Channel> channels = new ArrayList<Channel>(); channels.add(channel); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); source.start(); for (long i = 0; i < 100; i++) { source.process(); Event event = channel.take(); Assert.assertArrayEquals(String.valueOf(i).getBytes(), new String(event.getBody()).getBytes()); } source.stop(); }
Example #20
Source File: TestSequenceGeneratorSource.java From mt-flume with Apache License 2.0 | 5 votes |
@Test public void testProcess() throws InterruptedException, LifecycleException, EventDeliveryException { Channel channel = new PseudoTxnMemoryChannel(); Context context = new Context(); context.put("logicalNode.name", "test"); Configurables.configure(source, context); Configurables.configure(channel, context); List<Channel> channels = new ArrayList<Channel>(); channels.add(channel); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); for (long i = 0; i < 100; i++) { source.process(); Event event = channel.take(); Assert.assertArrayEquals(String.valueOf(i).getBytes(), new String(event.getBody()).getBytes()); } }
Example #21
Source File: TestHTTPSource.java From mt-flume with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUpClass() throws Exception { selectedPort = findFreePort(); source = new HTTPSource(); channel = new MemoryChannel(); Context ctx = new Context(); ctx.put("capacity", "100"); Configurables.configure(channel, ctx); List<Channel> channels = new ArrayList<Channel>(1); channels.add(channel); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); channel.start(); Context context = new Context(); context.put("port", String.valueOf(selectedPort)); context.put("host", "0.0.0.0"); Configurables.configure(source, context); source.start(); }
Example #22
Source File: FlumeThriftService.java From bahir-flink with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { //Flume Source ThriftSource source = new ThriftSource(); Channel ch = new MemoryChannel(); Configurables.configure(ch, new Context()); Context context = new Context(); context.put("port", String.valueOf(port)); context.put("bind", hostname); Configurables.configure(source, context); List<Channel> channels = new ArrayList<>(); channels.add(ch); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); source.start(); System.out.println("ThriftSource service start."); while (true) { Transaction transaction = ch.getTransaction(); transaction.begin(); Event event = ch.take(); if (null != event) { System.out.println(event); System.out.println(new String(event.getBody()).trim()); } transaction.commit(); transaction.close(); } }
Example #23
Source File: TestThriftSource.java From mt-flume with Apache License 2.0 | 5 votes |
private void configureSource() { List<Channel> channels = new ArrayList<Channel>(); channels.add(channel); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); }
Example #24
Source File: TestAvroSource.java From mt-flume with Apache License 2.0 | 5 votes |
@Before public void setUp() { source = new AvroSource(); channel = new MemoryChannel(); Configurables.configure(channel, new Context()); List<Channel> channels = new ArrayList<Channel>(); channels.add(channel); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(channels); source.setChannelProcessor(new ChannelProcessor(rcs)); }
Example #25
Source File: ChannelSelectorFactory.java From mt-flume with Apache License 2.0 | 5 votes |
public static ChannelSelector create(List<Channel> channels, ChannelSelectorConfiguration conf) { String type = ChannelSelectorType.REPLICATING.toString(); if (conf != null){ type = conf.getType(); } ChannelSelector selector = getSelectorForType(type); selector.setChannels(channels); Configurables.configure(selector, conf); return selector; }
Example #26
Source File: ChannelSelectorFactory.java From mt-flume with Apache License 2.0 | 5 votes |
public static ChannelSelector create(List<Channel> channels, Map<String, String> config) { ChannelSelector selector = getSelectorForType(config.get( BasicConfigurationConstants.CONFIG_TYPE)); selector.setChannels(channels); Context context = new Context(); context.putAll(config); Configurables.configure(selector, context); return selector; }
Example #27
Source File: ChannelProcessor.java From mt-flume with Apache License 2.0 | 4 votes |
public ChannelProcessor(ChannelSelector selector) { this.selector = selector; this.interceptorChain = new InterceptorChain(); }
Example #28
Source File: FlumeAgentServiceImpl.java From searchanalytics-bigdata with MIT License | 4 votes |
private void createAvroSourceWithSelectorHDFSAndESSinks() { Channel ESChannel = flumeESSinkService.getChannel(); Channel HDFSChannel = flumeHDFSSinkService.getChannel(); Channel HbaseChannel = flumeHbaseSinkService.getChannel(); final Map<String, String> properties = new HashMap<String, String>(); properties.put("type", "avro"); properties.put("bind", "localhost"); properties.put("port", "44444"); avroSource = new AvroSource(); avroSource.setName("AvroSource-" + UUID.randomUUID()); Context sourceContext = new Context(properties); avroSource.configure(sourceContext); ChannelSelector selector = new MultiplexingChannelSelector(); List<Channel> channels = new ArrayList<>(); channels.add(ESChannel); channels.add(HDFSChannel); channels.add(sparkAvroChannel); channels.add(HbaseChannel); selector.setChannels(channels); final Map<String, String> selectorProperties = new HashMap<String, String>(); selectorProperties.put("type", "multiplexing"); selectorProperties.put("header", "State"); // selectorProperties.put("mapping.VIEWED", HDFSChannel.getName() + " " // + ESChannel.getName()); // selectorProperties.put("mapping.FAVOURITE", HDFSChannel.getName() + // " " // + ESChannel.getName()); // selectorProperties.put("default", HDFSChannel.getName()); // In case spark avro sink is used. selectorProperties.put("mapping.VIEWED", HDFSChannel.getName() + " " + ESChannel.getName() + " " + sparkAvroChannel.getName() + " " + HbaseChannel.getName()); selectorProperties.put("mapping.FAVOURITE", HDFSChannel.getName() + " " + ESChannel.getName() + " " + sparkAvroChannel.getName() + " " + HbaseChannel.getName()); selectorProperties.put("default", HDFSChannel.getName() + " " + sparkAvroChannel.getName() + " " + HbaseChannel.getName()); Context selectorContext = new Context(selectorProperties); selector.configure(selectorContext); ChannelProcessor cp = new ChannelProcessor(selector); avroSource.setChannelProcessor(cp); avroSource.start(); }
Example #29
Source File: TestCensoringInterceptor.java From mt-flume with Apache License 2.0 | 4 votes |
@Test public void testCensor() { MemoryChannel memCh = new MemoryChannel(); memCh.configure(new Context()); memCh.start(); ChannelSelector cs = new ReplicatingChannelSelector(); cs.setChannels(Lists.<Channel>newArrayList(memCh)); ChannelProcessor cp = new ChannelProcessor(cs); // source config Map<String, String> cfgMap = Maps.newHashMap(); cfgMap.put("interceptors", "a"); String builderClass = CensoringInterceptor.Builder.class.getName(); cfgMap.put("interceptors.a.type", builderClass); Context ctx = new Context(cfgMap); // setup cp.configure(ctx); cp.initialize(); Map<String, String> headers = Maps.newHashMap(); String badWord = "scribe"; headers.put("Bad-Words", badWord); Event event1 = EventBuilder.withBody("test", Charsets.UTF_8, headers); Assert.assertEquals(badWord, event1.getHeaders().get("Bad-Words")); cp.processEvent(event1); Transaction tx = memCh.getTransaction(); tx.begin(); Event event1a = memCh.take(); Assert.assertNull(event1a.getHeaders().get("Bad-Words")); tx.commit(); tx.close(); // cleanup / shutdown cp.close(); memCh.stop(); }
Example #30
Source File: FlumeAgentServiceImpl.java From searchanalytics-bigdata with MIT License | 4 votes |
@SuppressWarnings("unused") private void createAvroSourceWithLocalFileRollingSink() { channel = new MemoryChannel(); String channelName = "AvroSourceMemoryChannel-" + UUID.randomUUID(); channel.setName(channelName); sink = new RollingFileSink(); sink.setName("RollingFileSink-" + UUID.randomUUID()); Map<String, String> paramters = new HashMap<>(); paramters.put("type", "file_roll"); paramters.put("sink.directory", "target/flumefilelog"); Context sinkContext = new Context(paramters); sink.configure(sinkContext); Configurables.configure(channel, sinkContext); sink.setChannel(channel); final Map<String, String> properties = new HashMap<String, String>(); properties.put("type", "avro"); properties.put("bind", "localhost"); properties.put("port", "44444"); properties.put("selector.type", "multiplexing"); properties.put("selector.header", "State"); properties.put("selector.mapping.VIEWED", channelName); properties.put("selector.mapping.default", channelName); avroSource = new AvroSource(); avroSource.setName("AvroSource-" + UUID.randomUUID()); Context sourceContext = new Context(properties); avroSource.configure(sourceContext); ChannelSelector selector = new MultiplexingChannelSelector(); List<Channel> channels = new ArrayList<>(); channels.add(channel); selector.setChannels(channels); final Map<String, String> selectorProperties = new HashMap<String, String>(); properties.put("default", channelName); Context selectorContext = new Context(selectorProperties); selector.configure(selectorContext); ChannelProcessor cp = new ChannelProcessor(selector); avroSource.setChannelProcessor(cp); sink.start(); channel.start(); avroSource.start(); }