use of org.opennms.netmgt.model.OnmsServiceType in project opennms by OpenNMS.
the class MockMonitoredServiceDao method updateSubObjects.
private void updateSubObjects(final OnmsMonitoredService svc) {
final OnmsServiceType serviceType = svc.getServiceType();
final OnmsServiceType existingServiceType = getServiceTypeDao().findByName(serviceType.getName());
if (existingServiceType != null && existingServiceType.getId() != serviceType.getId()) {
svc.setServiceType(existingServiceType);
}
getServiceTypeDao().saveOrUpdate(svc.getServiceType());
}
use of org.opennms.netmgt.model.OnmsServiceType in project opennms by OpenNMS.
the class AvailabilityDatabasePopulator method getServiceType.
private OnmsServiceType getServiceType(String name) {
OnmsServiceType serviceType = getServiceTypeDao().findByName(name);
if (serviceType == null) {
serviceType = new OnmsServiceType(name);
getServiceTypeDao().save(serviceType);
getServiceTypeDao().flush();
}
return serviceType;
}
use of org.opennms.netmgt.model.OnmsServiceType in project opennms by OpenNMS.
the class DatabasePopulator method doResetDatabase.
private void doResetDatabase() {
LOG.debug("==== DatabasePopulator Reset ====");
for (final OnmsOutage outage : m_outageDao.findAll()) {
m_outageDao.delete(outage);
}
for (final OnmsUserNotification not : m_userNotificationDao.findAll()) {
m_userNotificationDao.delete(not);
}
for (final OnmsNotification not : m_notificationDao.findAll()) {
m_notificationDao.delete(not);
}
for (final OnmsAlarm alarm : m_alarmDao.findAll()) {
m_alarmDao.delete(alarm);
}
for (final OnmsEvent event : m_eventDao.findAll()) {
m_eventDao.delete(event);
}
for (final OnmsSnmpInterface snmpIface : m_snmpInterfaceDao.findAll()) {
for (OnmsIpInterface eachIf : snmpIface.getIpInterfaces()) {
eachIf.setSnmpInterface(null);
snmpIface.getNode().getIpInterfaces().remove(eachIf);
}
snmpIface.getNode().getSnmpInterfaces().remove(snmpIface);
m_snmpInterfaceDao.delete(snmpIface);
}
for (final OnmsIpInterface iface : m_ipInterfaceDao.findAll()) {
iface.setSnmpInterface(null);
iface.getNode().getIpInterfaces().remove(iface);
m_ipInterfaceDao.delete(iface);
}
for (final OnmsNode node : m_nodeDao.findAll()) {
m_nodeDao.delete(node);
}
for (final OnmsServiceType service : m_serviceTypeDao.findAll()) {
m_serviceTypeDao.delete(service);
}
for (final OnmsMonitoringLocation location : m_monitoringLocationDao.findAll()) {
// Don't delete the default localhost monitoring location
if (!MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID.equals(location.getLocationName())) {
m_monitoringLocationDao.delete(location);
}
}
for (final OnmsCategory category : m_categoryDao.findAll()) {
m_categoryDao.delete(category);
}
LOG.debug("= DatabasePopulatorExtension Reset Starting =");
for (Extension eachExtension : extensions) {
DaoSupport daoSupport = eachExtension.getDaoSupport();
OnmsDao<?, ?> dao = daoSupport != null && daoSupport.getDaoClass() != null ? lookupDao(daoSupport.getDaoClass()) : null;
eachExtension.onShutdown(this, dao);
if (dao != null) {
dao.flush();
}
}
LOG.debug("= DatabasePopulatorExtension Reset Finished =");
m_outageDao.flush();
m_userNotificationDao.flush();
m_notificationDao.flush();
m_alarmDao.flush();
m_eventDao.flush();
m_snmpInterfaceDao.flush();
m_ipInterfaceDao.flush();
m_nodeDao.flush();
m_serviceTypeDao.flush();
LOG.debug("==== DatabasePopulator Reset Finished ====");
}
use of org.opennms.netmgt.model.OnmsServiceType in project opennms by OpenNMS.
the class PollerServiceTest method testPoll.
public void testPoll() throws EventProxyException {
final int expectedPolldId = 7;
OnmsServiceType svcType = new OnmsServiceType();
svcType.setId(3);
svcType.setName("HTTP");
OnmsNode node = new OnmsNode();
node.setId(1);
OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
iface.setSnmpInterface(snmpIface);
final OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
m_eventProxy.send(isA(Event.class));
expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
Event event = (Event) getCurrentArguments()[0];
assertEquals("Incorrect uei for demandPollService event", EventConstants.DEMAND_POLL_SERVICE_EVENT_UEI, event.getUei());
assertEquals("Incorrect nodeid for demandPollService event", monSvc.getNodeId().longValue(), event.getNodeid().longValue());
assertEquals("Incorrect ipadr for demandPollService event", InetAddressUtils.str(monSvc.getIpAddress()), event.getInterface());
assertEquals("Incorrect ifIndex for demandPollService event", monSvc.getIfIndex(), Integer.valueOf(event.getIfIndex()));
assertEquals("Incorrect service for demandPollService event", monSvc.getServiceType().getName(), event.getService());
EventUtils.requireParm(event, EventConstants.PARM_DEMAND_POLL_ID);
assertEquals(expectedPolldId, EventUtils.getIntParm(event, EventConstants.PARM_DEMAND_POLL_ID, -1));
return null;
}
});
replay(m_eventProxy);
m_pollerService.poll(monSvc, expectedPolldId);
verify(m_eventProxy);
}
use of org.opennms.netmgt.model.OnmsServiceType in project opennms by OpenNMS.
the class PollerBackEndIT method testReportResults.
@Test
@Transactional
public void testReportResults() throws InterruptedException {
final OnmsNode node = new OnmsNode(m_monitoringLocationDao.getDefaultLocation(), "foo");
final OnmsIpInterface iface = new OnmsIpInterface(InetAddressUtils.addr("192.168.1.1"), node);
OnmsServiceType serviceType = m_serviceTypeDao.findByName("HTTP");
if (serviceType == null) {
serviceType = new OnmsServiceType("HTTP");
m_serviceTypeDao.save(serviceType);
m_serviceTypeDao.flush();
}
final OnmsMonitoredService service = new OnmsMonitoredService(iface, serviceType);
iface.setMonitoredServices(Collections.singleton(service));
m_nodeDao.save(node);
m_nodeDao.flush();
final String locationMonitorId = m_backEnd.registerLocationMonitor("RDU");
final int serviceId = service.getId();
// make sure there is no rrd data
final File rrdFile = new File("target/test-data/distributed/" + locationMonitorId + "/" + InetAddressUtils.str(iface.getIpAddress()) + "/http" + m_rrdStrategy.getDefaultFileExtension());
if (rrdFile.exists()) {
rrdFile.delete();
}
assertFalse(rrdFile.exists());
m_backEnd.reportResult(locationMonitorId, serviceId, PollStatus.available(1234.0));
Thread.sleep(1000);
m_backEnd.reportResult(locationMonitorId, serviceId, PollStatus.unavailable());
final Collection<OnmsLocationSpecificStatus> statuses = m_locationMonitorDao.getStatusChangesForLocationBetween(new Date(0L), new Date(), "RDU");
assertEquals(2, statuses.size());
final Iterator<OnmsLocationSpecificStatus> statusIterator = statuses.iterator();
final OnmsLocationSpecificStatus status1 = statusIterator.next();
final OnmsLocationSpecificStatus status2 = statusIterator.next();
assertEquals(Double.valueOf(1234D), status1.getPollResult().getResponseTime());
assertNull(status2.getPollResult().getResponseTime());
assertTrue("rrd file doesn't exist at " + rrdFile.getAbsolutePath(), rrdFile.exists());
}
Aggregations