[jboss-cvs] JBossAS SVN: r111700 - in branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator: metrics and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jul 4 15:18:16 EDT 2011
Author: thauser at redhat.com
Date: 2011-07-04 15:18:15 -0400 (Mon, 04 Jul 2011)
New Revision: 111700
Modified:
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Generator.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/MIBGenerator.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Parser.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserAttributeBindings.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/ManagedBean.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/MappedAttribute.java
Log:
Changes to standalone operation, refinements to MIB naming methodology
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Generator.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Generator.java 2011-06-30 21:50:57 UTC (rev 111699)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Generator.java 2011-07-04 19:18:15 UTC (rev 111700)
@@ -135,11 +135,16 @@
/**
* Entry point method. Called by MIBGenerator class after all of the parsing is completed.
- * Does nothing really itself. Which methods are called depends on the -r flag.
+ * Does nothing really itself.
*/
public void writeFile(){
+ if (outputResName == null){
+ System.out.println("No output file location given. Aborting.");
+ System.exit(2);
+ }
try{
+
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputResName)));
createEntries();
writeMibHeader(out);
@@ -227,22 +232,43 @@
*/
private void createEntries(){
- for (MappedAttribute ma : maList){
- miboList.add(new MIBObject(ma));
+ if (maList != null){
+ for (MappedAttribute ma : maList){
+ if (ma.isAttributeTable())
+ tableList.add(new MIBTable(ma));
+ else
+ miboList.add(new MIBObject(ma));
+ }
}
- for(Mapping mibN : nmList){
- mibnList.add(new MIBNotification(mibN));
+ else {
+ maList = new ArrayList<MappedAttribute>(0);
+ System.out.println("Attribute parsing was skipped. No attribute MIB definitions written.");
}
- for(ManagedBean mb : mbList){
- // we only want to make a table if the MBean's name is a wildcard.
- ObjectName test = null;
- try{
- test = new ObjectName(mb.getName());
- }catch(Exception e){}
- if (test != null && test.isPattern()){
- tableList.add(new MIBTable(mb));
+ if (mbList != null){
+ for(ManagedBean mb : mbList){
+ // we only want to make a table if the MBean's name is a wildcard.
+ ObjectName test = null;
+ try{
+ test = new ObjectName(mb.getName());
+ }catch(Exception e){}
+ if (test != null && test.isPattern())
+ tableList.add(new MIBTable(mb));
+
}
}
+ else {
+ mbList = new AttributeMappings();
+ System.out.println("Attribute parsing was skipped. No list of MBeans is available.");
+ }
+ if (nmList != null){
+ for(Mapping mibN : nmList){
+ mibnList.add(new MIBNotification(mibN));
+ }
+ }
+ else {
+ nmList = new ArrayList<Mapping>(0);
+ System.out.println("Notification parsing was skipped. No notification MIB definitions written.");
+ }
}
/* Internal Classes ----- */
@@ -255,9 +281,7 @@
private class MIBObject extends MIBEntity{
private String fullOid;
private boolean rowEntry; //internally used to avoid adding an OIDDef for a member of an entry
-
-
-
+
MIBObject(String name, String fullOid, String oidDefName){
super();
this.name = name;
@@ -305,9 +329,6 @@
maxAccess = "read-only";
}
- if (ma.isIndex())
- maxAccess = "not-accessible";
-
this.status = (ma.getStatus()!=null) ? ma.getStatus() : "current";
// perhaps have this as an optional attribute in the attributes.xml? Left as blank
@@ -489,7 +510,6 @@
* @author thauser
*
*/
-
private class OIDDef{
private String name; // the name of the OID definition
private String definition; // the OID with '.' replaced by ' ', ready to be output into the MIB
@@ -551,13 +571,30 @@
/** Internal class representing a Table entry in the MIB **/
private class MIBTable extends MIBEntity{
+ private String tablePrefix;
private String rowName;
private MIBTableRow row; // the row created from information contained in
// this MIBTable
+ //creating a table out of an attribute
+ public MIBTable(MappedAttribute ma){
+ this.tablePrefix=ma.getName().substring(0,1).toLowerCase() + ma.getName().substring(1);
+ this.name = (this.tablePrefix!=null) ? this.tablePrefix+"Table" : "UKNOWNTable";
+ this.maxAccess = "not-accessible";
+ String [] temp = ma.getOid().split("\\.");
+ this.objectId = temp[temp.length-1];
+ this.description = (ma.getSnmpDesc()!=null) ? ma.getSnmpDesc() : "";
+ this.rowName = (this.tablePrefix!=null) ? this.tablePrefix+"Entry" : "UNKNOWNRow";
+ this.syntax = this.rowName.substring(0,1).toUpperCase() + this.rowName.substring(1);
+ this.status = (ma.getStatus()!=null) ? ma.getStatus() : "current";
+ setOidDef(ma.getOidPrefix(), ma.getOidDefName());
+ row = new MIBTableRow(this.name, this.tablePrefix, this.rowName, "1", ma.getMode());
+ }
+
// if we find a managedbean with a wildcard object name, we make a table
public MIBTable(ManagedBean mb){
- this.name = (mb.getTableName()!=null) ? mb.getTableName() : "UNKNOWNTABLE";
+ this.tablePrefix = mb.getTableName();
+ this.name = (this.tablePrefix!=null) ? this.tablePrefix+"Table" : "UNKNOWNTable";
this.maxAccess = "not-accessible";
String oid = mb.getOidPrefix();
String oidPrefix = "";
@@ -570,23 +607,13 @@
oidPrefix += temp[i]+".";
}
this.description = (mb.getDesc()!=null) ? mb.getDesc() : "";
- this.rowName = (mb.getRowName()!=null) ? mb.getRowName() : "UNKNOWNROW";
+ this.rowName = (this.tablePrefix!=null) ? this.tablePrefix+"Entry" : "UNKNOWNRow";
this.syntax = this.rowName.substring(0,1).toUpperCase() + this.rowName.substring(1);
this.status = (mb.getStatus()!=null) ? mb.getStatus() : "current";
setOidDef(oidPrefix, mb.getOidDefinition());
- ArrayList<String>indexNames = findIndexes(mb.getAttributes());
- row = new MIBTableRow(this.name, this.rowName, indexNames, temp[temp.length-1], (ArrayList<MappedAttribute>)mb.getAttributes());
+ row = new MIBTableRow(this.name, this.tablePrefix, this.rowName, temp[temp.length-1], (ArrayList<MappedAttribute>)mb.getAttributes());
}
- private ArrayList<String> findIndexes(List<MappedAttribute> maList){
- ArrayList<String> retVal = new ArrayList<String>(1);
- for (MappedAttribute ma : maList){
- if (ma.isIndex())
- retVal.add(ma.getName());
- }
- return retVal;
- }
-
@Override
public String toString(){
StringBuffer buf = new StringBuffer();
@@ -605,46 +632,84 @@
/**Internal class representing a Table Row entry in the MIB **/
private class MIBTableRow extends MIBEntity{
- private ArrayList<String> indexes;
private ArrayList<MIBObject> rowObjects;
private String tableName;
+ private String tablePrefix;
private String typeName;
+ private String indexName;
- MIBTableRow(String tableName, String rowName, ArrayList<String> indexNames, String rowOid, ArrayList<MappedAttribute> attrList){
+ //build from a table=true attribute index and contents are generic.
+ MIBTableRow(String tableName, String tablePrefix, String rowName, String rowOid, String mode){
+ this.tableName = tableName;
+ this.tablePrefix = tablePrefix;
this.name = rowName;
this.objectId = rowOid;
+ this.typeName = this.name.substring(0,1).toUpperCase() + this.name.substring(1);
+ this.syntax = rowName;
+ this.maxAccess="not-accessible";
+ this.status = "current";
+ this.description = "";
+ this.rowObjects = new ArrayList<MIBObject>(1);
+ MappedAttribute index = new MappedAttribute();
+ index.setSnmpType("DisplayString");
+ index.setName("index");
+ index.setOid(".1");
+ index.setMode("ro");
+ index.setOidDefName(this.name);
+ index.setMaxAccess("not-accessible");
+ index.setStatus("current");
+ rowObjects.add(new MIBObject(index,true));
+ this.indexName = "index";
+ MappedAttribute element = new MappedAttribute();
+ element.setSnmpType("DisplayString");
+ element.setName("element");
+ element.setOid(".2");
+ element.setMode(mode);
+ element.setOidDefName(this.name);
+ if (element.isReadWrite)
+ element.setMaxAccess("read-write");
+
+ else
+ element.setMaxAccess("read-only");
+ element.setStatus("current");
+ rowObjects.add(new MIBObject(element,true));
+ }
+
+
+
+ // build from ManagedBean, so we have an attrlist.
+ MIBTableRow(String tableName, String tablePrefix, String rowName, String rowOid, ArrayList<MappedAttribute> attrList){
this.tableName = tableName;
+ this.tablePrefix = tablePrefix;
+ this.name = rowName;
+ this.objectId = rowOid;
this.typeName = this.name.substring(0,1).toUpperCase() + this.name.substring(1);
this.syntax = rowName;
this.maxAccess = "not-accessible";
this.status = "current"; // doesn't make sense to define a table that is not current
this.description = "";
- this.indexes = indexNames;
+ this.indexName = "objectName";
setRowObjects(attrList);
}
private void setRowObjects(ArrayList<MappedAttribute> attrList){
this.rowObjects = new ArrayList<MIBObject>(1);
+ MappedAttribute objectName = new MappedAttribute();
+ objectName.setSnmpType("DisplayString");
+ objectName.setName(this.tablePrefix+"objectName");
+ objectName.setOid(".1");
+ objectName.setMode("ro");
+ objectName.setOidDefName(this.name);
+ objectName.setMaxAccess("not-accessible");
+ objectName.setStatus("current");
+ rowObjects.add(new MIBObject(objectName, true));
for (MappedAttribute ma : attrList){
ma.setOidDefName(this.name);
+ ma.setName(this.tablePrefix+ma.getName().substring(0,1).toUpperCase() + ma.getName().substring(1));
rowObjects.add(new MIBObject(ma,true));
-
}
}
-
- private String printIndexes(){
- StringBuffer buf = new StringBuffer();
- buf.append("INDEX\t{");
- for (int i = 0; i < indexes.size(); i++){
- if (i == indexes.size()-1) // if it's the last, we don't put a coma
- buf.append("\t"+indexes.get(i));
- else
- buf.append("\t"+indexes.get(i)+",");
- }
- buf.append("\n}");
- return buf.toString();
- }
-
+
private String writeRowDefinition(){
StringBuffer buf = new StringBuffer();
buf.append(this.typeName + " ::= SEQUENCE {\n");
@@ -666,7 +731,7 @@
.append("\tMAX-ACCESS\t") .append(this.maxAccess) .append("\n")
.append("\tSTATUS\t") .append(this.status) .append("\n")
.append("\tDESCRIPTION\n\t").append("\""+this.description+"\"\n")
- .append("\t").append(printIndexes()) .append("\n")
+ .append("\n\t\t").append("INDEX\t{\n\t\tIMPLIED "+this.indexName+"\n\t\t}\n")
.append("::= { ").append(this.tableName).append(" "+this.objectId)
.append(" }\t\t\n\n");
buf.append(writeRowDefinition()+"\n");
@@ -676,8 +741,6 @@
}
return buf.toString();
}
-
-
}
/** Abstract class containing all the different common fields of an entry in the MIB **/
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/MIBGenerator.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/MIBGenerator.java 2011-06-30 21:50:57 UTC (rev 111699)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/MIBGenerator.java 2011-07-04 19:18:15 UTC (rev 111700)
@@ -64,6 +64,7 @@
}
catch (Exception e){
printUsageMessage();
+ System.exit(1);
}
Boolean isHelp = (Boolean)cmdParser.getOptionValue(help, Boolean.FALSE);
String aFile = (String)cmdParser.getOptionValue(attributes);
@@ -74,16 +75,8 @@
printUsageMessage();
System.exit(0);
}
-
- if (aFile != null && nFile != null){
- parser = new Parser(aFile, nFile);
- }
- else if (aFile != null){
- parser = new Parser(aFile);
- }
- else if (nFile != null){
- parser = new Parser(nFile);
- }
+
+ parser = new Parser(aFile, nFile);
parser.parse();
Generator generator = new Generator(mibFile, parser.getMaList(), parser.getMbList(), parser.getNmList());
generator.writeFile();
@@ -91,11 +84,12 @@
private static void printUsageMessage(){
- System.out.println("Usage: java -jar jboss-as-varia-mib-generator [OPTION] [FILENAME] .. [OPTION] [FILENAME].." +
- "OPTION:\n-h , --help : display the usage information" +
- "-a , --attributes : indicate the name of attributes.xml, if any" +
- "-n , --notifications : indicate the name of the notification.xml file, if any." +
- "-m , --mib : indicate the desired name of the MIB file. this can be a path.");
+ System.out.println("Usage: java -jar mib-generator.jar [FLAG][FILENAME] .. [FLAG][FILENAME] .. [FLAG][FILENAME]\n" +
+ "[FLAG]s:\n-h , --help : display the usage information\n" +
+ "-a , --attributes : indicate the name of the snmp-adaptor formatted attributes.xml, if any.\n" +
+ "-n , --notifications : indicate the name of the snmp-adaptor formatted notification.xml file, if any.\n" +
+ "-m , --mib : indicate the desired name of the MIB file. This can be a path.\n"+
+ "Example: java -jar mib-generator.jar -a attributes.xml -n notifications.xml -m /home/user/TEST-MIB.mib");
}
}
\ No newline at end of file
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Parser.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Parser.java 2011-06-30 21:50:57 UTC (rev 111699)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Parser.java 2011-07-04 19:18:15 UTC (rev 111700)
@@ -21,8 +21,7 @@
*/
package org.jboss.jmx.adaptor.snmp.generator;
-import java.io.InputStream;
-import java.io.FileInputStream;
+import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -54,25 +53,12 @@
public class Parser {
String inputAttrFile;
String inputNotificationFile;
- InputStream inputAttrStream; //if we are given this in the constructor, use it instead of defining it in parseAttributesXml()
- InputStream inputNotiStream;
ArrayList<MappedAttribute> maList;
ArrayList<Mapping> nmList;//list of notifications that we care about.
AttributeMappings mbList;
- public Parser(){
-
- }
+ public Parser(){}
- // constructor with a single input file; simple, just parse this one file.
- public Parser(String inputAttrFile){
- this.inputAttrFile = inputAttrFile;
- this.inputNotificationFile = null;
- this.maList = new ArrayList<MappedAttribute>(1);
- this.mbList = new AttributeMappings();
-
- }
-
public Parser(String inputAttrFile, String inputNotificationFile){
this.inputAttrFile = inputAttrFile;
this.inputNotificationFile = inputNotificationFile;
@@ -128,8 +114,17 @@
public void parse(){
// TODO: refine the checks here. they are not enough
try {
- parseAttributesXml();
- parseNotificationsXml();
+ if (this.inputAttrFile != null){
+ parseAttributesXml();
+ }
+ else
+ System.out.println("No attributes file indicated, skipping.");
+
+ if (this.inputNotificationFile != null){
+ parseNotificationsXml();
+ }
+ else
+ System.out.println("No notifications file indicated, skipping;");
}
catch (Exception e){
e.printStackTrace();
@@ -140,17 +135,25 @@
private void parseNotificationsXml() throws Exception{
ObjectModelFactory omf = new ParserNotificationBindings();
- InputStream is = this.inputNotiStream;
ArrayList<Mapping> mappings = null;
+ FileInputStream is = null;
try{
- if(is == null){
- is = new FileInputStream(this.inputNotificationFile);
- }
+
+ is = new FileInputStream(this.inputNotificationFile);
+
Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
mappings = (ArrayList)unmarshaller.unmarshal(is,omf,null);
}
+ catch (NoClassDefFoundError e){
+ System.out.println("The notifications file is not formatted correctly: '"+this.inputNotificationFile+"'");
+ System.exit(1);
+ }
+ catch (FileNotFoundException e){
+ System.out.println("Filename given for notifications does not exist: '"+this.inputNotificationFile+"'");
+ System.exit(1);
+ }
catch (Exception e){
throw e;
}
@@ -183,14 +186,13 @@
*/
private void parseAttributesXml() throws Exception{
ObjectModelFactory omf = new ParserAttributeBindings();
- InputStream is = this.inputAttrStream;
AttributeMappings mappings = null;
+ FileInputStream is = null;
try{
- // locate resource
- if(is == null){
- is = new FileInputStream(this.inputAttrFile);
- }
+ is = new FileInputStream(this.inputAttrFile);
+
+
// create unmarshaller
Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
@@ -198,6 +200,14 @@
mappings = (AttributeMappings)unmarshaller.unmarshal(is, omf, null);
setMbList(mappings);
}
+ catch (NoClassDefFoundError e){
+ System.out.println("The attributes file is not formatted correctly: '"+this.inputAttrFile+"'");
+ System.exit(1);
+ }
+ catch (FileNotFoundException e){
+ System.out.println("Filename given for attributes.xml does not exist: '"+this.inputAttrFile+"'");
+ System.exit(1);
+ }
catch (Exception e){
throw e;
}
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserAttributeBindings.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserAttributeBindings.java 2011-06-30 21:50:57 UTC (rev 111699)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserAttributeBindings.java 2011-07-04 19:18:15 UTC (rev 111700)
@@ -70,7 +70,6 @@
String oidPrefix = attrs.getValue("oid-prefix");
String oidDefinition = attrs.getValue("definition-name");
String tableName = attrs.getValue("table-name");
- String rowName = attrs.getValue("row-name");
String desc = attrs.getValue("description");
String status = attrs.getValue("status");
ManagedBean child = new ManagedBean();
@@ -78,7 +77,6 @@
child.setOidPrefix(oidPrefix);
child.setOidDefinition(oidDefinition);
child.setTableName(tableName);
- child.setRowName(rowName);
child.setDesc(desc);
child.setStatus(status);
return child;
@@ -105,7 +103,7 @@
String maxAccess = attrs.getValue("max-access");
String desc = attrs.getValue("description");
String status = attrs.getValue("status");
- String indexCheck = attrs.getValue("index");
+ String table = attrs.getValue("table");
attribute = new MappedAttribute();
attribute.setName(name);
attribute.setOid(oid);
@@ -114,8 +112,7 @@
attribute.setMaxAccess(maxAccess);
attribute.setSnmpDesc(desc);
attribute.setStatus(status);
- boolean index = (indexCheck != null)? (indexCheck.equalsIgnoreCase("true")) : false;
- attribute.setIsIndex(index);
+ attribute.setTable(table);
}
return attribute;
}
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/ManagedBean.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/ManagedBean.java 2011-06-30 21:50:57 UTC (rev 111699)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/ManagedBean.java 2011-07-04 19:18:15 UTC (rev 111700)
@@ -38,7 +38,6 @@
private String oidPrefix;
private String oidDefinition;
private String tableName;
- private String rowName;
private String description;
private String status;
private List<MappedAttribute> attributes;
@@ -100,14 +99,6 @@
this.description = desc;
}
- public String getRowName(){
- return this.rowName;
- }
-
- public void setRowName(String rowName){
- this.rowName = rowName;
- }
-
public String getStatus(){
return this.status;
}
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/MappedAttribute.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/MappedAttribute.java 2011-06-30 21:50:57 UTC (rev 111699)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/MappedAttribute.java 2011-07-04 19:18:15 UTC (rev 111700)
@@ -34,7 +34,10 @@
private String name;
private String oid;
private String mode;
- private boolean isReadWrite = false;
+ private boolean isReadWrite = false;
+ private String table;
+ private boolean isAttributeTable = false;
+
private String mbName = ""; //the name of the mBean this MappedAttribute is associated with
private String snmpType = ""; //the type for the MIB we should use, if provided
private String oidPrefix = ""; // all of these metrics are useful in the MIB Generator
@@ -42,7 +45,6 @@
private String maxAccess = "";
private String description = "";
private String status = "";
- private boolean isIndex = false;
public MappedAttribute() {
}
@@ -84,7 +86,24 @@
isReadWrite = true;
}
}
+ /** Attribute table */
+ public boolean isAttributeTable() {
+ return isAttributeTable;
+ }
+ /** Attribute table */
+ public String getTable() {
+ return table;
+ }
+
+ @XmlAttribute(name="table")
+ public void setTable(String table) {
+ this.table = table;
+ if(table != null && Boolean.valueOf(table)) {
+ isAttributeTable = true;
+ }
+ }
+
public String getMbean(){
return this.mbName;
}
@@ -145,14 +164,6 @@
this.status = status;
}
- public boolean isIndex(){
- return this.isIndex;
- }
-
- public void setIsIndex(boolean b){
- isIndex = b;
- }
-
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append("[name=").append(name);
More information about the jboss-cvs-commits
mailing list