Search in sources :

Example 1 with OnmsLocationAvailDefinitionList

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

the class RemotePollerAvailabilityService method getAvailabilityByLocation.

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("availability/{location}")
public OnmsLocationAvailDefinitionList getAvailabilityByLocation(@Context final UriInfo uriInfo, @PathParam("location") String location) {
    final MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
    OnmsMonitoringLocation locationDefinition = m_monitoringLocationDao.get(location);
    if (locationDefinition == null) {
        throw getException(Status.BAD_REQUEST, "Cannot find location definition: {}", location);
    }
    Collection<OnmsLocationMonitor> monitors = m_locationMonitorDao.findByLocationDefinition(locationDefinition);
    OnmsLocationAvailDefinitionList availList = getAvailabilityList(createTimeChunker(queryParameters), getSortedApplications(), monitors, null);
    return availList;
}
Also used : OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsLocationAvailDefinitionList(org.opennms.netmgt.model.OnmsLocationAvailDefinitionList) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with OnmsLocationAvailDefinitionList

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

the class RemotePollerAvailabilityService method getAvailabilityList.

/**
 * @param timeChunker
 * @param sortedApplications
 * @param selectedMonitors
 * @param selectedNodes
 * @return
 */
private OnmsLocationAvailDefinitionList getAvailabilityList(TimeChunker timeChunker, List<OnmsApplication> sortedApplications, Collection<OnmsLocationMonitor> selectedMonitors, Collection<OnmsNode> selectedNodes) {
    OnmsLocationAvailDefinitionList availList = new OnmsLocationAvailDefinitionList();
    List<String> names = new ArrayList<String>(sortedApplications.size());
    for (OnmsApplication app : sortedApplications) {
        names.add(app.getName());
    }
    Collection<OnmsLocationSpecificStatus> statusesPeriod = m_locationMonitorDao.getStatusChangesBetweenForApplications(timeChunker.getStartDate(), timeChunker.getEndDate(), names);
    AvailCalculator availCalc = new AvailCalculator(timeChunker);
    removeUnneededMonitors(statusesPeriod, selectedMonitors);
    removeUnneededServices(statusesPeriod, selectedNodes);
    for (OnmsLocationSpecificStatus statusChange : statusesPeriod) {
        availCalc.onStatusChange(statusChange);
    }
    int counter = 0;
    for (int i = 0; i < timeChunker.getSegmentCount(); i++) {
        counter++;
        TimeChunk timeChunk = timeChunker.getAt(i);
        OnmsLocationAvailDataPoint point = new OnmsLocationAvailDataPoint();
        point.setTime(timeChunk.getEndDate());
        for (OnmsApplication application : sortedApplications) {
            double percentage = availCalc.getAvailabilityFor(m_monitoredServiceDao.findByApplication(application), i);
            String strPercent = new DecimalFormat("0.0").format(percentage * 100);
            point.addAvailDefinition(new OnmsLocationAvailDefinition(application.getName(), strPercent));
        }
        availList.add(point);
    }
    System.err.println(new Date() + "After Calculations total loops: " + counter);
    return availList;
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) OnmsLocationAvailDefinition(org.opennms.netmgt.model.OnmsLocationAvailDefinition) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsLocationAvailDataPoint(org.opennms.netmgt.model.OnmsLocationAvailDataPoint) OnmsLocationAvailDataPoint(org.opennms.netmgt.model.OnmsLocationAvailDataPoint) Date(java.util.Date) TimeChunk(org.opennms.web.rest.v1.support.TimeChunker.TimeChunk) OnmsLocationAvailDefinitionList(org.opennms.netmgt.model.OnmsLocationAvailDefinitionList)

Aggregations

OnmsLocationAvailDefinitionList (org.opennms.netmgt.model.OnmsLocationAvailDefinitionList)2 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)1 OnmsLocationAvailDataPoint (org.opennms.netmgt.model.OnmsLocationAvailDataPoint)1 OnmsLocationAvailDefinition (org.opennms.netmgt.model.OnmsLocationAvailDefinition)1 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)1 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)1 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)1 TimeChunk (org.opennms.web.rest.v1.support.TimeChunker.TimeChunk)1