Search in sources :

Example 11 with SubsetConfiguration

use of org.apache.commons.configuration2.SubsetConfiguration in project hadoop by apache.

the class TestPatternFilter method excludeOnlyShouldOnlyExcludeMatched.

/**
   * Filters should handle black-listing correctly
   */
@Test
public void excludeOnlyShouldOnlyExcludeMatched() {
    SubsetConfiguration bl = new ConfigBuilder().add("p.exclude", "foo").add("p.exclude.tags", "foo:f").subset("p");
    shouldAccept(bl, "bar");
    shouldAccept(bl, Arrays.asList(tag("bar", "", "")));
    shouldAccept(bl, mockMetricsRecord("bar", Arrays.asList(tag("bar", "", ""))));
    shouldReject(bl, "foo");
    shouldReject(bl, Arrays.asList(tag("bar", "", ""), tag("foo", "", "f")), new boolean[] { true, false });
    shouldReject(bl, mockMetricsRecord("foo", Arrays.asList(tag("bar", "", ""))));
    shouldReject(bl, mockMetricsRecord("bar", Arrays.asList(tag("bar", "", ""), tag("foo", "", "f"))));
}
Also used : ConfigBuilder(org.apache.hadoop.metrics2.impl.ConfigBuilder) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Test(org.junit.Test)

Example 12 with SubsetConfiguration

use of org.apache.commons.configuration2.SubsetConfiguration in project hadoop by apache.

the class TestPatternFilter method emptyConfigShouldAccept.

/**
   * Filters should default to accept
   */
@Test
public void emptyConfigShouldAccept() {
    SubsetConfiguration empty = new ConfigBuilder().subset("");
    shouldAccept(empty, "anything");
    shouldAccept(empty, Arrays.asList(tag("key", "desc", "value")));
    shouldAccept(empty, mockMetricsRecord("anything", Arrays.asList(tag("key", "desc", "value"))));
}
Also used : ConfigBuilder(org.apache.hadoop.metrics2.impl.ConfigBuilder) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Test(org.junit.Test)

Example 13 with SubsetConfiguration

use of org.apache.commons.configuration2.SubsetConfiguration in project hadoop by apache.

the class GangliaSink30 method init.

@Override
@SuppressWarnings("unchecked")
public void init(SubsetConfiguration conf) {
    super.init(conf);
    conf.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    Iterator<String> it = (Iterator<String>) conf.getKeys();
    while (it.hasNext()) {
        String propertyName = it.next();
        if (propertyName.startsWith(TAGS_FOR_PREFIX_PROPERTY_PREFIX)) {
            String contextName = propertyName.substring(TAGS_FOR_PREFIX_PROPERTY_PREFIX.length());
            String[] tags = conf.getStringArray(propertyName);
            boolean useAllTags = false;
            Set<String> set = new HashSet<>();
            for (String tag : tags) {
                tag = tag.trim();
                useAllTags |= tag.equals("*");
                if (tag.length() > 0) {
                    set.add(tag);
                }
            }
            if (useAllTags) {
                set = null;
            }
            useTagsMap.put(contextName, set);
        }
    }
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 14 with SubsetConfiguration

use of org.apache.commons.configuration2.SubsetConfiguration in project hadoop by apache.

the class TestGangliaSink method testShouldCreateMulticastSocket.

@Test
public void testShouldCreateMulticastSocket() throws Exception {
    SubsetConfiguration conf = new ConfigBuilder().add("test.sink.ganglia.multicast", true).subset("test.sink.ganglia");
    GangliaSink30 gangliaSink = new GangliaSink30();
    gangliaSink.init(conf);
    DatagramSocket socket = gangliaSink.getDatagramSocket();
    assertTrue("Did not create MulticastSocket", socket != null && socket instanceof MulticastSocket);
    int ttl = ((MulticastSocket) socket).getTimeToLive();
    assertEquals("Did not set default TTL", 1, ttl);
}
Also used : MulticastSocket(java.net.MulticastSocket) DatagramSocket(java.net.DatagramSocket) ConfigBuilder(org.apache.hadoop.metrics2.impl.ConfigBuilder) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Test(org.junit.Test)

Example 15 with SubsetConfiguration

use of org.apache.commons.configuration2.SubsetConfiguration in project hadoop by apache.

the class TestGangliaSink method testShouldSetMulticastSocketTtl.

@Test
public void testShouldSetMulticastSocketTtl() throws Exception {
    SubsetConfiguration conf = new ConfigBuilder().add("test.sink.ganglia.multicast", true).add("test.sink.ganglia.multicast.ttl", 3).subset("test.sink.ganglia");
    GangliaSink30 gangliaSink = new GangliaSink30();
    gangliaSink.init(conf);
    DatagramSocket socket = gangliaSink.getDatagramSocket();
    assertTrue("Did not create MulticastSocket", socket != null && socket instanceof MulticastSocket);
    int ttl = ((MulticastSocket) socket).getTimeToLive();
    assertEquals("Did not set TTL", 3, ttl);
}
Also used : MulticastSocket(java.net.MulticastSocket) DatagramSocket(java.net.DatagramSocket) ConfigBuilder(org.apache.hadoop.metrics2.impl.ConfigBuilder) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Test(org.junit.Test)

Aggregations

SubsetConfiguration (org.apache.commons.configuration2.SubsetConfiguration)14 Test (org.junit.Test)14 ConfigBuilder (org.apache.hadoop.metrics2.impl.ConfigBuilder)11 DatagramSocket (java.net.DatagramSocket)4 MulticastSocket (java.net.MulticastSocket)4 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 DefaultListDelimiterHandler (org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)1 Path (org.apache.hadoop.fs.Path)1 AbstractMetric (org.apache.hadoop.metrics2.AbstractMetric)1 MetricsException (org.apache.hadoop.metrics2.MetricsException)1 MetricsRecord (org.apache.hadoop.metrics2.MetricsRecord)1 MetricsTag (org.apache.hadoop.metrics2.MetricsTag)1 MetricsVisitor (org.apache.hadoop.metrics2.MetricsVisitor)1 KafkaSink (org.apache.hadoop.metrics2.sink.KafkaSink)1 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)1 RecordMetadata (org.apache.kafka.clients.producer.RecordMetadata)1