Skip to content

Commit

Permalink
HZN-926: Deprecate the SnmpAgentConfigFactory.getAgentConfig(InetAddr…
Browse files Browse the repository at this point in the history
…ess) method
  • Loading branch information
Chandra Gorantla committed Oct 27, 2016
1 parent 3b1a7a9 commit 38e5fd3
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected Object doExecute() throws Exception {
final List<SnmpObjId> snmpObjIds = m_oids.stream()
.map(oid -> SnmpObjId.get(oid))
.collect(Collectors.toList());
final SnmpAgentConfig agent = snmpAgentConfigFactory.getAgentConfig(InetAddress.getByName(m_host));
final SnmpAgentConfig agent = snmpAgentConfigFactory.getAgentConfig(InetAddress.getByName(m_host), m_location);
final CompletableFuture<List<SnmpResult>> future = locationAwareSnmpClient.walk(agent, snmpObjIds)
.withDescription("snmp:walk")
.withLocation(m_location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.opennms.netmgt.model.PrefabGraph;
import org.opennms.netmgt.model.ResourcePath;
import org.opennms.netmgt.model.RrdGraphAttribute;
import org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation;
import org.opennms.netmgt.snmp.SnmpAgentConfig;
import org.opennms.nrtg.api.NrtBroker;
import org.opennms.nrtg.api.model.CollectionJob;
Expand Down Expand Up @@ -254,7 +255,9 @@ private List<CollectionJob> createCollectionJobs(OnmsResource reportResource, Pr
//I know....
if (protocol.equals("SNMP") || protocol.equals("TCA")) {
collectionJob.setNetInterface(protocol);
final SnmpAgentConfig snmpAgentConfig = m_snmpAgentConfigFactory.getAgentConfig(node.getPrimaryInterface().getIpAddress());
OnmsMonitoringLocation location = node.getLocation();
String locationName = (location == null) ? null : location.getLocationName();
final SnmpAgentConfig snmpAgentConfig = m_snmpAgentConfigFactory.getAgentConfig(node.getPrimaryInterface().getIpAddress(), locationName);
collectionJob.setProtocolConfiguration(snmpAgentConfig.toProtocolConfigString());
collectionJob.setNetInterface(node.getPrimaryInterface().getIpAddress().getHostAddress());
collectionJobs.add(collectionJob);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ public InetAddress doInTransaction(TransactionStatus arg0) {
});

SnmpAgentConfig agentConfig = null;
agentConfig = m_snmpConfigDao.getAgentConfig(ipaddress);

String locationName = node.getLocation() != null ? node.getLocation().getLocationName() : null;
String locationName = node.getLocation() != null ? node.getLocation().getLocationName() : null;
agentConfig = m_snmpConfigDao.getAgentConfig(ipaddress, locationName);

final OnmsAssetRecord asset = node.getAssetRecord();
m_config.getReadLock().lock();
Expand Down Expand Up @@ -266,9 +265,9 @@ public InetAddress doInTransaction(final TransactionStatus arg0) {
}
});

final SnmpAgentConfig agentConfig = m_snmpConfigDao.getAgentConfig(ipaddress);

final String locationName = node.getLocation() != null ? node.getLocation().getLocationName() : null;
final String locationName = node.getLocation() != null ? node.getLocation().getLocationName() : null;
final SnmpAgentConfig agentConfig = m_snmpConfigDao.getAgentConfig(ipaddress, locationName);

final OnmsAssetRecord asset = node.getAssetRecord();
m_config.getReadLock().lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.opennms.netmgt.model.OnmsIpInterface;
import org.opennms.netmgt.model.OnmsNode;
import org.opennms.netmgt.model.events.EventBuilder;
import org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation;
import org.opennms.netmgt.provision.snmp.EntityPhysicalTableRow;
import org.opennms.netmgt.provision.snmp.EntityPhysicalTableTracker;
import org.opennms.netmgt.snmp.SnmpAgentConfig;
Expand Down Expand Up @@ -172,7 +173,9 @@ private void synchronizeInventory(int nodeId) {
LOG.warn("Skiping hardware discover because the node {} doesn't support SNMP", nodeId);
return;
}
SnmpAgentConfig agentConfig = m_snmpConfigDao.getAgentConfig(ipAddress);
OnmsMonitoringLocation location = node.getLocation();
String locationName = (location == null) ? null : location.getLocationName();
SnmpAgentConfig agentConfig = m_snmpConfigDao.getAgentConfig(ipAddress, locationName);
final OnmsHwEntity newRoot = getRootEntity(agentConfig, node);
newRoot.setNode(node);
final OnmsHwEntity currentRoot = m_hwEntityDao.findRootByNodeId(node.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ public interface SnmpAgentConfigFactory {
* <p>getAgentConfig</p>
*
* @param address a {@link java.net.InetAddress} object.
* @param location a {@link java.lang.String} object.
* @return a {@link org.opennms.netmgt.snmp.SnmpAgentConfig} object.
*/
public SnmpAgentConfig getAgentConfig(InetAddress address);

public SnmpAgentConfig getAgentConfig(InetAddress address, String location);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,14 @@
*/
public class AnAgentConfigFactory implements SnmpAgentConfigFactory {

@Override
public SnmpAgentConfig getAgentConfig(final InetAddress address) {
final SnmpAgentConfig agentConfig = new SnmpAgentConfig(address);
agentConfig.setVersion(SnmpAgentConfig.DEFAULT_VERSION);
return agentConfig;
public void define(final SnmpEventInfo info) {
}

public void define(final SnmpEventInfo info) {
}

@Override
public SnmpAgentConfig getAgentConfig(InetAddress address, String location) {
// TODO Auto-generated method stub
return null;
final SnmpAgentConfig agentConfig = new SnmpAgentConfig(address);
agentConfig.setVersion(SnmpAgentConfig.DEFAULT_VERSION);
return agentConfig;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ private InetAddress getAgentAddress() {
}

private SnmpAgentConfig getAgentConfig(InetAddress primaryAddress) {
return getAgentConfigFactory().getAgentConfig(primaryAddress);
return getAgentConfigFactory().getAgentConfig(primaryAddress,
(m_location == null) ? null : m_location.getLocationName());
}

private SnmpAgentConfigFactory getAgentConfigFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,8 @@ private void walkTable(final BatchTask currentPhase, final Set<InetAddress> prov
Assert.notNull(getAgentConfigFactory(), "agentConfigFactory was not injected");

try {
final SnmpAgentConfig agentConfig = getAgentConfigFactory().getAgentConfig(getAgentAddress());
String locationName = node.getLocation()== null ? null : node.getLocation().getLocationName();
final SnmpAgentConfig agentConfig = getAgentConfigFactory().getAgentConfig(getAgentAddress(), locationName);
m_provisionService.getLocationAwareSnmpClient().walk(agentConfig, tracker)
.withDescription("IP address tables")
.withLocation(getLocationName())
Expand Down Expand Up @@ -577,7 +578,8 @@ private void walkTable(final BatchTask currentPhase, final Set<InetAddress> prov

public void detectPhysicalInterfaces(final BatchTask currentPhase) {
if (isAborted()) { return; }
final SnmpAgentConfig agentConfig = getAgentConfigFactory().getAgentConfig(getAgentAddress());
String locationName = getLocation()== null ? null : getLocation().getLocationName();
final SnmpAgentConfig agentConfig = getAgentConfigFactory().getAgentConfig(getAgentAddress(), locationName);
Assert.notNull(getAgentConfigFactory(), "agentConfigFactory was not injected");

final PhysInterfaceTableTracker physIfTracker = new PhysInterfaceTableTracker() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public void scan(ScanContext context) throws InterruptedException {
if (agentAddress == null) {
return;
}
SnmpAgentConfig agentConfig = m_snmpAgentConfigFactory.getAgentConfig(agentAddress);

SnmpAgentConfig agentConfig = m_snmpAgentConfigFactory.getAgentConfig(agentAddress, null);

SnmpWalker walker = SnmpUtils.createWalker(agentConfig, getName(), createCollectionTracker(context));
walker.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.opennms.netmgt.model.OnmsIpInterface;
import org.opennms.netmgt.model.OnmsMonitoredService;
import org.opennms.netmgt.model.OnmsNode;
import org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation;
import org.opennms.netmgt.snmp.SnmpAgentConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -231,7 +232,10 @@ protected List<AgentResponse> getResponses(final String filterName, final String
if (sysObjectId != null) {
parameters.put("sysObjectId", sysObjectId);
}
final SnmpAgentConfig config = m_agentConfigFactory.getAgentConfig(ipAddress);
OnmsMonitoringLocation location = (node == null) ? null : node.getLocation();
String locationName = (location == null) ? null : location.getLocationName();

final SnmpAgentConfig config = m_agentConfigFactory.getAgentConfig(ipAddress, locationName);
if (config != null) {
port = config.getPort();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ public List<InetAddress> getActiveIPAddressList(final String rule) throws Filter
}

private static final class TestSnmpConfigDao implements SnmpAgentConfigFactory {
@Override
public SnmpAgentConfig getAgentConfig(final InetAddress address) {
return new SnmpAgentConfig(address, getDefaults());
}

private static SnmpConfiguration getDefaults() {
final SnmpConfiguration config = new SnmpConfiguration();
Expand All @@ -167,8 +163,7 @@ private static SnmpConfiguration getDefaults() {

@Override
public SnmpAgentConfig getAgentConfig(InetAddress address, String location) {
// TODO Auto-generated method stub
return null;
return new SnmpAgentConfig(address, getDefaults());
}
}
}

0 comments on commit 38e5fd3

Please sign in to comment.