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));
}
}
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);
}
}
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();
}
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);
}
}
}
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);
}
}
}
}
Aggregations