Search in sources :

Example 1 with CompAttrib

use of org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib in project opennms by OpenNMS.

the class JmxDatacollectionConfiggenerator method generateJmxConfigModel.

public JmxDatacollectionConfig generateJmxConfigModel(List<String> ids, MBeanServerConnection mBeanServerConnection, String serviceName, Boolean runStandardVmBeans, Boolean skipNonNumber, Map<String, String> dictionary) throws MBeanServerQueryException, IOException, JMException {
    logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: " + runStandardVmBeans + "\n dictionary" + dictionary);
    aliasList.clear();
    aliasMap.clear();
    nameCutter.setDictionary(dictionary);
    final QueryResult queryResult = queryMbeanServer(ids, mBeanServerConnection, runStandardVmBeans);
    final JmxDatacollectionConfig xmlJmxDatacollectionConfig = createJmxDataCollectionConfig(serviceName, rrd);
    final JmxCollection xmlJmxCollection = xmlJmxDatacollectionConfig.getJmxCollection().get(0);
    for (QueryResult.MBeanResult eachMBeanResult : queryResult.getMBeanResults()) {
        final ObjectName objectName = eachMBeanResult.objectName;
        final Mbean xmlMbean = createMbean(objectName);
        final QueryResult.AttributeResult attributeResult = eachMBeanResult.attributeResult;
        for (MBeanAttributeInfo jmxBeanAttributeInfo : attributeResult.attributes) {
            // check for CompositeData
            if ("javax.management.openmbean.CompositeData".equals(jmxBeanAttributeInfo.getType())) {
                CompAttrib compAttrib = createCompAttrib(mBeanServerConnection, objectName, jmxBeanAttributeInfo, skipNonNumber);
                if (compAttrib != null) {
                    xmlMbean.getCompAttrib().add(compAttrib);
                }
            }
            if (skipNonNumber && !numbers.contains(jmxBeanAttributeInfo.getType())) {
                logger.warn("The type of attribute '{}' is '{}' and '--skipNonNumber' is set. Ignoring.", jmxBeanAttributeInfo.getName(), jmxBeanAttributeInfo.getType());
            } else {
                Attrib xmlJmxAttribute = createAttr(jmxBeanAttributeInfo);
                xmlMbean.getAttrib().add(xmlJmxAttribute);
            }
        }
        if (!xmlMbean.getAttrib().isEmpty() || !xmlMbean.getCompAttrib().isEmpty()) {
            xmlJmxCollection.getMbeans().getMbean().add(xmlMbean);
        }
    }
    if (xmlJmxCollection.getMbeans().getMbean().size() != queryResult.getMBeanResults().size()) {
        logger.warn("Queried {} MBeans, but only got {} in the result set.", queryResult.getMBeanResults().size(), xmlJmxCollection.getMbeans().getMbean().size());
    }
    return xmlJmxDatacollectionConfig;
}
Also used : QueryResult(org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult) Mbean(org.opennms.xmlns.xsd.config.jmx_datacollection.Mbean) JmxDatacollectionConfig(org.opennms.xmlns.xsd.config.jmx_datacollection.JmxDatacollectionConfig) CompAttrib(org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib) JmxCollection(org.opennms.xmlns.xsd.config.jmx_datacollection.JmxCollection) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) CompAttrib(org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib) Attrib(org.opennms.xmlns.xsd.config.jmx_datacollection.Attrib) ObjectName(javax.management.ObjectName)

Example 2 with CompAttrib

use of org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib in project opennms by OpenNMS.

the class MbeansHierarchicalContainer method addNodes.

