Search in sources :

Example 6 with IPPollAddress

use of org.opennms.netmgt.model.discovery.IPPollAddress in project opennms by OpenNMS.

the class DiscoveryConfigFactory method getSpecifics.

/**
 * <p>getSpecifics</p>
 *
 * @return a {@link java.util.List} object.
 */
@Override
public List<IPPollAddress> getSpecifics() {
    final List<IPPollAddress> specifics = new LinkedList<IPPollAddress>();
    getReadLock().lock();
    try {
        Long defaultTimeout = getConfiguration().getTimeout().orElse(DEFAULT_TIMEOUT);
        Integer defaultRetries = getConfiguration().getRetries().orElse(DEFAULT_RETRIES);
        for (final Specific s : getConfiguration().getSpecifics()) {
            long timeout = s.getTimeout().orElse(defaultTimeout);
            int retries = s.getRetries().orElse(defaultRetries);
            final String address = s.getAddress();
            try {
                specifics.add(new IPPollAddress(s.getForeignSource().orElse(null), s.getLocation().orElse(null), InetAddressUtils.addr(address), timeout, retries));
            } catch (final IllegalArgumentException e) {
                LOG.warn("Failed to convert address {}", address, e);
            }
        }
        return specifics;
    } finally {
        getReadLock().unlock();
    }
}
Also used : IPPollAddress(org.opennms.netmgt.model.discovery.IPPollAddress) Specific(org.opennms.netmgt.config.discovery.Specific) LinkedList(java.util.LinkedList)

Example 7 with IPPollAddress

use of org.opennms.netmgt.model.discovery.IPPollAddress in project opennms by OpenNMS.

the class DiscoveryConfigFactoryTest method testAddToSpecificsFromURLViaURL.

@Test
public void testAddToSpecificsFromURLViaURL() throws Exception {
    final List<IPPollAddress> specifics = new ArrayList<>();
    final URL in = this.getClass().getResource("validDiscoveryIncludeFile.txt");
    final long timeout = 100;
    final int retries = 1;
    DiscoveryConfigFactory.addToSpecificsFromURL(specifics, in.toString(), null, null, timeout, retries);
    assertEquals(8, specifics.size());
    assertEquals("127.0.0.1", InetAddressUtils.str(specifics.get(0).getAddress()));
    assertEquals("10.1.1.1", InetAddressUtils.str(specifics.get(1).getAddress()));
    assertEquals("10.2.1.1", InetAddressUtils.str(specifics.get(2).getAddress()));
    assertEquals("8.8.8.8", InetAddressUtils.str(specifics.get(3).getAddress()));
    assertEquals("fe80:0000:0000:0000:ffff:eeee:dddd:cccc", InetAddressUtils.str(specifics.get(4).getAddress()));
    assertEquals("0000:0000:0000:0000:0000:0000:0000:0001", InetAddressUtils.str(specifics.get(5).getAddress()));
    assertEquals("fe80:0000:0000:0000:ffff:eeee:dddd:cccd", InetAddressUtils.str(specifics.get(6).getAddress()));
    assertEquals("fe80:0000:0000:0000:ffff:eeee:dddd:cccc", InetAddressUtils.str(specifics.get(7).getAddress()));
}
Also used : IPPollAddress(org.opennms.netmgt.model.discovery.IPPollAddress) ArrayList(java.util.ArrayList) URL(java.net.URL) Test(org.junit.Test)

Aggregations

IPPollAddress (org.opennms.netmgt.model.discovery.IPPollAddress)7 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 IPPollRange (org.opennms.netmgt.model.discovery.IPPollRange)2 Throwables (com.google.common.base.Throwables)1 Sets (com.google.common.collect.Sets)1 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 BufferedReader (java.io.BufferedReader)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetAddress (java.net.InetAddress)1 URL (java.net.URL)1 List (java.util.List)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1