use of org.opennms.netmgt.model.OnmsApplication in project opennms by OpenNMS.
the class LocationDataManagerTest method testGetApplicationInfo.
@Test
public void testGetApplicationInfo() {
String appName = "Domain Controllers";
OnmsApplication app = m_applicationDao.findByName(appName);
System.err.println("TEST testGetApplicationInfo: calling getApplicationInfo");
m_locationDataService.getApplicationInfo(app, new StatusDetails());
}
use of org.opennms.netmgt.model.OnmsApplication 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.OnmsApplication in project opennms by OpenNMS.
the class OutageRestServiceIT method setUp.
@Before
@Override
public void setUp() throws Throwable {
super.setUp();
Assert.assertNotNull(populator);
Assert.assertNotNull(applicationDao);
populator.addExtension(new DatabasePopulator.Extension<ApplicationDao>() {
private OnmsOutage unresolvedOutage;
private OnmsEvent outageEvent;
private OnmsApplication application;
@Override
public DatabasePopulator.DaoSupport<ApplicationDao> getDaoSupport() {
return new DatabasePopulator.DaoSupport<>(ApplicationDao.class, applicationDao);
}
@Override
public void onPopulate(DatabasePopulator populator, ApplicationDao dao) {
OnmsDistPoller distPoller = populator.getDistPollerDao().whoami();
outageEvent = populator.buildEvent(distPoller);
outageEvent.setEventSeverity(OnmsSeverity.MINOR.getId());
outageEvent.setEventCreateTime(new Date(1436881548292L));
outageEvent.setEventTime(new Date(1436881548292L));
populator.getEventDao().save(outageEvent);
populator.getEventDao().flush();
// create the application
application = new OnmsApplication();
application.setName("Awesome Application");
dao.save(application);
// get the SNMP service from node 1 and assign the application to it
final OnmsMonitoredService svc = populator.getMonitoredServiceDao().get(populator.getNode1().getId(), InetAddressUtils.addr("192.168.1.2"), "HTTP");
svc.addApplication(application);
application.addMonitoredService(svc);
populator.getMonitoredServiceDao().saveOrUpdate(svc);
populator.getMonitoredServiceDao().flush();
// create a unresolved outage
unresolvedOutage = new OnmsOutage(new Date(1436881548292L), outageEvent, svc);
populator.getOutageDao().save(unresolvedOutage);
populator.getOutageDao().flush();
}
@Override
public void onShutdown(DatabasePopulator populator, ApplicationDao dao) {
// Delete OnmsApplications
for (OnmsApplication application : dao.findAll()) {
dao.delete(application);
}
}
});
populator.populateDatabase();
}
use of org.opennms.netmgt.model.OnmsApplication in project opennms by OpenNMS.
the class StatusRestService method getApplications.
@GET
@Path("/applications")
public Response getApplications(@Context final UriInfo uriInfo) {
final QueryParameters queryParameters = QueryParametersBuilder.buildFrom(uriInfo);
final SeverityFilter severityFilter = getSeverityFilter(uriInfo);
final Query query = new Query(queryParameters, severityFilter);
final List<StatusEntity<OnmsApplication>> applications = applicationStatusService.getStatus(query);
final int totalCount = applicationStatusService.count(query);
final int offset = queryParameters.getOffset();
final List<ApplicationDTO> statusEntities = applications.stream().map(a -> {
ApplicationDTO dto = new ApplicationDTO();
dto.setId(a.getEntity().getId());
dto.setName(a.getEntity().getName());
dto.setSeverity(a.getStatus());
return dto;
}).collect(Collectors.toList());
final ApplicationDTOList list = new ApplicationDTOList(statusEntities);
list.setOffset(queryParameters.getOffset());
list.setTotalCount(totalCount);
return createResponse(list, offset, totalCount);
}
use of org.opennms.netmgt.model.OnmsApplication in project opennms by OpenNMS.
the class ApplicationDaoHibernate method getApplicationStatus.
@Override
public List<ApplicationStatus> getApplicationStatus(List<OnmsApplication> applications) {
// Applications do not have a alarm mapping, so we grab all nodeDown, interfaceDown and serviceLost alarms
// for all monitored services of each application to calculate the maximum severity (-> status)
final List<ApplicationStatus> statusList = new ArrayList<>();
for (OnmsApplication application : applications) {
final Set<String> reductionKeys = new HashSet<>();
for (OnmsMonitoredService eachService : application.getMonitoredServices()) {
reductionKeys.addAll(ReductionKeyHelper.getReductionKeys(eachService));
}
if (!reductionKeys.isEmpty()) {
final CriteriaBuilder builder = new CriteriaBuilder(OnmsAlarm.class);
builder.in("reductionKey", reductionKeys);
// findMatching would exepct OnmsApplications, but we need OnmsAlarms, so hack it
HibernateCallback<List<OnmsAlarm>> callback = buildHibernateCallback(builder.toCriteria());
List<OnmsAlarm> alarms = getHibernateTemplate().execute(callback);
// All alarms for the current application have been determined, now get the max severity
final Optional<OnmsAlarm> maxSeverity = alarms.stream().reduce((leftAlarm, rightAlarm) -> {
if (leftAlarm.getSeverity().isGreaterThan(rightAlarm.getSeverity())) {
return leftAlarm;
}
return rightAlarm;
});
if (maxSeverity.isPresent()) {
statusList.add(new ApplicationStatus(application, maxSeverity.get().getSeverity()));
} else {
// ensure that each application has a status
statusList.add(new ApplicationStatus(application, OnmsSeverity.NORMAL));
}
} else {
// ensure that each application has a status
statusList.add(new ApplicationStatus(application, OnmsSeverity.NORMAL));
}
}
return statusList;
}
Aggregations