Search in sources :

Example 31 with OnmsLocationMonitor

use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.

the class DefaultLocationDataService method getUpdatedLocationsBetween.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public Collection<LocationInfo> getUpdatedLocationsBetween(final Date startDate, final Date endDate) {
    waitForGeocoding("getApplicationDetails");
    final Collection<LocationInfo> locations = new ArrayList<LocationInfo>();
    final Map<String, OnmsMonitoringLocation> definitions = new HashMap<String, OnmsMonitoringLocation>();
    // check for any monitors that have changed status
    for (OnmsMonitoringLocation def : m_monitoringLocationDao.findAll()) {
        for (OnmsLocationMonitor mon : m_locationDao.findByLocationDefinition(def)) {
            final MonitorStatus status = m_monitorStatuses.get(mon.getLocation());
            if (status == null || !status.equals(mon.getStatus())) {
                definitions.put(def.getLocationName(), def);
                m_monitorStatuses.put(def.getLocationName(), mon.getStatus());
            }
        }
    }
    // check for any definitions that have status updates
    for (final OnmsLocationSpecificStatus status : m_locationDao.getStatusChangesBetween(startDate, endDate)) {
        final String definitionName = status.getLocationMonitor().getLocation();
        if (!definitions.containsKey(definitionName)) {
            definitions.put(definitionName, m_monitoringLocationDao.get(definitionName));
        }
    }
    for (final OnmsMonitoringLocation def : definitions.values()) {
        final LocationInfo location = getLocationInfo(def);
        locations.add(location);
    }
    return locations;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) ArrayList(java.util.ArrayList) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) MonitorStatus(org.opennms.netmgt.model.OnmsLocationMonitor.MonitorStatus) LocationInfo(org.opennms.features.poller.remote.gwt.client.location.LocationInfo) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Transactional(org.springframework.transaction.annotation.Transactional)

Example 32 with OnmsLocationMonitor

use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.

the class DefaultLocationDataService method getLocationDetails.

/**
 * <p>getLocationDetails</p>
 *
 * @param def a {@link org.opennms.netmgt.model.OnmsMonitoringLocationDefinition} object.
 * @return a {@link org.opennms.features.poller.remote.gwt.client.location.LocationDetails} object.
 */
@Transactional
@Override
public LocationDetails getLocationDetails(final OnmsMonitoringLocation def) {
    waitForGeocoding("getLocationDetails");
    final LocationDetails ld = new LocationDetails();
    final DefaultLocationDataService.MonitorStatusTracker mst = new DefaultLocationDataService.MonitorStatusTracker(def.getLocationName());
    final DefaultLocationDataService.ApplicationStatusTracker ast = new DefaultLocationDataService.ApplicationStatusTracker(def.getLocationName());
    final List<GWTLocationMonitor> monitors = new ArrayList<GWTLocationMonitor>();
    for (OnmsLocationMonitor mon : m_locationDao.findByLocationDefinition(def)) {
        monitors.add(transformLocationMonitor(mon));
    }
    final Set<ApplicationInfo> applications = new HashSet<ApplicationInfo>();
    for (final OnmsApplication application : m_applicationDao.findAll()) {
        applications.add(transformApplication(m_monitoredServiceDao.findByApplication(application), application));
    }
    // for (final OnmsMonitoredService service : m_monitoredServiceDao.findAll()) {
    // for (final OnmsApplication app : service.getApplications()) {
    // final String appName = app.getName();
    // Set<OnmsMonitoredService> serv = services.get(appName);
    // if (serv == null) {
    // serv = new HashSet<OnmsMonitoredService>();
    // services.put(appName, serv);
    // }
    // serv.add(service);
    // }
    // }
    final Date to = new Date();
    final Date from = new Date(to.getTime() - AVAILABILITY_MS);
    for (OnmsLocationSpecificStatus status : m_locationDao.getMostRecentStatusChangesForLocation(def.getLocationName())) {
        mst.onStatus(status);
        ast.onStatus(status);
    }
    ld.setLocationMonitorState(new LocationMonitorState(monitors, mst.drain()));
    ld.setApplicationState(new ApplicationState(from, to, applications, monitors, ast.drainStatuses()));
    LOG.debug("getLocationDetails({}) returning {}", def.getLocationName(), ld);
    return ld;
}
Also used : LocationDetails(org.opennms.features.poller.remote.gwt.client.location.LocationDetails) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) ApplicationState(org.opennms.features.poller.remote.gwt.client.ApplicationState) ArrayList(java.util.ArrayList) ApplicationInfo(org.opennms.features.poller.remote.gwt.client.ApplicationInfo) LocationMonitorState(org.opennms.features.poller.remote.gwt.client.LocationMonitorState) GWTLocationMonitor(org.opennms.features.poller.remote.gwt.client.GWTLocationMonitor) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) Date(java.util.Date) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with OnmsLocationMonitor

use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.

the class DefaultLocationDataService method getStatusDetailsForApplicationOld.

