use of org.opennms.netmgt.config.discovery.DiscoveryConfiguration in project opennms by OpenNMS.
the class RangeChunkerTest method testConsecutiveSpecificsWithDifferentLocations.
@Test
public void testConsecutiveSpecificsWithDifferentLocations() {
DiscoveryConfiguration config = new DiscoveryConfiguration();
for (int i = 0; i < 5; i++) {
Specific specific = new Specific();
specific.setAddress("10.0.0." + i);
specific.setForeignSource("ABC");
specific.setLocation(i % 2 == 0 ? "123" : "456");
specific.setRetries(1);
specific.setTimeout(1000l);
config.addSpecific(specific);
}
Map<String, List<DiscoveryJob>> jobs = new RangeChunker(ipAddressFilter).chunk(config);
printJobs(jobs);
assertEquals(2, jobs.size());
assertEquals(3, jobs.get("123").get(0).getRanges().size());
assertEquals(2, jobs.get("456").get(0).getRanges().size());
}
use of org.opennms.netmgt.config.discovery.DiscoveryConfiguration in project opennms by OpenNMS.
the class RangeChunkerTest method testConsecutiveSpecificsWithDifferentTimeouts.
@Test
public void testConsecutiveSpecificsWithDifferentTimeouts() {
DiscoveryConfiguration config = new DiscoveryConfiguration();
for (long i = 0; i < 5; i++) {
Specific specific = new Specific();
specific.setAddress("10.0.0." + i);
specific.setForeignSource("ABC");
specific.setLocation("123");
specific.setRetries(5);
specific.setTimeout(i + 1);
config.addSpecific(specific);
}
Map<String, List<DiscoveryJob>> jobs = new RangeChunker(ipAddressFilter).chunk(config);
printJobs(jobs);
assertEquals(1, jobs.get("123").size());
assertEquals(5, jobs.get("123").get(0).getRanges().size());
}
use of org.opennms.netmgt.config.discovery.DiscoveryConfiguration in project opennms by OpenNMS.
the class DiscoveryRestService method getDiscoveryConfig.
private DiscoveryConfiguration getDiscoveryConfig(DiscoveryConfigurationDTO discoveryConfigurationDTO) {
DiscoveryConfiguration discoveryConfiguration = new DiscoveryConfiguration();
discoveryConfiguration.setTimeout(discoveryConfigurationDTO.getTimeout());
discoveryConfiguration.setRetries(discoveryConfigurationDTO.getRetries());
discoveryConfiguration.setForeignSource(discoveryConfigurationDTO.getForeignSource());
discoveryConfiguration.setLocation(discoveryConfigurationDTO.getLocation());
discoveryConfiguration.setChunkSize(discoveryConfigurationDTO.getChunkSize());
for (DiscoveryConfigurationDTO.SpecificDTO specificDTO : discoveryConfigurationDTO.getSpecificDTOList()) {
Specific specific = new Specific();
specific.setAddress(specificDTO.getContent());
specific.setTimeout(specificDTO.getTimeout());
specific.setRetries(specificDTO.getRetries());
specific.setForeignSource(specificDTO.getForeignSource());
specific.setLocation(specificDTO.getLocation());
discoveryConfiguration.addSpecific(specific);
}
for (DiscoveryConfigurationDTO.IncludeUrlDTO includeUrlDTO : discoveryConfigurationDTO.getIncludeUrlDTOList()) {
IncludeUrl includeUrl = new IncludeUrl();
includeUrl.setUrl(includeUrlDTO.getContent());
includeUrl.setTimeout(includeUrlDTO.getTimeout());
includeUrl.setRetries(includeUrlDTO.getRetries());
includeUrl.setForeignSource(includeUrlDTO.getForeignSource());
includeUrl.setLocation(includeUrlDTO.getLocation());
discoveryConfiguration.addIncludeUrl(includeUrl);
}
for (DiscoveryConfigurationDTO.IncludeRangeDTO includeRangeDTO : discoveryConfigurationDTO.getIncludeRangeDTOList()) {
IncludeRange includeRange = new IncludeRange();
includeRange.setBegin(includeRangeDTO.getBegin());
includeRange.setEnd(includeRangeDTO.getEnd());
includeRange.setTimeout(includeRangeDTO.getTimeout());
includeRange.setRetries(includeRangeDTO.getRetries());
includeRange.setForeignSource(includeRangeDTO.getForeignSource());
includeRange.setLocation(includeRangeDTO.getLocation());
discoveryConfiguration.addIncludeRange(includeRange);
}
for (DiscoveryConfigurationDTO.ExcludeRangeDTO excludeRangeDTO : discoveryConfigurationDTO.getExcludeRangeDTOList()) {
ExcludeRange excludeRange = new ExcludeRange();
excludeRange.setBegin(excludeRangeDTO.getBegin());
excludeRange.setEnd(excludeRangeDTO.getEnd());
discoveryConfiguration.addExcludeRange(excludeRange);
}
return discoveryConfiguration;
}
use of org.opennms.netmgt.config.discovery.DiscoveryConfiguration in project opennms by OpenNMS.
the class DiscoveryRestService method scan.
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response scan(DiscoveryConfigurationDTO discoveryConfigurationDTO) {
DiscoveryConfiguration discoveryConfiguration = getDiscoveryConfig(discoveryConfigurationDTO);
DiscoveryTaskExecutor discoveryTaskExecutor = serviceRegistry.findProvider(DiscoveryTaskExecutor.class);
if (discoveryTaskExecutor != null) {
discoveryTaskExecutor.handleDiscoveryTask(discoveryConfiguration);
} else {
LOG.warn("No DiscoveryTaskExecutor service is available");
return Response.serverError().build();
}
return Response.ok().build();
}
use of org.opennms.netmgt.config.discovery.DiscoveryConfiguration in project opennms by OpenNMS.
the class RangeChunker method chunk.
public Map<String, List<DiscoveryJob>> chunk(final DiscoveryConfiguration config) {
final int chunkSize = config.getChunkSize().orElse(DiscoveryConfigFactory.DEFAULT_CHUNK_SIZE);
final double packetsPerSecond = config.getPacketsPerSecond().orElse(DiscoveryConfigFactory.DEFAULT_PACKETS_PER_SECOND);
// If the foreign source for the discovery config is not set than use
// a value of null so that non-requisitioned nodes are created.
//
// TODO: Use the "default" foreign source instead so that we can move
// away from using non-requisitioned nodes.
//
final String foreignSourceFromConfig = config.getForeignSource().isPresent() ? config.getForeignSource().get().trim() : null;
// If the monitoring location for the discovery config is not set than use
// the default localhost location
final String locationFromConfig = config.getLocation().map(l -> {
final String trimmed = l.trim();
if ("".equals(trimmed)) {
return null;
}
return trimmed;
}).orElse(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID);
final DiscoveryConfigFactory configFactory = new DiscoveryConfigFactory(config);
final AtomicReference<IPPollRange> previousRange = new AtomicReference<>();
return StreamSupport.stream(configFactory.getConfiguredAddresses().spliterator(), false).filter(address -> {
// If there is no IP address filter set or the filter matches
return ipAddressFilter.matches(address.getLocation(), address.getAddress());
}).map(address -> {
// Create a singleton IPPollRange
return new IPPollRange(// Make sure that foreignSource is not null so that we can partition on the value
address.getForeignSource() == null ? foreignSourceFromConfig : address.getForeignSource(), // Make sure that location is not null so that we can partition on the value
address.getLocation() == null ? locationFromConfig : address.getLocation(), address.getAddress(), address.getAddress(), address.getTimeout(), address.getRetries());
}).collect(Collectors.groupingBy(range -> {
// Create a Map<ForeignSourceLocationKey,List<IPPollRange>>
return new ForeignSourceLocationKey(// Make sure that foreignSource is not null so that we can partition on the value
range.getForeignSource() == null ? foreignSourceFromConfig : range.getForeignSource(), // Make sure that location is not null so that we can partition on the value
range.getLocation() == null ? locationFromConfig : range.getLocation());
}, LinkedHashMap::new, Collectors.toList())).entrySet().stream().flatMap(entry -> {
// Partition the list of address values
return Lists.partition(entry.getValue(), chunkSize).stream().map(ranges -> {
DiscoveryJob retval = new DiscoveryJob(ranges.stream().map(address -> {
// then just extend the range to cover this address too
if (isConsecutive(previousRange.get(), address)) {
previousRange.get().getAddressRange().incrementEnd();
return null;
}
previousRange.set(address);
return address;
}).filter(Objects::nonNull).collect(Collectors.toList()), entry.getKey().getForeignSource(), entry.getKey().getLocation(), packetsPerSecond);
// Reset the previousRange value
previousRange.set(null);
return retval;
}).collect(Collectors.toList()).stream();
}).collect(Collectors.groupingBy(DiscoveryJob::getLocation, LinkedHashMap::new, Collectors.toList()));
}
Aggregations