Search in sources :

Example 1 with RpcDefinition

use of org.opendaylight.yangtools.yang.model.api.RpcDefinition in project controller by opendaylight.

the class RuntimeBeanEntry method extractSubtree.

/**
 * Get direct descendants of this subtree, together with attributes defined
 * in subtree.
 */
private static AttributesRpcsAndRuntimeBeans extractSubtree(final String packageName, final DataNodeContainer subtree, final TypeProviderWrapper typeProviderWrapper, final Module currentModule, final SchemaContext ctx) {
    Multimap<QName, RpcDefinition> identitiesToRpcs = getIdentitiesToRpcs(ctx);
    List<AttributeIfc> attributes = Lists.newArrayList();
    List<RuntimeBeanEntry> runtimeBeanEntries = new ArrayList<>();
    for (DataSchemaNode child : subtree.getChildNodes()) {
        // runtime beans
        if (child instanceof LeafSchemaNode) {
            // just save the attribute
            LeafSchemaNode leaf = (LeafSchemaNode) child;
            attributes.add(new JavaAttribute(leaf, typeProviderWrapper));
        } else if (child instanceof ContainerSchemaNode) {
            ContainerSchemaNode container = (ContainerSchemaNode) child;
            // this can be either TO or hierarchical RB
            TOAttribute toAttribute = TOAttribute.create(container, typeProviderWrapper, packageName);
            attributes.add(toAttribute);
        } else if (child instanceof ListSchemaNode) {
            if (isInnerStateBean(child)) {
                ListSchemaNode listSchemaNode = (ListSchemaNode) child;
                RuntimeBeanEntry hierarchicalChild = createHierarchical(packageName, listSchemaNode, typeProviderWrapper, currentModule, ctx);
                runtimeBeanEntries.add(hierarchicalChild);
            } else /* ordinary list attribute */
            {
                ListAttribute listAttribute = ListAttribute.create((ListSchemaNode) child, typeProviderWrapper, packageName);
                attributes.add(listAttribute);
            }
        } else if (child instanceof LeafListSchemaNode) {
            ListAttribute listAttribute = ListAttribute.create((LeafListSchemaNode) child, typeProviderWrapper);
            attributes.add(listAttribute);
        } else {
            throw new IllegalStateException("Unexpected running-data node " + child);
        }
    }
    Set<Rpc> rpcs = new HashSet<>();
    SchemaNode subtreeSchemaNode = (SchemaNode) subtree;
    for (UnknownSchemaNode unknownSchemaNode : subtreeSchemaNode.getUnknownSchemaNodes()) {
        if (ConfigConstants.RPC_CONTEXT_INSTANCE_EXTENSION_QNAME.equals(unknownSchemaNode.getNodeType())) {
            String localIdentityName = unknownSchemaNode.getNodeParameter();
            QName identityQName = unknownSchemaNode.isAddedByUses() ? findQNameFromGrouping(subtree, ctx, unknownSchemaNode, localIdentityName) : QName.create(currentModule.getNamespace(), currentModule.getRevision(), localIdentityName);
            // convert RpcDefinition to Rpc
            for (RpcDefinition rpcDefinition : identitiesToRpcs.get(identityQName)) {
                String name = TypeProviderWrapper.findJavaParameter(rpcDefinition);
                AttributeIfc returnType;
                if (rpcDefinition.getOutput() == null || rpcDefinition.getOutput().getChildNodes().isEmpty()) {
                    returnType = VoidAttribute.getInstance();
                } else if (rpcDefinition.getOutput().getChildNodes().size() == 1) {
                    DataSchemaNode returnDSN = rpcDefinition.getOutput().getChildNodes().iterator().next();
                    returnType = getReturnTypeAttribute(returnDSN, typeProviderWrapper, packageName);
                } else {
                    throw new IllegalArgumentException("More than one child node in rpc output is not supported. " + "Error occured in " + rpcDefinition);
                }
                List<JavaAttribute> parameters = new ArrayList<>();
                for (DataSchemaNode childNode : sortAttributes(rpcDefinition.getInput().getChildNodes())) {
                    if (childNode.isAddedByUses() == false) {
                        // skip
                        // refined
                        // context-instance
                        checkArgument(childNode instanceof LeafSchemaNode, "Unexpected type of rpc input type. " + "Currently only leafs and empty output nodes are supported, got " + childNode);
                        JavaAttribute javaAttribute = new JavaAttribute((LeafSchemaNode) childNode, typeProviderWrapper);
                        parameters.add(javaAttribute);
                    }
                }
                Rpc newRpc = new Rpc(returnType, name, rpcDefinition.getQName().getLocalName(), parameters);
                rpcs.add(newRpc);
            }
        }
    }
    return new AttributesRpcsAndRuntimeBeans(runtimeBeanEntries, attributes, rpcs);
}
Also used : RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) ArrayList(java.util.ArrayList) TOAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) UnknownSchemaNode(org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode) JavaAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute) HashSet(java.util.HashSet) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) UnknownSchemaNode(org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) ListAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute)

Example 2 with RpcDefinition

use of org.opendaylight.yangtools.yang.model.api.RpcDefinition in project controller by opendaylight.

the class RuntimeBeanEntry method getIdentitiesToRpcs.

