Skip to content

Commit

Permalink
Removed redundant getInetAddress() function and converted the "all"
Browse files Browse the repository at this point in the history
and "ignore" type fields into constants.
  • Loading branch information
soleger committed Apr 23, 2014
1 parent a771cf6 commit ced3e36
Show file tree
Hide file tree
Showing 29 changed files with 66 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public class AttributeGroupType {
private final String m_name;
private final String m_ifType;

/**
* TODO Document this value.
*/
public static final String IF_TYPE_ALL = "all";

/**
* TODO Document this value.
*/
public static final String IF_TYPE_IGNORE = "ignore";

private SortedSet<AttributeDefinition> m_attributeTypes = new TreeSet<AttributeDefinition>(new ByNameComparator());

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ public interface CollectionAgent extends NetworkInterface<InetAddress> {
@Override
String toString();

/**
* <p>getInetAddress</p>
*
* @return a {@link java.net.InetAddress} object.
*/
InetAddress getInetAddress();

/**
* <p>getSavedSysUpTime</p>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void initialize(CollectionAgent agent, Map<String, Object> parameters) {
LOG.debug(sb.toString());
throw new IllegalStateException(sb.toString());
} else {
nodeState = new JdbcAgentState(agent.getInetAddress(), parameters);
nodeState = new JdbcAgentState(agent.getAddress(), parameters);
LOG.info("initialize: Scheduling interface for collection: {}", nodeState.getAddress());
m_scheduledNodes.put(scheduledNodeKey, nodeState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void setCollectionTimestamp(Date date) {
*/
protected void collect() throws CollectionException {
try {
TcaData tracker = new TcaData(m_agent.getInetAddress());
TcaData tracker = new TcaData(m_agent.getAddress());
SnmpWalker walker = SnmpUtils.createWalker(m_agent.getAgentConfig(), "TcaCollector for " + m_agent.getHostAddress(), tracker);
walker.start();
LOG.debug("collect: successfully instantiated TCA Collector for {}", m_agent.getHostAddress());
Expand Down Expand Up @@ -205,7 +205,7 @@ protected List<TcaCollectionResource> getCollectionResources() {
*/
private void process(TcaData tracker) throws Exception {
LOG.debug("process: processing raw TCA data for {} peers.", tracker.size());
AttributeGroupType attribGroupType = new AttributeGroupType(TcaCollectionResource.RESOURCE_TYPE_NAME, "all"); // It will be treated like a Multi-Instance Resource
AttributeGroupType attribGroupType = new AttributeGroupType(TcaCollectionResource.RESOURCE_TYPE_NAME, AttributeGroupType.IF_TYPE_ALL); // It will be treated like a Multi-Instance Resource
long timestamp = 0;
for (TcaDataEntry entry : tracker.getEntries()) {
long lastTimestamp = getLastTimestamp(new TcaCollectionResource(m_agent, entry.getPeerAddress()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,6 @@ public InetAddress getAddress() {
return m_address;
}

/**
* <p>getInetAddress</p>
*
* @return a {@link java.net.InetAddress} object.
*/
public InetAddress getInetAddress() {
return m_address;
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private void initializeRrdDirs() {
*/
private void loadAttributeGroupList(final VmwareCimCollection collection) {
for (final VmwareCimGroup vpm : collection.getVmwareCimGroup()) {
final AttributeGroupType attribGroupType1 = new AttributeGroupType(vpm.getName(), "all");
final AttributeGroupType attribGroupType1 = new AttributeGroupType(vpm.getName(), AttributeGroupType.IF_TYPE_ALL);
m_groupTypeList.put(vpm.getName(), attribGroupType1);
}
}
Expand Down Expand Up @@ -319,7 +319,7 @@ public CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<Strin
if (!cimObjects.containsKey(cimClass)) {
List<CIMObject> cimList = null;
try {
cimList = vmwareViJavaAccess.queryCimObjects(hostSystem, cimClass, InetAddressUtils.str(agent.getInetAddress()));
cimList = vmwareViJavaAccess.queryCimObjects(hostSystem, cimClass, InetAddressUtils.str(agent.getAddress()));
} catch (Exception e) {
logger.warn("Error retrieving CIM values from host system '{}'. Error message: '{}'", vmwareManagedObjectId, e.getMessage());
return collectionSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<Strin
}

for (final VmwareGroup vmwareGroup : collection.getVmwareGroup()) {
final AttributeGroupType attribGroupType = new AttributeGroupType(vmwareGroup.getName(), "all");
final AttributeGroupType attribGroupType = new AttributeGroupType(vmwareGroup.getName(), AttributeGroupType.IF_TYPE_ALL);

if ("node".equalsIgnoreCase(vmwareGroup.getResourceType())) {
// single instance value
Expand Down
4 changes: 4 additions & 0 deletions opennms-config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
<groupId>org.opennms</groupId>
<artifactId>opennms-model</artifactId>
</dependency>
<dependency>
<groupId>org.opennms.features.collection</groupId>
<artifactId>org.opennms.features.collection.api</artifactId>
</dependency>
<dependency>
<groupId>org.opennms.features.poller</groupId>
<artifactId>org.opennms.features.poller.api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.opennms.core.spring.FileReloadContainer;
import org.opennms.core.utils.ConfigFileConstants;
import org.opennms.core.xml.AbstractJaxbConfigDao;
import org.opennms.netmgt.collection.api.AttributeGroupType;
import org.opennms.netmgt.config.datacollection.DatacollectionConfig;
import org.opennms.netmgt.config.datacollection.Group;
import org.opennms.netmgt.config.datacollection.Groups;
Expand Down Expand Up @@ -415,11 +416,11 @@ private void processGroupName(final String cName, final String groupName, final

boolean addGroupObjects = false;
if (ifType == NODE_ATTRIBUTES) {
if (groupIfType.equals("ignore")) {
if (groupIfType.equals(AttributeGroupType.IF_TYPE_IGNORE)) {
addGroupObjects = true;
}
} else {
if (groupIfType.equals("all")) {
if (groupIfType.equals(AttributeGroupType.IF_TYPE_ALL)) {
addGroupObjects = true;
} else if ("ignore".equals(groupIfType)) {
// Do nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private boolean isSchedulingComplete() {
private void sendEvent(String uei, String reason) {
EventBuilder builder = new EventBuilder(uei, "OpenNMS.Collectd");
builder.setNodeid(m_nodeId);
builder.setInterface(m_agent.getInetAddress());
builder.setInterface(m_agent.getAddress());
builder.setService(m_spec.getServiceName());
builder.setHost(InetAddressUtils.getLocalHostName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@ private DefaultCollectionAgent(final CollectionAgentService agentService) {
/** {@inheritDoc} */
@Override
public InetAddress getAddress() {
return getInetAddress();
}

/** {@inheritDoc} */
@Override
public InetAddress getInetAddress() {
if (m_inetAddress == null) {
m_inetAddress = m_agentService.getInetAddress();
}
Expand Down Expand Up @@ -136,7 +130,7 @@ public Boolean isStoreByForeignSource() {
*/
@Override
public String getHostAddress() {
return InetAddressUtils.str(getInetAddress());
return InetAddressUtils.str(getAddress());
}

/* (non-Javadoc)
Expand Down Expand Up @@ -335,7 +329,7 @@ public String toString() {
*/
@Override
public SnmpAgentConfig getAgentConfig() {
return SnmpPeerFactory.getInstance().getAgentConfig(getInetAddress());
return SnmpPeerFactory.getInstance().getAgentConfig(getAddress());
}

private Set<SnmpIfData> getSnmpInterfaceData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Event createForceResanEvent() {

bldr.setNodeid(m_agent.getNodeId());

bldr.setInterface(m_agent.getInetAddress());
bldr.setInterface(m_agent.getAddress());

bldr.setService(SnmpCollector.SERVICE_NAME);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ private static List<HttpCollectionAttribute> processResponse(final Locale respon
if (matches) {
LOG.debug("processResponse: found matching attributes: {}", matches);
final List<Attrib> attribDefs = collectionSet.getUriDef().getAttributes().getAttribCollection();
final AttributeGroupType groupType = new AttributeGroupType(collectionSet.getUriDef().getName(),"all");
final AttributeGroupType groupType = new AttributeGroupType(collectionSet.getUriDef().getName(), AttributeGroupType.IF_TYPE_ALL);

final List<Locale> locales = new ArrayList<Locale>();
if (responseLocale != null) {
Expand Down Expand Up @@ -699,7 +699,7 @@ private static List<NameValuePair> buildRequestParameters(final HttpCollectionSe

private static URI buildUri(final HttpCollectionSet collectionSet) throws URISyntaxException {
HashMap<String,String> substitutions = new HashMap<String,String>();
substitutions.put("ipaddr", InetAddressUtils.str(collectionSet.getAgent().getInetAddress()));
substitutions.put("ipaddr", InetAddressUtils.str(collectionSet.getAgent().getAddress()));
substitutions.put("nodeid", Integer.toString(collectionSet.getAgent().getNodeId()));

URIBuilder ub = new URIBuilder();
Expand Down Expand Up @@ -811,7 +811,7 @@ private static class HttpCollectionResource implements CollectionResource {

public HttpCollectionResource(CollectionAgent agent, Uri uriDef) {
m_agent=agent;
m_attribGroup=new AttributeGroup(this, new AttributeGroupType(uriDef.getName(), "all"));
m_attribGroup=new AttributeGroup(this, new AttributeGroupType(uriDef.getName(), AttributeGroupType.IF_TYPE_ALL));
}

public void storeResults(List<HttpCollectionAttribute> results) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<Strin
String excludeList = beanInfo.getExcludes();
//All JMX collected values are per node
String obj = useMbeanForRrds ? mbeanName : objectName;
AttributeGroupType attribGroupType=new AttributeGroupType(fixGroupName(obj),"all");
AttributeGroupType attribGroupType=new AttributeGroupType(fixGroupName(obj), AttributeGroupType.IF_TYPE_ALL);

List<String> attribNames = beanInfo.getAttributeNames();
List<String> compAttribNames = beanInfo.getCompositeAttributeNames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ public List<SnmpAttributeType> loadAliasAttributeTypes(SnmpCollectionAgent agent
ifAliasMibObject.setInstance("ifIndex");

ifAliasMibObject.setGroupName("aliasedResource");
ifAliasMibObject.setGroupIfType("all");
ifAliasMibObject.setGroupIfType(AttributeGroupType.IF_TYPE_ALL);

AttributeGroupType groupType = new AttributeGroupType(ifAliasMibObject.getGroupName(), ifAliasMibObject.getGroupIfType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public SnmpNodeCollector getNodeCollector() {
private SnmpNodeCollector createNodeCollector() {
SnmpNodeCollector nodeCollector = null;
if (!getAttributeList().isEmpty()) {
nodeCollector = new SnmpNodeCollector(m_agent.getInetAddress(), getAttributeList(), this);
nodeCollector = new SnmpNodeCollector(m_agent.getAddress(), getAttributeList(), this);
}
return nodeCollector;
}
Expand All @@ -213,7 +213,7 @@ private SnmpIfCollector createIfCollector() {
SnmpIfCollector ifCollector = null;
// construct the ifCollector
if (hasInterfaceDataToCollect() || hasGenericIndexResourceDataToCollect()) {
ifCollector = new SnmpIfCollector(m_agent.getInetAddress(), getCombinedIndexedAttributes(), this);
ifCollector = new SnmpIfCollector(m_agent.getAddress(), getCombinedIndexedAttributes(), this);
}
return ifCollector;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private SnmpAttribute buildStringAttribute() {
mibObject.setMaxval(null);
mibObject.setMinval(null);

SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", "ignore"));
SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));

return new SnmpAttribute(resource, attributeType, SnmpUtils.getValueFactory().getOctetString("foo".getBytes()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void collectSingleMbeanWithSingleAttribute() {
CollectionSet collectionSet = jmxCollector.collect(collectionAgent, null, null);
SingleResourceCollectionSet jmxCollectionSet = (SingleResourceCollectionSet) collectionSet;
JMXCollectionResource jmxCollectionResource = (JMXCollectionResource)jmxCollectionSet.getCollectionResource();
AttributeGroup group = jmxCollectionResource.getGroup(new AttributeGroupType("java_lang_type_Compilation", "all"));
AttributeGroup group = jmxCollectionResource.getGroup(new AttributeGroupType("java_lang_type_Compilation", AttributeGroupType.IF_TYPE_ALL));
assertEquals(1, group.getAttributes().size());
printDebugAttributeGroup(group);

Expand All @@ -173,7 +173,7 @@ public void collectSingleMbeanWithOneNotAvailableAttribute() {
CollectionSet collectionSet = jmxCollector.collect(collectionAgent, null, null);
SingleResourceCollectionSet jmxCollectionSet = (SingleResourceCollectionSet) collectionSet;
JMXCollectionResource jmxCollectionResource = (JMXCollectionResource)jmxCollectionSet.getCollectionResource();
AttributeGroup group = jmxCollectionResource.getGroup(new AttributeGroupType("java_lang_type_Compilation", "all"));
AttributeGroup group = jmxCollectionResource.getGroup(new AttributeGroupType("java_lang_type_Compilation", AttributeGroupType.IF_TYPE_ALL));
assertEquals(0, group.getAttributes().size());
printDebugAttributeGroup(group);

Expand All @@ -190,7 +190,7 @@ public void collectSingleMbeanWithOneNotAvailableAttributesAndOneAvailableAttrib
CollectionSet collectionSet = jmxCollector.collect(collectionAgent, null, null);
SingleResourceCollectionSet jmxCollectionSet = (SingleResourceCollectionSet) collectionSet;
JMXCollectionResource jmxCollectionResource = (JMXCollectionResource)jmxCollectionSet.getCollectionResource();
AttributeGroup group = jmxCollectionResource.getGroup(new AttributeGroupType("java_lang_type_Compilation", "all"));
AttributeGroup group = jmxCollectionResource.getGroup(new AttributeGroupType("java_lang_type_Compilation", AttributeGroupType.IF_TYPE_ALL));
assertEquals(1, group.getAttributes().size());
printDebugAttributeGroup(group);

Expand All @@ -207,7 +207,7 @@ public void collectSingleMbeanWithManyNotAvailableAttributesAndManyAvailableAttr
CollectionSet collectionSet = jmxCollector.collect(collectionAgent, null, null);
SingleResourceCollectionSet jmxCollectionSet = (SingleResourceCollectionSet) collectionSet;
JMXCollectionResource jmxCollectionResource = (JMXCollectionResource)jmxCollectionSet.getCollectionResource();
AttributeGroup group = jmxCollectionResource.getGroup(new AttributeGroupType("java_lang_type_OperatingSystem", "all"));
AttributeGroup group = jmxCollectionResource.getGroup(new AttributeGroupType("java_lang_type_OperatingSystem", AttributeGroupType.IF_TYPE_ALL));
assertEquals(8, group.getAttributes().size());
printDebugAttributeGroup(group);

Expand All @@ -224,7 +224,7 @@ public void collectSingleMbeanWithOneCompAttribWithAllItsCompMembers() {
CollectionSet collectionSet = jmxCollector.collect(collectionAgent, null, null);
SingleResourceCollectionSet jmxCollectionSet = (SingleResourceCollectionSet) collectionSet;
JMXCollectionResource jmxCollectionResource = (JMXCollectionResource)jmxCollectionSet.getCollectionResource();
AttributeGroup group = jmxCollectionResource.getGroup(new AttributeGroupType("java_lang_type_Memory", "all"));
AttributeGroup group = jmxCollectionResource.getGroup(new AttributeGroupType("java_lang_type_Memory", AttributeGroupType.IF_TYPE_ALL));
assertEquals(4, group.getAttributes().size());
printDebugAttributeGroup(group);

Expand All @@ -241,7 +241,7 @@ public void collectSingleMbeanWithOneCompAttribWithOneIgnoredCompMembers() {
CollectionSet collectionSet = jmxCollector.collect(collectionAgent, null, null);
SingleResourceCollectionSet jmxCollectionSet = (SingleResourceCollectionSet) collectionSet;
JMXCollectionResource jmxCollectionResource = (JMXCollectionResource)(JMXCollectionResource)jmxCollectionSet.getCollectionResource();
AttributeGroup group = jmxCollectionResource.getGroup(new AttributeGroupType("java_lang_type_Memory", "all"));
AttributeGroup group = jmxCollectionResource.getGroup(new AttributeGroupType("java_lang_type_Memory", AttributeGroupType.IF_TYPE_ALL));
assertEquals(3, group.getAttributes().size());
printDebugAttributeGroup(group);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void testCommitWithDeclaredAttribute() throws Exception {

SnmpCollectionSet collectionSet = new SnmpCollectionSet(agent, collection);

SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", "ignore"));
SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
attributeType.storeResult(collectionSet, null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), SnmpUtils.getValueFactory().getOctetString("hello".getBytes())));

PersistOperationBuilder builder = new PersistOperationBuilder(repository, resource, "rrdName");
Expand Down Expand Up @@ -183,7 +183,7 @@ public void testCommitWithDeclaredAttributeAndValue() throws Exception {

SnmpCollectionSet collectionSet = new SnmpCollectionSet(agent, collection);

SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", "ignore"));
SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
attributeType.storeResult(collectionSet, null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), SnmpUtils.getValueFactory().getOctetString("hello".getBytes())));

PersistOperationBuilder builder = new PersistOperationBuilder(repository, resource, "rrdName");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void setUp() throws Exception {

resourceA = new GenericIndexResource(resourceType, rt.getName(), new SnmpInstId("1.2.3.4.5.6.7.8.9.1.1"));

AttributeGroupType groupType = new AttributeGroupType("mib2-interfaces", "all");
AttributeGroupType groupType = new AttributeGroupType("mib2-interfaces", AttributeGroupType.IF_TYPE_ALL);
MibObject mibObject = new MibObject();
mibObject.setOid(".1.2.3.4.5.6.7.8.9.2.1");
mibObject.setInstance("1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private void testPersisting(String matchValue, SnmpValue snmpValue) throws Excep
mibObject.setAlias("temp_ulko");
mibObject.setType("gauge");

NumericAttributeType attributeType = new NumericAttributeType(resourceType, snmpCollection.getName(), mibObject, new AttributeGroupType("foo", "ignore"));
NumericAttributeType attributeType = new NumericAttributeType(resourceType, snmpCollection.getName(), mibObject, new AttributeGroupType("foo", AttributeGroupType.IF_TYPE_IGNORE));

attributeType.storeResult(new SnmpCollectionSet(agent, snmpCollection), null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), snmpValue));

Expand Down
Loading

0 comments on commit ced3e36

Please sign in to comment.