From c8bd3fef5432584c764ef3528af92fbeb990b245 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 13 May 2021 10:26:21 +0200 Subject: [PATCH] Update RestconfDataServiceImpl stream lifecycle This is a follow-up patch to cleanup more checkExist() invocations, which are no longer needed, as the datastore handles container/list lifecycle. Change-Id: I8c9ad9b0718a3854af553ea1a20eea1812a8c9f6 Signed-off-by: Robert Varga (cherry picked from commit 330737a5a8b048bf8306035e25a108065403bea1) --- .../impl/RestconfDataServiceImpl.java | 26 ++++--------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java index 7c4520f949..bfb43b3cc5 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java @@ -215,7 +215,6 @@ public class RestconfDataServiceImpl implements RestconfDataService { private void createAllYangNotificationStreams(final RestconfStrategy strategy, final EffectiveModelContext schemaContext, final UriInfo uriInfo) { final RestconfTransaction transaction = strategy.prepareWriteExecution(); - final boolean exist = checkExist(schemaContext, strategy); for (final NotificationDefinition notificationDefinition : schemaContext.getNotifications()) { final NotificationListenerAdapter notifiStreamXML = @@ -224,8 +223,8 @@ public class RestconfDataServiceImpl implements RestconfDataService { final NotificationListenerAdapter notifiStreamJSON = CreateStreamUtil.createYangNotifiStream(notificationDefinition, schemaContext, NotificationOutputType.JSON); - writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction, exist, notifiStreamXML); - writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction, exist, notifiStreamJSON); + writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction, notifiStreamXML); + writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction, notifiStreamJSON); } try { transaction.commit().get(); @@ -235,33 +234,18 @@ public class RestconfDataServiceImpl implements RestconfDataService { } private void writeNotificationStreamToDatastore(final EffectiveModelContext schemaContext, - final UriInfo uriInfo, final RestconfTransaction transaction, final boolean exist, - final NotificationListenerAdapter listener) { + final UriInfo uriInfo, final RestconfTransaction transaction, final NotificationListenerAdapter listener) { final URI uri = streamUtils.prepareUriByStreamName(uriInfo, listener.getStreamName()); final MapEntryNode mapToStreams = RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring( listener.getSchemaPath().lastNodeIdentifier(), schemaContext.getNotifications(), null, listener.getOutputType(), uri, SubscribeToStreamUtil.getMonitoringModule(schemaContext)); final String name = listener.getSchemaPath().lastNodeIdentifier().getLocalName(); - final String pathId; - if (exist) { - pathId = Rfc8040.MonitoringModule.PATH_TO_STREAM_WITHOUT_KEY + name; - } else { - pathId = Rfc8040.MonitoringModule.PATH_TO_STREAMS; - } - transaction.merge(LogicalDatastoreType.OPERATIONAL, IdentifierCodec.deserialize(pathId, schemaContext), + transaction.merge(LogicalDatastoreType.OPERATIONAL, + IdentifierCodec.deserialize(Rfc8040.MonitoringModule.PATH_TO_STREAM_WITHOUT_KEY + name, schemaContext), mapToStreams); } - private static boolean checkExist(final EffectiveModelContext schemaContext, final RestconfStrategy strategy) { - try { - return strategy.exists(LogicalDatastoreType.OPERATIONAL, - IdentifierCodec.deserialize(Rfc8040.MonitoringModule.PATH_TO_STREAMS, schemaContext)).get(); - } catch (final InterruptedException | ExecutionException exception) { - throw new RestconfDocumentedException("Problem while checking data if exists", exception); - } - } - @Override public Response putData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) { requireNonNull(payload); -- 2.36.6