/**
 * <p>getStatusDetailsForApplicationOld</p>
 *
 * @param app a {@link org.opennms.netmgt.model.OnmsApplication} object.
 * @return a {@link org.opennms.features.poller.remote.gwt.client.StatusDetails} object.
 */
@Transactional
public StatusDetails getStatusDetailsForApplicationOld(final OnmsApplication app) {
    waitForGeocoding("getStatusDetailsForApplication");
    List<GWTLocationSpecificStatus> statuses = new ArrayList<GWTLocationSpecificStatus>();
    final Date to = new Date();
    final Date from = new Date(to.getTime() - AVAILABILITY_MS);
    final Collection<OnmsMonitoredService> services = m_monitoredServiceDao.findByApplication(app);
    final List<GWTLocationMonitor> monitors = new ArrayList<GWTLocationMonitor>();
    final Set<GWTMonitoredService> gwtServices = new LinkedHashSet<GWTMonitoredService>(services.size());
    for (final OnmsMonitoredService service : services) {
        gwtServices.add(transformMonitoredService(service));
    }
    for (final OnmsLocationMonitor monitor : m_locationDao.findByApplication(app)) {
        monitors.add(transformLocationMonitor(monitor));
        for (final OnmsLocationSpecificStatus locationSpecificStatus : m_locationDao.getStatusChangesForLocationBetween(from, to, monitor.getLocation())) {
            if (services.contains(locationSpecificStatus.getMonitoredService())) {
                statuses.add(transformLocationSpecificStatus(locationSpecificStatus));
            }
        }
    }
    StatusDetails statusDetails = new AppStatusDetailsComputer(from, to, monitors, gwtServices, statuses).compute();
    LOG.warn("getStatusDetailsForApplication({}) returning {}", app.getName(), statusDetails);
    return statusDetails;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) ArrayList(java.util.ArrayList) GWTLocationMonitor(org.opennms.features.poller.remote.gwt.client.GWTLocationMonitor) GWTMonitoredService(org.opennms.features.poller.remote.gwt.client.GWTMonitoredService) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) AppStatusDetailsComputer(org.opennms.features.poller.remote.gwt.client.AppStatusDetailsComputer) GWTLocationSpecificStatus(org.opennms.features.poller.remote.gwt.client.GWTLocationSpecificStatus) StatusDetails(org.opennms.features.poller.remote.gwt.client.StatusDetails) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with OnmsLocationMonitor

use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.

the class DefaultPollerBackEnd method registerLocationMonitor.

/**
 * {@inheritDoc}
 */
@Override
public String registerLocationMonitor(final String monitoringLocationId) {
    final OnmsMonitoringLocation def = m_monitoringLocationDao.get(monitoringLocationId);
    if (def == null) {
        throw new ObjectRetrievalFailureException(OnmsMonitoringLocation.class, monitoringLocationId, "Location monitor definition with the id '" + monitoringLocationId + "' not found", null);
    }
    final OnmsLocationMonitor mon = new OnmsLocationMonitor();
    mon.setId(UUID.randomUUID().toString());
    mon.setLocation(def.getLocationName());
    mon.setStatus(MonitorStatus.REGISTERED);
    m_locMonDao.save(mon);
    sendMonitorRegisteredEvent(mon);
    return mon.getId();
}
Also used : ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 35 with OnmsLocationMonitor

use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.

the class DefaultPollerBackEnd method pollerStarting.

/**
 * {@inheritDoc}
 */
@Override
public boolean pollerStarting(final String locationMonitorId, final Map<String, String> pollerDetails) {
    final OnmsLocationMonitor mon = m_locMonDao.get(locationMonitorId);
    if (mon == null) {
        return false;
    }
    mon.setStatus(MonitorStatus.STARTED);
    mon.setLastUpdated(m_timeKeeper.getCurrentDate());
    updateConnectionHostDetails(mon, pollerDetails);
    m_locMonDao.update(mon);
    sendMonitorStartedEvent(mon);
    return true;
}
Also used : OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor)

Aggregations

OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)53 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)18 Date (java.util.Date)15 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)15 ArrayList (java.util.ArrayList)14 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)14 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)14 Transactional (org.springframework.transaction.annotation.Transactional)10 LinkedList (java.util.LinkedList)8 Test (org.junit.Test)6 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)6 LocationMonitorIdCommand (org.opennms.web.svclayer.model.LocationMonitorIdCommand)6 BindException (org.springframework.validation.BindException)6 HashSet (java.util.HashSet)5 ObjectError (org.springframework.validation.ObjectError)5 GWTLocationMonitor (org.opennms.features.poller.remote.gwt.client.GWTLocationMonitor)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 Criteria (org.opennms.core.criteria.Criteria)3 ApplicationInfo (org.opennms.features.poller.remote.gwt.client.ApplicationInfo)3 LocationMonitorState (org.opennms.features.poller.remote.gwt.client.LocationMonitorState)3