Search in sources :

Example 96 with OnmsMonitoredService

use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.

the class DefaultLocationDataService method getStatusDetailsForApplicationOld.

/**
 * <p>getStatusDetailsForApplicationOld</p>
 *
 * @param app a {@link org.opennms.netmgt.model.OnmsApplication} object.
 * @return a {@link org.opennms.features.poller.remote.gwt.client.StatusDetails} object.
 */
@Transactional
public StatusDetails getStatusDetailsForApplicationOld(final OnmsApplication app) {
    waitForGeocoding("getStatusDetailsForApplication");
    List<GWTLocationSpecificStatus> statuses = new ArrayList<GWTLocationSpecificStatus>();
    final Date to = new Date();
    final Date from = new Date(to.getTime() - AVAILABILITY_MS);
    final Collection<OnmsMonitoredService> services = m_monitoredServiceDao.findByApplication(app);
    final List<GWTLocationMonitor> monitors = new ArrayList<GWTLocationMonitor>();
    final Set<GWTMonitoredService> gwtServices = new LinkedHashSet<GWTMonitoredService>(services.size());
    for (final OnmsMonitoredService service : services) {
        gwtServices.add(transformMonitoredService(service));
    }
    for (final OnmsLocationMonitor monitor : m_locationDao.findByApplication(app)) {
        monitors.add(transformLocationMonitor(monitor));
        for (final OnmsLocationSpecificStatus locationSpecificStatus : m_locationDao.getStatusChangesForLocationBetween(from, to, monitor.getLocation())) {
            if (services.contains(locationSpecificStatus.getMonitoredService())) {
                statuses.add(transformLocationSpecificStatus(locationSpecificStatus));
            }
        }
    }
    StatusDetails statusDetails = new AppStatusDetailsComputer(from, to, monitors, gwtServices, statuses).compute();
    LOG.warn("getStatusDetailsForApplication({}) returning {}", app.getName(), statusDetails);
    return statusDetails;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) ArrayList(java.util.ArrayList) GWTLocationMonitor(org.opennms.features.poller.remote.gwt.client.GWTLocationMonitor) GWTMonitoredService(org.opennms.features.poller.remote.gwt.client.GWTMonitoredService) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) AppStatusDetailsComputer(org.opennms.features.poller.remote.gwt.client.AppStatusDetailsComputer) GWTLocationSpecificStatus(org.opennms.features.poller.remote.gwt.client.GWTLocationSpecificStatus) StatusDetails(org.opennms.features.poller.remote.gwt.client.StatusDetails) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Transactional(org.springframework.transaction.annotation.Transactional)

Example 97 with OnmsMonitoredService

use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.

the class DefaultSurveillanceViewService method getNodeListForCriteria.

/**
 * Returns a list of node RTC calculations for the given criterias.
 *
 * @param serviceCriteria the service criteria
 * @param outageCriteria  the outage criteries
 * @return the list of {@link org.opennms.features.vaadin.surveillanceviews.service.SurveillanceViewService.NodeRtc} instances
 */
