use of org.opennms.netmgt.model.OnmsMonitoredService 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;
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class DefaultSurveillanceViewService method getNodeListForCriteria.
/**
* Returns a list of node RTC calculations for the given criterias.
*
* @param serviceCriteria the service criteria
* @param outageCriteria the outage criteries
* @return the list of {@link org.opennms.features.vaadin.surveillanceviews.service.SurveillanceViewService.NodeRtc} instances
*/
private List<NodeRtc> getNodeListForCriteria(final Criteria serviceCriteria, final Criteria outageCriteria) {
List<Order> ordersService = new ArrayList<>();
ordersService.add(Order.asc("node.label"));
ordersService.add(Order.asc("node.id"));
ordersService.add(Order.asc("ipInterface.ipAddress"));
ordersService.add(Order.asc("serviceType.name"));
serviceCriteria.setOrders(ordersService);
Date periodEnd = new Date(System.currentTimeMillis());
Date periodStart = new Date(periodEnd.getTime() - (24 * 60 * 60 * 1000));
outageCriteria.addRestriction(Restrictions.any(Restrictions.isNull("ifRegainedService"), Restrictions.ge("ifLostService", periodStart), Restrictions.ge("ifRegainedService", periodStart)));
List<Order> ordersOutage = new ArrayList<>();
ordersOutage.add(Order.asc("monitoredService"));
ordersOutage.add(Order.asc("ifLostService"));
outageCriteria.setOrders(ordersOutage);
List<OnmsMonitoredService> services = m_monitoredServiceDao.findMatching(serviceCriteria);
List<OnmsOutage> outages = m_outageDao.findMatching(outageCriteria);
Map<OnmsMonitoredService, Long> serviceDownTime = calculateServiceDownTime(periodEnd, periodStart, outages);
List<NodeRtc> model = new ArrayList<>();
OnmsNode lastNode = null;
int serviceCount = 0;
int serviceDownCount = 0;
long downMillisCount = 0;
for (OnmsMonitoredService service : services) {
if (!service.getIpInterface().getNode().equals(lastNode) && lastNode != null) {
Double availability = calculateAvailability(serviceCount, downMillisCount);
model.add(new NodeRtc(lastNode, serviceCount, serviceDownCount, availability));
serviceCount = 0;
serviceDownCount = 0;
downMillisCount = 0;
}
serviceCount++;
if (service.isDown()) {
serviceDownCount++;
}
Long downMillis = serviceDownTime.get(service);
if (downMillis != null) {
downMillisCount += downMillis;
}
lastNode = service.getIpInterface().getNode();
}
if (lastNode != null) {
Double availability = calculateAvailability(serviceCount, downMillisCount);
model.add(new NodeRtc(lastNode, serviceCount, serviceDownCount, availability));
}
return model;
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class PathOutageStatusProviderIT method createService.
/**
* This method creates a service for a given node
* @param node Node
* @return Resulting service
*/
private OnmsMonitoredService createService(OnmsNode node) {
OnmsMonitoredService monitoredService = new OnmsMonitoredService();
OnmsServiceType serviceType = createType("someType");
serviceTypeDao.save(serviceType);
monitoredService.setServiceType(serviceType);
monitoredService.setIpInterface(node.getIpInterfaces().toArray(new OnmsIpInterface[node.getIpInterfaces().size()])[0]);
return monitoredService;
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class DefaultProvisionService method deleteService.
/**
* {@inheritDoc}
*/
@Transactional
@Override
public void deleteService(final Integer nodeId, final InetAddress addr, final String svcName) {
LOG.debug("deleteService: nodeId={}, addr={}, service={}", nodeId, addr, svcName);
final OnmsMonitoredService service = m_monitoredServiceDao.get(nodeId, addr, svcName);
if (service != null) {
final OnmsIpInterface iface = service.getIpInterface();
final OnmsNode node = iface.getNode();
final boolean lastService = (iface.getMonitoredServices().size() == 1);
final boolean lastInterface = (node.getIpInterfaces().size() == 1);
final DeleteEventVisitor visitor = new DeleteEventVisitor(m_eventForwarder);
iface.removeMonitoredService(service);
m_nodeDao.saveOrUpdate(node);
m_nodeDao.flush();
service.visit(visitor);
if (lastService) {
LOG.debug("Deleting interface {} from node {}", InetAddressUtils.str(iface.getIpAddress()), nodeId);
node.removeIpInterface(iface);
m_nodeDao.saveOrUpdate(node);
m_nodeDao.flush();
iface.visit(visitor);
if (lastInterface) {
LOG.debug("Deleting node {}", nodeId);
m_nodeDao.delete(node);
m_nodeDao.flush();
node.visit(visitor);
}
}
}
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class SaveOrUpdateOperation method foundMonitoredService.
/**
* <p>foundMonitoredService</p>
*
* @param serviceName a {@link java.lang.String} object.
*/
public void foundMonitoredService(String serviceName) {
// current interface may be null if it has no ipaddr
if (m_currentInterface != null) {
OnmsServiceType svcType = getProvisionService().createServiceTypeIfNecessary(serviceName);
OnmsMonitoredService service = new OnmsMonitoredService(m_currentInterface, svcType);
service.setStatus("A");
m_currentInterface.getMonitoredServices().add(service);
}
}
Aggregations