- /**
- * Used to close all Services, that should support AutoCloseable Pattern
- *
- * @param toClose
- * @throws Exception
- */
- private void close(AutoCloseable... toCloseList) throws Exception {
- for (AutoCloseable element : toCloseList) {
- if (element != null) {
- element.close();
- }
- }
- }
-
- /*-------------------------------------------------------------------------------------------
- * Functions for interface DeviceManagerService
- */
-
- /**
- * For each mounted device a mountpoint is created and this listener is called.
- * Mountpoint was created or existing. Managed device is now fully connected to node/mountpoint.
- * @param action provide action
- * @param nNodeId id of the mountpoint
- * @param nNode mountpoint contents
- */
- public void startListenerOnNodeForConnectedState(Action action, NodeId nNodeId, NetconfNode nNode) {
-
- String mountPointNodeName = nNodeId.getValue();
- LOG.info("Starting Event listener on Netconf for mountpoint {} Action {}", mountPointNodeName, action);
-
- boolean preConditionMissing = false;
- if (mountPointService == null) {
- preConditionMissing = true;
- LOG.warn("No mountservice available.");
- }
- if (!devicemanagerInitializationOk) {
- preConditionMissing = true;
- LOG.warn("Devicemanager initialization still pending.");
- }
- if (preConditionMissing) {
- return;
- }
-
- if (networkElementRepresentations.containsKey(mountPointNodeName)) {
- LOG.warn("Mountpoint {} already registered. Leave startup procedure.", mountPointNodeName);
- return;
- }
-
- if (!isMaster(nNode)) {
- // Change Devicemonitor-status to connected ... for non master mountpoints.
- deviceMonitor.deviceConnectSlaveIndication(mountPointNodeName);
- return;
- }
-
- InstanceIdentifier<Node> instanceIdentifier =
- NETCONF_TOPO_IID.child(Node.class, new NodeKey(new NodeId(mountPointNodeName)));
-
- Optional<MountPoint> optionalMountPoint = null;
- int timeout = 10000;
- while (!(optionalMountPoint = mountPointService.getMountPoint(instanceIdentifier)).isPresent() && timeout > 0) {
- LOG.info("Event listener waiting for mount point for Netconf device :: Name : {}", mountPointNodeName);
- sleepMs(1000);
- timeout -= 1000;
- }
-
- if (!optionalMountPoint.isPresent()) {
- LOG.warn("Event listener timeout while waiting for mount point for Netconf device :: Name : {} ",
- mountPointNodeName);
- return;
- }
- // Mountpoint is present for sure
- MountPoint mountPoint = optionalMountPoint.get();
- //BindingDOMDataBrokerAdapter.BUILDER_FACTORY;
- LOG.info("Mountpoint with id: {} class {} toString {}", mountPoint.getIdentifier(), mountPoint.getClass().getName(), mountPoint);
- Optional<DataBroker> optionalNetconfNodeDatabroker = mountPoint.getService(DataBroker.class);
-
- if (! optionalNetconfNodeDatabroker.isPresent()) {
- LOG.info("Slave mountpoint {} without databroker", mountPointNodeName);
- return;
- }
-
- DataBroker netconfNodeDataBroker = optionalNetconfNodeDatabroker.get();
- LOG.info("Master mountpoint {}", mountPointNodeName);
- // getNodeInfoTest(dataBroker);
-
- // create automatic empty maintenance entry into db before reading and listening for problems
- this.maintenanceService.createIfNotExists(mountPointNodeName);
-
- // Setup microwaveEventListener for Notificationservice
-
- // MicrowaveEventListener microwaveEventListener = new
- // MicrowaveEventListener(mountPointNodeName, websocketmanagerService,
- // xmlMapper, databaseClientEvents);
- ONFCoreNetworkElementRepresentation ne = ONFCoreNetworkElementFactory.create(mountPointNodeName, dataBroker,
- webSocketService, databaseClientEvents, instanceIdentifier, netconfNodeDataBroker, dcaeProviderClient,
- aotsMProvider, maintenanceService, notificationDelayService);
- networkElementRepresentations.put(mountPointNodeName, ne);
- ne.doRegisterMicrowaveEventListener(mountPoint);
-
- // Register netconf stream
- registerNotificationStream(mountPointNodeName, mountPoint, "NETCONF");
-
- // -- Read data from NE
- ne.initialReadFromNetworkElement();
- ne.initSynchronizationExtension();