use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class AvailCalculatorTest method testGetAvailabilityUnavailableBefore.
@Test
public void testGetAvailabilityUnavailableBefore() {
Date endTime = new Date(System.currentTimeMillis());
Date startTime = new Date(endTime.getTime() - 100);
TimeChunker chunker = new TimeChunker((int) (endTime.getTime() - startTime.getTime()), startTime, endTime);
AvailCalculator calculator = new AvailCalculator(chunker);
calculator.onStatusChange(createStatusChange(PollStatus.unavailable(), new Date(endTime.getTime() - 150)));
calculator.onStatusChange(createStatusChange(PollStatus.available(), new Date(endTime.getTime() - 50)));
Collection<OnmsMonitoredService> svcs = getServices();
double uptimePercent = calculator.getAvailabilityFor(svcs, 0);
assertEquals(0.5, uptimePercent, 0.00);
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class DetectorsOnMinionIT method getnumberOfServicesDetected.
public static Callable<Integer> getnumberOfServicesDetected(RestClient client) {
return new Callable<Integer>() {
public Integer call() throws Exception {
List<OnmsNode> nodes = client.getNodes();
Integer number = null;
if (Iterables.any(nodes, (node) -> "foreignSource".equals(node.getForeignSource()))) {
List<OnmsMonitoredService> services = client.getServicesForANode("foreignSource:foreignId", LOCALHOST);
if (!CollectionUtils.isEmpty(services)) {
number = services.size();
LOG.info("The services detected are \n");
for (OnmsMonitoredService service : services) {
LOG.info(" {} ", service.getServiceName());
}
}
}
return number;
}
};
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class BusinessServiceDaoIT method canCreateReadUpdateAndDeleteBusinessServices.
@Test
@Transactional
public void canCreateReadUpdateAndDeleteBusinessServices() {
final int ifServiceCount = m_monitoredServiceDao.countAll();
// Initially there should be no business services
assertEquals(0, m_businessServiceDao.countAll());
// Create a business service
BusinessServiceEntity bs = new BusinessServiceEntityBuilder().name("Web Servers").addAttribute("dc", "RDU").addReductionKey("TestReductionKeyA", new IdentityEntity()).addReductionKey("TestReductionKeyB", new IdentityEntity()).reduceFunction(m_highestSeverity).toEntity();
m_businessServiceDao.save(bs);
m_businessServiceDao.flush();
// Read a business service
assertEquals(bs, m_businessServiceDao.get(bs.getId()));
assertEquals(2, m_businessServiceDao.get(bs.getId()).getReductionKeyEdges().size());
// Update a business service
bs.setName("Application Servers");
bs.getAttributes().put("dc", "!RDU");
bs.getAttributes().put("cd", "/");
// Grab the first monitored service from node 1
OnmsMonitoredService ipService = m_databasePopulator.getNode1().getIpInterfaces().iterator().next().getMonitoredServices().iterator().next();
bs.addIpServiceEdge(ipService, m_ignore);
m_businessServiceDao.update(bs);
m_businessServiceDao.flush();
// Verify the update
assertEquals(bs, m_businessServiceDao.get(bs.getId()));
// Delete
m_businessServiceDao.delete(bs);
m_businessServiceDao.flush();
// There should be no business services after the delete
assertEquals(0, m_businessServiceDao.countAll());
// No if service should have been deleted
assertEquals(ifServiceCount, m_monitoredServiceDao.countAll());
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class BusinessServiceDaoIT method verifyBusinessServicesWithRelatedIpServicesAreDeletedOnCascade.
@Test
@Transactional
public void verifyBusinessServicesWithRelatedIpServicesAreDeletedOnCascade() throws InterruptedException {
// Initially there should be no business services
assertEquals("Check that there are no initial BusinessServices", 0, m_businessServiceDao.countAll());
// Create a business service with an associated IP Service
final BusinessServiceEntity bs = new BusinessServiceEntity();
bs.setName("Mont Cascades");
bs.setReductionFunction(m_highestSeverity);
final OnmsNode node = m_databasePopulator.getNode1();
final OnmsMonitoredService ipService = getMonitoredServiceFromNode1();
bs.addIpServiceEdge(ipService, m_ignore);
m_businessServiceDao.save(bs);
m_businessServiceDao.flush();
// We should have a single business service with a single IP service associated
assertEquals(1, m_businessServiceDao.countAll());
assertEquals(1, m_businessServiceDao.get(bs.getId()).getIpServiceEdges().size());
assertNotNull(m_monitoredServiceDao.get(ipService.getId()));
// Now delete the node
m_nodeDao.delete(node);
m_nodeDao.flush();
// The business service should still be present, but the IP service should have been deleted by the foreign
// key constraint. We have to clear the session, otherwise hibernate does not know about the node deletion
m_businessServiceDao.clear();
assertEquals(1, m_businessServiceDao.countAll());
assertEquals(0, m_businessServiceDao.get(bs.getId()).getIpServiceEdges().size());
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class LocationDataServiceIT method createService.
private OnmsMonitoredService createService(OnmsApplication app, OnmsIpInterface localhostIpInterface, OnmsServiceType httpServiceType) {
OnmsMonitoredService service = new OnmsMonitoredService();
service.addApplication(app);
app.addMonitoredService(service);
service.setIpInterface(localhostIpInterface);
service.setLastFail(m_pollingEnd);
service.setLastGood(m_pollingEnd);
service.setNotify("N");
service.setServiceType(httpServiceType);
service.setStatus("A");
service.setSource("P");
m_monitoredServiceDao.saveOrUpdate(service);
m_applicationDao.saveOrUpdate(app);
return service;
}
Aggregations