private void connectDevices() { NetconfProviderConfig cfg = cfgService.getConfig(appId, NetconfProviderConfig.class); if (cfg != null) { try { cfg.getDevicesAddresses() .stream() .forEach( addr -> { try { NetconfDeviceInfo netconf = new NetconfDeviceInfo(addr.name(), addr.password(), addr.ip(), addr.port()); controller.connectDevice(netconf); Device device = deviceService.getDevice(netconf.getDeviceId()); if (device.is(PortDiscovery.class)) { PortDiscovery portConfig = device.as(PortDiscovery.class); if (portConfig != null) { providerService.updatePorts(netconf.getDeviceId(), portConfig.getPorts()); } } else { log.warn("No portGetter behaviour for device {}", netconf.getDeviceId()); } } catch (IOException e) { throw new RuntimeException( new NetconfException( "Can't connect to NETCONF " + "device on " + addr.ip() + ":" + addr.port(), e)); } }); } catch (ConfigException e) { log.error("Cannot read config error " + e); } } }
private void connectDevices() { RestProviderConfig cfg = cfgService.getConfig(appId, RestProviderConfig.class); try { if (cfg != null && cfg.getDevicesAddresses() != null) { // Precomputing the devices to be removed Set<RestSBDevice> toBeRemoved = new HashSet<>(controller.getDevices().values()); toBeRemoved.removeAll(cfg.getDevicesAddresses()); // Adding new devices cfg.getDevicesAddresses() .stream() .filter(device -> testDeviceConnection(device)) .forEach( device -> { deviceAdded(device); }); // Removing devices not wanted anymore toBeRemoved.stream().forEach(device -> deviceRemoved(device)); } } catch (ConfigException e) { log.error("Configuration error {}", e); } log.info("REST Devices {}", controller.getDevices()); controller .getDevices() .keySet() .forEach( deviceId -> { DriverHandler h = driverService.createHandler(deviceId); PortDiscovery portConfig = h.behaviour(PortDiscovery.class); if (portConfig != null) { providerService.updatePorts(deviceId, portConfig.getPorts()); } else { log.warn("No portGetter behaviour for device {}", deviceId); } }); }