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;
}
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);
}
}
}
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;
}
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;
}
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;
}
Aggregations