Search in sources :

Example 1 with Attrib

use of org.opennms.xmlns.xsd.config.jmx_datacollection.Attrib 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 Attrib

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

the class AttributeValidatorTest method testAttribAttributeValidator.

@Test
public void testAttribAttributeValidator() {
    // simple test first
    Attrib attrib = new Attrib();
    attrib.setAlias("ulf");
    attrib.setName("ulf");
    validationManager.validate(attrib, result);
    Assert.assertEquals(Boolean.TRUE, result.isValid());
    // lets have a length issue
    attrib.setAlias(Strings.repeat("X", Config.ATTRIBUTES_ALIAS_MAX_LENGTH + 1));
    validationManager.validate(attrib, result);
    verifyResult(result, attrib, 1, MaximumLengthValidator.ERROR_MESSAGE);
    // lets also have a name issue
    attrib.setAlias("Ülf");
    validationManager.validate(attrib, result);
    verifyResult(result, attrib, 2, MaximumLengthValidator.ERROR_MESSAGE, AttributeNameValidator.ERROR_MESSAGE);
}
Also used : Attrib(org.opennms.xmlns.xsd.config.jmx_datacollection.Attrib) Test(org.junit.Test)

Example 3 with Attrib

use of org.opennms.xmlns.xsd.config.jmx_datacollection.Attrib 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 4 with Attrib

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

the class JmxCollectionCloner method clone.

/**
	 * Clones an Attrib object. Makes a deep copy!
	 * 
	 * @param input
	 * @return
	 */
public static Attrib clone(Attrib input) {
    Attrib output = new Attrib();
    output.setAlias(input.getAlias());
    output.setMaxval(input.getMaxval());
    output.setMinval(input.getMinval());
    output.setName(input.getName());
    output.setType(input.getType());
    return output;
}
Also used : Attrib(org.opennms.xmlns.xsd.config.jmx_datacollection.Attrib) CompAttrib(org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib)

Example 5 with Attrib

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

the class JmxCollectionCloner method clone.

/**
	 * Clones a Mbean object. Makes a deep copy!
	 * 
	 * @param input
	 * @return
	 */
public static Mbean clone(Mbean input) {
    Mbean output = new Mbean();
    output.setExclude(input.getExclude());
    output.setKeyAlias(input.getKeyAlias());
    output.setKeyfield(input.getKeyfield());
    output.setName(input.getName());
    output.setObjectname(input.getObjectname());
    output.getIncludeMbean().addAll(input.getIncludeMbean());
    for (Attrib inputAttrib : input.getAttrib()) {
        output.getAttrib().add(clone(inputAttrib));
    }
    for (CompAttrib inputCombAttrib : input.getCompAttrib()) {
        output.getCompAttrib().add(clone(inputCombAttrib));
    }
    return output;
}
Also used : Mbean(org.opennms.xmlns.xsd.config.jmx_datacollection.Mbean) CompAttrib(org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib) Attrib(org.opennms.xmlns.xsd.config.jmx_datacollection.Attrib) CompAttrib(org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib)

Aggregations

Attrib (org.opennms.xmlns.xsd.config.jmx_datacollection.Attrib)10 CompAttrib (org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib)9 Mbean (org.opennms.xmlns.xsd.config.jmx_datacollection.Mbean)4 ArrayList (java.util.ArrayList)2 CompMember (org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember)2 JmxDatacollectionConfig (org.opennms.xmlns.xsd.config.jmx_datacollection.JmxDatacollectionConfig)2 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 ObjectName (javax.management.ObjectName)1 Test (org.junit.Test)1 QueryResult (org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult)1 JmxCollection (org.opennms.xmlns.xsd.config.jmx_datacollection.JmxCollection)1