use of org.opennms.netmgt.dao.api.MonitoredServiceDao in project opennms by OpenNMS.
the class DefaultProvisionService method updateMonitoredServiceState.
@Transactional
@Override
public OnmsMonitoredService updateMonitoredServiceState(final Integer nodeId, final String ipAddress, final String svcName) {
final OnmsIpInterface iface = m_ipInterfaceDao.findByNodeIdAndIpAddress(nodeId, ipAddress);
assertNotNull(iface, "could not find interface with nodeid %d and ipAddr %s", nodeId, ipAddress);
return new UpsertTemplate<OnmsMonitoredService, MonitoredServiceDao>(m_transactionManager, m_monitoredServiceDao) {
@Override
protected OnmsMonitoredService query() {
return iface.getMonitoredServiceByServiceType(svcName);
}
@Override
protected OnmsMonitoredService doUpdate(OnmsMonitoredService dbObj) {
// NMS-3906
LOG.debug("current status of service {} on node with IP {} is {} ", dbObj.getServiceName(), dbObj.getIpAddress().getHostAddress(), dbObj.getStatus());
switch(dbObj.getStatus()) {
case "S":
LOG.debug("suspending polling for service {} on node with IP {}", dbObj.getServiceName(), dbObj.getIpAddress().getHostAddress());
dbObj.setStatus("F");
m_monitoredServiceDao.update(dbObj);
sendEvent(EventConstants.SUSPEND_POLLING_SERVICE_EVENT_UEI, dbObj);
break;
case "R":
LOG.debug("resume polling for service {} on node with IP {}", dbObj.getServiceName(), dbObj.getIpAddress().getHostAddress());
dbObj.setStatus("A");
m_monitoredServiceDao.update(dbObj);
sendEvent(EventConstants.RESUME_POLLING_SERVICE_EVENT_UEI, dbObj);
break;
case "A":
// we can ignore active statuses
break;
default:
LOG.warn("Unhandled state: {}", dbObj.getStatus());
break;
}
return dbObj;
}
@Override
protected OnmsMonitoredService doInsert() {
return null;
}
private void sendEvent(String eventUEI, OnmsMonitoredService dbObj) {
final EventBuilder bldr = new EventBuilder(eventUEI, "ProvisionService");
bldr.setNodeid(dbObj.getNodeId());
bldr.setInterface(dbObj.getIpAddress());
bldr.setService(dbObj.getServiceName());
m_eventForwarder.sendNow(bldr.getEvent());
}
}.execute();
}
Aggregations