private static Multimap<QName, /* of identity */
RpcDefinition> getIdentitiesToRpcs(final SchemaContext schemaCtx) {
    Multimap<QName, RpcDefinition> result = HashMultimap.create();
    for (Module currentModule : schemaCtx.getModules()) {
        // Find all identities in current module for later identity->rpc mapping
        Set<QName> allIdentitiesInModule = Sets.newHashSet(Collections2.transform(currentModule.getIdentities(), SchemaNode::getQName));
        for (RpcDefinition rpc : currentModule.getRpcs()) {
            ContainerSchemaNode input = rpc.getInput();
            if (input != null) {
                for (UsesNode uses : input.getUses()) {
                    // Check if the rpc is config rpc by looking for input argument rpc-context-ref
                    Iterator<QName> pathFromRoot = uses.getGroupingPath().getPathFromRoot().iterator();
                    if (!pathFromRoot.hasNext() || !pathFromRoot.next().equals(ConfigConstants.RPC_CONTEXT_REF_GROUPING_QNAME)) {
                        continue;
                    }
                    for (SchemaNode refinedNode : uses.getRefines().values()) {
                        for (UnknownSchemaNode unknownSchemaNode : refinedNode.getUnknownSchemaNodes()) {
                            if (ConfigConstants.RPC_CONTEXT_INSTANCE_EXTENSION_QNAME.equals(unknownSchemaNode.getNodeType())) {
                                String localIdentityName = unknownSchemaNode.getNodeParameter();
                                QName identityQName = QName.create(currentModule.getNamespace(), currentModule.getRevision(), localIdentityName);
                                Preconditions.checkArgument(allIdentitiesInModule.contains(identityQName), "Identity referenced by rpc not found. Identity: %s, rpc: %s", localIdentityName, rpc);
                                result.put(identityQName, rpc);
                            }
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) UnknownSchemaNode(org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) QName(org.opendaylight.yangtools.yang.common.QName) Module(org.opendaylight.yangtools.yang.model.api.Module) UnknownSchemaNode(org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode) UsesNode(org.opendaylight.yangtools.yang.model.api.UsesNode)

Example 3 with RpcDefinition

use of org.opendaylight.yangtools.yang.model.api.RpcDefinition in project controller by opendaylight.

the class RpcUtil method decomposeRpcService.

static Collection<SchemaPath> decomposeRpcService(final Class<RpcService> service, final SchemaContext schemaContext, final Predicate<RpcRoutingStrategy> filter) {
    final QNameModule moduleName = BindingReflections.getQNameModule(service);
    final Module module = schemaContext.findModule(moduleName).get();
    LOG.debug("Resolved service {} to module {}", service, module);
    final Collection<RpcDefinition> rpcs = module.getRpcs();
    final Collection<SchemaPath> ret = new ArrayList<>(rpcs.size());
    for (RpcDefinition rpc : rpcs) {
        final RpcRoutingStrategy strategy = RpcRoutingStrategy.from(rpc);
        if (filter.test(strategy)) {
            ret.add(rpc.getPath());
        }
    }
    return ret;
}
Also used : RpcRoutingStrategy(org.opendaylight.controller.md.sal.dom.broker.spi.rpc.RpcRoutingStrategy) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) ArrayList(java.util.ArrayList) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule)

Example 4 with RpcDefinition

use of org.opendaylight.yangtools.yang.model.api.RpcDefinition in project controller by opendaylight.

the class DOMRpcRoutingTable method createRpcEntry.

private static AbstractDOMRpcRoutingTableEntry createRpcEntry(final SchemaContext context, final SchemaPath key, final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> implementations) {
    final RpcDefinition rpcDef = findRpcDefinition(context, key);
    if (rpcDef == null) {
        return new UnknownDOMRpcRoutingTableEntry(key, implementations);
    }
    final RpcRoutingStrategy strategy = RpcRoutingStrategy.from(rpcDef);
    if (strategy.isContextBasedRouted()) {
        return new RoutedDOMRpcRoutingTableEntry(rpcDef, YangInstanceIdentifier.of(strategy.getLeaf()), implementations);
    }
    return new GlobalDOMRpcRoutingTableEntry(rpcDef, implementations);
}
Also used : RpcRoutingStrategy(org.opendaylight.controller.md.sal.dom.broker.spi.rpc.RpcRoutingStrategy) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition)

Example 5 with RpcDefinition

use of org.opendaylight.yangtools.yang.model.api.RpcDefinition in project controller by opendaylight.

the class BindingToNormalizedNodeCodec method getRpcMethodToSchema.

public ImmutableBiMap<Method, RpcDefinition> getRpcMethodToSchema(final Class<? extends RpcService> key) {
    final Module module = getModuleBlocking(key);
    final ImmutableBiMap.Builder<Method, RpcDefinition> ret = ImmutableBiMap.builder();
    try {
        for (final RpcDefinition rpcDef : module.getRpcs()) {
            final Method method = findRpcMethod(key, rpcDef);
            ret.put(method, rpcDef);
        }
    } catch (final NoSuchMethodException e) {
        throw new IllegalStateException("Rpc defined in model does not have representation in generated class.", e);
    }
    return ret.build();
}
Also used : ImmutableBiMap(com.google.common.collect.ImmutableBiMap) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) Method(java.lang.reflect.Method) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module)

Aggregations

RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)7 Module (org.opendaylight.yangtools.yang.model.api.Module)5 QName (org.opendaylight.yangtools.yang.common.QName)3 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)3 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 RpcRoutingStrategy (org.opendaylight.controller.md.sal.dom.broker.spi.rpc.RpcRoutingStrategy)2 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)2 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)2 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)2 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)2 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)2 SchemaNode (org.opendaylight.yangtools.yang.model.api.SchemaNode)2 SchemaPath (org.opendaylight.yangtools.yang.model.api.SchemaPath)2 UnknownSchemaNode (org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode)2 HashSet (java.util.HashSet)1 AttributeIfc (org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc)1 JavaAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute)1 ListAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute)1