use of org.opennms.netmgt.model.ServiceInfo in project opennms by OpenNMS.
the class JmxDaemonStatusDaoTest method testGetAllStatuses.
public void testGetAllStatuses() {
// get all the services
try {
Map<String, ServiceInfo> services = jmxDaemonStatusDao.getCurrentDaemonStatus();
// assert on count
assertEquals("Unexpected number of mbeans found", 4, services.size());
// assert presense of specific service
ServiceInfo service = services.get("notifd");
// assert on status of a specific service
String status = service.getServiceStatus();
assertEquals("Unexpected State: ", "Started", status);
} catch (Throwable e) {
e.printStackTrace();
}
}
use of org.opennms.netmgt.model.ServiceInfo in project opennms by OpenNMS.
the class JmxDaemonStatusDao method getCurrentDaemonStatus.
/**
* <p>getCurrentDaemonStatus</p>
*
* @return a {@link java.util.Map} object.
*/
@Override
public Map<String, ServiceInfo> getCurrentDaemonStatus() {
// TODO Auto-generated method stub
Map<String, ServiceInfo> serviceInfo = new HashMap<String, ServiceInfo>();
// go to the JMX Server and ask for all the MBeans...
// ArrayList<MBeanServer> mbeans =
// MBeanServerFactory.findMBeanServer(null);
// get their names and corresponding status and plugit into Service Info
Set<ObjectName> mBeanNames;
try {
mBeanNames = queryMbeanServerForNames(new ObjectName("opennms:*"), null);
} catch (MalformedObjectNameException e) {
throw new JmxObjectNameException("Object name 'opennms:*' was malformed!", e);
} catch (NullPointerException e) {
throw new JmxObjectNameException("Object name param is null.", e);
}
for (ObjectName mBeanName : mBeanNames) {
ServiceDaemon serviceDaemon = buildProxy(mBeanName);
String name = serviceDaemon.getName();
String status = serviceDaemon.getStatusText();
serviceInfo.put(name, new ServiceInfo(name, status));
}
// Map the name of the service to ServiceInfo...
// for testing adding a dummy service info node...
serviceInfo.put("test", new ServiceInfo("test", "started"));
return Collections.unmodifiableMap(serviceInfo);
}
Aggregations