Search in sources :

Example 1 with EmbeddedAgent

use of org.apache.flume.agent.embedded.EmbeddedAgent in project cdap-ingest by caskdata.

the class CdapFlumeIT method eventProcessingWithCdapFailTest.

/**
   * Test simulate CDAP fail. CDAP port is swapped in runtime to simulate work with not accessible port.
   */
@Test
public void eventProcessingWithCdapFailTest() throws Exception {
    String cdapPortStrValue = String.valueOf(streamReader.getCdapPort());
    EmbeddedAgent agent = new EmbeddedAgent("test-flume");
    Method method = agent.getClass().getDeclaredMethod("doConfigure", Map.class);
    method.setAccessible(true);
    Map<String, String> propertyMap = new HashMap<String, String>();
    for (final String name : properties.stringPropertyNames()) {
        propertyMap.put(name, properties.getProperty(name));
    }
    agent.configure(propertyMap);
    agent.start();
    method.invoke(agent, propertyMap);
    long startTime = System.currentTimeMillis();
    writeEvents(agent, 0, EVENT_FAIL_START_NUMBER);
    Assert.assertNotEquals(cdapPortStrValue, INVALID_PORT);
    propertyMap.put("sink1.port", INVALID_PORT);
    method.invoke(agent, propertyMap);
    writeEvents(agent, EVENT_FAIL_START_NUMBER, FAIL_EVENT_END_NUMBER);
    propertyMap.put("sink1.port", cdapPortStrValue);
    method.invoke(agent, propertyMap);
    writeEvents(agent, FAIL_EVENT_END_NUMBER, EVENT_NUMBER);
    Thread.sleep(SLEEP_INTERVAL);
    agent.stop();
    checkDeliveredEvents(startTime);
}
Also used : EmbeddedAgent(org.apache.flume.agent.embedded.EmbeddedAgent) HashMap(java.util.HashMap) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 2 with EmbeddedAgent

use of org.apache.flume.agent.embedded.EmbeddedAgent in project chassis by Kixeye.

the class FlumeLoggerLoader method initialize.

@PostConstruct
public void initialize() {
    multicaster.addApplicationListener(loggingListener);
    ConcurrentHashMap<String, String> flumeConfig = new ConcurrentHashMap<>();
    List<String> sinks = new ArrayList<>();
    for (String server : servers) {
        String sinkName = server.replace(":", "-").replace(".", "_");
        String[] servers = server.split(":", 2);
        if (servers.length == 2) {
            flumeConfig.put(sinkName + ".type", "avro");
            flumeConfig.put(sinkName + ".channels", "channel-" + name);
            flumeConfig.put(sinkName + ".hostname", servers[0]);
            flumeConfig.put(sinkName + ".port", servers[1]);
        } else {
            logger.error("Invalid server format [{}], should be [hostname:port]", server);
        }
        sinks.add(sinkName);
    }
    // force some properties
    flumeConfig.put("channel.type", "file");
    flumeConfig.put("sinks", StringUtils.collectionToDelimitedString(sinks, " "));
    flumeConfig.putIfAbsent("processor.type", serversUsage);
    flumeConfig.put("channel.checkpointDir", SystemPropertyUtils.resolvePlaceholders("${user.dir}/flume-data/checkpoint"));
    flumeConfig.put("channel.dataDirs", SystemPropertyUtils.resolvePlaceholders("${user.dir}/flume-data/data"));
    agent = new EmbeddedAgent(name);
    agent.configure(flumeConfig);
    agent.start();
    appender = new FlumeLogAppender(agent, serviceName);
    installFlumeAppender();
}
Also used : EmbeddedAgent(org.apache.flume.agent.embedded.EmbeddedAgent) ArrayList(java.util.ArrayList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PostConstruct(javax.annotation.PostConstruct)

Example 3 with EmbeddedAgent

use of org.apache.flume.agent.embedded.EmbeddedAgent in project cdap-ingest by caskdata.

the class CdapFlumeIT method baseEventProcessingTest.

@Test
public void baseEventProcessingTest() throws Exception {
    EmbeddedAgent agent = new EmbeddedAgent("test-flume");
    Map<String, String> propertyMap = new HashMap<String, String>();
    for (final String name : properties.stringPropertyNames()) {
        propertyMap.put(name, properties.getProperty(name));
    }
    agent.configure(propertyMap);
    agent.start();
    long startTime = System.currentTimeMillis();
    writeEvents(agent, 0, EVENT_NUMBER);
    Thread.sleep(SLEEP_INTERVAL);
    agent.stop();
    checkDeliveredEvents(startTime);
}
Also used : EmbeddedAgent(org.apache.flume.agent.embedded.EmbeddedAgent) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

EmbeddedAgent (org.apache.flume.agent.embedded.EmbeddedAgent)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 PostConstruct (javax.annotation.PostConstruct)1