private List<NodeRtc> getNodeListForCriteria(final Criteria serviceCriteria, final Criteria outageCriteria) {
    List<Order> ordersService = new ArrayList<>();
    ordersService.add(Order.asc("node.label"));
    ordersService.add(Order.asc("node.id"));
    ordersService.add(Order.asc("ipInterface.ipAddress"));
    ordersService.add(Order.asc("serviceType.name"));
    serviceCriteria.setOrders(ordersService);
    Date periodEnd = new Date(System.currentTimeMillis());
    Date periodStart = new Date(periodEnd.getTime() - (24 * 60 * 60 * 1000));
    outageCriteria.addRestriction(Restrictions.any(Restrictions.isNull("ifRegainedService"), Restrictions.ge("ifLostService", periodStart), Restrictions.ge("ifRegainedService", periodStart)));
    List<Order> ordersOutage = new ArrayList<>();
    ordersOutage.add(Order.asc("monitoredService"));
    ordersOutage.add(Order.asc("ifLostService"));
    outageCriteria.setOrders(ordersOutage);
    List<OnmsMonitoredService> services = m_monitoredServiceDao.findMatching(serviceCriteria);
    List<OnmsOutage> outages = m_outageDao.findMatching(outageCriteria);
    Map<OnmsMonitoredService, Long> serviceDownTime = calculateServiceDownTime(periodEnd, periodStart, outages);
    List<NodeRtc> model = new ArrayList<>();
    OnmsNode lastNode = null;
    int serviceCount = 0;
    int serviceDownCount = 0;
    long downMillisCount = 0;
    for (OnmsMonitoredService service : services) {
        if (!service.getIpInterface().getNode().equals(lastNode) && lastNode != null) {
            Double availability = calculateAvailability(serviceCount, downMillisCount);
            model.add(new NodeRtc(lastNode, serviceCount, serviceDownCount, availability));
            serviceCount = 0;
            serviceDownCount = 0;
            downMillisCount = 0;
        }
        serviceCount++;
        if (service.isDown()) {
            serviceDownCount++;
        }
        Long downMillis = serviceDownTime.get(service);
        if (downMillis != null) {
            downMillisCount += downMillis;
        }
        lastNode = service.getIpInterface().getNode();
    }
    if (lastNode != null) {
        Double availability = calculateAvailability(serviceCount, downMillisCount);
        model.add(new NodeRtc(lastNode, serviceCount, serviceDownCount, availability));
    }
    return model;
}
Also used : Order(org.opennms.core.criteria.Order) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) ArrayList(java.util.ArrayList) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 98 with OnmsMonitoredService

use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.

the class PathOutageStatusProviderIT method createService.

/**
 * This method creates a service for a given node
 * @param node Node
 * @return Resulting service
 */
private OnmsMonitoredService createService(OnmsNode node) {
    OnmsMonitoredService monitoredService = new OnmsMonitoredService();
    OnmsServiceType serviceType = createType("someType");
    serviceTypeDao.save(serviceType);
    monitoredService.setServiceType(serviceType);
    monitoredService.setIpInterface(node.getIpInterfaces().toArray(new OnmsIpInterface[node.getIpInterfaces().size()])[0]);
    return monitoredService;
}
Also used : OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 99 with OnmsMonitoredService

use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.

the class DefaultProvisionService method deleteService.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public void deleteService(final Integer nodeId, final InetAddress addr, final String svcName) {
    LOG.debug("deleteService: nodeId={}, addr={}, service={}", nodeId, addr, svcName);
    final OnmsMonitoredService service = m_monitoredServiceDao.get(nodeId, addr, svcName);
    if (service != null) {
        final OnmsIpInterface iface = service.getIpInterface();
        final OnmsNode node = iface.getNode();
        final boolean lastService = (iface.getMonitoredServices().size() == 1);
        final boolean lastInterface = (node.getIpInterfaces().size() == 1);
        final DeleteEventVisitor visitor = new DeleteEventVisitor(m_eventForwarder);
        iface.removeMonitoredService(service);
        m_nodeDao.saveOrUpdate(node);
        m_nodeDao.flush();
        service.visit(visitor);
        if (lastService) {
            LOG.debug("Deleting interface {} from node {}", InetAddressUtils.str(iface.getIpAddress()), nodeId);
            node.removeIpInterface(iface);
            m_nodeDao.saveOrUpdate(node);
            m_nodeDao.flush();
            iface.visit(visitor);
            if (lastInterface) {
                LOG.debug("Deleting node {}", nodeId);
                m_nodeDao.delete(node);
                m_nodeDao.flush();
                node.visit(visitor);
            }
        }
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) DeleteEventVisitor(org.opennms.netmgt.model.events.DeleteEventVisitor) Transactional(org.springframework.transaction.annotation.Transactional)

Example 100 with OnmsMonitoredService

use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.

the class SaveOrUpdateOperation method foundMonitoredService.

/**
 * <p>foundMonitoredService</p>
 *
 * @param serviceName a {@link java.lang.String} object.
 */
public void foundMonitoredService(String serviceName) {
    // current interface may be null if it has no ipaddr
    if (m_currentInterface != null) {
        OnmsServiceType svcType = getProvisionService().createServiceTypeIfNecessary(serviceName);
        OnmsMonitoredService service = new OnmsMonitoredService(m_currentInterface, svcType);
        service.setStatus("A");
        m_currentInterface.getMonitoredServices().add(service);
    }
}
Also used : OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) 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