import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.leaf_list.LeafListStatementRFC6020Support;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.leaf_list.LeafListStatementRFC7950Support;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.length.LengthStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.list.ConfigListWarningNamespace;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.list.ListStatementRFC6020Support;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.list.ListStatementRFC7950Support;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.mandatory.MandatoryStatementSupport;
.addVersionSpecificSupport(VERSION_1_1, GroupingStatementRFC7950Support.getInstance())
.addVersionSpecificSupport(VERSION_1, ListStatementRFC6020Support.getInstance())
.addVersionSpecificSupport(VERSION_1_1, ListStatementRFC7950Support.getInstance())
+ .addSupport(ConfigListWarningNamespace.BEHAVIOUR)
.addSupport(UniqueStatementSupport.getInstance())
.addVersionSpecificSupport(VERSION_1_1, ActionStatementSupport.getInstance())
.addVersionSpecificSupport(VERSION_1, RpcStatementRFC6020Support.getInstance())
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.list;
+import static com.google.common.base.Verify.verify;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ElementCountConstraint;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
protected final ListEffectiveStatement createEffective(
final StmtContext<QName, ListStatement, ListEffectiveStatement> ctx,
final ListStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
- final StatementSourceReference ref = ctx.getStatementSourceReference();
final SchemaPath path = ctx.getSchemaPath().get();
final ListSchemaNode original = (ListSchemaNode) ctx.getOriginalCtx().map(StmtContext::buildEffective)
.orElse(null);
}
for (final QName keyQName : keyStmt.argument()) {
if (!possibleLeafQNamesForKey.contains(keyQName)) {
- throw new InferenceException(ref, "Key '%s' misses node '%s' in list '%s'",
- keyStmt.getDeclared().rawArgument(), keyQName.getLocalName(), ctx.getStatementArgument());
+ throw new InferenceException(ctx.getStatementSourceReference(),
+ "Key '%s' misses node '%s' in list '%s'", keyStmt.getDeclared().rawArgument(),
+ keyQName.getLocalName(), ctx.getStatementArgument());
}
keyDefinitionInit.add(keyQName);
}
.equals(Ordering.USER))
.toFlags();
if (configuration && keyDefinition.isEmpty() && isInstantied(ctx)) {
- LOG.info("Configuration list {} does not define any keys in violation of RFC7950 section 7.8.2. While "
- + " this is fine with OpenDaylight, it can cause interoperability issues with other systems "
- + "[at {}]", ctx.getStatementArgument(), ref);
+ warnConfigList(ctx);
}
final Optional<ElementCountConstraint> elementCountConstraint =
elementCountConstraint.orElse(null), original);
}
+ private static void warnConfigList(final @NonNull StmtContext<QName, ListStatement, ListEffectiveStatement> ctx) {
+ final StmtContext<QName, ListStatement, ListEffectiveStatement> warnCtx = ctx.getOriginalCtx().orElse(ctx);
+ final Boolean warned = warnCtx.getFromNamespace(ConfigListWarningNamespace.class, Boolean.TRUE);
+ // Hacky check if we have issued a warning for the original statement
+ if (warned == null) {
+ verify(warnCtx instanceof Mutable, "Unexpected context %s", warnCtx);
+ ((Mutable<?, ?, ?>) warnCtx).addToNs(ConfigListWarningNamespace.class, Boolean.TRUE, Boolean.TRUE);
+ LOG.info("Configuration list {} does not define any keys in violation of RFC7950 section 7.8.2. While "
+ + "this is fine with OpenDaylight, it can cause interoperability issues with other systems "
+ + "[defined at {}]", ctx.getStatementArgument(), warnCtx.getStatementSourceReference());
+ }
+ }
+
private static boolean isInstantied(final StmtContext<?, ?, ?> ctx) {
for (StmtContext<?, ?, ?> parent = ctx.getParentContext(); parent != null; parent = parent.getParentContext()) {
if (UNINSTANTIATED_DATATREE_STATEMENTS.contains(parent.getPublicDefinition())) {
--- /dev/null
+/*
+ * Copyright (c) 2020 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.yangtools.yang.parser.rfc7950.stmt.list;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
+
+@Beta
+public interface ConfigListWarningNamespace extends IdentifierNamespace<Boolean, Boolean> {
+ NamespaceBehaviour<Boolean, Boolean, @NonNull ConfigListWarningNamespace> BEHAVIOUR =
+ NamespaceBehaviour.statementLocal(ConfigListWarningNamespace.class);
+}