Moving NetconfDeviceConfig to API bundle
- Move the class to API bundle to allow config manipulation via API
- Avoid sweeping whole device tree on every Device event.
- code clean up
Change-Id: I58ebdc89688c6c9250bb546585c227d486b30df2
diff --git a/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
index 41a6ed1..b30c6a0 100644
--- a/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
+++ b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
@@ -67,6 +67,7 @@
import org.onosproject.netconf.NetconfController;
import org.onosproject.netconf.NetconfDeviceListener;
import org.onosproject.netconf.NetconfException;
+import org.onosproject.netconf.config.NetconfDeviceConfig;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
@@ -154,9 +155,10 @@
protected ScheduledFuture<?> scheduledTask;
protected final List<ConfigFactory> factories = ImmutableList.of(
+ // TODO consider moving Config registration to NETCONF ctl bundle
new ConfigFactory<DeviceId, NetconfDeviceConfig>(
SubjectFactories.DEVICE_SUBJECT_FACTORY,
- NetconfDeviceConfig.class, SCHEME_NAME) {
+ NetconfDeviceConfig.class, NetconfDeviceConfig.CONFIG_KEY) {
@Override
public NetconfDeviceConfig createConfig() {
return new NetconfDeviceConfig();
@@ -351,23 +353,35 @@
Set<DeviceId> deviceSubjects =
cfgService.getSubjects(DeviceId.class, NetconfDeviceConfig.class);
deviceSubjects.forEach(deviceId -> {
- NetconfDeviceConfig config =
- cfgService.getConfig(deviceId, NetconfDeviceConfig.class);
- DeviceDescription deviceDescription = createDeviceRepresentation(deviceId, config);
- log.debug("Connecting NETCONF device {}, on {}:{} with username {}",
- deviceId, config.ip(), config.port(), config.username());
- storeDeviceKey(config.sshKey(), config.username(), config.password(), deviceId);
- if (deviceService.getDevice(deviceId) == null) {
- providerService.deviceConnected(deviceId, deviceDescription);
- }
- try {
- checkAndUpdateDevice(deviceId, deviceDescription);
- } catch (Exception e) {
- log.error("Unhandled exception checking {}", deviceId, e);
- }
+ connectDevice(cfgService.getConfig(deviceId, NetconfDeviceConfig.class));
});
}
+
+ private void connectDevice(NetconfDeviceConfig config) {
+ if (config == null) {
+ return;
+ }
+ DeviceId deviceId = config.subject();
+ if (!deviceId.uri().getScheme().equals(SCHEME_NAME)) {
+ // not under my scheme, skipping
+ log.trace("{} not my scheme, skipping", deviceId);
+ return;
+ }
+ DeviceDescription deviceDescription = createDeviceRepresentation(deviceId, config);
+ log.debug("Connecting NETCONF device {}, on {}:{} with username {}",
+ deviceId, config.ip(), config.port(), config.username());
+ storeDeviceKey(config.sshKey(), config.username(), config.password(), deviceId);
+ if (deviceService.getDevice(deviceId) == null) {
+ providerService.deviceConnected(deviceId, deviceDescription);
+ }
+ try {
+ checkAndUpdateDevice(deviceId, deviceDescription);
+ } catch (Exception e) {
+ log.error("Unhandled exception checking {}", deviceId, e);
+ }
+ }
+
private void checkAndUpdateDevice(DeviceId deviceId, DeviceDescription deviceDescription) {
Device device = deviceService.getDevice(deviceId);
if (device == null) {
@@ -580,7 +594,7 @@
@Override
public void event(NetworkConfigEvent event) {
if (event.configClass().equals(NetconfDeviceConfig.class)) {
- executor.execute(NetconfDeviceProvider.this::connectDevices);
+ executor.execute(() -> connectDevice((NetconfDeviceConfig) event.config().get()));
} else {
log.warn("Injecting device via this Json is deprecated, " +
"please put configuration under devices/ as shown in the wiki");