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));
}
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;
}
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());
}
}
Aggregations