use of org.opennms.netmgt.model.CdpElement in project opennms by OpenNMS.
the class EnhancedLinkdServiceImpl method reconcileCdp.
@Override
public void reconcileCdp(int nodeId, Date now) {
CdpElement element = m_cdpElementDao.findByNodeId(nodeId);
if (element != null && element.getCdpNodeLastPollTime().getTime() < now.getTime()) {
m_cdpElementDao.delete(element);
m_cdpElementDao.flush();
}
m_cdpLinkDao.deleteByNodeIdOlderThen(nodeId, now);
m_cdpLinkDao.flush();
}
use of org.opennms.netmgt.model.CdpElement in project opennms by OpenNMS.
the class EnhancedLinkdServiceImpl method store.
@Override
@Transactional
public void store(int nodeId, CdpElement element) {
if (element == null)
return;
final OnmsNode node = m_nodeDao.get(nodeId);
if (node == null)
return;
CdpElement dbelement = node.getCdpElement();
if (dbelement != null) {
dbelement.merge(element);
node.setCdpElement(dbelement);
} else {
element.setNode(node);
element.setCdpNodeLastPollTime(element.getCdpNodeCreateTime());
node.setCdpElement(element);
}
m_nodeDao.saveOrUpdate(node);
m_nodeDao.flush();
}
use of org.opennms.netmgt.model.CdpElement in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProvider method getCdpLinks.
private void getCdpLinks(Map<Integer, OnmsNode> nodemap, Map<Integer, List<OnmsSnmpInterface>> nodesnmpmap, Map<Integer, OnmsIpInterface> ipprimarymap, Map<InetAddress, OnmsIpInterface> ipmap) {
Map<Integer, CdpElement> cdpelementmap = new HashMap<Integer, CdpElement>();
for (CdpElement cdpelement : m_cdpElementDao.findAll()) {
cdpelementmap.put(cdpelement.getNode().getId(), cdpelement);
}
List<CdpLink> allLinks = m_cdpLinkDao.findAll();
Set<CdpLinkDetail> combinedLinkDetails = new HashSet<CdpLinkDetail>();
Set<Integer> parsed = new HashSet<Integer>();
for (CdpLink sourceLink : allLinks) {
if (parsed.contains(sourceLink.getId()))
continue;
LOG.debug("loadtopology: cdp link with id '{}' link '{}' ", sourceLink.getId(), sourceLink);
CdpElement sourceCdpElement = cdpelementmap.get(sourceLink.getNode().getId());
CdpLink targetLink = null;
for (CdpLink link : allLinks) {
if (sourceLink.getId().intValue() == link.getId().intValue() || parsed.contains(link.getId()))
continue;
LOG.debug("loadtopology: checking cdp link with id '{}' link '{}' ", link.getId(), link);
CdpElement element = cdpelementmap.get(link.getNode().getId());
// Compare the remote data to the targetNode element data
if (!sourceLink.getCdpCacheDeviceId().equals(element.getCdpGlobalDeviceId()) || !link.getCdpCacheDeviceId().equals(sourceCdpElement.getCdpGlobalDeviceId()))
continue;
if (sourceLink.getCdpInterfaceName().equals(link.getCdpCacheDevicePort()) && link.getCdpInterfaceName().equals(sourceLink.getCdpCacheDevicePort())) {
targetLink = link;
LOG.info("loadtopology: found cdp mutual link: '{}' and '{}' ", sourceLink, targetLink);
break;
}
}
if (targetLink == null) {
if (sourceLink.getCdpCacheAddressType() == CiscoNetworkProtocolType.ip) {
try {
InetAddress targetAddress = InetAddressUtils.addr(sourceLink.getCdpCacheAddress());
if (ipmap.containsKey(targetAddress)) {
targetLink = reverseCdpLink(ipmap.get(targetAddress), sourceCdpElement, sourceLink);
LOG.info("loadtopology: found cdp link using cdp cache address: '{}' and '{}'", sourceLink, targetLink);
}
} catch (Exception e) {
LOG.warn("loadtopology: cannot convert ip address: {}", sourceLink.getCdpCacheAddress(), e);
}
}
}
if (targetLink == null) {
LOG.info("loadtopology: cannot found target node for link: '{}'", sourceLink);
continue;
}
parsed.add(sourceLink.getId());
parsed.add(targetLink.getId());
Vertex source = getOrCreateVertex(nodemap.get(sourceLink.getNode().getId()), ipprimarymap.get(sourceLink.getNode().getId()));
Vertex target = getOrCreateVertex(nodemap.get(targetLink.getNode().getId()), ipprimarymap.get(targetLink.getNode().getId()));
combinedLinkDetails.add(new CdpLinkDetail(Math.min(sourceLink.getId(), targetLink.getId()) + "|" + Math.max(sourceLink.getId(), targetLink.getId()), source, sourceLink, target, targetLink));
}
for (CdpLinkDetail linkDetail : combinedLinkDetails) {
LinkdEdge edge = connectVertices(linkDetail, CDP_EDGE_NAMESPACE);
edge.setTooltipText(getEdgeTooltipText(linkDetail, nodesnmpmap));
}
}
use of org.opennms.netmgt.model.CdpElement in project opennms by OpenNMS.
the class CdpGlobalGroupTracker method getCdpElement.
public CdpElement getCdpElement() {
CdpElement cdpElement = new CdpElement();
cdpElement.setCdpGlobalRun(TruthValue.get(getCdpGlobalRun()));
cdpElement.setCdpGlobalDeviceId(getCdpDeviceId());
if (getCdpGlobalDeviceFormat() != null) {
try {
cdpElement.setCdpGlobalDeviceIdFormat(CdpGlobalDeviceIdFormat.get(getCdpGlobalDeviceFormat()));
} catch (IllegalArgumentException e) {
LOG.info("setCdpGlobalDeviceIdFormat not supported: ", e.getLocalizedMessage());
}
}
return cdpElement;
}
use of org.opennms.netmgt.model.CdpElement in project opennms by OpenNMS.
the class EnLinkdElementFactory method convertFromModel.
@Transactional
@SuppressWarnings("deprecation")
private CdpLinkNode convertFromModel(int nodeid, CdpLink link) {
CdpLinkNode linknode = new CdpLinkNode();
linknode.setCdpLocalPort(getPortString(link.getCdpCacheIfIndex(), link.getCdpInterfaceName(), null));
if (link.getCdpCacheIfIndex() != null)
linknode.setCdpLocalPortUrl(getSnmpInterfaceUrl(nodeid, link.getCdpCacheIfIndex()));
linknode.setCdpCacheAddressType(CiscoNetworkProtocolType.getTypeString(link.getCdpCacheAddressType().getValue()));
linknode.setCdpCacheAddress(link.getCdpCacheAddress());
linknode.setCdpCacheDeviceId(link.getCdpCacheDeviceId());
linknode.setCdpCacheDevicePlatform(link.getCdpCacheDevicePlatform());
linknode.setCdpCacheVersion(link.getCdpCacheVersion());
linknode.setCdpCacheDevicePort(link.getCdpCacheDevicePort());
CdpElement cdpCacheElement = m_cdpElementDao.findByGlobalDeviceId(link.getCdpCacheDeviceId());
if (cdpCacheElement != null) {
linknode.setCdpCacheDeviceUrl(getNodeUrl(cdpCacheElement.getNode().getId()));
OnmsSnmpInterface cdpcachesnmp = getFromCdpCacheDevicePort(cdpCacheElement.getNode().getId(), link.getCdpCacheDevicePort());
if (cdpcachesnmp != null) {
linknode.setCdpCacheDevicePort(getPortString(cdpcachesnmp.getIfIndex(), link.getCdpCacheDevicePort(), cdpcachesnmp.getIfAlias()));
linknode.setCdpCacheDevicePortUrl(getSnmpInterfaceUrl(cdpCacheElement.getNode().getId(), cdpcachesnmp.getIfIndex()));
}
}
linknode.setCdpCreateTime(Util.formatDateToUIString(link.getCdpLinkCreateTime()));
linknode.setCdpLastPollTime(Util.formatDateToUIString(link.getCdpLinkLastPollTime()));
return linknode;
}
Aggregations