Search in sources :

Example 1 with SnmpInterfaceDao

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();
}
Also used : UpsertTemplate(org.opennms.netmgt.dao.support.UpsertTemplate) OnmsNode(org.opennms.netmgt.model.OnmsNode) SnmpInterfaceDao(org.opennms.netmgt.dao.api.SnmpInterfaceDao) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Example 2 with SnmpInterfaceDao

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;
    }
}
Also used : BeanFactoryReference(org.springframework.beans.factory.access.BeanFactoryReference) SnmpInterfaceDao(org.opennms.netmgt.dao.api.SnmpInterfaceDao) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) TransactionStatus(org.springframework.transaction.TransactionStatus)

Aggregations

SnmpInterfaceDao (org.opennms.netmgt.dao.api.SnmpInterfaceDao)2 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)2 UpsertTemplate (org.opennms.netmgt.dao.support.UpsertTemplate)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 BeanFactoryReference (org.springframework.beans.factory.access.BeanFactoryReference)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)1