Search in sources :

Example 1 with JmxGetter

use of voldemort.annotations.jmx.JmxGetter in project voldemort by voldemort.

the class JmxUtils method extractOperationInfo.

/**
     * Extract all operations and attributes from the given object that have
     * been annotated with the Jmx annotation. Operations are all methods that
     * are marked with the JmxOperation annotation.
     * 
     * @param object The object to process
     * @return An array of operations taken from the object
     */
public static ModelMBeanOperationInfo[] extractOperationInfo(Object object) {
    ArrayList<ModelMBeanOperationInfo> infos = new ArrayList<ModelMBeanOperationInfo>();
    for (Method m : object.getClass().getMethods()) {
        JmxOperation jmxOperation = m.getAnnotation(JmxOperation.class);
        JmxGetter jmxGetter = m.getAnnotation(JmxGetter.class);
        JmxSetter jmxSetter = m.getAnnotation(JmxSetter.class);
        if (jmxOperation != null || jmxGetter != null || jmxSetter != null) {
            String description = "";
            int visibility = 1;
            int impact = MBeanOperationInfo.UNKNOWN;
            if (jmxOperation != null) {
                description = jmxOperation.description();
                impact = jmxOperation.impact();
            } else if (jmxGetter != null) {
                description = jmxGetter.description();
                impact = MBeanOperationInfo.INFO;
                visibility = 4;
            } else if (jmxSetter != null) {
                description = jmxSetter.description();
                impact = MBeanOperationInfo.ACTION;
                visibility = 4;
            }
            ModelMBeanOperationInfo info = new ModelMBeanOperationInfo(m.getName(), description, extractParameterInfo(m), m.getReturnType().getName(), impact);
            info.getDescriptor().setField("visibility", Integer.toString(visibility));
            infos.add(info);
        }
    }
    return infos.toArray(new ModelMBeanOperationInfo[infos.size()]);
}
Also used : ModelMBeanOperationInfo(javax.management.modelmbean.ModelMBeanOperationInfo) JmxOperation(voldemort.annotations.jmx.JmxOperation) JmxGetter(voldemort.annotations.jmx.JmxGetter) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) JmxSetter(voldemort.annotations.jmx.JmxSetter)

Example 2 with JmxGetter

use of voldemort.annotations.jmx.JmxGetter in project voldemort by voldemort.

the class JmxUtils method extractAttributeInfo.

/**
     * Extract all operations from the given object that have been annotated
     * with the Jmx annotation. Operations are all methods that are marked with
     * the JMX annotation and are not getters and setters (which are extracted
     * as attributes).
     * 
     * @param object The object to process
     * @return An array of attributes taken from the object
     */
public static ModelMBeanAttributeInfo[] extractAttributeInfo(Object object) {
    Map<String, Method> getters = new HashMap<String, Method>();
    Map<String, Method> setters = new HashMap<String, Method>();
    Map<String, String> descriptions = new HashMap<String, String>();
    for (Method m : object.getClass().getMethods()) {
        JmxGetter getter = m.getAnnotation(JmxGetter.class);
        if (getter != null) {
            getters.put(getter.name(), m);
            descriptions.put(getter.name(), getter.description());
        }
        JmxSetter setter = m.getAnnotation(JmxSetter.class);
        if (setter != null) {
            setters.put(setter.name(), m);
            descriptions.put(setter.name(), setter.description());
        }
    }
    Set<String> attributes = new HashSet<String>(getters.keySet());
    attributes.addAll(setters.keySet());
    List<ModelMBeanAttributeInfo> infos = new ArrayList<ModelMBeanAttributeInfo>();
    for (String name : attributes) {
        try {
            Method getter = getters.get(name);
            Method setter = setters.get(name);
            ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(name, descriptions.get(name), getter, setter);
            Descriptor descriptor = info.getDescriptor();
            if (getter != null)
                descriptor.setField("getMethod", getter.getName());
            if (setter != null)
                descriptor.setField("setMethod", setter.getName());
            info.setDescriptor(descriptor);
            infos.add(info);
        } catch (IntrospectionException e) {
            throw new VoldemortException(e);
        }
    }
    return infos.toArray(new ModelMBeanAttributeInfo[infos.size()]);
}
Also used : JmxGetter(voldemort.annotations.jmx.JmxGetter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IntrospectionException(javax.management.IntrospectionException) Method(java.lang.reflect.Method) VoldemortException(voldemort.VoldemortException) JmxSetter(voldemort.annotations.jmx.JmxSetter) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) Descriptor(javax.management.Descriptor) HashSet(java.util.HashSet)

Example 3 with JmxGetter

use of voldemort.annotations.jmx.JmxGetter in project voldemort by voldemort.

the class BannagePeriodFailureDetector method getUnavailableNodesBannageExpiration.

@JmxGetter(name = "unavailableNodesBannageExpiration", description = "List of unavailable nodes and their respective bannage expiration")
public String getUnavailableNodesBannageExpiration() {
    List<String> list = new ArrayList<String>();
    long bannagePeriod = failureDetectorConfig.getBannagePeriod();
    long currentTime = failureDetectorConfig.getTime().getMilliseconds();
    for (Node node : getConfig().getCluster().getNodes()) {
        if (!isAvailable(node)) {
            NodeStatus nodeStatus = getNodeStatus(node);
            long millis = 0;
            synchronized (nodeStatus) {
                millis = (nodeStatus.getLastChecked() + bannagePeriod) - currentTime;
            }
            list.add(node.getId() + "=" + millis);
        }
    }
    return StringUtils.join(list, ",");
}
Also used : Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) JmxGetter(voldemort.annotations.jmx.JmxGetter)

Example 4 with JmxGetter

use of voldemort.annotations.jmx.JmxGetter in project voldemort by voldemort.

the class ThresholdFailureDetector method getNodeThresholdStats.

@JmxGetter(name = "nodeThresholdStats", description = "Each node is listed with its status (available/unavailable) and success percentage")
public String getNodeThresholdStats() {
    List<String> list = new ArrayList<String>();
    for (Node node : getConfig().getCluster().getNodes()) {
        NodeStatus nodeStatus = getNodeStatus(node);
        boolean isAvailabile = false;
        long percentage = 0;
        synchronized (nodeStatus) {
            isAvailabile = nodeStatus.isAvailable();
            percentage = nodeStatus.getTotal() > 0 ? (nodeStatus.getSuccess() * 100) / nodeStatus.getTotal() : 0;
        }
        list.add(node.getId() + ",status=" + (isAvailabile ? "available" : "unavailable") + ",percentage=" + percentage + "%");
    }
    return StringUtils.join(list, ";");
}
Also used : Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) JmxGetter(voldemort.annotations.jmx.JmxGetter)

Aggregations

ArrayList (java.util.ArrayList)4 JmxGetter (voldemort.annotations.jmx.JmxGetter)4 Method (java.lang.reflect.Method)2 JmxSetter (voldemort.annotations.jmx.JmxSetter)2 Node (voldemort.cluster.Node)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Descriptor (javax.management.Descriptor)1 IntrospectionException (javax.management.IntrospectionException)1 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)1 ModelMBeanOperationInfo (javax.management.modelmbean.ModelMBeanOperationInfo)1 VoldemortException (voldemort.VoldemortException)1 JmxOperation (voldemort.annotations.jmx.JmxOperation)1