@Test @Transactional public void dwoTestCreateLink(){ Collection<DataLinkInterface> dataLinks = m_dataLinkDao.findByNodeId(END_POINT3_ID); assertEquals(0, dataLinks.size()); m_nodeLinkService.createLink(END_POINT1_ID, END_POINT3_ID); dataLinks = m_dataLinkDao.findByNodeId(END_POINT3_ID); assertEquals(1, dataLinks.size()); }
@Transactional public void createLink(final int nodeParentId, final int nodeId) { infof(this, "adding link between node: %d and node: %d", nodeParentId, nodeId); final OnmsNode parentNode = m_nodeDao.get(nodeParentId); Assert.notNull(parentNode, "node with id: " + nodeParentId + " does not exist"); final OnmsNode node = m_nodeDao.get(nodeId); Assert.notNull(node, "node with id: " + nodeId + " does not exist"); final OnmsCriteria criteria = new OnmsCriteria(DataLinkInterface.class); criteria.createAlias("node", "node", OnmsCriteria.LEFT_JOIN); criteria.add(Restrictions.eq("node.id", nodeId)); criteria.add(Restrictions.eq("nodeParentId", nodeParentId)); final Collection<DataLinkInterface> dataLinkInterface = m_dataLinkDao.findMatching(criteria); DataLinkInterface dli = null; if (dataLinkInterface.size() > 1) { warnf(this, "more than one data link interface exists for nodes %d and %d", nodeParentId, nodeId); return; } else if (dataLinkInterface.size() > 0) { dli = dataLinkInterface.iterator().next(); infof(this, "link between nodes %d and %d already exists", nodeParentId, nodeId); } else { dli = new DataLinkInterface(); dli.setNode(node); dli.setNodeParentId(nodeParentId); dli.setIfIndex(getPrimaryIfIndexForNode(node)); dli.setParentIfIndex(getPrimaryIfIndexForNode(parentNode)); infof(this, "creating new link between nodes %d and %d", nodeParentId, nodeId); } OnmsLinkState onmsLinkState = null; if (dli.getId() != null) { onmsLinkState = m_linkStateDao.findByDataLinkInterfaceId(dli.getId()); } if (onmsLinkState == null) { onmsLinkState = new OnmsLinkState(); } onmsLinkState.setDataLinkInterface(dli); Boolean nodeParentEndPoint = getEndPointStatus(nodeParentId); Boolean nodeEndPoint = getEndPointStatus(nodeId); LinkState state = LinkState.LINK_UP; LinkEventSendingStateTransition transition = new LinkEventSendingStateTransition(dli, m_eventForwarder, this); if (nodeParentEndPoint == null) { state = state.parentNodeEndPointDeleted(transition); } else if (!nodeParentEndPoint) { state = state.parentNodeDown(transition); } if (nodeEndPoint == null) { state = state.nodeEndPointDeleted(transition); } else if (!nodeEndPoint) { state = state.nodeDown(null); } dli.setStatus(state.getDataLinkInterfaceStateType()); onmsLinkState.setLinkState(state); dli.setLastPollTime(new Date()); dli.setLinkTypeId(777); m_dataLinkDao.save(dli); m_linkStateDao.save(onmsLinkState); m_dataLinkDao.flush(); m_linkStateDao.flush(); }
DefaultNodeLinkService implements NodeLinkService, InitializingBean { @Transactional public void createLink(final int nodeParentId, final int nodeId) { infof(this, "adding link between node: %d and node: %d", nodeParentId, nodeId); final OnmsNode parentNode = m_nodeDao.get(nodeParentId); Assert.notNull(parentNode, "node with id: " + nodeParentId + " does not exist"); final OnmsNode node = m_nodeDao.get(nodeId); Assert.notNull(node, "node with id: " + nodeId + " does not exist"); final OnmsCriteria criteria = new OnmsCriteria(DataLinkInterface.class); criteria.createAlias("node", "node", OnmsCriteria.LEFT_JOIN); criteria.add(Restrictions.eq("node.id", nodeId)); criteria.add(Restrictions.eq("nodeParentId", nodeParentId)); final Collection<DataLinkInterface> dataLinkInterface = m_dataLinkDao.findMatching(criteria); DataLinkInterface dli = null; if (dataLinkInterface.size() > 1) { warnf(this, "more than one data link interface exists for nodes %d and %d", nodeParentId, nodeId); return; } else if (dataLinkInterface.size() > 0) { dli = dataLinkInterface.iterator().next(); infof(this, "link between nodes %d and %d already exists", nodeParentId, nodeId); } else { dli = new DataLinkInterface(); dli.setNode(node); dli.setNodeParentId(nodeParentId); dli.setIfIndex(getPrimaryIfIndexForNode(node)); dli.setParentIfIndex(getPrimaryIfIndexForNode(parentNode)); infof(this, "creating new link between nodes %d and %d", nodeParentId, nodeId); } OnmsLinkState onmsLinkState = null; if (dli.getId() != null) { onmsLinkState = m_linkStateDao.findByDataLinkInterfaceId(dli.getId()); } if (onmsLinkState == null) { onmsLinkState = new OnmsLinkState(); } onmsLinkState.setDataLinkInterface(dli); Boolean nodeParentEndPoint = getEndPointStatus(nodeParentId); Boolean nodeEndPoint = getEndPointStatus(nodeId); LinkState state = LinkState.LINK_UP; LinkEventSendingStateTransition transition = new LinkEventSendingStateTransition(dli, m_eventForwarder, this); if (nodeParentEndPoint == null) { state = state.parentNodeEndPointDeleted(transition); } else if (!nodeParentEndPoint) { state = state.parentNodeDown(transition); } if (nodeEndPoint == null) { state = state.nodeEndPointDeleted(transition); } else if (!nodeEndPoint) { state = state.nodeDown(null); } dli.setStatus(state.getDataLinkInterfaceStateType()); onmsLinkState.setLinkState(state); dli.setLastPollTime(new Date()); dli.setLinkTypeId(777); m_dataLinkDao.save(dli); m_linkStateDao.save(onmsLinkState); m_dataLinkDao.flush(); m_linkStateDao.flush(); } }
DefaultNodeLinkService implements NodeLinkService, InitializingBean { @Transactional public void createLink(final int nodeParentId, final int nodeId) { infof(this, "adding link between node: %d and node: %d", nodeParentId, nodeId); final OnmsNode parentNode = m_nodeDao.get(nodeParentId); Assert.notNull(parentNode, "node with id: " + nodeParentId + " does not exist"); final OnmsNode node = m_nodeDao.get(nodeId); Assert.notNull(node, "node with id: " + nodeId + " does not exist"); final OnmsCriteria criteria = new OnmsCriteria(DataLinkInterface.class); criteria.createAlias("node", "node", OnmsCriteria.LEFT_JOIN); criteria.add(Restrictions.eq("node.id", nodeId)); criteria.add(Restrictions.eq("nodeParentId", nodeParentId)); final Collection<DataLinkInterface> dataLinkInterface = m_dataLinkDao.findMatching(criteria); DataLinkInterface dli = null; if (dataLinkInterface.size() > 1) { warnf(this, "more than one data link interface exists for nodes %d and %d", nodeParentId, nodeId); return; } else if (dataLinkInterface.size() > 0) { dli = dataLinkInterface.iterator().next(); infof(this, "link between nodes %d and %d already exists", nodeParentId, nodeId); } else { dli = new DataLinkInterface(); dli.setNode(node); dli.setNodeParentId(nodeParentId); dli.setIfIndex(getPrimaryIfIndexForNode(node)); dli.setParentIfIndex(getPrimaryIfIndexForNode(parentNode)); infof(this, "creating new link between nodes %d and %d", nodeParentId, nodeId); } OnmsLinkState onmsLinkState = null; if (dli.getId() != null) { onmsLinkState = m_linkStateDao.findByDataLinkInterfaceId(dli.getId()); } if (onmsLinkState == null) { onmsLinkState = new OnmsLinkState(); } onmsLinkState.setDataLinkInterface(dli); Boolean nodeParentEndPoint = getEndPointStatus(nodeParentId); Boolean nodeEndPoint = getEndPointStatus(nodeId); LinkState state = LinkState.LINK_UP; LinkEventSendingStateTransition transition = new LinkEventSendingStateTransition(dli, m_eventForwarder, this); if (nodeParentEndPoint == null) { state = state.parentNodeEndPointDeleted(transition); } else if (!nodeParentEndPoint) { state = state.parentNodeDown(transition); } if (nodeEndPoint == null) { state = state.nodeEndPointDeleted(transition); } else if (!nodeEndPoint) { state = state.nodeDown(null); } dli.setStatus(state.getDataLinkInterfaceStateType()); onmsLinkState.setLinkState(state); dli.setLastPollTime(new Date()); dli.setLinkTypeId(777); m_dataLinkDao.save(dli); m_linkStateDao.save(onmsLinkState); m_dataLinkDao.flush(); m_linkStateDao.flush(); }  }
DefaultNodeLinkService implements NodeLinkService, InitializingBean { @Transactional public void createLink(final int nodeParentId, final int nodeId) { infof(this, "adding link between node: %d and node: %d", nodeParentId, nodeId); final OnmsNode parentNode = m_nodeDao.get(nodeParentId); Assert.notNull(parentNode, "node with id: " + nodeParentId + " does not exist"); final OnmsNode node = m_nodeDao.get(nodeId); Assert.notNull(node, "node with id: " + nodeId + " does not exist"); final OnmsCriteria criteria = new OnmsCriteria(DataLinkInterface.class); criteria.createAlias("node", "node", OnmsCriteria.LEFT_JOIN); criteria.add(Restrictions.eq("node.id", nodeId)); criteria.add(Restrictions.eq("nodeParentId", nodeParentId)); final Collection<DataLinkInterface> dataLinkInterface = m_dataLinkDao.findMatching(criteria); DataLinkInterface dli = null; if (dataLinkInterface.size() > 1) { warnf(this, "more than one data link interface exists for nodes %d and %d", nodeParentId, nodeId); return; } else if (dataLinkInterface.size() > 0) { dli = dataLinkInterface.iterator().next(); infof(this, "link between nodes %d and %d already exists", nodeParentId, nodeId); } else { dli = new DataLinkInterface(); dli.setNode(node); dli.setNodeParentId(nodeParentId); dli.setIfIndex(getPrimaryIfIndexForNode(node)); dli.setParentIfIndex(getPrimaryIfIndexForNode(parentNode)); infof(this, "creating new link between nodes %d and %d", nodeParentId, nodeId); } OnmsLinkState onmsLinkState = null; if (dli.getId() != null) { onmsLinkState = m_linkStateDao.findByDataLinkInterfaceId(dli.getId()); } if (onmsLinkState == null) { onmsLinkState = new OnmsLinkState(); } onmsLinkState.setDataLinkInterface(dli); Boolean nodeParentEndPoint = getEndPointStatus(nodeParentId); Boolean nodeEndPoint = getEndPointStatus(nodeId); LinkState state = LinkState.LINK_UP; LinkEventSendingStateTransition transition = new LinkEventSendingStateTransition(dli, m_eventForwarder, this); if (nodeParentEndPoint == null) { state = state.parentNodeEndPointDeleted(transition); } else if (!nodeParentEndPoint) { state = state.parentNodeDown(transition); } if (nodeEndPoint == null) { state = state.nodeEndPointDeleted(transition); } else if (!nodeEndPoint) { state = state.nodeDown(null); } dli.setStatus(state.getDataLinkInterfaceStateType()); onmsLinkState.setLinkState(state); dli.setLastPollTime(new Date()); dli.setLinkTypeId(777); m_dataLinkDao.save(dli); m_linkStateDao.save(onmsLinkState); m_dataLinkDao.flush(); m_linkStateDao.flush(); }  @Override void afterPropertiesSet(); @Transactional void saveLinkState(OnmsLinkState state); @Transactional void createLink(final int nodeParentId, final int nodeId); @Transactional(readOnly=true) Integer getNodeId(String endPoint); @Transactional(readOnly=true) String getNodeLabel(int nodeId); @Transactional(readOnly=true) Collection<DataLinkInterface> getLinkContainingNodeId(int nodeId); @Transactional(readOnly=true) OnmsLinkState getLinkStateForInterface(DataLinkInterface dataLinkInterface); @Transactional void updateLinkStatus(int nodeParentId, int nodeId, String status); @Transactional(readOnly=true) String getPrimaryAddress(int nodeId); @Transactional(readOnly=true) boolean nodeHasEndPointService(int nodeId); @Transactional(readOnly=true) Boolean getEndPointStatus(int nodeId); }
DefaultNodeLinkService implements NodeLinkService, InitializingBean { @Transactional public void createLink(final int nodeParentId, final int nodeId) { infof(this, "adding link between node: %d and node: %d", nodeParentId, nodeId); final OnmsNode parentNode = m_nodeDao.get(nodeParentId); Assert.notNull(parentNode, "node with id: " + nodeParentId + " does not exist"); final OnmsNode node = m_nodeDao.get(nodeId); Assert.notNull(node, "node with id: " + nodeId + " does not exist"); final OnmsCriteria criteria = new OnmsCriteria(DataLinkInterface.class); criteria.createAlias("node", "node", OnmsCriteria.LEFT_JOIN); criteria.add(Restrictions.eq("node.id", nodeId)); criteria.add(Restrictions.eq("nodeParentId", nodeParentId)); final Collection<DataLinkInterface> dataLinkInterface = m_dataLinkDao.findMatching(criteria); DataLinkInterface dli = null; if (dataLinkInterface.size() > 1) { warnf(this, "more than one data link interface exists for nodes %d and %d", nodeParentId, nodeId); return; } else if (dataLinkInterface.size() > 0) { dli = dataLinkInterface.iterator().next(); infof(this, "link between nodes %d and %d already exists", nodeParentId, nodeId); } else { dli = new DataLinkInterface(); dli.setNode(node); dli.setNodeParentId(nodeParentId); dli.setIfIndex(getPrimaryIfIndexForNode(node)); dli.setParentIfIndex(getPrimaryIfIndexForNode(parentNode)); infof(this, "creating new link between nodes %d and %d", nodeParentId, nodeId); } OnmsLinkState onmsLinkState = null; if (dli.getId() != null) { onmsLinkState = m_linkStateDao.findByDataLinkInterfaceId(dli.getId()); } if (onmsLinkState == null) { onmsLinkState = new OnmsLinkState(); } onmsLinkState.setDataLinkInterface(dli); Boolean nodeParentEndPoint = getEndPointStatus(nodeParentId); Boolean nodeEndPoint = getEndPointStatus(nodeId); LinkState state = LinkState.LINK_UP; LinkEventSendingStateTransition transition = new LinkEventSendingStateTransition(dli, m_eventForwarder, this); if (nodeParentEndPoint == null) { state = state.parentNodeEndPointDeleted(transition); } else if (!nodeParentEndPoint) { state = state.parentNodeDown(transition); } if (nodeEndPoint == null) { state = state.nodeEndPointDeleted(transition); } else if (!nodeEndPoint) { state = state.nodeDown(null); } dli.setStatus(state.getDataLinkInterfaceStateType()); onmsLinkState.setLinkState(state); dli.setLastPollTime(new Date()); dli.setLinkTypeId(777); m_dataLinkDao.save(dli); m_linkStateDao.save(onmsLinkState); m_dataLinkDao.flush(); m_linkStateDao.flush(); }  @Override void afterPropertiesSet(); @Transactional void saveLinkState(OnmsLinkState state); @Transactional void createLink(final int nodeParentId, final int nodeId); @Transactional(readOnly=true) Integer getNodeId(String endPoint); @Transactional(readOnly=true) String getNodeLabel(int nodeId); @Transactional(readOnly=true) Collection<DataLinkInterface> getLinkContainingNodeId(int nodeId); @Transactional(readOnly=true) OnmsLinkState getLinkStateForInterface(DataLinkInterface dataLinkInterface); @Transactional void updateLinkStatus(int nodeParentId, int nodeId, String status); @Transactional(readOnly=true) String getPrimaryAddress(int nodeId); @Transactional(readOnly=true) boolean nodeHasEndPointService(int nodeId); @Transactional(readOnly=true) Boolean getEndPointStatus(int nodeId);  }