X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FControllerContext.java;h=e3beaa2287d01f5734b50a467b4e5cdd47cfcf6f;hp=a0b05150a84344a8c0cff9ca08472ac3067f2498;hb=e631dc96f0461b2270377dc072b9f969a875667a;hpb=f55f03931ef55344b0fb71b75fb0cb577fa89d54 diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java index a0b05150a8..e3beaa2287 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java @@ -27,7 +27,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import javax.ws.rs.core.Response.Status; @@ -42,17 +41,15 @@ import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag; import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType; import org.opendaylight.yangtools.concepts.Codec; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; -import org.opendaylight.yangtools.yang.model.api.ChoiceNode; +import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; @@ -86,6 +83,8 @@ public class ControllerContext implements SchemaContextListener { private static final Splitter SLASH_SPLITTER = Splitter.on('/'); + private static final YangInstanceIdentifier ROOT = YangInstanceIdentifier.builder().build(); + private final AtomicReference> qnameToRpc = new AtomicReference<>(Collections.emptyMap()); @@ -135,6 +134,10 @@ public class ControllerContext implements SchemaContextListener { private InstanceIdentifierContext toIdentifier(final String restconfInstance, final boolean toMountPointIdentifier) { checkPreconditions(); + if(restconfInstance == null) { + return new InstanceIdentifierContext<>(ROOT, globalSchema, null, globalSchema); + } + final List pathArgs = urlPathArgsDecode(SLASH_SPLITTER.split(restconfInstance)); omitFirstAndLastEmptyString(pathArgs); if (pathArgs.isEmpty()) { @@ -439,7 +442,7 @@ public class ControllerContext implements SchemaContextListener { return null; } - private static DataSchemaNode childByQName(final ChoiceNode container, final QName name) { + private static DataSchemaNode childByQName(final ChoiceSchemaNode container, final QName name) { for (final ChoiceCaseNode caze : container.getCases()) { final DataSchemaNode ret = ControllerContext.childByQName(caze, name); if (ret != null) { @@ -474,8 +477,8 @@ public class ControllerContext implements SchemaContextListener { final DataSchemaNode ret = container.getDataChildByName(name); if (ret == null) { for (final DataSchemaNode node : container.getChildNodes()) { - if ((node instanceof ChoiceNode)) { - final ChoiceNode choiceNode = ((ChoiceNode) node); + if ((node instanceof ChoiceSchemaNode)) { + final ChoiceSchemaNode choiceNode = ((ChoiceSchemaNode) node); final DataSchemaNode childByQName = ControllerContext.childByQName(choiceNode, name); if (childByQName != null) { return childByQName; @@ -501,7 +504,7 @@ public class ControllerContext implements SchemaContextListener { } if (strings.isEmpty()) { - return new InstanceIdentifierContext(builder.toInstance(), ((DataSchemaNode) parentNode), mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema); + return createContext(builder.toInstance(), ((DataSchemaNode) parentNode), mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema); } final String head = strings.iterator().next(); @@ -523,7 +526,7 @@ public class ControllerContext implements SchemaContextListener { ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED); } - final YangInstanceIdentifier partialPath = builder.toInstance(); + final YangInstanceIdentifier partialPath = dataNormalizer.toNormalized(builder.build()); final Optional mountOpt = mountService.getMountPoint(partialPath); if (!mountOpt.isPresent()) { LOG.debug("Instance identifier to missing mount point: {}", partialPath); @@ -538,12 +541,7 @@ public class ControllerContext implements SchemaContextListener { ErrorType.APPLICATION, ErrorTag.UNKNOWN_ELEMENT); } - if (returnJustMountPoint) { - final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance(); - return new InstanceIdentifierContext(instance, mountPointSchema, mount,mountPointSchema); - } - - if (strings.size() == 1) { + if (returnJustMountPoint || strings.size() == 1) { final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance(); return new InstanceIdentifierContext(instance, mountPointSchema, mount,mountPointSchema); } @@ -671,7 +669,14 @@ public class ControllerContext implements SchemaContextListener { returnJustMountPoint); } - return new InstanceIdentifierContext(builder.toInstance(), targetNode, mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema); + return createContext(builder.build(), targetNode, mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema); + } + + private InstanceIdentifierContext createContext(final YangInstanceIdentifier instance, final DataSchemaNode dataSchemaNode, + final DOMMountPoint mountPoint, final SchemaContext schemaContext) { + + final YangInstanceIdentifier instanceIdentifier = new DataNormalizer(schemaContext).toNormalized(instance); + return new InstanceIdentifierContext(instanceIdentifier, dataSchemaNode, mountPoint,schemaContext); } public static DataSchemaNode findInstanceDataChildByNameAndNamespace(final DataNodeContainer container, final String name, @@ -700,9 +705,9 @@ public class ControllerContext implements SchemaContextListener { return instantiatedDataNodeContainers; } - private static final Function> CHOICE_FUNCTION = new Function>() { + private static final Function> CHOICE_FUNCTION = new Function>() { @Override - public Set apply(final ChoiceNode node) { + public Set apply(final ChoiceSchemaNode node) { return node.getCases(); } }; @@ -727,7 +732,7 @@ public class ControllerContext implements SchemaContextListener { } } - final Iterable choiceNodes = Iterables.filter(container.getChildNodes(), ChoiceNode.class); + final Iterable choiceNodes = Iterables.filter(container.getChildNodes(), ChoiceSchemaNode.class); final Iterable> map = Iterables.transform(choiceNodes, CHOICE_FUNCTION); final Iterable allCases = Iterables. concat(map); @@ -859,9 +864,9 @@ public class ControllerContext implements SchemaContextListener { private CharSequence convertToRestconfIdentifier(final PathArgument argument, final DataNodeContainer node, final DOMMountPoint mount) { if (argument instanceof NodeIdentifier && node instanceof ContainerSchemaNode) { - return convertToRestconfIdentifier((NodeIdentifier) argument, (ContainerSchemaNode) node); + return convertToRestconfIdentifier((NodeIdentifier) argument, mount); } else if (argument instanceof NodeIdentifierWithPredicates && node instanceof ListSchemaNode) { - return convertToRestconfIdentifier(argument, node, mount); + return convertToRestconfIdentifierWithPredicates((NodeIdentifierWithPredicates) argument, (ListSchemaNode) node, mount); } else if (argument != null && node != null) { throw new IllegalArgumentException("Conversion of generic path argument is not supported"); } else { @@ -870,11 +875,11 @@ public class ControllerContext implements SchemaContextListener { } } - private CharSequence convertToRestconfIdentifier(final NodeIdentifier argument, final ContainerSchemaNode node) { - return "/" + this.toRestconfIdentifier(argument.getNodeType()); + private CharSequence convertToRestconfIdentifier(final NodeIdentifier argument, final DOMMountPoint node) { + return "/" + this.toRestconfIdentifier(argument.getNodeType(),node); } - private CharSequence convertToRestconfIdentifier(final NodeIdentifierWithPredicates argument, + private CharSequence convertToRestconfIdentifierWithPredicates(final NodeIdentifierWithPredicates argument, final ListSchemaNode node, final DOMMountPoint mount) { final QName nodeType = argument.getNodeType(); final CharSequence nodeIdentifier = this.toRestconfIdentifier(nodeType, mount); @@ -914,8 +919,8 @@ public class ControllerContext implements SchemaContextListener { private static DataSchemaNode childByQName(final Object container, final QName name) { if (container instanceof ChoiceCaseNode) { return childByQName((ChoiceCaseNode) container, name); - } else if (container instanceof ChoiceNode) { - return childByQName((ChoiceNode) container, name); + } else if (container instanceof ChoiceSchemaNode) { + return childByQName((ChoiceSchemaNode) container, name); } else if (container instanceof ContainerSchemaNode) { return childByQName((ContainerSchemaNode) container, name); } else if (container instanceof ListSchemaNode) { @@ -930,15 +935,6 @@ public class ControllerContext implements SchemaContextListener { } } - public Entry> toNormalized(final YangInstanceIdentifier legacy, - final CompositeNode compositeNode) { - try { - return dataNormalizer.toNormalized(legacy, compositeNode); - } catch (final NullPointerException e) { - throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e); - } - } - public YangInstanceIdentifier toNormalized(final YangInstanceIdentifier legacy) { try { return dataNormalizer.toNormalized(legacy); @@ -947,30 +943,21 @@ public class ControllerContext implements SchemaContextListener { } } - public CompositeNode toLegacy(final YangInstanceIdentifier instanceIdentifier, - final NormalizedNode normalizedNode) { - try { - return dataNormalizer.toLegacy(instanceIdentifier, normalizedNode); - } catch (final NullPointerException e) { - throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e); - } - } - public YangInstanceIdentifier toXpathRepresentation(final YangInstanceIdentifier instanceIdentifier) { try { return dataNormalizer.toLegacy(instanceIdentifier); - } catch (NullPointerException e) { + } catch (final NullPointerException e) { throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e); - } catch (DataNormalizationException e) { + } catch (final DataNormalizationException e) { throw new RestconfDocumentedException("Data normalizer failed. Normalization isn't possible", e); } } - public boolean isNodeMixin(YangInstanceIdentifier path) { + public boolean isNodeMixin(final YangInstanceIdentifier path) { final DataNormalizationOperation operation; try { operation = dataNormalizer.getOperation(path); - } catch (DataNormalizationException e) { + } catch (final DataNormalizationException e) { throw new RestconfDocumentedException("Data normalizer failed. Normalization isn't possible", e); } return operation.isMixin();