@Test public void testDirectConnectionForNotNetconfDevice() throws NetconfClientDispatcherException { List<Device> devices = new ArrayList<>(); Device device = createDirectDevice("4"); device.getDeviceManagement().setNetconf(false); devices.add(device); when(m_deviceDao.findAllDevices()).thenReturn(devices); m_cm.auditConnections(); ArgumentCaptor<NetconfClientConfiguration> captor = ArgumentCaptor.forClass(NetconfClientConfiguration.class); verify(m_dispatcher, never()).createClient(captor.capture()); }
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();  }