use of org.opennms.netmgt.model.ncs.NCSComponent.NodeIdentification in project opennms by OpenNMS.
the class EventMappingRulesIT method findSubcomponentsOnNode.
private Set<String> findSubcomponentsOnNode(NCSComponent svc, String nodeForeignSource, String nodeForeignId) {
final Set<String> expectedIds = new HashSet<String>();
final NodeIdentification nodeIdent = new NodeIdentification(nodeForeignSource, nodeForeignId);
NCSComponentVisitor visitor = new AbstractNCSComponentVisitor() {
@Override
public void visitComponent(NCSComponent component) {
if (nodeIdent.equals(component.getNodeIdentification())) {
expectedIds.add(component.getForeignSource() + ":" + component.getForeignId());
}
}
};
svc.visit(visitor);
return expectedIds;
}
use of org.opennms.netmgt.model.ncs.NCSComponent.NodeIdentification in project opennms by OpenNMS.
the class NCSEdgeProvider method getEdges.
/**
* This factory works by using {@link NCSServiceCriteria} to construct edges based on
* connecting all of the ServiceElements that make up a Service to each other.
*
* @param criteria An {@link NCSServiceCriteria} object
*/
@Override
public List<Edge> getEdges(Criteria... criteria) {
List<Edge> retval = new ArrayList<Edge>();
for (Criteria criterium : criteria) {
try {
NCSServiceCriteria crit = (NCSServiceCriteria) criterium;
for (Long id : crit) {
NCSComponent service = m_dao.get(id);
if (service == null) {
LoggerFactory.getLogger(this.getClass()).warn("NCSComponent not found for ID {}", id);
} else {
//Check foreignsource of the subcomponents to make sure it matches the Service's foreignsource
NCSComponent[] subs = checkForeignSource(service.getForeignSource(), service.getSubcomponents());
// Connect all of the ServiceElements to one another
for (int i = 0; i < subs.length; i++) {
for (int j = i + 1; j < subs.length; j++) {
String foreignSource = null, foreignId = null;
OnmsNode sourceNode = null, targetNode = null;
NodeIdentification ident = subs[i].getNodeIdentification();
String sourceLabel = subs[i].getName();
if (ident != null) {
foreignSource = ident.getForeignSource();
foreignId = ident.getForeignId();
sourceNode = m_nodeDao.findByForeignId(foreignSource, foreignId);
if (sourceNode == null) {
continue;
}
if (sourceLabel == null) {
sourceLabel = sourceNode.getLabel();
}
}
ident = subs[j].getNodeIdentification();
String targetLabel = subs[j].getName();
if (ident != null) {
foreignSource = ident.getForeignSource();
foreignId = ident.getForeignId();
targetNode = m_nodeDao.findByForeignId(foreignSource, foreignId);
if (targetNode == null) {
continue;
}
if (targetLabel == null) {
targetLabel = targetNode.getLabel();
}
}
String sourceElementName = subs[i].getForeignSource() + "::" + subs[i].getForeignId();
String targetElementName = subs[j].getForeignSource() + "::" + subs[j].getForeignId();
retval.add(new NCSEdge(subs[i].getForeignId(), service.getName(), sourceElementName, targetElementName, new NCSVertex(String.valueOf(sourceNode.getId()), sourceLabel), new NCSVertex(String.valueOf(targetNode.getId()), targetLabel)));
}
}
}
}
} catch (ClassCastException e) {
}
}
return retval;
}
Aggregations