- }
-
- @Override
- @SuppressFBWarnings(
- value = "SF_SWITCH_FALLTHROUGH",
- justification = "intentional fallthrough")
- public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Node>> changes) {
- LOG.info("onDataTreeChanged");
- for (DataTreeModification<Node> change : changes) {
- DataObjectModification<Node> rootNode = change.getRootNode();
- if ((rootNode.getDataAfter() == null) && (rootNode.getModificationType() != ModificationType.DELETE)) {
- LOG.error("rootNode.getDataAfter is null : Node not connected via Netconf protocol");
- continue;
- }
- if (rootNode.getModificationType() == ModificationType.DELETE) {
- if (rootNode.getDataBefore() != null) {
- String nodeId = rootNode.getDataBefore().key().getNodeId().getValue();
- LOG.info("Node {} deleted", nodeId);
- this.networkModelService.deleteOpenRoadmnode(nodeId);
- onDeviceDisConnected(nodeId);
- } else {
- LOG.error("rootNode.getDataBefore is null !");
- }
- continue;
- }
- String nodeId = rootNode.getDataAfter().key().getNodeId().getValue();
- NetconfNode netconfNode = rootNode.getDataAfter().augmentation(NetconfNode.class);
-
- if ((netconfNode != null) && !StringConstants.DEFAULT_NETCONF_NODEID.equals(nodeId)) {
- switch (rootNode.getModificationType()) {
- case WRITE:
- LOG.info("Node added: {}", nodeId);
- //fallthrough
- case SUBTREE_MODIFIED:
- NetconfNodeConnectionStatus.ConnectionStatus connectionStatus =
- netconfNode.getConnectionStatus();
- try {
- List<AvailableCapability> deviceCapabilities = netconfNode.getAvailableCapabilities()
- .getAvailableCapability().stream().filter(cp -> cp.getCapability()
- .contains(StringConstants.OPENROADM_DEVICE_MODEL_NAME)).collect(Collectors.toList());
- if (!deviceCapabilities.isEmpty()) {
- Collections.sort(deviceCapabilities, (cp0, cp1) -> cp1.getCapability()
- .compareTo(cp0.getCapability()));
- LOG.info("OpenROADM node detected: {} {}", nodeId, connectionStatus.name());
- switch (connectionStatus) {
- case Connected:
- this.networkModelService.createOpenRoadmNode(nodeId, deviceCapabilities.get(0)
- .getCapability());
- onDeviceConnected(nodeId,deviceCapabilities.get(0).getCapability());
- break;
- case Connecting:
- case UnableToConnect:
- this.networkModelService.setOpenRoadmNodeStatus(nodeId, connectionStatus);
- onDeviceDisConnected(nodeId);
- break;
- default:
- LOG.warn("Unsupported device state {}", connectionStatus.getName());
- break;
- }
- }
-
- } catch (NullPointerException e) {
- LOG.error("Cannot get available Capabilities");
- }
- break;
- default:
- LOG.warn("Unexpected connection status : {}", rootNode.getModificationType());
- break;
- }
- }