DeviceManagementSubsystem extends AbstractSubSystem { @Override public void notifyChanged(List<ChangeNotification> changeNotificationList) { LOGGER.debug("notification received : {}", changeNotificationList); for (ChangeNotification notification : changeNotificationList) { EditConfigChangeNotification editNotif = (EditConfigChangeNotification) notification; LOGGER.debug("notification received : {}", editNotif); ModelNodeId nodeId = editNotif.getModelNodeId(); EditContainmentNode changeData = editNotif.getChange().getChangeData(); if (nodeId.equals(MANAGED_DEVICES_ID_TEMPLATE) && "device".equals(editNotif.getChange().getChangeData().getName())) { LOGGER.debug("ModelNodeId[{}] matched device holder template", nodeId); handleDeviceCreateOrDelete(nodeId, editNotif); } else if (nodeId.matchesTemplate(AUTH_ID_TEMPLATE)) { handleAuthChanged(nodeId.getRdnValue("name"), changeData); } else if (nodeId.matchesTemplate(SNMP_AUTH_ID_TEMPLATE)) { handleAuthChanged(nodeId.getRdnValue("name"), changeData); } } } DeviceManagementSubsystem(SchemaRegistry schemaRegistry, AdapterManager adapterManager); DeviceManager getDeviceManager(); void setDeviceManager(DeviceManager deviceManager); NetconfConnectionManager getConnectionManager(); void setConnectionManager(NetconfConnectionManager connectionManager); @Override void notifyChanged(List<ChangeNotification> changeNotificationList);  }
@Test public void testNotifyChangedDeviceCreate() { List<ChangeNotification> notifs = new ArrayList<>(); ModelNodeId nodeId = new ModelNodeId("/container=network-manager/container=" + MANAGED_DEVICES, NS); EditContainmentNode editContainmentNode = new EditContainmentNode(QName.create(NS, DEVICE), EditConfigOperations.CREATE); editContainmentNode.addMatchNode(QName.create(NS, DEVICE), new GenericConfigAttribute("device", NS, DEVICE_A)); ModelNodeChange change = new ModelNodeChange(ModelNodeChangeType.create, editContainmentNode); notifs.add(new EditConfigChangeNotification(nodeId, change, StandardDataStores.RUNNING, mock(ModelNode.class))); m_deviceManagementSubsystem.notifyChanged(notifs); verify(m_deviceManager).deviceAdded(DEVICE_A); verify(m_deviceManager, never()).deviceRemoved(DEVICE_A); verify(m_deviceManager, never()).devicePropertyChanged(DEVICE_A); }
@Test public void testNotifyChangedDeviceDelete() { List<ChangeNotification> notifs = new ArrayList<>(); ModelNodeId nodeId = new ModelNodeId("/container=network-manager/container=" + MANAGED_DEVICES, NS); EditContainmentNode editContainmentNode = new EditContainmentNode(QName.create(NS, DEVICE), EditConfigOperations.DELETE); editContainmentNode.addMatchNode(QName.create(NS, DEVICE), new GenericConfigAttribute("device", NS, DEVICE_A)); ModelNodeChange change = new ModelNodeChange(ModelNodeChangeType.delete, editContainmentNode); notifs.add(new EditConfigChangeNotification(nodeId, change, StandardDataStores.RUNNING, mock(ModelNode.class))); m_deviceManagementSubsystem.notifyChanged(notifs); verify(m_deviceManager).deviceRemoved(DEVICE_A); verify(m_deviceManager, never()).deviceAdded(DEVICE_A); verify(m_deviceManager, never()).devicePropertyChanged(DEVICE_A); }
@Test public void testNotifyChangedDevicePropertyChanged() { List<ChangeNotification> notifs = new ArrayList<>(); ModelNodeId nodeId = new ModelNodeId("/container=network-manager/container=managed-devices" + "/container=device/name=" + DEVICE_A + "/container=device-management/container=device-connection" + "/container=password-auth/container=authentication", NS); EditContainmentNode editContainmentNode = new EditContainmentNode(QName.create(NS, AUTHENTICATION), EditConfigOperations.MERGE); editContainmentNode.addLeafChangeNode(QName.create(NS, MANAGEMENT_PORT), new GenericConfigAttribute(MANAGEMENT_PORT, NS, String.valueOf(30))); ModelNodeChange change = new ModelNodeChange(ModelNodeChangeType.merge, editContainmentNode); notifs.add(new EditConfigChangeNotification(nodeId, change, StandardDataStores.RUNNING, mock(ModelNode.class))); m_deviceManagementSubsystem.notifyChanged(notifs); verify(m_deviceManager, never()).deviceRemoved(DEVICE_A); verify(m_deviceManager, never()).deviceAdded(DEVICE_A); verify(m_deviceManager).devicePropertyChanged(DEVICE_A); }