use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class DefaultDistributedPollerService method getLocationMonitorDetails.
/**
* {@inheritDoc}
*/
@Override
public LocationMonitorListModel getLocationMonitorDetails(LocationMonitorIdCommand cmd, BindingResult errors) {
LocationMonitorListModel model = new LocationMonitorListModel();
model.setErrors(errors);
if (errors.getErrorCount() > 0) {
return model;
}
OnmsLocationMonitor monitor = m_locationMonitorDao.load(cmd.getMonitorId());
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 NodeRestService method addNode.
/**
* <p>addNode</p>
*
* @param node a {@link org.opennms.netmgt.model.OnmsNode} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@POST
@Consumes(MediaType.APPLICATION_XML)
public Response addNode(@Context final UriInfo uriInfo, final OnmsNode node) {
writeLock();
try {
if (node.getLocation() == null) {
OnmsMonitoringLocation location = m_locationDao.getDefaultLocation();
LOG.debug("addNode: Assigning new node to default location: {}", location.getLocationName());
node.setLocation(location);
}
// see NMS-8019
if (node.getType() == null) {
throw getException(Status.BAD_REQUEST, "Node type must be set.");
}
// see NMS-9855
if (node.getAssetRecord() != null && node.getAssetRecord().getNode() == null) {
node.getAssetRecord().setNode(node);
}
LOG.debug("addNode: Adding node {}", node);
m_nodeDao.save(node);
sendEvent(EventConstants.NODE_ADDED_EVENT_UEI, node.getId(), node.getLabel());
return Response.created(uriInfo.getRequestUriBuilder().path(node.getNodeId()).build()).build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class DefaultDistributedStatusServiceTest method testWrongLocationDetails.
public void testWrongLocationDetails() {
List<OnmsMonitoringLocation> locationDefinitions = new LinkedList<>();
locationDefinitions.add(m_locationDefinition1);
locationDefinitions.add(m_locationDefinition2);
locationDefinitions.add(m_locationDefinition3);
expect(m_monitoringLocationDao.findAll()).andReturn(locationDefinitions);
List<OnmsApplication> applications = new ArrayList<>();
applications.add(m_application1);
applications.add(m_application2);
expect(m_applicationDao.findAll()).andReturn(applications);
expect(m_monitoringLocationDao.get("Raleigh-bad")).andReturn(null);
expect(m_applicationDao.findByName("Application 2")).andReturn(m_application2);
List<OnmsLocationMonitor> monitors = new ArrayList<>();
monitors.add(m_locationMonitor1_1);
expect(m_locationMonitorDao.findByLocationDefinition(m_locationDefinition1)).andReturn(monitors);
for (OnmsMonitoredService service : m_applicationServices2) {
m_locationMonitorDao.initialize(service.getIpInterface());
m_locationMonitorDao.initialize(service.getIpInterface().getNode());
}
String locationName = "Raleigh-bad";
String applicationName = m_application2.getName();
String monitorId = "";
String previousLocation = "";
String timeSpan = "";
expect(m_monitoredServiceDao.findByApplication(m_application2)).andReturn(m_applicationServices2).times(2);
expectResourceDaoCall(m_locationMonitor1_1, m_applicationServices2);
m_easyMockUtils.replayAll();
DistributedStatusHistoryModel summary = m_service.createHistoryModel(locationName, monitorId, applicationName, timeSpan, previousLocation);
m_easyMockUtils.verifyAll();
assertNotNull("summary should not be null", summary);
assertNotNull("summary locations list should not be null", summary.getLocations());
assertNotNull("summary applications list should not be null", summary.getApplications());
assertNotNull("summary chosen location should not be null", summary.getChosenLocation());
assertNotNull("summary chosen application should not be null", summary.getChosenApplication());
assertNotNull("summary error list should not be null", summary.getErrors());
assertEquals("summary locations list size", locationDefinitions.size(), summary.getLocations().size());
assertEquals("summary applications list size", applications.size(), summary.getApplications().size());
assertEquals("summary error list size", 1, summary.getErrors().size());
// Verify sorting of applications
assertEquals("summary applications 1", m_application1, summary.getApplications().get(0));
assertEquals("summary applications 2", m_application2, summary.getApplications().get(1));
// Verify errors
assertEquals("summary error 1", "Could not find location definition 'Raleigh-bad'", summary.getErrors().get(0));
// Verify chosen ones
assertEquals("summary chosen location", m_locationDefinition1, summary.getChosenLocation());
assertEquals("summary chosen application", m_application2, summary.getChosenApplication());
// And verify that they are in the lists in the right place
assertEquals("summary chosen location matches list", summary.getLocations().get(0), summary.getChosenLocation());
assertEquals("summary chosen application matches list", summary.getApplications().get(1), summary.getChosenApplication());
}
use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class DefaultDistributedStatusServiceTest method testCreateFacilityStatusTableOneApplicationOneOfTwoLocationsReporting.
/*
* XXX need to check sorting
*/
public void testCreateFacilityStatusTableOneApplicationOneOfTwoLocationsReporting() throws Exception {
OnmsApplication app = m_application2;
// No need to shuffle, since this is a list
List<OnmsMonitoringLocation> locationDefinitions = new LinkedList<>();
locationDefinitions.add(m_locationDefinition1);
locationDefinitions.add(m_locationDefinition2);
OnmsMonitoredService httpsService = findMonitoredService(m_services, m_ip, "HTTPS");
Collection<OnmsLocationSpecificStatus> mostRecentStatuses = new LinkedList<>();
mostRecentStatuses.add(createStatus(m_locationMonitor1_1, httpsService, PollStatus.available(), "20061011-00:00:00"));
Collection<OnmsLocationSpecificStatus> statusChanges = new LinkedList<>();
statusChanges.add(createStatus(m_locationMonitor1_1, httpsService, PollStatus.available(), "20061011-00:00:00"));
Date startDate = s_dbDate.parse("2006-10-12 00:00:00.0");
Date endDate = s_dbDate.parse("2006-10-13 00:00:00.0");
expect(m_monitoringLocationDao.findAll()).andReturn(locationDefinitions);
expect(m_applicationDao.findAll()).andReturn(Collections.singletonList(app));
expect(m_locationMonitorDao.getAllMostRecentStatusChanges()).andReturn(mostRecentStatuses);
expect(m_locationMonitorDao.findByLocationDefinition(locationDefinitions.get(0))).andReturn(Collections.singleton(m_locationMonitor1_1));
expect(m_locationMonitorDao.findByLocationDefinition(locationDefinitions.get(1))).andReturn(Collections.singleton(m_locationMonitor2_1));
expect(m_locationMonitorDao.getStatusChangesBetween(startDate, endDate)).andReturn(statusChanges);
expect(m_locationMonitorDao.getAllStatusChangesAt(startDate)).andReturn(new HashSet<OnmsLocationSpecificStatus>());
expect(m_monitoredServiceDao.findByApplication(app)).andReturn(m_applicationServices2).times(2);
m_easyMockUtils.replayAll();
SimpleWebTable table = m_service.createFacilityStatusTable(startDate, endDate);
m_easyMockUtils.verifyAll();
SimpleWebTable expectedTable = new SimpleWebTable();
expectedTable.setTitle("Distributed Status Summary");
expectedTable.addColumn("Area", "");
expectedTable.addColumn("Location", "");
expectedTable.addColumn(app.getName(), "");
expectedTable.newRow();
expectedTable.addCell("OpenNMS NC", "");
expectedTable.addCell("Raleigh", "");
expectedTable.addCell("100.000%", "Normal", "distributedStatusHistory.htm?location=Raleigh&application=Application+2");
expectedTable.newRow();
expectedTable.addCell("OpenNMS NC", "");
expectedTable.addCell("Durham", "");
expectedTable.addCell("No data", "Indeterminate");
assertTableEquals(expectedTable, table);
}
use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class DefaultDistributedStatusServiceTest method testWrongApplicationDetails.
public void testWrongApplicationDetails() {
List<OnmsMonitoringLocation> locationDefinitions = new LinkedList<>();
locationDefinitions.add(m_locationDefinition1);
locationDefinitions.add(m_locationDefinition2);
locationDefinitions.add(m_locationDefinition3);
expect(m_monitoringLocationDao.findAll()).andReturn(locationDefinitions);
List<OnmsApplication> applications = new ArrayList<>();
applications.add(m_application1);
applications.add(m_application2);
expect(m_applicationDao.findAll()).andReturn(applications);
expect(m_monitoringLocationDao.get(m_locationDefinition2.getLocationName())).andReturn(m_locationDefinition2);
expect(m_applicationDao.findByName("Big Bad Voodoo Daddy Application")).andReturn(null);
List<OnmsLocationMonitor> monitors = new ArrayList<>();
monitors.add(m_locationMonitor2_1);
monitors.add(m_locationMonitor2_2);
expect(m_locationMonitorDao.findByLocationDefinition(m_locationDefinition2)).andReturn(monitors);
for (OnmsMonitoredService service : m_applicationServices1) {
m_locationMonitorDao.initialize(service.getIpInterface());
m_locationMonitorDao.initialize(service.getIpInterface().getNode());
}
String locationName = m_locationDefinition2.getLocationName();
String applicationName = "Big Bad Voodoo Daddy Application";
String monitorId = "";
String previousLocation = "";
String timeSpan = "";
expect(m_monitoredServiceDao.findByApplication(m_application1)).andReturn(m_applicationServices1).times(2);
expectResourceDaoCall(m_locationMonitor2_1, m_applicationServices1);
m_easyMockUtils.replayAll();
DistributedStatusHistoryModel summary = m_service.createHistoryModel(locationName, monitorId, applicationName, timeSpan, previousLocation);
m_easyMockUtils.verifyAll();
assertNotNull("summary should not be null", summary);
assertNotNull("summary locations list should not be null", summary.getLocations());
assertNotNull("summary applications list should not be null", summary.getApplications());
assertNotNull("summary chosen location should not be null", summary.getChosenLocation());
assertNotNull("summary chosen application should not be null", summary.getChosenApplication());
assertNotNull("summary error list should not be null", summary.getErrors());
assertEquals("summary locations list size", locationDefinitions.size(), summary.getLocations().size());
assertEquals("summary applications list size", applications.size(), summary.getApplications().size());
assertEquals("summary error list size", 1, summary.getErrors().size());
// Verify sorting of applications
assertEquals("summary applications 1", m_application1, summary.getApplications().get(0));
assertEquals("summary applications 2", m_application2, summary.getApplications().get(1));
// Verify errors
assertEquals("summary error 1", "Could not find application 'Big Bad Voodoo Daddy Application'", summary.getErrors().get(0));
// Verify chosen ones
assertEquals("summary chosen location", m_locationDefinition2, summary.getChosenLocation());
assertEquals("summary chosen application", m_application1, summary.getChosenApplication());
// And verify that they are in the lists in the right place
assertEquals("summary chosen location matches list", summary.getLocations().get(1), summary.getChosenLocation());
assertEquals("summary chosen application matches list", summary.getApplications().get(0), summary.getChosenApplication());
}
Aggregations