Search in sources :

Example 66 with OnmsIpInterface

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));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) IPAddressRange(org.opennms.core.network.IPAddressRange) IPAddress(org.opennms.core.network.IPAddress) Test(org.junit.Test)

Example 67 with OnmsIpInterface

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);
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 68 with OnmsIpInterface

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();
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Event(org.opennms.netmgt.xml.event.Event)

Example 69 with OnmsIpInterface

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();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface)

Example 70 with OnmsIpInterface

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;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)186 OnmsNode (org.opennms.netmgt.model.OnmsNode)117 Test (org.junit.Test)53 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)43 InetAddress (java.net.InetAddress)40 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)33 Transactional (org.springframework.transaction.annotation.Transactional)30 ArrayList (java.util.ArrayList)22 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)21 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)20 Date (java.util.Date)17 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)17 File (java.io.File)16 HashMap (java.util.HashMap)15 Before (org.junit.Before)15 LinkedList (java.util.LinkedList)14 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)14 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)12 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)12 OnmsResource (org.opennms.netmgt.model.OnmsResource)11