use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class EnLinkdElementFactory method convertFromModel.
@Transactional
@SuppressWarnings("deprecation")
private BridgeLinkNode convertFromModel(int nodeid, SharedSegment segment) {
final BridgeLinkNode linknode = new BridgeLinkNode();
for (BridgePort link : segment.getBridgePortsOnSegment()) {
final Integer rempnodeId = link.getNode().getId();
final Integer rembridgePortIfIndex = link.getBridgePortIfIndex();
final OnmsSnmpInterface remiface = rembridgePortIfIndex == null ? null : m_snmpInterfaceDao.findByNodeIdAndIfIndex(rempnodeId, rembridgePortIfIndex);
if (link.getNode().getId().intValue() == nodeid) {
if (remiface != null) {
linknode.setNodeLocalPort(getPortString(rembridgePortIfIndex, remiface.getIfName(), remiface.getIfAlias()));
} else {
linknode.setNodeLocalPort(getPortString(rembridgePortIfIndex, null, null));
}
linknode.setBridgeLocalVlan(link.getVlan());
continue;
}
final BridgeLinkRemoteNode remlinknode = new BridgeLinkRemoteNode();
remlinknode.setBridgeRemoteNode(link.getNode().getLabel());
remlinknode.setBridgeRemoteUrl(getNodeUrl(rempnodeId));
if (remiface != null) {
remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, remiface.getIfName(), remiface.getIfAlias()));
} else {
remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, null, null));
}
remlinknode.setBridgeRemotePortUrl(getSnmpInterfaceUrl(rempnodeId, rembridgePortIfIndex));
remlinknode.setBridgeRemoteVlan(link.getVlan());
linknode.getBridgeLinkRemoteNodes().add(remlinknode);
}
if (segment.getBridgeBridgeLinks().isEmpty()) {
for (BridgeMacLink link : segment.getBridgeMacLinks()) {
if (link.getNode().getId().intValue() == nodeid) {
linknode.setBridgeLinkCreateTime(Util.formatDateToUIString(link.getBridgeMacLinkCreateTime()));
linknode.setBridgeLinkLastPollTime(Util.formatDateToUIString(link.getBridgeMacLinkLastPollTime()));
break;
}
}
} else {
for (BridgeBridgeLink link : segment.getBridgeBridgeLinks()) {
if (link.getNode().getId().intValue() == nodeid || link.getDesignatedNode().getId().intValue() == nodeid) {
linknode.setBridgeLinkCreateTime(Util.formatDateToUIString(link.getBridgeBridgeLinkCreateTime()));
linknode.setBridgeLinkLastPollTime(Util.formatDateToUIString(link.getBridgeBridgeLinkLastPollTime()));
break;
}
}
}
Map<String, List<IpNetToMedia>> sharedmacs = new HashMap<String, List<IpNetToMedia>>();
for (String shredmac : segment.getMacsOnSegment()) {
sharedmacs.put(shredmac, new ArrayList<IpNetToMedia>());
sharedmacs.get(shredmac).addAll(m_ipNetToMediaDao.findByPhysAddress(shredmac));
}
Map<String, List<OnmsIpInterface>> sharedhosts = new HashMap<String, List<OnmsIpInterface>>();
for (String shredmac : sharedmacs.keySet()) {
if (sharedmacs.get(shredmac).isEmpty()) {
BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
OnmsSnmpInterface snmp = getFromPhysAddress(shredmac);
if (snmp == null) {
remlinknode.setSharedHost(shredmac + " No ip address found");
} else {
remlinknode.setSharedHost(snmp.getNode().getLabel());
remlinknode.setSharedHostUrl(getNodeUrl(snmp.getNode().getId()));
remlinknode.setSharedHostPort(getPortString(snmp.getIfIndex(), snmp.getIfName(), snmp.getIfAlias()));
remlinknode.setSharedHostPortUrl(getSnmpInterfaceUrl(snmp.getNode().getId(), snmp.getIfIndex()));
}
linknode.getBridgeLinkSharedHost().add(remlinknode);
continue;
}
sharedhosts.put(shredmac, new ArrayList<OnmsIpInterface>());
for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) sharedhosts.get(shredmac).addAll(m_ipInterfaceDao.findByIpAddress(ipnettomedia.getNetAddress().getHostAddress()));
}
for (String shredmac : sharedhosts.keySet()) {
BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
Set<InetAddress> ips = new HashSet<InetAddress>();
if (sharedhosts.get(shredmac).isEmpty()) {
for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) {
ips.add(ipnettomedia.getNetAddress());
}
remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " No node found");
linknode.getBridgeLinkSharedHost().add(remlinknode);
continue;
}
OnmsIpInterface first = null;
boolean multiplenodeids = false;
for (OnmsIpInterface ip : sharedhosts.get(shredmac)) {
if (first == null)
first = ip;
if (first.getNode().getId().intValue() != ip.getNode().getId().intValue())
multiplenodeids = true;
ips.add(ip.getIpAddress());
}
if (multiplenodeids) {
remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " duplicated ip multiple node associated in db");
} else {
remlinknode.setSharedHost(first.getNode().getLabel());
remlinknode.setSharedHostUrl(getNodeUrl(first.getNode().getId()));
}
remlinknode.setSharedHostPort(getNodePortString(ips, shredmac));
if (ips.size() == 1) {
remlinknode.setSharedHostPortUrl(getIpInterfaceUrl(first));
}
linknode.getBridgeLinkSharedHost().add(remlinknode);
}
return linknode;
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class NetworkElementFactory method getIpPrimaryAddress.
/* (non-Javadoc)
* @see org.opennms.web.element.NetworkElementFactoryInterface#getIpPrimaryAddress(int)
*/
@Override
public String getIpPrimaryAddress(int nodeId) {
final CriteriaBuilder cb = new CriteriaBuilder(OnmsIpInterface.class);
cb.and(new EqRestriction("node.id", nodeId), new EqRestriction("isSnmpPrimary", PrimaryType.PRIMARY));
final List<OnmsIpInterface> ifaces = m_ipInterfaceDao.findMatching(cb.toCriteria());
if (ifaces.size() > 0) {
final OnmsIpInterface iface = ifaces.get(0);
return InetAddressUtils.str(iface.getIpAddress());
} else {
return null;
}
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class NetworkElementFactory method getInterface.
/* (non-Javadoc)
* @see org.opennms.web.element.NetworkElementFactoryInterface#getInterface(int)
*/
@Override
public Interface getInterface(int ipInterfaceId) {
OnmsCriteria criteria = new OnmsCriteria(OnmsIpInterface.class);
criteria.add(Restrictions.eq("id", ipInterfaceId));
criteria.setFetchMode("snmpInterface", FetchMode.JOIN);
List<OnmsIpInterface> ifaces = m_ipInterfaceDao.findMatching(criteria);
if (ifaces.size() > 0) {
return new Interface(ifaces.get(0));
}
return null;
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class DatabasePopulator method doResetDatabase.
private void doResetDatabase() {
LOG.debug("==== DatabasePopulator Reset ====");
for (final OnmsOutage outage : m_outageDao.findAll()) {
m_outageDao.delete(outage);
}
for (final OnmsUserNotification not : m_userNotificationDao.findAll()) {
m_userNotificationDao.delete(not);
}
for (final OnmsNotification not : m_notificationDao.findAll()) {
m_notificationDao.delete(not);
}
for (final OnmsAlarm alarm : m_alarmDao.findAll()) {
m_alarmDao.delete(alarm);
}
for (final OnmsEvent event : m_eventDao.findAll()) {
m_eventDao.delete(event);
}
for (final OnmsSnmpInterface snmpIface : m_snmpInterfaceDao.findAll()) {
for (OnmsIpInterface eachIf : snmpIface.getIpInterfaces()) {
eachIf.setSnmpInterface(null);
snmpIface.getNode().getIpInterfaces().remove(eachIf);
}
snmpIface.getNode().getSnmpInterfaces().remove(snmpIface);
m_snmpInterfaceDao.delete(snmpIface);
}
for (final OnmsIpInterface iface : m_ipInterfaceDao.findAll()) {
iface.setSnmpInterface(null);
iface.getNode().getIpInterfaces().remove(iface);
m_ipInterfaceDao.delete(iface);
}
for (final OnmsNode node : m_nodeDao.findAll()) {
m_nodeDao.delete(node);
}
for (final OnmsServiceType service : m_serviceTypeDao.findAll()) {
m_serviceTypeDao.delete(service);
}
for (final OnmsMonitoringLocation location : m_monitoringLocationDao.findAll()) {
// Don't delete the default localhost monitoring location
if (!MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID.equals(location.getLocationName())) {
m_monitoringLocationDao.delete(location);
}
}
for (final OnmsCategory category : m_categoryDao.findAll()) {
m_categoryDao.delete(category);
}
LOG.debug("= DatabasePopulatorExtension Reset Starting =");
for (Extension eachExtension : extensions) {
DaoSupport daoSupport = eachExtension.getDaoSupport();
OnmsDao<?, ?> dao = daoSupport != null && daoSupport.getDaoClass() != null ? lookupDao(daoSupport.getDaoClass()) : null;
eachExtension.onShutdown(this, dao);
if (dao != null) {
dao.flush();
}
}
LOG.debug("= DatabasePopulatorExtension Reset Finished =");
m_outageDao.flush();
m_userNotificationDao.flush();
m_notificationDao.flush();
m_alarmDao.flush();
m_eventDao.flush();
m_snmpInterfaceDao.flush();
m_ipInterfaceDao.flush();
m_nodeDao.flush();
m_serviceTypeDao.flush();
LOG.debug("==== DatabasePopulator Reset Finished ====");
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class DefaultPollingContext method getInterfaceList.
protected OnmsIpInterfaceList getInterfaceList() {
StringBuffer filterRules = new StringBuffer(getPackage().getEffectiveFilter());
List<InetAddress> ipList = FilterDaoFactory.getInstance().getActiveIPAddressList(filterRules.toString());
OnmsIpInterfaceList ifaces = new OnmsIpInterfaceList();
// Only poll the primary interface
final Criteria criteria = new Criteria(OnmsIpInterface.class);
criteria.addRestriction(new EqRestriction("isSnmpPrimary", PrimaryType.PRIMARY));
List<OnmsIpInterface> allValidIfaces = getIpInterfaceDao().findMatching(criteria);
for (OnmsIpInterface iface : allValidIfaces) {
if (ipList.contains(iface.getIpAddress())) {
ifaces.add(iface);
}
}
return ifaces;
}
Aggregations