Search in sources :

Example 1 with ServiceInfo

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();
    }
}
Also used : ServiceInfo(org.opennms.netmgt.model.ServiceInfo)

Example 2 with ServiceInfo

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);
}
Also used : ServiceInfo(org.opennms.netmgt.model.ServiceInfo) MalformedObjectNameException(javax.management.MalformedObjectNameException) HashMap(java.util.HashMap) ServiceDaemon(org.opennms.netmgt.model.ServiceDaemon) ObjectName(javax.management.ObjectName)

Aggregations

ServiceInfo (org.opennms.netmgt.model.ServiceInfo)2 HashMap (java.util.HashMap)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ObjectName (javax.management.ObjectName)1 ServiceDaemon (org.opennms.netmgt.model.ServiceDaemon)1