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=39f4eef657bd0d06d42c7dd7c6cbbb222a97c856;hp=16bbf9a4b144dc0e522db765cfc4755e2efde28b;hb=eb887b1c2c8cd2768f8b4c2ed2b5054f97798466;hpb=b4f974d0a1cb64873d7cb8cf8aef82199a0ea81c 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 16bbf9a4b1..39f4eef657 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 @@ -9,6 +9,7 @@ package org.opendaylight.controller.sal.restconf.impl; import com.google.common.base.Function; import com.google.common.base.Objects; +import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.base.Splitter; @@ -17,7 +18,6 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; - import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URLDecoder; @@ -31,22 +31,20 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; - import javax.ws.rs.core.Response.Status; - -import org.opendaylight.controller.sal.core.api.mount.MountInstance; -import org.opendaylight.controller.sal.core.api.mount.MountService; +import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; +import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; import org.opendaylight.controller.sal.rest.api.Draft02; import org.opendaylight.controller.sal.rest.impl.RestUtil; 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.InstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.InstanceIdentifierBuilder; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +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.model.api.AnyXmlSchemaNode; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; import org.opendaylight.yangtools.yang.model.api.ChoiceNode; @@ -91,13 +89,13 @@ public class ControllerContext implements SchemaContextListener { new AtomicReference<>(Collections.emptyMap()); private volatile SchemaContext globalSchema; - private volatile MountService mountService; + private volatile DOMMountPointService mountService; public void setGlobalSchema(final SchemaContext globalSchema) { this.globalSchema = globalSchema; } - public void setMountService(final MountService mountService) { + public void setMountService(final DOMMountPointService mountService) { this.mountService = mountService; } @@ -142,7 +140,7 @@ public class ControllerContext implements SchemaContextListener { ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); } - InstanceIdentifierBuilder builder = InstanceIdentifier.builder(); + InstanceIdentifierBuilder builder = YangInstanceIdentifier.builder(); Module latestModule = this.getLatestModule(globalSchema, startModule); InstanceIdWithSchemaNode iiWithSchemaNode = this.collectPathArguments(builder, pathArgs, latestModule, null, toMountPointIdentifier); @@ -207,7 +205,7 @@ public class ControllerContext implements SchemaContextListener { return this.getLatestModule(globalSchema, moduleName); } - public Module findModuleByName(final MountInstance mountPoint, final String moduleName) { + public Module findModuleByName(final DOMMountPoint mountPoint, final String moduleName) { Preconditions.checkArgument(moduleName != null && mountPoint != null); final SchemaContext mountPointSchema = mountPoint.getSchemaContext(); @@ -222,7 +220,7 @@ public class ControllerContext implements SchemaContextListener { return moduleSchemas == null ? null : this.filterLatestModule(moduleSchemas); } - public Module findModuleByNamespace(final MountInstance mountPoint, final URI namespace) { + public Module findModuleByNamespace(final DOMMountPoint mountPoint, final URI namespace) { Preconditions.checkArgument(namespace != null && mountPoint != null); final SchemaContext mountPointSchema = mountPoint.getSchemaContext(); @@ -237,7 +235,7 @@ public class ControllerContext implements SchemaContextListener { return globalSchema.findModuleByName(module.getLocalName(), module.getRevision()); } - public Module findModuleByNameAndRevision(final MountInstance mountPoint, final QName module) { + public Module findModuleByNameAndRevision(final DOMMountPoint mountPoint, final QName module) { this.checkPreconditions(); Preconditions.checkArgument(module != null && module.getLocalName() != null && module.getRevision() != null && mountPoint != null); @@ -247,7 +245,7 @@ public class ControllerContext implements SchemaContextListener { module.getRevision()); } - public DataNodeContainer getDataNodeContainerFor(final InstanceIdentifier path) { + public DataNodeContainer getDataNodeContainerFor(final YangInstanceIdentifier path) { this.checkPreconditions(); final Iterable elements = path.getPathArguments(); @@ -268,7 +266,7 @@ public class ControllerContext implements SchemaContextListener { return node; } - public String toFullRestconfIdentifier(final InstanceIdentifier path) { + public String toFullRestconfIdentifier(final YangInstanceIdentifier path) { this.checkPreconditions(); final Iterable elements = path.getPathArguments(); @@ -306,7 +304,7 @@ public class ControllerContext implements SchemaContextListener { return moduleName; } - public String findModuleNameByNamespace(final MountInstance mountPoint, final URI namespace) { + public String findModuleNameByNamespace(final DOMMountPoint mountPoint, final URI namespace) { final Module module = this.findModuleByNamespace(mountPoint, namespace); return module == null ? null : module.getName(); } @@ -324,12 +322,12 @@ public class ControllerContext implements SchemaContextListener { return namespace; } - public URI findNamespaceByModuleName(final MountInstance mountPoint, final String moduleName) { + public URI findNamespaceByModuleName(final DOMMountPoint mountPoint, final String moduleName) { final Module module = this.findModuleByName(mountPoint, moduleName); return module == null ? null : module.getNamespace(); } - public Set getAllModules(final MountInstance mountPoint) { + public Set getAllModules(final DOMMountPoint mountPoint) { this.checkPreconditions(); SchemaContext schemaContext = mountPoint == null ? null : mountPoint.getSchemaContext(); @@ -363,7 +361,7 @@ public class ControllerContext implements SchemaContextListener { return builder.toString(); } - public CharSequence toRestconfIdentifier(final MountInstance mountPoint, final QName qname) { + public CharSequence toRestconfIdentifier(final DOMMountPoint mountPoint, final QName qname) { if (mountPoint == null) { return null; } @@ -508,9 +506,9 @@ public class ControllerContext implements SchemaContextListener { DataSchemaNode ret = container.getDataChildByName(name); if (ret == null) { for (final DataSchemaNode node : container.getChildNodes()) { - if ((node instanceof ChoiceCaseNode)) { - final ChoiceCaseNode caseNode = ((ChoiceCaseNode) node); - DataSchemaNode childByQName = ControllerContext.childByQName(caseNode, name); + if ((node instanceof ChoiceNode)) { + final ChoiceNode choiceNode = ((ChoiceNode) node); + DataSchemaNode childByQName = ControllerContext.childByQName(choiceNode, name); if (childByQName != null) { return childByQName; } @@ -525,7 +523,7 @@ public class ControllerContext implements SchemaContextListener { } private InstanceIdWithSchemaNode collectPathArguments(final InstanceIdentifierBuilder builder, - final List strings, final DataNodeContainer parentNode, final MountInstance mountPoint, + final List strings, final DataNodeContainer parentNode, final DOMMountPoint mountPoint, final boolean returnJustMountPoint) { Preconditions.> checkNotNull(strings); @@ -556,13 +554,14 @@ public class ControllerContext implements SchemaContextListener { ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED); } - final InstanceIdentifier partialPath = builder.toInstance(); - final MountInstance mount = mountService.getMountPoint(partialPath); - if (mount == null) { + final YangInstanceIdentifier partialPath = builder.toInstance(); + final Optional mountOpt = mountService.getMountPoint(partialPath); + if (!mountOpt.isPresent()) { LOG.debug("Instance identifier to missing mount point: {}", partialPath); throw new RestconfDocumentedException("Mount point does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT); } + DOMMountPoint mount = mountOpt.get(); final SchemaContext mountPointSchema = mount.getSchemaContext(); if (mountPointSchema == null) { @@ -571,12 +570,12 @@ public class ControllerContext implements SchemaContextListener { } if (returnJustMountPoint) { - InstanceIdentifier instance = InstanceIdentifier.builder().toInstance(); + YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance(); return new InstanceIdWithSchemaNode(instance, mountPointSchema, mount); } if (strings.size() == 1) { - InstanceIdentifier instance = InstanceIdentifier.builder().toInstance(); + YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance(); return new InstanceIdWithSchemaNode(instance, mountPointSchema, mount); } @@ -595,7 +594,7 @@ public class ControllerContext implements SchemaContextListener { } List subList = strings.subList(1, strings.size()); - return this.collectPathArguments(InstanceIdentifier.builder(), subList, moduleBehindMountPoint, mount, + return this.collectPathArguments(YangInstanceIdentifier.builder(), subList, moduleBehindMountPoint, mount, returnJustMountPoint); } @@ -764,7 +763,7 @@ public class ControllerContext implements SchemaContextListener { } private void addKeyValue(final HashMap map, final DataSchemaNode node, final String uriValue, - final MountInstance mountPoint) { + final DOMMountPoint mountPoint) { Preconditions. checkNotNull(uriValue); Preconditions.checkArgument((node instanceof LeafSchemaNode));