use of org.opennms.netmgt.dao.api.SnmpInterfaceDao in project opennms by OpenNMS.
the class DefaultUpsertService method upsert.
@Override
public OnmsSnmpInterface upsert(final int nodeId, final OnmsSnmpInterface snmpInterface, final int sleep) {
UpsertTemplate<OnmsSnmpInterface, SnmpInterfaceDao> upzerter = new UpsertTemplate<OnmsSnmpInterface, SnmpInterfaceDao>(m_transactionManager, m_snmpInterfaceDao) {
@Override
public OnmsSnmpInterface query() {
OnmsSnmpInterface dbSnmpIface = m_snmpInterfaceDao.findByNodeIdAndIfIndex(nodeId, snmpInterface.getIfIndex());
sleep(sleep);
return dbSnmpIface;
}
@Override
public OnmsSnmpInterface doUpdate(OnmsSnmpInterface dbSnmpIface) {
// update the interface that was found
LOG.debug("nodeId = {}, ifIndex = {}, dbSnmpIface = {}", nodeId, snmpInterface.getIfIndex(), dbSnmpIface);
dbSnmpIface.mergeSnmpInterfaceAttributes(snmpInterface);
LOG.info("Updating SnmpInterface {}", dbSnmpIface);
m_snmpInterfaceDao.update(dbSnmpIface);
m_snmpInterfaceDao.flush();
return dbSnmpIface;
}
@Override
public OnmsSnmpInterface doInsert() {
// add the interface to the node, if it wasn't found
final OnmsNode dbNode = m_nodeDao.get(nodeId);
// for performance reasons we don't add the snmp interface to the node so we avoid loading all the interfaces
// setNode only sets the node in the interface
snmpInterface.setNode(dbNode);
LOG.info("Saving SnmpInterface {}", snmpInterface);
m_snmpInterfaceDao.save(snmpInterface);
m_snmpInterfaceDao.flush();
return snmpInterface;
}
};
return upzerter.execute();
}
use of org.opennms.netmgt.dao.api.SnmpInterfaceDao in project opennms by OpenNMS.
the class InsAbstractSession method getIfAlias.
/**
* @param nodeid
* @param ifindex
* @return
*/
protected String getIfAlias(final int nodeid, final int ifindex) {
LOG.debug("getting ifalias for nodeid: {} and ifindex: {}", nodeid, ifindex);
setCriteria("nodeid = " + nodeid + " AND snmpifindex = " + ifindex);
BeanFactoryReference bf = BeanUtils.getBeanFactory("daoContext");
final SnmpInterfaceDao snmpInterfaceDao = BeanUtils.getBean(bf, "snmpInterfaceDao", SnmpInterfaceDao.class);
final TransactionTemplate transTemplate = BeanUtils.getBean(bf, "transactionTemplate", TransactionTemplate.class);
final OnmsSnmpInterface iface = transTemplate.execute(new TransactionCallback<OnmsSnmpInterface>() {
public OnmsSnmpInterface doInTransaction(final TransactionStatus status) {
return snmpInterfaceDao.findByNodeIdAndIfIndex(nodeid, ifindex);
}
});
if (iface == null) {
return "-1";
} else {
final String ifAlias = iface.getIfAlias();
LOG.debug("ifalias found: {}", ifAlias);
return ifAlias;
}
}
Aggregations