From: Robert Varga Date: Tue, 10 Jan 2023 23:34:22 +0000 (+0100) Subject: Acquire DOMNotificationService before changing state X-Git-Tag: v5.0.2~59 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=9980ac0d27d383bd386b8424e6bf6405e8b31127;p=netconf.git Acquire DOMNotificationService before changing state We have a potential source of exceptions triggering after we have mutated state. Fix that. Change-Id: Id178c124c37cde804b10975590a773fab0df644e Signed-off-by: Robert Varga --- diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java index 13972dcca9..ab8bc3d4dd 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java @@ -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()