summaryrefslogtreecommitdiffstats
path: root/netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsResourceUtils.java
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2023-01-31 16:57:11 -0500
committerDan Timoney <dtimoney@att.com>2023-01-31 16:57:11 -0500
commitd76e58f792700c96d864237efd4539505cbf2b60 (patch)
tree645019d6cbee581a30aba87c29305ba95e33e9d9 /netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsResourceUtils.java
parentd4d6fbd430eb502cce6cb01a667ec799d487a510 (diff)
Port Biermann-draft-02 API to Chlorine
Made changes to get a clean compile under Chlorine. NOTE: changes in Chlorine break the jUnit testing for this feature - mostly due to changes in yangtools making classes sealed, which prevents use of mockito to simulate these classes. There are other changes as well that caused breakage. For now, pom.xml has been changed to disable jUnit, but this should be corrected. Issue-ID: CCSDK-3843 Signed-off-by: Dan Timoney <dtimoney@att.com> Change-Id: Ic53c6d580d644fab069a06f033db515c05dff6f2
Diffstat (limited to 'netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsResourceUtils.java')
-rw-r--r--netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsResourceUtils.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsResourceUtils.java b/netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsResourceUtils.java
new file mode 100644
index 0000000..ada0442
--- /dev/null
+++ b/netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsResourceUtils.java
@@ -0,0 +1,70 @@
+/*
+ * 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.restconf.common.util;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Map.Entry;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
+import org.opendaylight.yangtools.yang.common.Empty;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
+
+
+// FIXME: remove this class
+public final class OperationsResourceUtils {
+ private OperationsResourceUtils() {
+ // Hidden on purpose
+ }
+
+ public static @NonNull Entry<InstanceIdentifierContext, ContainerNode>
+ contextForModelContext(final @NonNull SchemaContext context, final @Nullable DOMMountPoint mountPoint) {
+ // Determine which modules we need and construct leaf schemas to correspond to all RPC definitions
+ final Collection<Module> modules = new ArrayList<>();
+ final ArrayList<OperationsLeafSchemaNode> rpcLeafSchemas = new ArrayList<>();
+ for (final Module m : context.getModules()) {
+ final Collection<? extends RpcDefinition> rpcs = m.getRpcs();
+ if (!rpcs.isEmpty()) {
+ modules.add(new OperationsImportedModule(m));
+ rpcLeafSchemas.ensureCapacity(rpcLeafSchemas.size() + rpcs.size());
+ for (RpcDefinition rpc : rpcs) {
+ rpcLeafSchemas.add(new OperationsLeafSchemaNode(rpc));
+ }
+ }
+ }
+
+ // Now generate a module for RESTCONF so that operations contain what they need
+ final OperationsContainerSchemaNode operatationsSchema = new OperationsContainerSchemaNode(rpcLeafSchemas);
+ modules.add(new OperationsRestconfModule(operatationsSchema));
+
+ // Now build the operations container and combine it with the context
+ final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> operationsBuilder = Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(OperationsContainerSchemaNode.QNAME));
+ for (final OperationsLeafSchemaNode leaf : rpcLeafSchemas) {
+ operationsBuilder.withChild(ImmutableNodes.leafNode(leaf.getQName(), Empty.value()));
+ }
+
+ final var opContext = new OperationsEffectiveModuleContext(ImmutableSet.copyOf(modules));
+ final var stack = SchemaInferenceStack.of(opContext);
+ stack.enterSchemaTree(operatationsSchema.getQName());
+
+ return Map.entry(InstanceIdentifierContext.ofStack(stack, mountPoint), operationsBuilder.build());
+ }
+}