Acquire DOMNotificationService before changing state 77/103977/4
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 10 Jan 2023 23:34:22 +0000 (00:34 +0100)
committerRobert Varga <nite@hq.sk>
Mon, 30 Jan 2023 15:00:05 +0000 (15:00 +0000)
We have a potential source of exceptions triggering after we have
mutated state. Fix that.

Change-Id: Id178c124c37cde804b10975590a773fab0df644e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java

index 13972dcca959b920f217b32a8c6794c84df6ff7d..ab8bc3d4dd0fea990f61acd50919c10aa31018c6 100644 (file)
@@ -169,7 +169,9 @@ final class CreateStreamUtil {
             .orElseThrow(() -> new RestconfDocumentedException("Mount point not available", ErrorType.APPLICATION,
                 ErrorTag.OPERATION_FAILED));
 
-        final NotificationOutputType outputType = prepareOutputType(data);
+        final DOMNotificationService mountNotifService = mountPoint.getService(DOMNotificationService.class)
+            .orElseThrow(() -> new RestconfDocumentedException("Mount point does not support notifications",
+                ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED));
 
         // FIXME: what is the relationship to the unused refSchemaCtx?
         final EffectiveModelContext mountModelContext = mountPoint.getService(DOMSchemaService.class)
@@ -187,9 +189,9 @@ final class CreateStreamUtil {
             .collect(Collectors.toUnmodifiableSet());
 
         final DeviceNotificationListenerAdaptor notificationListenerAdapter = ListenersBroker.getInstance()
-            .registerDeviceNotificationListener(deviceName, outputType, mountModelContext, mountPointService,
-                mountPoint.getIdentifier());
-        notificationListenerAdapter.listen(mountPoint.getService(DOMNotificationService.class).get(), absolutes);
+            .registerDeviceNotificationListener(deviceName, prepareOutputType(data), mountModelContext,
+                mountPointService, mountPoint.getIdentifier());
+        notificationListenerAdapter.listen(mountNotifService, absolutes);
 
         // building of output
         return new DefaultDOMRpcResult(Builders.containerBuilder()