X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FControllerContext.xtend;h=624178569d4e71551507f7733cec7c93bf4b032c;hb=7007ef0c2b418b9b49e56e6c3525e8906fefa522;hp=2218023cafe16ff1b53ad6131c21b390f87882b8;hpb=521d199e057a03929ad64925d7d37ba79deba167;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend index 2218023caf..624178569d 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend @@ -24,9 +24,14 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode import org.opendaylight.yangtools.yang.model.api.SchemaContext import static com.google.common.base.Preconditions.* +import org.opendaylight.controller.sal.core.api.model.SchemaServiceListener +import org.opendaylight.yangtools.yang.model.api.RpcDefinition +import java.util.concurrent.ConcurrentHashMap + +class ControllerContext implements SchemaServiceListener { + + val static ControllerContext INSTANCE = new ControllerContext -class ControllerContext { - val static NULL_VALUE = "null" @Property @@ -34,6 +39,18 @@ class ControllerContext { private val BiMap uriToModuleName = HashBiMap.create(); private val Map moduleNameToUri = uriToModuleName.inverse(); + private val Map qnameToRpc = new ConcurrentHashMap(); + + + private new() { + if (INSTANCE != null) { + throw new IllegalStateException("Already instantiated"); + } + } + + static def getInstance() { + return INSTANCE + } public def InstanceIdWithSchemaNode toInstanceIdentifier(String restconfInstance) { val ret = InstanceIdentifier.builder(); @@ -196,6 +213,7 @@ class ControllerContext { if (targetNode instanceof ListSchemaNode) { val listNode = targetNode as ListSchemaNode; val keysSize = listNode.keyDefinition.size + // every key has to be filled if ((strings.length - consumed) < keysSize) { return null; @@ -205,6 +223,7 @@ class ControllerContext { var i = 0; for (key : listNode.keyDefinition) { val uriKeyValue = uriKeyValues.get(i); + // key value cannot be NULL if (uriKeyValue.equals(NULL_VALUE)) { return null @@ -215,6 +234,7 @@ class ControllerContext { consumed = consumed + i; builder.nodeWithKey(targetNode.QName, keyValues); } else { + // Only one instance of node is allowed builder.node(targetNode.QName); } @@ -256,6 +276,27 @@ class ControllerContext { } } - public def QName toRpcQName(String name) { + public def QName toQName(String name) { + val module = name.toModuleName; + val node = name.toNodeName; + val namespace = moduleNameToUri.get(module); + return new QName(namespace,null,node); + } + + override onGlobalContextUpdated(SchemaContext context) { + this.schemas = context; + for(operation : context.operations) { + val qname = new QName(operation.QName.namespace,null,operation.QName.localName); + qnameToRpc.put(qname,operation); + } } + + def ContainerSchemaNode getRpcOutputSchema(QName name) { + qnameToRpc.get(name)?.output; + } + + def ContainerSchemaNode getRpcInputSchema(QName name) { + qnameToRpc.get(name)?.input; + } + }