use of org.opennms.netmgt.model.minion.OnmsMinion in project opennms by OpenNMS.
the class RestClient method getAllMinions.
public List<OnmsMinion> getAllMinions() {
GenericType<List<OnmsMinion>> minions = new GenericType<List<OnmsMinion>>() {
};
final WebTarget target = getTargetV2().path("minions");
return getBuilder(target).accept(MediaType.APPLICATION_XML).get(minions);
}
use of org.opennms.netmgt.model.minion.OnmsMinion in project opennms by OpenNMS.
the class MinionDaoIT method testQueryByLocation.
@Test
public void testQueryByLocation() throws Exception {
final Date now = new Date();
m_minionDao.save(new OnmsMinion(UUID.randomUUID().toString(), "TestLocation", "Started", now));
m_minionDao.save(new OnmsMinion(UUID.randomUUID().toString(), "TestLocation", "Stopped", now));
m_minionDao.save(new OnmsMinion(UUID.randomUUID().toString(), "OtherLocation", "Stopped", now));
final Collection<OnmsMinion> testMinions = m_minionDao.findByLocation("TestLocation");
assertEquals(2, testMinions.size());
}
use of org.opennms.netmgt.model.minion.OnmsMinion in project opennms by OpenNMS.
the class MinionHeartbeatMonitor method poll.
@Override
public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameters) {
// Minions send heartbeat every 30 seconds - we check that we can skip not more than one beat
final int period = 2 * ParameterMap.getKeyedInteger(parameters, "period", 30 * 1000);
// Get the minion to test whereas the minion ID is the nodes foreign ID by convention
final OnmsNode node = nodeDao.get().get(svc.getNodeId());
final OnmsMinion minion = minionDao.get().findById(node.getForeignId());
// Calculate the time since the last heartbeat was received
final long lastSeen = System.currentTimeMillis() - minion.getLastUpdated().getTime();
final PollStatus status;
if (lastSeen <= period) {
status = PollStatus.available();
} else if (ManagementFactory.getRuntimeMXBean().getUptime() < period) {
status = PollStatus.unknown("JVM has not been started long enough to process a heartbeat.");
} else {
status = PollStatus.unavailable(String.format("Last heartbeat was %.2f seconds ago", lastSeen / 1000.0));
}
return status;
}
use of org.opennms.netmgt.model.minion.OnmsMinion in project opennms by OpenNMS.
the class HeartbeatConsumer method handleMessage.
@Override
@Transactional
public void handleMessage(MinionIdentityDTO minionHandle) {
LOG.info("Received heartbeat for Minion with id: {} at location: {}", minionHandle.getId(), minionHandle.getLocation());
OnmsMinion minion = minionDao.findById(minionHandle.getId());
if (minion == null) {
minion = new OnmsMinion();
minion.setId(minionHandle.getId());
// The real location is filled in below, but we set this to null
// for now to detect requisition changes
minion.setLocation(null);
}
final String prevLocation = minion.getLocation();
final String nextLocation = minionHandle.getLocation();
minion.setLocation(minionHandle.getLocation());
// Provision the minions node before we alter the location
this.provision(minion, prevLocation, nextLocation);
if (minionHandle.getTimestamp() == null) {
// The heartbeat does not contain a timestamp - use the current time
minion.setLastUpdated(new Date());
LOG.info("Received heartbeat without a timestamp: {}", minionHandle);
} else if (minion.getLastUpdated() == null) {
// The heartbeat does contain a timestamp, and we don't have
// one set yet, so use whatever we've been given
minion.setLastUpdated(minionHandle.getTimestamp());
} else if (minionHandle.getTimestamp().after(minion.getLastUpdated())) {
// The timestamp in the heartbeat is more recent than the one we
// have stored, so update it
minion.setLastUpdated(minionHandle.getTimestamp());
} else {
// The timestamp in the heartbeat is earlier than the
// timestamp we have stored, so ignore it
LOG.info("Ignoring stale timestamp from heartbeat: {}", minionHandle);
}
minionDao.saveOrUpdate(minion);
if (prevLocation == null) {
final EventBuilder eventBuilder = new EventBuilder(EventConstants.MONITORING_SYSTEM_ADDED_UEI, "OpenNMS.Minion.Heartbeat");
eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_TYPE, OnmsMonitoringSystem.TYPE_MINION);
eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_ID, minionHandle.getId());
eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_LOCATION, nextLocation);
try {
eventProxy.send(eventBuilder.getEvent());
} catch (final EventProxyException e) {
throw new DataAccessResourceFailureException("Unable to send event", e);
}
} else if (!prevLocation.equals(nextLocation)) {
final EventBuilder eventBuilder = new EventBuilder(EventConstants.MONITORING_SYSTEM_LOCATION_CHANGED_UEI, "OpenNMS.Minion.Heartbeat");
eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_TYPE, OnmsMonitoringSystem.TYPE_MINION);
eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_ID, minionHandle.getId());
eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_PREV_LOCATION, prevLocation);
eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_LOCATION, nextLocation);
try {
eventProxy.send(eventBuilder.getEvent());
} catch (final EventProxyException e) {
throw new DataAccessResourceFailureException("Unable to send event", e);
}
}
}
use of org.opennms.netmgt.model.minion.OnmsMinion in project opennms by OpenNMS.
the class MinionDaoIT method testProperties.
@Test
@Transactional
public void testProperties() throws Exception {
final Date now = new Date();
final OnmsMinion a = new OnmsMinion(UUID.randomUUID().toString(), "TestLocation", "Started", now);
final OnmsMinion b = new OnmsMinion(UUID.randomUUID().toString(), "OtherLocation", "Started", now);
a.getProperties().put("Yes", "No");
a.setProperty("Up", "Down");
b.setProperty("Left", "Right");
b.setProperty("Wrong", "Right");
m_minionDao.save(a);
m_minionDao.save(b);
m_minionDao.flush();
assertEquals(Integer.valueOf(4), m_jdbcTemplate.queryForObject("select count(*) from monitoringsystemsproperties", Integer.class));
assertEquals(Integer.valueOf(2), m_jdbcTemplate.queryForObject("select count(*) from monitoringsystemsproperties where monitoringsystemid = ?", new Object[] { a.getId() }, Integer.class));
assertEquals(Integer.valueOf(2), m_jdbcTemplate.queryForObject("select count(*) from monitoringsystemsproperties where monitoringsystemid = ?", new Object[] { b.getId() }, Integer.class));
String prop = m_minionDao.findById(a.getId()).getProperties().get("Left");
// a doesn't have that property, b does
assertNull(prop);
prop = m_minionDao.findById(b.getId()).getProperties().get("Left");
assertNotNull(prop);
assertEquals("Right", prop);
}
Aggregations