Search in sources :

Example 61 with OnmsMonitoredService

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);
}
Also used : AvailCalculator(org.opennms.web.rest.v1.AvailCalculator) TimeChunker(org.opennms.web.rest.v1.support.TimeChunker) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test)

Example 62 with OnmsMonitoredService

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;
        }
    };
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Callable(java.util.concurrent.Callable) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 63 with OnmsMonitoredService

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());
}
Also used : BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 64 with OnmsMonitoredService

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());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 65 with OnmsMonitoredService

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;
}
Also used : OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Aggregations

OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)119 Date (java.util.Date)37 OnmsNode (org.opennms.netmgt.model.OnmsNode)36 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)33 Test (org.junit.Test)27 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)25 Transactional (org.springframework.transaction.annotation.Transactional)22 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)20 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)18 ArrayList (java.util.ArrayList)17 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)17 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)15 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)15 LinkedList (java.util.LinkedList)13 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)13 HashSet (java.util.HashSet)9 Before (org.junit.Before)6 Criteria (org.opennms.core.criteria.Criteria)5 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)5 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)5