use of org.opennms.netmgt.mock.MockService 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());
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollablesIT method anticipateUnresponsive.
private void anticipateUnresponsive(MockElement element) {
MockVisitor visitor = new MockVisitorAdapter() {
@Override
public void visitService(MockService svc) {
m_eventMgr.getEventAnticipator().anticipateEvent(svc.createUnresponsiveEvent());
}
};
element.visit(visitor);
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollablesIT method testAddDownServiceToUpNode.
private void testAddDownServiceToUpNode(int nodeId, String nodeLabel, String nodeLocation, String ipAddr, String existingSvcName, String newSvcName) {
PollableService pExistingSvc = m_network.getService(nodeId, getInetAddress(ipAddr), existingSvcName);
PollableInterface pIface = pExistingSvc.getInterface();
PollableNode pNode = pExistingSvc.getNode();
// first we cause a poll for the up node just be make sure everythings working
pExistingSvc.doPoll();
m_network.processStatusChange(new Date());
verifyAnticipated();
// no we add the mock serve
MockService mSvc = m_mockNetwork.addService(nodeId, ipAddr, newSvcName);
m_db.writeService(mSvc);
// bring down the service
mSvc.bringDown();
// expect a nodeLostService event
anticipateDown(mSvc);
// add the service to the PollableNetowrk (simulates nodeGainedService event)
PollableService pSvc = addServiceToNetwork(nodeId, nodeLabel, nodeLocation, ipAddr, newSvcName);
assertNotNull(pSvc);
// before the first call nothing has a cause
assertElementHasNullCause(pSvc);
assertElementHasNullCause(pExistingSvc);
assertElementHasNullCause(pIface);
assertElementHasNullCause(pNode);
// and everything is up
assertUp(pSvc);
assertUp(pExistingSvc);
assertUp(pIface);
assertUp(pNode);
// now poll
pSvc.doPoll();
// expect the svc to be down and everythign else up
assertDown(pSvc);
assertUp(pExistingSvc);
assertUp(pIface);
assertUp(pNode);
// no we send the events and update the causes
m_network.processStatusChange(new Date());
// only the svc has a cause
assertNotNull(pSvc.getCause());
assertElementHasNullCause(pExistingSvc);
assertElementHasNullCause(pIface);
assertElementHasNullCause(pNode);
verifyAnticipated();
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollablesIT method testAddUpSvcToUpNode.
private void testAddUpSvcToUpNode(int nodeId, String nodeLabel, String nodeLocation, String ipAddr, String existingSvcName, String newSvcName) {
PollableService pExistingSvc = m_network.getService(nodeId, getInetAddress(ipAddr), existingSvcName);
assertNotNull(pExistingSvc);
PollableInterface pIface = pExistingSvc.getInterface();
PollableNode pNode = pIface.getNode();
pExistingSvc.doPoll();
m_network.processStatusChange(new Date());
verifyAnticipated();
MockService mSvc = m_mockNetwork.addService(nodeId, ipAddr, newSvcName);
m_db.writeService(mSvc);
PollableService pSvc = addServiceToNetwork(nodeId, nodeLabel, nodeLocation, ipAddr, newSvcName);
assertNotNull(pSvc);
assertElementHasNullCause(pSvc);
assertElementHasNullCause(pExistingSvc);
assertElementHasNullCause(pIface);
assertElementHasNullCause(pNode);
assertUp(pSvc);
assertUp(pExistingSvc);
assertUp(pIface);
assertUp(pNode);
anticipateDown(mSvc);
mSvc.bringDown();
pSvc.doPoll();
m_network.processStatusChange(new Date());
verifyAnticipated();
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class MockPollContext method closeOutage.
public void closeOutage(PollableService pSvc, PollEvent svcRegainEvent) {
MockService mSvc = m_mockNetwork.getService(pSvc.getNodeId(), pSvc.getIpAddr(), pSvc.getSvcName());
Timestamp eventTime = new Timestamp(svcRegainEvent.getDate().getTime());
MockUtil.println("Resolving Outage for " + mSvc);
m_db.resolveOutage(mSvc, svcRegainEvent.getEventId(), eventTime);
}
Aggregations