use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class JdbcFilterDaoIT method verifyPerformance.
// Verifies that if a bunch of interfaces exists, checking if an ip address is valid should be faster
// than retrieving all interfaces.
// See HZN-1161 for more details.
@Test
public void verifyPerformance() {
// Create a bunch of interfaces
final OnmsNode node1 = m_populator.getNode1();
final IPAddressRange ipAddresses = new IPAddressRange("10.10.0.0", "10.10.255.255");
final Iterator<IPAddress> iterator = ipAddresses.iterator();
while (iterator.hasNext()) {
IPAddress address = iterator.next();
OnmsIpInterface ipInterface = new OnmsIpInterface();
ipInterface.setNode(node1);
ipInterface.setIpAddress(address.toInetAddress());
m_interfaceDao.save(ipInterface);
}
final int numberOfInterfaces = m_interfaceDao.countAll();
assertThat(numberOfInterfaces, greaterThan(255 * 255));
// verify
assertThat(m_dao.getActiveIPAddressList("IPADDR != '0.0.0.0'"), Matchers.hasSize(numberOfInterfaces));
assertThat(m_dao.isValid("10.10.0.1", "IPADDR != '0.0.0.0'"), is(true));
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class ResourceDaoIntegrityIT method createNodes.
/**
* Creates a set of nodes and assigns a single IP address from
* the resource-tree-ips.txt file to each node.
*/
private void createNodes() throws IOException {
final int NUM_NODES = 250;
String fileAsString = IOUtils.toString(new ClassPathResource("resource-tree-ips.txt").getInputStream());
String[] resourceTreeIps = fileAsString.split("\\r?\\n");
// Make sure every IP address is represented at least once
assertTrue(resourceTreeIps.length < NUM_NODES);
for (int i = 1; i <= NUM_NODES; i++) {
OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "node" + i);
node.setForeignSource("NODES");
node.setForeignId(Integer.toString(i));
m_nodeDao.save(node);
OnmsIpInterface intf = new OnmsIpInterface();
intf.setIpAddress(InetAddressUtils.addr(resourceTreeIps[i % resourceTreeIps.length]));
intf.setNode(node);
m_ipInterfaceDao.save(intf);
node.setIpInterfaces(Collections.singleton(intf));
m_nodeDao.saveOrUpdate(node);
}
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class NodeMonitoredServiceRestService method doCreate.
@Override
protected Response doCreate(SecurityContext securityContext, UriInfo uriInfo, OnmsMonitoredService service) {
final OnmsIpInterface iface = getInterface(uriInfo);
if (iface == null) {
throw getException(Status.BAD_REQUEST, "IP interface was not found");
} else if (service == null) {
throw getException(Status.BAD_REQUEST, "Service object cannot be null");
} else if (service.getServiceType() == null || service.getServiceType().getName() == null) {
throw getException(Status.BAD_REQUEST, "Service type names cannot be null");
}
service.setServiceType(getServiceType(service.getServiceName()));
service.setIpInterface(iface);
iface.addMonitoredService(service);
getDao().save(service);
final Event e = EventUtils.createNodeGainedServiceEvent("ReST", iface.getNode().getId(), iface.getIpAddress(), service.getServiceName(), iface.getNode().getLabel(), iface.getNode().getLabelSource(), iface.getNode().getSysName(), iface.getNode().getSysDescription());
sendEvent(e);
return Response.created(RedirectHelper.getRedirectUri(uriInfo, service.getServiceName())).build();
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class NodeSnmpInterfacesRestService method doCreate.
@Override
protected Response doCreate(SecurityContext securityContext, UriInfo uriInfo, OnmsSnmpInterface snmpInterface) {
OnmsNode node = getNode(uriInfo);
if (node == null) {
throw getException(Status.BAD_REQUEST, "Node was not found.");
} else if (snmpInterface == null) {
throw getException(Status.BAD_REQUEST, "SNMP Interface object cannot be null");
} else if (snmpInterface.getIfIndex() == null) {
throw getException(Status.BAD_REQUEST, "SNMP Interface's ifIndex cannot be null");
}
node.addSnmpInterface(snmpInterface);
if (snmpInterface.getPrimaryIpInterface() != null) {
final OnmsIpInterface iface = snmpInterface.getPrimaryIpInterface();
iface.setSnmpInterface(snmpInterface);
}
getDao().save(snmpInterface);
return Response.created(RedirectHelper.getRedirectUri(uriInfo, snmpInterface.getIfIndex())).build();
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class OnmsIpInterfaceResource method getIpInterface.
/**
* <p>getIpInterface</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @param ipAddress a {@link java.lang.String} object.
* @return a {@link org.opennms.netmgt.model.OnmsIpInterface} object.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("{ipAddress}")
public OnmsIpInterface getIpInterface(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ipAddress") final String ipAddress) {
final OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null) {
throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
}
final OnmsIpInterface iface = node.getIpInterfaceByIpAddress(InetAddressUtils.getInetAddress(ipAddress));
if (iface == null) {
throw getException(Status.NOT_FOUND, "IP Interface {} was not found on node {}.", ipAddress, nodeCriteria);
}
return iface;
}
Aggregations