Update RestconfDataServiceImpl stream lifecycle 57/96157/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 13 May 2021 08:26:21 +0000 (10:26 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 13 May 2021 09:38:29 +0000 (11:38 +0200)
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 <robert.varga@pantheon.tech>
(cherry picked from commit 330737a5a8b048bf8306035e25a108065403bea1)

restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java

index 7c4520f94970310b03a710257e8df73f7d80040e..bfb43b3cc5953f31f5ffaa819c3438eef544e656 100644 (file)
@@ -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);