private void addNodes(Mbean mbean) {
    List newNodeList = MBeansHelper.getMBeansTreeElements(mbean);
    newNodeList.add(mbean);
    String rootItemId = addNodes(newNodeList);
    // add optional comp attributes, if there are any
    if (mbean.getCompAttrib() != null && !mbean.getCompAttrib().isEmpty()) {
        for (CompAttrib eachCompAttrib : mbean.getCompAttrib()) {
            addNode(rootItemId, eachCompAttrib, false);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) CompAttrib(org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib)

Example 3 with CompAttrib

use of org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib in project opennms by OpenNMS.

the class TestHelper method createCompAttrib.

public static CompAttrib createCompAttrib(String name, CompMember... compMember) {
    CompAttrib compAttrib = new CompAttrib();
    compAttrib.setName(name);
    for (CompMember eachMember : compMember) {
        compAttrib.getCompMember().add(eachMember);
    }
    return compAttrib;
}
Also used : CompAttrib(org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib) CompMember(org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember)

Example 4 with CompAttrib

use of org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib in project opennms by OpenNMS.

the class MBeansView method createJmxDataCollectionAccordingToSelection.

/**
	 * The whole point was to select/deselect
	 * Mbeans/Attribs/CompMembers/CompAttribs. In this method we simply create a
	 * JmxDatacollectionConfig considering the choices we made in the gui. To do
	 * this, we clone the original <code>JmxDatacollectionConfig</code>
	 * loaded at the beginning. After that we remove all
	 * MBeans/Attribs/CompMembers/CompAttribs and add all selected
	 * MBeans/Attribs/CompMembers/CompAttribs afterwards.
	 *
	 * @return
	 */
private static JmxDatacollectionConfig createJmxDataCollectionAccordingToSelection(final UiModel uiModel, final SelectionManager selectionManager) {
    /*
		 * At First we clone the original collection. This is done, because if
		 * we make any modifications (e.g. deleting not selected elements) the
		 * data isn't available in the GUI, too. To avoid reloading the data
		 * from server, we just clone it.
		 */
    JmxDatacollectionConfig clone = JmxCollectionCloner.clone(uiModel.getRawModel());
    /*
		 * At second we remove all MBeans from original data and get only
		 * selected once.
		 */
    List<Mbean> exportBeans = clone.getJmxCollection().get(0).getMbeans().getMbean();
    exportBeans.clear();
    Iterable<Mbean> selectedMbeans = selectionManager.getSelectedMbeans();
    for (Mbean mbean : selectedMbeans) {
        /*
			 * We remove all Attributes from Mbean, because we only want
			 * selected ones.
			 */
        Mbean exportBean = JmxCollectionCloner.clone(mbean);
        // we only want selected ones :)
        exportBean.getAttrib().clear();
        for (Attrib att : selectionManager.getSelectedAttributes(mbean)) {
            exportBean.getAttrib().add(JmxCollectionCloner.clone(att));
        }
        // we do not add the parent
        if (!exportBean.getAttrib().isEmpty()) {
            exportBeans.add(exportBean);
        }
        /*
			 * We remove all CompAttribs and CompMembers from MBean,
			 * because we only want selected ones.
			 */
        exportBean.getCompAttrib().clear();
        for (CompAttrib compAtt : selectionManager.getSelectedCompositeAttributes(mbean)) {
            CompAttrib cloneCompAtt = JmxCollectionCloner.clone(compAtt);
            cloneCompAtt.getCompMember().clear();
            for (CompMember compMember : selectionManager.getSelectedCompositeMembers(compAtt)) {
                cloneCompAtt.getCompMember().add(JmxCollectionCloner.clone(compMember));
            }
            // we do not add the child
            if (!cloneCompAtt.getCompMember().isEmpty()) {
                exportBean.getCompAttrib().add(cloneCompAtt);
            }
        }
    }
    // we sort the order, so the result is deterministic
    sort(exportBeans);
    // Last but not least, we need to update the service name
    clone.getJmxCollection().get(0).setName(uiModel.getServiceName());
    return clone;
}
Also used : Mbean(org.opennms.xmlns.xsd.config.jmx_datacollection.Mbean) JmxDatacollectionConfig(org.opennms.xmlns.xsd.config.jmx_datacollection.JmxDatacollectionConfig) CompAttrib(org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib) CompAttrib(org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib) Attrib(org.opennms.xmlns.xsd.config.jmx_datacollection.Attrib) CompMember(org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember)

Example 5 with CompAttrib

use of org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib in project opennms by OpenNMS.

the class JmxCollectionCloner method clone.

/**
	 * Clones a CompAttrib object. Makes a deep copy!
	 * 
	 * @param input
	 * @return
	 */
public static CompAttrib clone(CompAttrib input) {
    CompAttrib output = new CompAttrib();
    output.setAlias(input.getAlias());
    output.setName(input.getName());
    output.setType(input.getType());
    for (CompMember inputMember : input.getCompMember()) {
        output.getCompMember().add(clone(inputMember));
    }
    return output;
}
Also used : CompAttrib(org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib) CompMember(org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember)

Aggregations

CompAttrib (org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib)13 CompMember (org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember)8 Mbean (org.opennms.xmlns.xsd.config.jmx_datacollection.Mbean)7 Attrib (org.opennms.xmlns.xsd.config.jmx_datacollection.Attrib)5 ArrayList (java.util.ArrayList)3 JmxDatacollectionConfig (org.opennms.xmlns.xsd.config.jmx_datacollection.JmxDatacollectionConfig)2 Collection (java.util.Collection)1 List (java.util.List)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 ObjectName (javax.management.ObjectName)1 CompositeData (javax.management.openmbean.CompositeData)1 Before (org.junit.Before)1 QueryResult (org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult)1 SelectionManager (org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.SelectionManager)1 ValidationResult (org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.validation.ValidationResult)1 JmxCollection (org.opennms.xmlns.xsd.config.jmx_datacollection.JmxCollection)1