Search in sources :

Example 1 with AvailabilityNode

use of org.opennms.web.category.AvailabilityNode in project opennms by OpenNMS.

the class AvailabilityRestServiceIT method testGetAvailabilityNode.

@Test
@JUnitTemporaryDatabase
public void testGetAvailabilityNode() throws Exception {
    final OnmsNode node = m_populator.getNode1();
    final AvailabilityRestService ars = new AvailabilityRestService();
    ars.setNodeDao(m_populator.getNodeDao());
    final AvailabilityNode an = ars.getAvailabilityNode(node.getId());
    assertNotNull(an);
    System.err.println(JaxbUtils.marshal(an));
    // Compare the object to the same node fetched via REST
    String url = "/availability/nodes/" + node.getId();
    AvailabilityNode restNode = getXmlObject(JaxbUtils.getContextFor(AvailabilityNode.class), url, 200, AvailabilityNode.class);
    Assert.assertNotNull(restNode);
    Assert.assertTrue(an.toString() + " != " + restNode.toString(), an.equals(restNode));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) AvailabilityNode(org.opennms.web.category.AvailabilityNode) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 2 with AvailabilityNode

use of org.opennms.web.category.AvailabilityNode in project opennms by OpenNMS.

the class AvailabilityRestService method getAvailabilityNode.

AvailabilityNode getAvailabilityNode(final int id) throws Exception {
    final OnmsNode dbNode = m_nodeDao.get(id);
    initialize(dbNode);
    if (dbNode == null) {
        throw getException(Status.NOT_FOUND, "Node {} was not found.", Integer.toString(id));
    }
    final double nodeAvail = CategoryModel.getNodeAvailability(id);
    final AvailabilityNode node = new AvailabilityNode(dbNode, nodeAvail);
    for (final OnmsIpInterface iface : dbNode.getIpInterfaces()) {
        final double ifaceAvail = CategoryModel.getInterfaceAvailability(id, str(iface.getIpAddress()));
        final AvailabilityIpInterface ai = new AvailabilityIpInterface(iface, ifaceAvail);
        for (final OnmsMonitoredService svc : iface.getMonitoredServices()) {
            final double serviceAvail = CategoryModel.getServiceAvailability(id, str(iface.getIpAddress()), svc.getServiceId());
            final AvailabilityMonitoredService ams = new AvailabilityMonitoredService(svc, serviceAvail);
            ai.addService(ams);
        }
        node.addIpInterface(ai);
    }
    return node;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) AvailabilityNode(org.opennms.web.category.AvailabilityNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) AvailabilityIpInterface(org.opennms.web.category.AvailabilityIpInterface) AvailabilityMonitoredService(org.opennms.web.category.AvailabilityMonitoredService) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 3 with AvailabilityNode

use of org.opennms.web.category.AvailabilityNode in project opennms by OpenNMS.

the class AvailabilityRestService method getCategoryNode.

@GET
@Path("/categories/{category}/nodes/{nodeId}")
public AvailabilityNode getCategoryNode(@PathParam("category") final String categoryName, @PathParam("nodeId") final Long nodeId) {
    try {
        final String category = URLDecoder.decode(categoryName, StandardCharsets.UTF_8.name());
        final Category cat = CategoryModel.getInstance().getCategory(category);
        if (cat == null) {
            throw getException(Status.NOT_FOUND, "Category {} was not found.", categoryName);
        }
        final AvailabilityNode node = cat.getNode(nodeId);
        if (node == null) {
            throw getException(Status.NOT_FOUND, "Node {} was not found for category {}.", Long.toString(nodeId), categoryName);
        }
        return getAvailabilityNode(node.getId().intValue());
    } catch (final Exception e) {
        LOG.warn("Failed to get availability data for category {}: {}", categoryName, e.getMessage(), e);
        throw getException(Status.INTERNAL_SERVER_ERROR, "Failed to get availability data for category {} : {}", categoryName, e.getMessage());
    }
}
Also used : Category(org.opennms.web.category.Category) AvailabilityNode(org.opennms.web.category.AvailabilityNode) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

AvailabilityNode (org.opennms.web.category.AvailabilityNode)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Test (org.junit.Test)1 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)1 AvailabilityIpInterface (org.opennms.web.category.AvailabilityIpInterface)1 AvailabilityMonitoredService (org.opennms.web.category.AvailabilityMonitoredService)1 Category (org.opennms.web.category.Category)1