use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class EnLinkdIT method testLoadTopology.
@Test
public void testLoadTopology() {
final OnmsMonitoringLocation location = new OnmsMonitoringLocation(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID);
ABCTopology topology = new ABCTopology();
OnmsNode lnodeA = topology.nodeA;
lnodeA.setForeignSource("linkd");
lnodeA.setForeignId("nodeA");
lnodeA.setLabel("nodeA");
lnodeA.setLocation(location);
OnmsNode lnodeB = topology.nodeB;
lnodeB.setForeignSource("linkd");
lnodeB.setForeignId("nodeB");
lnodeB.setLabel("nodeB");
lnodeB.setLocation(location);
OnmsNode lnodeC = topology.nodeC;
lnodeC.setForeignSource("linkd");
lnodeC.setForeignId("nodeC");
lnodeC.setLabel("nodeC");
lnodeC.setLocation(location);
BridgeElement elementD = new BridgeElement();
BridgeElement elementE = new BridgeElement();
BridgeElement elementK = new BridgeElement();
OnmsNode lnodeD = new OnmsNode();
lnodeD.setId(topology.nodeAId + 1234);
lnodeD.setForeignSource("linkd");
lnodeD.setForeignId("nodeD");
lnodeD.setLabel("nodeD");
lnodeD.setLocation(location);
elementD.setNode(lnodeD);
elementD.setBaseBridgeAddress("dddddddddddd");
OnmsNode lnodeE = new OnmsNode();
lnodeE.setId(topology.nodeBId + 1234);
lnodeE.setForeignSource("linkd");
lnodeE.setForeignId("nodeE");
lnodeE.setLabel("nodeE");
lnodeE.setLocation(location);
elementE.setNode(lnodeE);
elementE.setBaseBridgeAddress("eeeeeeeeeeee");
OnmsNode lnodeK = new OnmsNode();
lnodeK.setId(topology.nodeCId + 12345);
lnodeK.setForeignSource("linkd");
lnodeK.setForeignId("nodeK");
lnodeK.setLabel("nodeK");
lnodeK.setLocation(location);
elementK.setNode(lnodeK);
elementK.setBaseBridgeAddress("aaaabbbbcccc");
m_nodeDao.save(lnodeA);
m_nodeDao.save(lnodeB);
m_nodeDao.save(lnodeC);
m_nodeDao.save(lnodeD);
m_nodeDao.save(lnodeE);
m_nodeDao.save(lnodeK);
OnmsNode nodeA = m_nodeDao.findByForeignId("linkd", "nodeA");
OnmsNode nodeB = m_nodeDao.findByForeignId("linkd", "nodeB");
OnmsNode nodeC = m_nodeDao.findByForeignId("linkd", "nodeC");
OnmsNode nodeD = m_nodeDao.findByForeignId("linkd", "nodeD");
OnmsNode nodeE = m_nodeDao.findByForeignId("linkd", "nodeE");
OnmsNode nodeK = m_nodeDao.findByForeignId("linkd", "nodeK");
topology.nodeAId = nodeA.getId();
topology.nodeBId = nodeB.getId();
topology.nodeCId = nodeC.getId();
topology.nodeA = nodeA;
topology.nodeB = nodeB;
topology.nodeC = nodeC;
BridgeBridgeLink delink = new BridgeBridgeLink();
delink.setNode(nodeD);
delink.setBridgePort(45);
delink.setDesignatedNode(nodeE);
delink.setDesignatedPort(54);
delink.setBridgeBridgeLinkLastPollTime(delink.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(delink);
BridgeBridgeLink ablink = new BridgeBridgeLink();
ablink.setNode(nodeA);
ablink.setBridgePort(topology.portAB);
ablink.setDesignatedNode(nodeB);
ablink.setDesignatedPort(topology.portBA);
ablink.setBridgeBridgeLinkLastPollTime(ablink.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(ablink);
BridgeBridgeLink bclink = new BridgeBridgeLink();
bclink.setNode(nodeC);
bclink.setBridgePort(topology.portCB);
bclink.setDesignatedNode(nodeB);
bclink.setDesignatedPort(topology.portBC);
bclink.setBridgeBridgeLinkLastPollTime(ablink.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(bclink);
BridgeMacLink forward = new BridgeMacLink();
forward.setNode(nodeB);
forward.setBridgePort(topology.portBA);
forward.setMacAddress(topology.macA);
forward.setBridgeMacLinkLastPollTime(forward.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(forward);
BridgeMacLink sharedB = new BridgeMacLink();
sharedB.setNode(nodeB);
sharedB.setBridgePort(topology.portBC);
sharedB.setMacAddress(topology.shar);
sharedB.setBridgeMacLinkLastPollTime(sharedB.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(sharedB);
BridgeMacLink sharedC = new BridgeMacLink();
sharedC.setNode(nodeC);
sharedC.setBridgePort(topology.portCB);
sharedC.setMacAddress(topology.shar);
sharedC.setBridgeMacLinkLastPollTime(sharedC.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(sharedC);
BridgeMacLink mac1 = new BridgeMacLink();
mac1.setNode(nodeA);
mac1.setBridgePort(topology.portA);
mac1.setMacAddress(topology.mac1);
mac1.setBridgeMacLinkLastPollTime(mac1.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(mac1);
BridgeMacLink mac2 = new BridgeMacLink();
mac2.setNode(nodeB);
mac2.setBridgePort(topology.portB);
mac2.setMacAddress(topology.mac2);
mac2.setBridgeMacLinkLastPollTime(mac2.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(mac2);
BridgeMacLink mac3 = new BridgeMacLink();
mac3.setNode(nodeC);
mac3.setBridgePort(topology.portC);
mac3.setMacAddress(topology.mac3);
mac3.setBridgeMacLinkLastPollTime(mac3.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(mac3);
BridgeMacLink sharedD = new BridgeMacLink();
sharedD.setNode(nodeD);
sharedD.setBridgePort(45);
sharedD.setMacAddress(topology.shar);
sharedD.setBridgeMacLinkLastPollTime(sharedD.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(sharedD);
BridgeMacLink sharedE = new BridgeMacLink();
sharedE.setNode(nodeE);
sharedE.setBridgePort(54);
sharedE.setMacAddress(topology.shar);
sharedE.setBridgeMacLinkLastPollTime(sharedE.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(sharedE);
BridgeMacLink sharedK = new BridgeMacLink();
sharedK.setNode(nodeK);
sharedK.setBridgePort(1099);
sharedK.setMacAddress(topology.shar);
sharedK.setBridgeMacLinkLastPollTime(sharedK.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(sharedK);
BridgeMacLink macK = new BridgeMacLink();
macK.setNode(nodeK);
macK.setBridgePort(1099);
macK.setMacAddress("1234567800aa");
macK.setBridgeMacLinkLastPollTime(macK.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(macK);
m_bridgeMacLinkDao.flush();
m_bridgeBridgeLinkDao.flush();
assertEquals(10, m_bridgeMacLinkDao.countAll());
assertEquals(3, m_bridgeBridgeLinkDao.countAll());
assertNotNull(m_bridgeTopologyDao);
m_linkd.getQueryManager().loadBridgeTopology();
assertEquals(3, m_linkd.getQueryManager().getAllBroadcastDomains().size());
BroadcastDomain nodeAbd = m_linkd.getQueryManager().getBroadcastDomain(nodeA.getId().intValue());
assertNotNull(nodeAbd);
BroadcastDomain nodeBbd = m_linkd.getQueryManager().getBroadcastDomain(nodeB.getId().intValue());
BroadcastDomain nodeCbd = m_linkd.getQueryManager().getBroadcastDomain(nodeC.getId().intValue());
assertEquals(nodeAbd, nodeBbd);
assertEquals(nodeAbd, nodeCbd);
nodeAbd.hierarchySetUp(nodeAbd.getBridge(nodeA.getId()));
topology.checkwithshared(nodeAbd);
assertEquals(0, nodeAbd.getForwarders(topology.nodeAId).size());
assertEquals(1, nodeAbd.getForwarders(topology.nodeBId).size());
assertEquals(0, nodeAbd.getForwarders(topology.nodeCId).size());
List<SharedSegment> nodeASegments = m_bridgeTopologyDao.getBridgeSharedSegments(nodeA.getId());
assertEquals(2, nodeASegments.size());
System.err.println(nodeAbd.printTopology());
BroadcastDomain nodeDbd = m_linkd.getQueryManager().getBroadcastDomain(nodeD.getId().intValue());
assertNotNull(nodeDbd);
BroadcastDomain nodeEbd = m_linkd.getQueryManager().getBroadcastDomain(nodeE.getId().intValue());
assertEquals(nodeDbd, nodeEbd);
assertEquals(2, nodeDbd.getBridges().size());
assertEquals(1, nodeDbd.getTopology().size());
assertTrue(nodeDbd.containBridgeId(nodeD.getId()));
assertTrue(nodeDbd.containBridgeId(nodeE.getId()));
SharedSegment deSegment = nodeDbd.getTopology().iterator().next();
assertEquals(2, deSegment.getBridgePortsOnSegment().size());
assertEquals(1, deSegment.getMacsOnSegment().size());
assertEquals(45, deSegment.getPortForBridge(nodeD.getId()).intValue());
assertEquals(54, deSegment.getPortForBridge(nodeE.getId()).intValue());
assertTrue(deSegment.containsMac(topology.shar));
System.err.println(nodeDbd.printTopology());
BroadcastDomain nodeKbd = m_linkd.getQueryManager().getBroadcastDomain(nodeK.getId().intValue());
assertNotNull(nodeKbd);
assertEquals(1, nodeKbd.getBridges().size());
assertEquals(1, nodeKbd.getTopology().size());
assertTrue(nodeKbd.containBridgeId(nodeK.getId()));
SharedSegment kSegment = nodeKbd.getTopology().iterator().next();
assertEquals(1, kSegment.getBridgePortsOnSegment().size());
assertEquals(2, kSegment.getMacsOnSegment().size());
assertEquals(1099, kSegment.getPortForBridge(nodeK.getId()).intValue());
assertTrue(kSegment.containsMac(topology.shar));
assertTrue(kSegment.containsMac("1234567800aa"));
System.err.println(nodeKbd.printTopology());
}
use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class DefaultDistributedPollerService method getLocationMonitorList.
/**
* <p>getLocationMonitorList</p>
*
* @return a {@link org.opennms.web.svclayer.model.LocationMonitorListModel} object.
*/
@Override
public LocationMonitorListModel getLocationMonitorList() {
List<OnmsLocationMonitor> monitors = m_locationMonitorDao.findAll();
Collections.sort(monitors, m_comparator);
LocationMonitorListModel model = new LocationMonitorListModel();
for (OnmsLocationMonitor monitor : monitors) {
OnmsMonitoringLocation def = m_monitoringLocationDao.get(monitor.getLocation());
model.addLocationMonitor(new LocationMonitorModel(monitor, def));
}
return model;
}
use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class DefaultDistributedStatusService method findLocationSpecificStatus.
/**
* <p>findLocationSpecificStatus</p>
*
* @param command a {@link org.opennms.web.command.DistributedStatusDetailsCommand} object.
* @param errors a {@link org.springframework.validation.Errors} object.
* @return a {@link java.util.List} object or null if no location monitors are registered for the specified location and application tuple
*/
protected List<OnmsLocationSpecificStatus> findLocationSpecificStatus(DistributedStatusDetailsCommand command, Errors errors) throws IllegalArgumentException {
String locationName = command.getLocation();
String applicationName = command.getApplication();
Assert.notNull(locationName, "location cannot be null");
Assert.notNull(applicationName, "application cannot be null");
OnmsMonitoringLocation location = m_monitoringLocationDao.get(locationName);
if (location == null) {
throw new IllegalArgumentException("Could not find location for " + "location name \"" + locationName + "\"");
}
OnmsApplication application = m_applicationDao.findByName(applicationName);
if (application == null) {
throw new IllegalArgumentException("Could not find application " + "for application name \"" + applicationName + "\"");
}
Collection<OnmsLocationMonitor> locationMonitors = m_locationMonitorDao.findByLocationDefinition(location);
if (locationMonitors.size() == 0) {
errors.reject("location.no-monitors", new Object[] { applicationName, locationName }, "No remote pollers have registered for this " + "application and location");
return null;
}
List<OnmsLocationMonitor> sortedLocationMonitors = new ArrayList<OnmsLocationMonitor>(locationMonitors);
Collections.sort(sortedLocationMonitors);
Collection<OnmsMonitoredService> services = m_monitoredServiceDao.findByApplication(application);
List<OnmsMonitoredService> sortedServices = new ArrayList<OnmsMonitoredService>(services);
Collections.sort(sortedServices);
List<OnmsLocationSpecificStatus> status = new LinkedList<>();
for (OnmsMonitoredService service : sortedServices) {
for (OnmsLocationMonitor locationMonitor : sortedLocationMonitors) {
OnmsLocationSpecificStatus currentStatus = m_locationMonitorDao.getMostRecentStatusChange(locationMonitor, service);
if (currentStatus == null) {
status.add(new OnmsLocationSpecificStatus(locationMonitor, service, NO_RECORDED_STATUS));
} else {
status.add(currentStatus);
}
}
}
return status;
}
use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class DefaultDistributedStatusService method createHistoryModel.
/**
* {@inheritDoc}
*/
@Override
public DistributedStatusHistoryModel createHistoryModel(String locationName, String monitorId, String applicationName, String timeSpan, String previousLocationName) {
List<String> errors = new LinkedList<>();
List<OnmsMonitoringLocation> locationDefinitions = m_monitoringLocationDao.findAll();
List<RelativeTimePeriod> periods = Arrays.asList(RelativeTimePeriod.getDefaultPeriods());
Collection<OnmsApplication> applications = m_applicationDao.findAll();
List<OnmsApplication> sortedApplications = new ArrayList<OnmsApplication>(applications);
Collections.sort(sortedApplications);
OnmsMonitoringLocation location = new OnmsMonitoringLocation();
if (locationName == null) {
if (!locationDefinitions.isEmpty()) {
location = locationDefinitions.get(0);
}
} else {
location = m_monitoringLocationDao.get(locationName);
if (location == null) {
errors.add("Could not find location definition '" + locationName + "'");
if (!locationDefinitions.isEmpty()) {
location = locationDefinitions.get(0);
}
}
}
OnmsApplication application = new OnmsApplication();
if (applicationName == null) {
if (!sortedApplications.isEmpty()) {
application = sortedApplications.get(0);
}
} else {
application = m_applicationDao.findByName(applicationName);
if (application == null) {
errors.add("Could not find application '" + applicationName + "'");
if (!sortedApplications.isEmpty()) {
application = sortedApplications.get(0);
}
}
}
Collection<OnmsLocationMonitor> monitors = m_locationMonitorDao.findByLocationDefinition(location);
List<OnmsLocationMonitor> sortedMonitors = new LinkedList<OnmsLocationMonitor>(monitors);
Collections.sort(sortedMonitors);
OnmsLocationMonitor monitor = null;
if (monitorId != null && !"".equals(monitorId.trim()) && location.getLocationName().equals(previousLocationName)) {
for (OnmsLocationMonitor m : sortedMonitors) {
if (m.getId().equals(monitorId)) {
monitor = m;
break;
}
}
}
if (monitor == null && !sortedMonitors.isEmpty()) {
monitor = sortedMonitors.get(0);
}
RelativeTimePeriod period = RelativeTimePeriod.getPeriodByIdOrDefault(timeSpan);
/*
* Initialize the hierarchy under the service so that we don't get
* a LazyInitializationException later when the JSP page is pulling
* data out of the model object.
*/
Collection<OnmsMonitoredService> memberServices = m_monitoredServiceDao.findByApplication(application);
for (OnmsMonitoredService service : memberServices) {
m_locationMonitorDao.initialize(service.getIpInterface());
m_locationMonitorDao.initialize(service.getIpInterface().getNode());
}
Collection<OnmsMonitoredService> applicationMemberServices = m_monitoredServiceDao.findByApplication(application);
if (applicationMemberServices.isEmpty()) {
errors.add("There are no services in the application '" + applicationName + "'");
}
DistributedStatusHistoryModel model = new DistributedStatusHistoryModel(locationDefinitions, sortedApplications, sortedMonitors, periods, location, application, applicationMemberServices, monitor, period, errors);
initializeGraphUrls(model);
return model;
}
use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class DefaultDistributedStatusService method createFacilityStatusTable.
/**
* {@inheritDoc}
*/
@Override
public SimpleWebTable createFacilityStatusTable(Date start, Date end) {
Assert.notNull(start, "argument start cannot be null");
Assert.notNull(end, "argument end cannot be null");
if (!start.before(end)) {
throw new IllegalArgumentException("start date (" + start + ") must be older than end date (" + end + ")");
}
SimpleWebTable table = new SimpleWebTable();
List<OnmsMonitoringLocation> locationDefinitions = m_monitoringLocationDao.findAll();
Collection<OnmsApplication> applications = m_applicationDao.findAll();
if (applications.size() == 0) {
throw new IllegalArgumentException("there are no applications");
}
List<OnmsApplication> sortedApplications = new ArrayList<OnmsApplication>(applications);
Collections.sort(sortedApplications);
Collection<OnmsLocationSpecificStatus> mostRecentStatuses = m_locationMonitorDao.getAllMostRecentStatusChanges();
Collection<OnmsLocationSpecificStatus> statusesPeriod = new HashSet<>();
statusesPeriod.addAll(m_locationMonitorDao.getAllStatusChangesAt(start));
statusesPeriod.addAll(m_locationMonitorDao.getStatusChangesBetween(start, end));
table.setTitle("Distributed Status Summary");
table.addColumn("Area", "");
table.addColumn("Location", "");
for (OnmsApplication application : sortedApplications) {
table.addColumn(application.getName(), "");
}
for (OnmsMonitoringLocation locationDefinition : locationDefinitions) {
Collection<OnmsLocationMonitor> monitors = m_locationMonitorDao.findByLocationDefinition(locationDefinition);
table.newRow();
table.addCell(locationDefinition.getMonitoringArea(), "");
table.addCell(locationDefinition.getLocationName(), "");
for (OnmsApplication application : sortedApplications) {
Collection<OnmsMonitoredService> memberServices = m_monitoredServiceDao.findByApplication(application);
Severity status = calculateCurrentStatus(monitors, memberServices, mostRecentStatuses);
Set<OnmsLocationSpecificStatus> selectedStatuses = filterStatus(statusesPeriod, monitors, memberServices);
if (selectedStatuses.size() > 0) {
String percentage = calculatePercentageUptime(memberServices, selectedStatuses, start, end);
table.addCell(percentage, status.getStyle(), createHistoryPageUrl(locationDefinition, application));
} else {
table.addCell("No data", status.getStyle());
}
}
}
if (isLayoutApplicationsVertically()) {
SimpleWebTable newTable = new SimpleWebTable();
newTable.setErrors(table.getErrors());
newTable.setTitle(table.getTitle());
newTable.addColumn("Application");
for (List<Cell> row : table.getRows()) {
// The location is in the second row
newTable.addColumn(row.get(1).getContent(), row.get(1).getStyleClass());
}
for (Cell columnHeader : table.getColumnHeaders().subList(2, table.getColumnHeaders().size())) {
// This is the index into collumn list of the old table to get the data for the current application
int rowColumnIndex = newTable.getRows().size() + 2;
newTable.newRow();
newTable.addCell(columnHeader.getContent(), columnHeader.getStyleClass());
for (List<Cell> row : table.getRows()) {
newTable.addCell(row.get(rowColumnIndex).getContent(), row.get(rowColumnIndex).getStyleClass(), row.get(rowColumnIndex).getLink());
}
}
return newTable;
}
return table;
}
Aggregations