Search in sources :

Example 1 with DeleteEventVisitor

use of org.opennms.netmgt.model.events.DeleteEventVisitor in project opennms by OpenNMS.

the class OnmsIpInterface method mergeMonitoredServices.

/**
 * <p>mergeMonitoredServices</p>
 *
 * @param scannedIface a {@link org.opennms.netmgt.model.OnmsIpInterface} object.
 * @param eventForwarder a {@link org.opennms.netmgt.events.api.EventForwarder} object.
 * @param deleteMissing a boolean.
 */
public void mergeMonitoredServices(OnmsIpInterface scannedIface, EventForwarder eventForwarder, boolean deleteMissing) {
    // create map of services to serviceType
    Map<OnmsServiceType, OnmsMonitoredService> serviceTypeMap = new HashMap<OnmsServiceType, OnmsMonitoredService>();
    for (OnmsMonitoredService svc : scannedIface.getMonitoredServices()) {
        serviceTypeMap.put(svc.getServiceType(), svc);
    }
    // for each service in the database
    for (Iterator<OnmsMonitoredService> it = getMonitoredServices().iterator(); it.hasNext(); ) {
        OnmsMonitoredService svc = it.next();
        // find the corresponding scanned service
        OnmsMonitoredService imported = serviceTypeMap.get(svc.getServiceType());
        if (imported == null) {
            if (deleteMissing) {
                // there is no scanned service... delete it from the database
                it.remove();
                svc.visit(new DeleteEventVisitor(eventForwarder));
            }
        } else {
            // otherwice update the service attributes
            svc.mergeServiceAttributes(imported);
        }
        // mark the service is updated
        serviceTypeMap.remove(svc.getServiceType());
    }
    // for any services not found in the database, add them
    Collection<OnmsMonitoredService> newServices = serviceTypeMap.values();
    for (OnmsMonitoredService svc : newServices) {
        svc.setIpInterface(this);
        getMonitoredServices().add(svc);
        svc.visit(new AddEventVisitor(eventForwarder));
    }
}
Also used : AddEventVisitor(org.opennms.netmgt.model.events.AddEventVisitor) HashMap(java.util.HashMap) DeleteEventVisitor(org.opennms.netmgt.model.events.DeleteEventVisitor)

Example 2 with DeleteEventVisitor

use of org.opennms.netmgt.model.events.DeleteEventVisitor in project opennms by OpenNMS.

the class DefaultProvisionService method deleteNode.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public void deleteNode(final Integer nodeId) {
    LOG.debug("deleteNode: nodeId={}", nodeId);
    final OnmsNode node = m_nodeDao.get(nodeId);
    if (node != null) {
        final DeleteEventVisitor visitor = new DeleteEventVisitor(m_eventForwarder);
        m_nodeDao.delete(node);
        m_nodeDao.flush();
        node.visit(visitor);
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) DeleteEventVisitor(org.opennms.netmgt.model.events.DeleteEventVisitor) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with DeleteEventVisitor

use of org.opennms.netmgt.model.events.DeleteEventVisitor in project opennms by OpenNMS.

the class DefaultProvisionService method deleteObsoleteInterfaces.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public void deleteObsoleteInterfaces(final Integer nodeId, final Date scanStamp) {
    final List<OnmsIpInterface> obsoleteInterfaces = m_nodeDao.findObsoleteIpInterfaces(nodeId, scanStamp);
    final EventAccumulator accumulator = new EventAccumulator(m_eventForwarder);
    for (final OnmsIpInterface iface : obsoleteInterfaces) {
        iface.visit(new DeleteEventVisitor(accumulator));
    }
    m_nodeDao.deleteObsoleteInterfaces(nodeId, scanStamp);
    accumulator.flush();
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) DeleteEventVisitor(org.opennms.netmgt.model.events.DeleteEventVisitor) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with DeleteEventVisitor

use of org.opennms.netmgt.model.events.DeleteEventVisitor in project opennms by OpenNMS.

the class DefaultProvisionService method deleteInterface.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public void deleteInterface(final Integer nodeId, final String ipAddr) {
    LOG.debug("deleteInterface: nodeId={}, addr={}", nodeId, ipAddr);
    final OnmsIpInterface iface = m_ipInterfaceDao.findByNodeIdAndIpAddress(nodeId, ipAddr);
    if (iface != null) {
        final OnmsNode node = iface.getNode();
        final boolean lastInterface = (node.getIpInterfaces().size() == 1);
        final DeleteEventVisitor visitor = new DeleteEventVisitor(m_eventForwarder);
        m_ipInterfaceDao.delete(iface);
        m_ipInterfaceDao.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) DeleteEventVisitor(org.opennms.netmgt.model.events.DeleteEventVisitor) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with DeleteEventVisitor

use of org.opennms.netmgt.model.events.DeleteEventVisitor 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)

Aggregations

DeleteEventVisitor (org.opennms.netmgt.model.events.DeleteEventVisitor)6 Transactional (org.springframework.transaction.annotation.Transactional)4 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 HashMap (java.util.HashMap)2 AddEventVisitor (org.opennms.netmgt.model.events.AddEventVisitor)2 InetAddress (java.net.InetAddress)1 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)1 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)1