Search in sources :

Example 16 with OnmsApplication

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

the class DefaultAdminApplicationService method findServiceApplications.

/**
 * {@inheritDoc}
 */
@Override
public ServiceEditModel findServiceApplications(String ifServiceIdString) {
    if (ifServiceIdString == null) {
        throw new IllegalArgumentException("ifServiceIdString must not be null");
    }
    OnmsMonitoredService service = findService(ifServiceIdString);
    List<OnmsApplication> applications = findAllApplications();
    m_monitoredServiceDao.initialize(service.getIpInterface());
    m_monitoredServiceDao.initialize(service.getIpInterface().getNode());
    return new ServiceEditModel(service, applications);
}
Also used : OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 17 with OnmsApplication

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

the class DefaultAdminApplicationService method removeApplication.

/**
 * {@inheritDoc}
 */
@Override
public void removeApplication(String applicationIdString) {
    OnmsApplication application = findApplication(applicationIdString);
    m_applicationDao.delete(application);
}
Also used : OnmsApplication(org.opennms.netmgt.model.OnmsApplication)

Example 18 with OnmsApplication

use of org.opennms.netmgt.model.OnmsApplication 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;
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) ArrayList(java.util.ArrayList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) LinkedList(java.util.LinkedList) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 19 with OnmsApplication

use of org.opennms.netmgt.model.OnmsApplication 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;
}
Also used : ArrayList(java.util.ArrayList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) LinkedList(java.util.LinkedList) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) DistributedStatusHistoryModel(org.opennms.web.svclayer.model.DistributedStatusHistoryModel) RelativeTimePeriod(org.opennms.web.svclayer.model.RelativeTimePeriod) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 20 with OnmsApplication

use of org.opennms.netmgt.model.OnmsApplication 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;
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) ArrayList(java.util.ArrayList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Cell(org.opennms.web.svclayer.model.SimpleWebTable.Cell) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) HashSet(java.util.HashSet)

Aggregations

OnmsApplication (org.opennms.netmgt.model.OnmsApplication)42 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)20 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)14 ArrayList (java.util.ArrayList)13 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)12 Date (java.util.Date)11 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)11 LinkedList (java.util.LinkedList)8 Transactional (org.springframework.transaction.annotation.Transactional)6 HashSet (java.util.HashSet)5 ApplicationInfo (org.opennms.features.poller.remote.gwt.client.ApplicationInfo)4 StatusDetails (org.opennms.features.poller.remote.gwt.client.StatusDetails)4 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)4 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 Test (org.junit.Test)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)3 DistributedStatusHistoryModel (org.opennms.web.svclayer.model.DistributedStatusHistoryModel)3 HashMap (java.util.HashMap)2