From 55cd345aff37b14e56e79cb2e2fcb8e4719d49ca Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 26 Oct 2021 10:27:43 +0200 Subject: [PATCH] Advertize skip-notification-data capability Add SkipNotificationDataParam to hold the details abound skip-notification-data. Also define a new capability URI and advertize it in the datastore. JIRA: NETCONF-823 Change-Id: I4c907a2d359afaa4e47fbd8cb2790dd3395b3c16 Signed-off-by: Robert Varga --- .../nb/rfc8040/NotificationQueryParams.java | 17 +++-- .../nb/rfc8040/SkipNotificationDataParam.java | 70 +++++++++++++++++++ .../rfc8040/databind/jaxrs/QueryParams.java | 9 +-- .../handlers/SchemaContextHandler.java | 2 + .../services/impl/SubscribeToStreamUtil.java | 4 +- .../listeners/AbstractQueryParams.java | 6 +- .../handlers/SchemaContextHandlerTest.java | 3 +- .../listeners/ListenerAdapterTest.java | 3 +- 8 files changed, 97 insertions(+), 17 deletions(-) create mode 100644 restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/SkipNotificationDataParam.java diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/NotificationQueryParams.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/NotificationQueryParams.java index afa522f0b4..1894198761 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/NotificationQueryParams.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/NotificationQueryParams.java @@ -19,13 +19,13 @@ import org.opendaylight.yangtools.concepts.Immutable; * Parser and holder of query parameters from uriInfo for notifications. */ public final class NotificationQueryParams implements Immutable { + private final SkipNotificationDataParam skipNotificationData; private final StartTimeParam startTime; private final StopTimeParam stopTime; private final FilterParam filter; - private final boolean skipNotificationData; private NotificationQueryParams(final StartTimeParam startTime, final StopTimeParam stopTime, - final FilterParam filter, final boolean skipNotificationData) { + final FilterParam filter, final SkipNotificationDataParam skipNotificationData) { this.startTime = startTime; this.stopTime = stopTime; this.filter = filter; @@ -33,7 +33,7 @@ public final class NotificationQueryParams implements Immutable { } public static @NonNull NotificationQueryParams of(final StartTimeParam startTime, final StopTimeParam stopTime, - final FilterParam filter, final boolean skipNotificationData) { + final FilterParam filter, final SkipNotificationDataParam skipNotificationData) { checkArgument(stopTime == null || startTime != null, "Stop-time parameter has to be used with start-time parameter."); return new NotificationQueryParams(startTime, stopTime, filter, skipNotificationData); @@ -67,11 +67,11 @@ public final class NotificationQueryParams implements Immutable { } /** - * Check whether this query should notify changes without data. + * Get odl-skip-notification-data query parameter. * - * @return true if this query should notify about changes with data + * @return odl-skip-notification-data */ - public boolean isSkipNotificationData() { + public @Nullable SkipNotificationDataParam skipNotificationData() { return skipNotificationData; } @@ -87,6 +87,9 @@ public final class NotificationQueryParams implements Immutable { if (filter != null) { helper.add("filter", filter.paramValue()); } - return helper.add("skipNotificationData", skipNotificationData).toString(); + if (skipNotificationData != null) { + helper.add("skipNotificationData", skipNotificationData.value()); + } + return helper.toString(); } } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/SkipNotificationDataParam.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/SkipNotificationDataParam.java new file mode 100644 index 0000000000..117d618d2f --- /dev/null +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/SkipNotificationDataParam.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.restconf.nb.rfc8040; + +import java.net.URI; +import org.eclipse.jdt.annotation.NonNull; + +/** + * OpenDaylight extension parameter. When used as {@code odl-skip-notification-data=true}, it will instruct the listener + * streams to prune data from notifications. + */ +public final class SkipNotificationDataParam implements RestconfQueryParam { + // API consistency: must not be confused with enum constants + @SuppressWarnings("checkstyle:ConstantName") + public static final String uriName = "odl-skip-notification-data"; + + private static final @NonNull URI CAPABILITY = + URI.create("urn:opendaylight:params:restconf:capability:skip-notification-data:1.0"); + private static final @NonNull SkipNotificationDataParam FALSE = new SkipNotificationDataParam(false); + private static final @NonNull SkipNotificationDataParam TRUE = new SkipNotificationDataParam(true); + + private final boolean value; + + private SkipNotificationDataParam(final boolean value) { + this.value = value; + } + + public static @NonNull SkipNotificationDataParam of(final boolean value) { + return value ? TRUE : FALSE; + } + + public static @NonNull SkipNotificationDataParam forUriValue(final String uriValue) { + switch (uriValue) { + case "false": + return FALSE; + case "true": + return TRUE; + default: + throw new IllegalArgumentException("Value can be 'false' or 'true', not '" + uriValue + "'"); + } + } + + @Override + public Class<@NonNull SkipNotificationDataParam> javaClass() { + return SkipNotificationDataParam.class; + } + + @Override + public String paramName() { + return uriName; + } + + @Override + public String paramValue() { + return String.valueOf(value); + } + + public boolean value() { + return value; + } + + public static @NonNull URI capabilityUri() { + return CAPABILITY; + } +} diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/jaxrs/QueryParams.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/jaxrs/QueryParams.java index d0ecbeba3b..7788d69579 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/jaxrs/QueryParams.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/jaxrs/QueryParams.java @@ -32,6 +32,7 @@ import org.opendaylight.restconf.nb.rfc8040.InsertParam; import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams; import org.opendaylight.restconf.nb.rfc8040.PointParam; import org.opendaylight.restconf.nb.rfc8040.ReadDataParams; +import org.opendaylight.restconf.nb.rfc8040.SkipNotificationDataParam; import org.opendaylight.restconf.nb.rfc8040.StartTimeParam; import org.opendaylight.restconf.nb.rfc8040.StopTimeParam; import org.opendaylight.restconf.nb.rfc8040.WithDefaultsParam; @@ -67,7 +68,7 @@ public final class QueryParams { StartTimeParam startTime = null; StopTimeParam stopTime = null; FilterParam filter = null; - boolean skipNotificationData = false; + SkipNotificationDataParam skipNotificationData = null; for (Entry> entry : uriInfo.getQueryParameters().entrySet()) { final String paramName = entry.getKey(); @@ -84,9 +85,9 @@ public final class QueryParams { case StopTimeParam.uriName: stopTime = optionalParam(StopTimeParam::forUriValue, paramName, paramValues); break; - case "odl-skip-notification-data": - // FIXME: this should be properly encapsulated in SkipNotificatioDataParameter - skipNotificationData = Boolean.parseBoolean(optionalParam(paramName, paramValues)); + case SkipNotificationDataParam.uriName: + skipNotificationData = optionalParam(SkipNotificationDataParam::forUriValue, paramName, + paramValues); break; default: throw unhandledParam("notification", paramName); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java index b8e7bc08ef..f36bf96aec 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java @@ -33,6 +33,7 @@ import org.opendaylight.restconf.nb.rfc8040.DepthParam; import org.opendaylight.restconf.nb.rfc8040.FieldsParam; import org.opendaylight.restconf.nb.rfc8040.FilterParam; import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary; +import org.opendaylight.restconf.nb.rfc8040.SkipNotificationDataParam; import org.opendaylight.restconf.nb.rfc8040.WithDefaultsParam; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.monitoring.rev170126.RestconfState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.monitoring.rev170126.restconf.state.Capabilities; @@ -183,6 +184,7 @@ public class SchemaContextHandler implements EffectiveModelContextListener, Auto .withChildValue(FilterParam.capabilityUri().toString()) .withChildValue(AbstractReplayParam.capabilityUri().toString()) .withChildValue(WithDefaultsParam.capabilityUri().toString()) + .withChildValue(SkipNotificationDataParam.capabilityUri().toString()) .build()) .build()) .build(); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java index 4c7dc29bb8..3a6afed996 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java @@ -135,7 +135,7 @@ abstract class SubscribeToStreamUtil { notificationQueryParams.startTime(), notificationQueryParams.stopTime(), notificationQueryParams.filter(), - false, notificationQueryParams.isSkipNotificationData()); + false, notificationQueryParams.skipNotificationData()); final DOMDataBroker dataBroker = handlersHolder.getDataBroker(); notificationListenerAdapter.setCloseVars(dataBroker, handlersHolder.getSchemaHandler()); final MapEntryNode mapToStreams = RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring( @@ -187,7 +187,7 @@ abstract class SubscribeToStreamUtil { notificationQueryParams.startTime(), notificationQueryParams.stopTime(), notificationQueryParams.filter(), - false, notificationQueryParams.isSkipNotificationData()); + false, notificationQueryParams.skipNotificationData()); final DOMDataBroker dataBroker = handlersHolder.getDataBroker(); final SchemaContextHandler schemaHandler = handlersHolder.getSchemaHandler(); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractQueryParams.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractQueryParams.java index e58f8ffa8a..2d9f2c1181 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractQueryParams.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractQueryParams.java @@ -18,6 +18,7 @@ import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.nb.rfc8040.FilterParam; +import org.opendaylight.restconf.nb.rfc8040.SkipNotificationDataParam; import org.opendaylight.restconf.nb.rfc8040.StartTimeParam; import org.opendaylight.restconf.nb.rfc8040.StopTimeParam; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; @@ -56,11 +57,12 @@ abstract class AbstractQueryParams extends AbstractNotificationsData { */ @SuppressWarnings("checkstyle:hiddenField") public final void setQueryParams(final StartTimeParam startTime, final StopTimeParam stopTime, - final FilterParam filter, final boolean leafNodesOnly, final boolean skipNotificationData) { + final FilterParam filter, final boolean leafNodesOnly, + final SkipNotificationDataParam skipNotificationData) { start = startTime == null ? Instant.now() : parseDateAndTime(startTime.value()); stop = stopTime == null ? null : parseDateAndTime(stopTime.value()); this.leafNodesOnly = leafNodesOnly; - this.skipNotificationData = skipNotificationData; + this.skipNotificationData = skipNotificationData == null ? false : skipNotificationData.value(); if (filter != null) { try { diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandlerTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandlerTest.java index 444c74bce9..e04a3a8275 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandlerTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandlerTest.java @@ -153,7 +153,8 @@ public class SchemaContextHandlerTest { equalTo("urn:ietf:params:restconf:capability:fields:1.0"), equalTo("urn:ietf:params:restconf:capability:filter:1.0"), equalTo("urn:ietf:params:restconf:capability:replay:1.0"), - equalTo("urn:ietf:params:restconf:capability:with-defaults:1.0"))); + equalTo("urn:ietf:params:restconf:capability:with-defaults:1.0"), + equalTo("urn:opendaylight:params:restconf:capability:skip-notification-data:1.0"))); } } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java index 40a0f67efb..13fa69cef1 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java @@ -34,6 +34,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService; import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.mdsal.dom.api.DOMSchemaService; +import org.opendaylight.restconf.nb.rfc8040.SkipNotificationDataParam; import org.opendaylight.restconf.nb.rfc8040.StartTimeParam; import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121.PatchCont; @@ -121,7 +122,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { final boolean leafNodesOnly, final boolean skipNotificationData) { super(path, streamName, outputType); setQueryParams(StartTimeParam.forUriValue("1970-01-01T00:00:00Z"), null, null, leafNodesOnly, - skipNotificationData); + SkipNotificationDataParam.of(skipNotificationData)); } @Override -- 2.36.6