@Test public void verifyClosedSessionAreNotKept() throws Exception { m_cm.auditConnections(); when(m_sessions.get(getIp("2")).isOpen()).thenReturn(false); m_cm.auditConnections(); verify(m_connectionListener).deviceConnected(m_devices.get(0), m_sessions.get(getIp("1"))); verify(m_connectionListener).deviceConnected(m_devices.get(1), m_sessions.get(getIp("2"))); verify(m_connectionListener).deviceConnected(m_devices.get(2), m_sessions.get(getIp("3"))); verify(m_dispatcher, times(4)).createClient(anyObject()); }
void auditConnections() { m_txService.executeWithTx(new TXTemplate<Void>() { @Override public Void execute() { List<Device> allDevices = m_deviceDao.findAllDevices(); for (Device meta : allDevices) { NetconfClientSession session = null; try { if (!meta.getDeviceManagement().getDeviceConnection().getConnectionModel().equals("call-home")) { session = m_connPool.borrowObject(meta); } } catch (Exception e) { LOGGER.debug(String.format("Could not setup connection to device %s", meta), e); } finally { if (session != null) { m_connPool.returnObject(meta, session); } } } Set<Device> deletedDevices = new HashSet<>(m_factory.getAllKeys()); deletedDevices.removeAll(allDevices); for (Device meta : deletedDevices) { LOGGER.debug(String.format("Device %s has been un-managed, closing the connection", meta)); m_connPool.clear(meta); m_factory.getAllKeys().remove(meta); } return null; } }); }
NetconfConnectionManagerImpl implements NetconfConnectionManager, CallHomeListener { void auditConnections() { m_txService.executeWithTx(new TXTemplate<Void>() { @Override public Void execute() { List<Device> allDevices = m_deviceDao.findAllDevices(); for (Device meta : allDevices) { NetconfClientSession session = null; try { if (!meta.getDeviceManagement().getDeviceConnection().getConnectionModel().equals("call-home")) { session = m_connPool.borrowObject(meta); } } catch (Exception e) { LOGGER.debug(String.format("Could not setup connection to device %s", meta), e); } finally { if (session != null) { m_connPool.returnObject(meta, session); } } } Set<Device> deletedDevices = new HashSet<>(m_factory.getAllKeys()); deletedDevices.removeAll(allDevices); for (Device meta : deletedDevices) { LOGGER.debug(String.format("Device %s has been un-managed, closing the connection", meta)); m_connPool.clear(meta); m_factory.getAllKeys().remove(meta); } return null; } }); } }
NetconfConnectionManagerImpl implements NetconfConnectionManager, CallHomeListener { void auditConnections() { m_txService.executeWithTx(new TXTemplate<Void>() { @Override public Void execute() { List<Device> allDevices = m_deviceDao.findAllDevices(); for (Device meta : allDevices) { NetconfClientSession session = null; try { if (!meta.getDeviceManagement().getDeviceConnection().getConnectionModel().equals("call-home")) { session = m_connPool.borrowObject(meta); } } catch (Exception e) { LOGGER.debug(String.format("Could not setup connection to device %s", meta), e); } finally { if (session != null) { m_connPool.returnObject(meta, session); } } } Set<Device> deletedDevices = new HashSet<>(m_factory.getAllKeys()); deletedDevices.removeAll(allDevices); for (Device meta : deletedDevices) { LOGGER.debug(String.format("Device %s has been un-managed, closing the connection", meta)); m_connPool.clear(meta); m_factory.getAllKeys().remove(meta); } return null; } }); } NetconfConnectionManagerImpl(CallHomeListenerComposite callHomeListenerComposite,
                                        NetconfClientDispatcher dispatcher); }
