use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class LocationDataServiceIT method setUp.
@Before
public void setUp() throws Exception {
Properties p = new Properties();
p.setProperty("log4j.logger.org.hibernate", "INFO");
p.setProperty("log4j.logger.org.hibernate.SQL", "DEBUG");
MockLogAppender.setupLogging(p);
OnmsMonitoringLocation location = new OnmsMonitoringLocation("RDU", "East Coast", new String[] { "example1" }, new String[0], "Research Triangle Park, NC", 35.715751f, -79.16262f, 1L, "odd");
m_monitoringLocationDao.saveOrUpdate(location);
OnmsApplication app = new OnmsApplication();
app.setName("TestApp1");
m_applicationDao.saveOrUpdate(app);
OnmsNode localhostNode = new OnmsNode(location, "localhost");
m_nodeDao.saveOrUpdate(localhostNode);
OnmsNode googleNode = new OnmsNode(location, "google");
m_nodeDao.saveOrUpdate(googleNode);
OnmsIpInterface localhostIpInterface = new OnmsIpInterface(addr("127.0.0.1"), localhostNode);
m_ipInterfaceDao.saveOrUpdate(localhostIpInterface);
OnmsIpInterface googleIpInterface = new OnmsIpInterface(addr("66.249.80.104"), googleNode);
m_ipInterfaceDao.saveOrUpdate(googleIpInterface);
OnmsServiceType httpServiceType = new OnmsServiceType("HTTP");
m_serviceTypeDao.saveOrUpdate(httpServiceType);
m_localhostHttpService = createService(app, localhostIpInterface, httpServiceType);
m_googleHttpService = createService(app, googleIpInterface, httpServiceType);
m_rduMonitor1 = new OnmsLocationMonitor();
m_rduMonitor1.setId(UUID.randomUUID().toString());
m_rduMonitor1.setLocation("RDU");
m_rduMonitor1.setLastUpdated(m_pollingEnd);
m_rduMonitor1.setStatus(MonitorStatus.STARTED);
m_locationMonitorDao.saveOrUpdate(m_rduMonitor1);
m_rduMonitor2 = new OnmsLocationMonitor();
m_rduMonitor2.setId(UUID.randomUUID().toString());
m_rduMonitor2.setLocation("RDU");
m_rduMonitor2.setLastUpdated(m_pollingEnd);
m_rduMonitor2.setStatus(MonitorStatus.STARTED);
m_locationMonitorDao.saveOrUpdate(m_rduMonitor2);
m_applicationDao.flush();
m_distPollerDao.flush();
m_nodeDao.flush();
m_ipInterfaceDao.flush();
m_serviceTypeDao.flush();
m_monitoredServiceDao.flush();
m_locationMonitorDao.flush();
OnmsApplication onmsApp = m_applicationDao.findByName("TestApp1");
assertTrue(onmsApp.equals(app));
assertEquals("Count of applications associated with services is wrong", 1, m_localhostHttpService.getApplications().size());
assertEquals("Count of applications associated with services is wrong", 1, m_googleHttpService.getApplications().size());
assertEquals("Count of services associated with application is wrong", 2, app.getMonitoredServices().size());
m_pollingEnd = new Date();
m_pollingStart = new Date(m_pollingEnd.getTime() - (1000 * 60 * 60 * 24));
}
use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class AvailCalculatorTest method setUp.
@Before
public void setUp() {
m_locationMon = new OnmsLocationMonitor();
m_locationMon.setLocation("IPv6");
m_locationMon.setStatus(MonitorStatus.STARTED);
m_svc = new OnmsMonitoredService();
}
use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class PollerBackEndIT method testPollingStarted.
@Test
@Transactional
public void testPollingStarted() {
final String locationMonitorId = m_backEnd.registerLocationMonitor("RDU");
m_backEnd.pollerStarting(locationMonitorId, getPollerDetails());
final OnmsLocationMonitor monitor = m_locationMonitorDao.get(locationMonitorId);
assertNotNull(monitor);
final Map<String, String> details = monitor.getProperties();
assertNotNull(details);
assertEquals(MonitorStatus.STARTED, monitor.getStatus());
assertEquals(2, details.keySet().size());
assertEquals("WonkaOS", details.get("os.name"));
}
use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class DefaultPollerBackEnd method checkForDisconnectedMonitors.
/**
* <p>checkForDisconnectedMonitors</p>
*/
@Override
public void checkForDisconnectedMonitors() {
LOG.debug("Checking for disconnected monitors: disconnectedTimeout = {}", m_disconnectedTimeout);
try {
final Date now = m_timeKeeper.getCurrentDate();
final Date earliestAcceptable = new Date(now.getTime() - m_disconnectedTimeout);
final Criteria criteria = new Criteria(OnmsLocationMonitor.class);
criteria.addRestriction(new EqRestriction("status", MonitorStatus.STARTED));
criteria.addRestriction(new NotNullRestriction("lastUpdated"));
criteria.addRestriction(new LtRestriction("lastUpdated", earliestAcceptable));
// Lock all of the records for update since we will be marking them as DISCONNECTED
criteria.setLockType(LockType.PESSIMISTIC_READ);
final Collection<OnmsLocationMonitor> monitors = m_locMonDao.findMatching(criteria);
LOG.debug("Found {} monitor(s) that are transitioning to disconnected state", monitors.size());
for (final OnmsLocationMonitor monitor : monitors) {
LOG.debug("Monitor {} has stopped responding", monitor.getName());
monitor.setStatus(MonitorStatus.DISCONNECTED);
m_locMonDao.update(monitor);
sendDisconnectedEvent(monitor);
}
} catch (final Throwable e) {
LOG.warn("An error occurred checking for disconnected monitors.", e);
}
}
use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class PollerBackEndTest method testTimeOutOnCheckin.
public void testTimeOutOnCheckin() {
final Date now = new Date();
m_locationMonitor.setStatus(MonitorStatus.STARTED);
m_locationMonitor.setLastUpdated(new Date(now.getTime() - DISCONNECTED_TIMEOUT - 100));
expect(m_locMonDao.findMatching(EasyMock.anyObject(Criteria.class))).andReturn(Collections.singletonList(m_locationMonitor));
expect(m_timeKeeper.getCurrentDate()).andReturn(now);
anticipateDisconnectedEvent();
m_locMonDao.update(m_locationMonitor);
expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
OnmsLocationMonitor mon = (OnmsLocationMonitor) getCurrentArguments()[0];
assertEquals(MonitorStatus.DISCONNECTED, mon.getStatus());
assertTrue(mon.getLastUpdated().before(new Date(now.getTime() - DISCONNECTED_TIMEOUT)));
return null;
}
});
m_mocks.replayAll();
m_backEnd.checkForDisconnectedMonitors();
}
Aggregations