use of org.opennms.core.utils.Querier in project opennms by OpenNMS.
the class MockDatabase method getOutages.
public Collection<Outage> getOutages(String criteria, Object... values) {
String critSql = (criteria == null ? "" : " and " + criteria);
final List<Outage> outages = new LinkedList<>();
Querier loadExisting = new Querier(this, "select * from outages, ifServices, ipInterface, node, service where outages.ifServiceId = ifServices.id and ifServices.ipInterfaceId = ipInterface.id and ipInterface.nodeId = node.nodeId and ifServices.serviceId = service.serviceId" + critSql) {
@Override
public void processRow(ResultSet rs) throws SQLException {
Outage outage = new Outage(rs.getInt("nodeId"), rs.getString("ipAddr"), rs.getInt("serviceId"));
outage.setServiceName(rs.getString("serviceName"));
outage.setLostEvent(rs.getInt("svcLostEventID"), rs.getTimestamp("ifLostService"));
boolean open = (rs.getObject("ifRegainedService") == null);
if (!open) {
outage.setRegainedEvent(rs.getInt("svcRegainedEventID"), rs.getTimestamp("ifRegainedService"));
}
outages.add(outage);
}
};
loadExisting.execute(values);
return outages;
}
use of org.opennms.core.utils.Querier in project opennms by OpenNMS.
the class PassiveStatusKeeper method onInit.
/**
* <p>onInit</p>
*/
@Override
protected void onInit() {
if (m_initialized)
return;
checkPreRequisites();
createMessageSelectorAndSubscribe();
m_statusTable = new HashMap<PassiveStatusKey, PollStatus>();
String sql = "select node.nodeLabel AS nodeLabel, ipInterface.ipAddr AS ipAddr, service.serviceName AS serviceName " + "FROM outages " + "JOIN ifServices ON outages.ifServiceId = ifServices.id " + "JOIN ipInterface ON ifServices.ipInterfaceId = ipInterface.id " + "JOIN node ON ipInterface.nodeId = node.nodeId " + "JOIN service ON ifServices.serviceId = service.serviceId " + "WHERE outages.ifRegainedService is NULL";
Querier querier = new Querier(m_dataSource, sql) {
@Override
public void processRow(ResultSet rs) throws SQLException {
PassiveStatusKey key = new PassiveStatusKey(rs.getString("nodeLabel"), rs.getString("ipAddr"), rs.getString("serviceName"));
m_statusTable.put(key, PollStatus.down());
}
};
querier.execute();
m_initialized = true;
}
use of org.opennms.core.utils.Querier in project opennms by OpenNMS.
the class MockDatabaseIT method testOutage.
public void testOutage() {
final MockService svc = m_network.getService(1, "192.168.1.1", "ICMP");
Event svcLostEvent = MockEventUtil.createNodeLostServiceEvent("TEST", svc);
m_db.writeEvent(svcLostEvent);
m_db.createOutage(svc, svcLostEvent);
assertEquals(1, m_db.countOutagesForService(svc));
Querier querier = new Querier(m_db, "select node.nodeid as nodeid, ipinterface.ipaddr as ipaddr, ifservices.serviceid as serviceid from outages, ifservices, ipinterface, node where outages.ifserviceid = ifservices.id and ifservices.ipinterfaceid = ipinterface.id and ipinterface.nodeid = node.nodeid") {
@Override
public void processRow(ResultSet rs) throws SQLException {
int nodeId = rs.getInt("nodeId");
String ipAddr = rs.getString("ipAddr");
int serviceId = rs.getInt("serviceId");
assertEquals(nodeId, svc.getNodeId());
assertEquals(ipAddr, svc.getIpAddr());
assertEquals(serviceId, svc.getSvcId());
}
};
querier.execute();
assertEquals(1, querier.getCount());
}
use of org.opennms.core.utils.Querier in project opennms by OpenNMS.
the class MockDatabaseIT method testNodeQuery.
public void testNodeQuery() {
Querier querier = new Querier(m_db, "select * from node") {
@Override
public void processRow(ResultSet rs) throws SQLException {
int nodeId = rs.getInt("nodeId");
String label = rs.getString("nodeLabel");
MockNode node = m_network.getNode(nodeId);
assertNotNull(node);
assertEquals(nodeId, node.getNodeId());
assertEquals(label, node.getLabel());
}
};
querier.execute();
assertEquals(m_network.getNodeCount(), querier.getCount());
}
use of org.opennms.core.utils.Querier in project opennms by OpenNMS.
the class MockDatabaseIT method testServiceQuery.
public void testServiceQuery() {
Querier querier = new Querier(m_db, "select node.nodeid as nodeId, ipinterface.ipaddr as ipAddr, ifServices.status as status, ifServices.serviceId as serviceId, service.serviceName as serviceName from ifServices, ipinterface, node, service where ifServices.serviceId = service.serviceId and ipinterface.id = ifServices.ipInterfaceId and node.nodeid = ipinterface.nodeid;") {
@Override
public void processRow(ResultSet rs) throws SQLException {
int nodeId = rs.getInt("nodeId");
String ipAddr = rs.getString("ipAddr");
int serviceId = rs.getInt("serviceId");
String serviceName = rs.getString("serviceName");
String status = rs.getString("status");
MockService svc = m_network.getService(nodeId, ipAddr, serviceName);
assertNotNull(svc);
assertEquals("Assertion failed: " + svc, svc.getNodeId(), nodeId);
assertEquals("Assertion failed: " + svc, svc.getIpAddr(), ipAddr);
assertEquals("Assertion failed: " + svc, svc.getSvcName(), serviceName);
assertEquals("Assertion failed: " + svc, svc.getSvcId(), serviceId);
assertEquals("Assertion failed: " + svc, svc.getMgmtStatus().toDbString(), status);
}
};
querier.execute();
assertEquals(m_network.getServiceCount(), querier.getCount());
}
Aggregations