NetconfConnectionManagerImpl implements NetconfConnectionManager, CallHomeListener { void auditConnections() { m_txService.executeWithTx(new TXTemplate<Void>() { @Override public Void execute() { List<Device> allDevices = m_deviceDao.findAllDevices(); for (Device meta : allDevices) { NetconfClientSession session = null; try { if (!meta.getDeviceManagement().getDeviceConnection().getConnectionModel().equals("call-home")) { session = m_connPool.borrowObject(meta); } } catch (Exception e) { LOGGER.debug(String.format("Could not setup connection to device %s", meta), e); } finally { if (session != null) { m_connPool.returnObject(meta, session); } } } Set<Device> deletedDevices = new HashSet<>(m_factory.getAllKeys()); deletedDevices.removeAll(allDevices); for (Device meta : deletedDevices) { LOGGER.debug(String.format("Device %s has been un-managed, closing the connection", meta)); m_connPool.clear(meta); m_factory.getAllKeys().remove(meta); } return null; } }); } NetconfConnectionManagerImpl(CallHomeListenerComposite callHomeListenerComposite,
                                        NetconfClientDispatcher dispatcher); DeviceDao getDeviceDao(); void setDeviceDao(DeviceDao deviceDao); TxService getTxService(); void setTxService(TxService txService); static void fillTransportDetails(Authentication authentication, NetconfClientConfigurationBuilder
            configurationBuilder); Map<String, List<DefaultPooledObjectInfo>> getAllSessions(); @Override Future<NetConfResponse> executeNetconf(Device device, AbstractNetconfRequest request); @Override Future<NetConfResponse> executeNetconf(String deviceName, AbstractNetconfRequest request); @Override RT executeWithSession(Device device, NetconfTemplate<RT> netconfTemplate); @Override boolean isConnected(Device device); @Override ConnectionState getConnectionState(Device device); @Override List<NewDeviceInfo> getNewDevices(); @Override void dropNewDeviceConnection(String duid); @Override void registerDeviceConnectionListener(ConnectionListener connectionListener); @Override void unregisterDeviceConnectionListener(ConnectionListener connectionListener); void init(); @Override void connectionEstablished(NetconfClientSession deviceSession, NetconfLoginProvider netconfLoginProvider,
                                      X509Certificate deviceCert, boolean isSelfSigned); String extractDuid(X509Certificate x509Certificate, String ipAddress, Integer port); void destroy(); }
NetconfConnectionManagerImpl implements NetconfConnectionManager, CallHomeListener { void auditConnections() { m_txService.executeWithTx(new TXTemplate<Void>() { @Override public Void execute() { List<Device> allDevices = m_deviceDao.findAllDevices(); for (Device meta : allDevices) { NetconfClientSession session = null; try { if (!meta.getDeviceManagement().getDeviceConnection().getConnectionModel().equals("call-home")) { session = m_connPool.borrowObject(meta); } } catch (Exception e) { LOGGER.debug(String.format("Could not setup connection to device %s", meta), e); } finally { if (session != null) { m_connPool.returnObject(meta, session); } } } Set<Device> deletedDevices = new HashSet<>(m_factory.getAllKeys()); deletedDevices.removeAll(allDevices); for (Device meta : deletedDevices) { LOGGER.debug(String.format("Device %s has been un-managed, closing the connection", meta)); m_connPool.clear(meta); m_factory.getAllKeys().remove(meta); } return null; } }); } NetconfConnectionManagerImpl(CallHomeListenerComposite callHomeListenerComposite,
                                        NetconfClientDispatcher dispatcher); DeviceDao getDeviceDao(); void setDeviceDao(DeviceDao deviceDao); TxService getTxService(); void setTxService(TxService txService); static void fillTransportDetails(Authentication authentication, NetconfClientConfigurationBuilder
            configurationBuilder); Map<String, List<DefaultPooledObjectInfo>> getAllSessions(); @Override Future<NetConfResponse> executeNetconf(Device device, AbstractNetconfRequest request); @Override Future<NetConfResponse> executeNetconf(String deviceName, AbstractNetconfRequest request); @Override RT executeWithSession(Device device, NetconfTemplate<RT> netconfTemplate); @Override boolean isConnected(Device device); @Override ConnectionState getConnectionState(Device device); @Override List<NewDeviceInfo> getNewDevices(); @Override void dropNewDeviceConnection(String duid); @Override void registerDeviceConnectionListener(ConnectionListener connectionListener); @Override void unregisterDeviceConnectionListener(ConnectionListener connectionListener); void init(); @Override void connectionEstablished(NetconfClientSession deviceSession, NetconfLoginProvider netconfLoginProvider,
                                      X509Certificate deviceCert, boolean isSelfSigned); String extractDuid(X509Certificate x509Certificate, String ipAddress, Integer port); void destroy();  }